-
Notifications
You must be signed in to change notification settings - Fork 335
Replaces CloudSqlAutoConfiguration with CloudSqlEnvironmentPostProcessor #131
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
Conversation
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,\ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
...rc/main/java/com/google/cloud/spring/autoconfigure/sql/CloudSqlEnvironmentPostProcessor.java
Outdated
Show resolved
Hide resolved
...rc/main/java/com/google/cloud/spring/autoconfigure/sql/CloudSqlEnvironmentPostProcessor.java
Show resolved
Hide resolved
return null; | ||
} | ||
|
||
private boolean isOnClasspath(String className) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can getResource()
return null?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
...st/java/com/google/cloud/spring/autoconfigure/sql/CloudSqlEnvironmentPostProcessorTests.java
Show resolved
Hide resolved
There was a problem hiding this 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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
…sor (GoogleCloudPlatform#131) * Sets Postgres default username: `postgres` * Improves tests and documentation for Cloud SQL Fixes: spring-attic/spring-cloud-gcp#272
Fixes: spring-attic/spring-cloud-gcp#272