Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces CloudSqlAutoConfiguration with CloudSqlEnvironmentPostProcessor #131

Merged
merged 8 commits into from
Nov 21, 2020

Conversation

meltsufin
Copy link
Member

org.springframework.cloud.gcp.autoconfigure.firestore.FirestoreRepositoriesAutoConfiguration,\
org.springframework.cloud.gcp.autoconfigure.pubsub.health.PubSubHealthIndicatorAutoConfiguration,\
org.springframework.cloud.gcp.autoconfigure.metrics.GcpStackdriverMetricsAutoConfiguration
com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubEmulatorAutoConfiguration,\
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a big miss in my find/replace script, yet everything seems to work as expected. What does this file do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't miss it. It's actually fine. I just had issues reapplying changes that I initially started on the old repo to here. Look at the overall diff.

@meltsufin meltsufin marked this pull request as ready for review November 19, 2020 20:20
Copy link
Contributor

@elefeint elefeint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of my comments are on code that got moved from one class to another, so not really blocking this specific PR. Still, any cleanup is welcome.

return null;
}

private boolean isOnClasspath(String className) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no Spring utility we can use for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find it. They do exactly the same thing in their @ConditionalOnClass implementation, but it's not reusable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what version you looked at but OnClassCondition uses ClassUtils#isPresent that does what this method does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might've actually seen it somewhere else. ClassUtils#isPresent works, Thanks!


private CloudSqlJdbcInfoProvider buildCloudSqlJdbcInfoProvider(ConfigurableEnvironment environment, DatabaseType databaseType) {
CloudSqlJdbcInfoProvider cloudSqlJdbcInfoProvider = new DefaultCloudSqlJdbcInfoProvider(
getSqlProperty(environment, "database-name", null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be documenting these properties? Or at least enumerating them in some enum or constant set?

Copy link
Member Author

@meltsufin meltsufin Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit (for the enum or constant)?
I believe these props are already documented.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have to answer the question of "did we document everything", it would be easier to look in one spot and not play hide-and-seek with string constants. But it's up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I added them.

String globalCredentialsLocation = environment.getProperty("spring.cloud.gcp.credentials.location", (String) null);
// First tries the SQL configuration credential.
if (sqlCredentialsLocation != null) {
credentialsLocationFile = application.getResourceLoader().getResource(sqlCredentialsLocation).getFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can getResource() return null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc says it's never null, but getFile() can throw an IOException which I guess is what we want anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Resource#exists or Resource#isFile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're fine with IOException here.

* Improve tests and documentation
Copy link
Contributor

@snicoll snicoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping @meltsufin, this looks much better. I've adde a few comments.


private boolean isOnClasspath(String className) {
try {
ClassUtils.forName(className, null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use ClassUtils#isPresent rather.

String globalCredentialsLocation = environment.getProperty("spring.cloud.gcp.credentials.location", (String) null);
// First tries the SQL configuration credential.
if (sqlCredentialsLocation != null) {
credentialsLocationFile = application.getResourceLoader().getResource(sqlCredentialsLocation).getFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Resource#exists or Resource#isFile.

return null;
}

private boolean isOnClasspath(String className) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what version you looked at but OnClassCondition uses ClassUtils#isPresent that does what this method does.

* @author Øystein Urdahl Hardeng
*/
@ConfigurationProperties("spring.cloud.gcp.sql")
public class GcpCloudSqlProperties {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused. If you remove this class, no metadata is going to be generated for those keys anymore. If you hare exclusively using those in the EnvironmentPostProcessor you could keep this object and binds it programmatically using the Binder. If you don't, you need to generate the metadata manually so that those keys are still advertized in the IDE.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about Binder and forgot about the metadata support. I'll look into it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please see if I did it right in the last commit? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up. The use of Binder looks correct to me.

@meltsufin meltsufin merged commit 71d45f7 into master Nov 21, 2020
@meltsufin meltsufin deleted the sql-env branch November 21, 2020 01:14
kateryna216 added a commit to kateryna216/spring-cloud-gcp that referenced this pull request Oct 20, 2022
…sor (GoogleCloudPlatform#131)

* Sets Postgres default username: `postgres`
* Improves tests and documentation for Cloud SQL

Fixes: spring-attic/spring-cloud-gcp#272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataSourceProperties should not be changed by GcpCloudSqlAutoConfiguration
4 participants