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

add spring boot integration #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

rursprung
Copy link
Collaborator

this adds an AutoConfiguration for spring which automatically triggers
the liquibase migration if this library is added to a project which
already has spring boot on the classpath.
the dependency to spring boot is marked as optional, thus it is not
added as a transitive dependency to consumers which do not use spring
boot.

this needs to be added here until a more generic solution exists
directly within spring. see spring-projects/spring-boot#37936 for more
details.

the test coverage for this is a bit small since we currently don't have
access to the instanciated OpenSearchClient and would instead have to
create one on our own just for the test.

in the best case we'd be able to share some code with
spring-data-opensearch-testcontainers (or pull it in as a
dependency) to support @ServiceConnection usage. however, it seems
that this library hasn't yet been published to maven, thus this isn't
possible and copying over all the code might not make that much sense.

for more information see these links:

@rursprung
Copy link
Collaborator Author

@reta: do you know why spring-data-opensearch-testcontainers has not been released?
do you think that it would make sense to use it here once it's released? we have nothing directly to do with spring-data but i think we could profit from the ServiceConnection implementation (maybe that'd need some refactoring on the spring-data-opensearch repo side to make sure that it's disentangled?)

this adds an `AutoConfiguration` for spring which automatically triggers
the liquibase migration if this library is added to a project which
already has spring boot on the classpath.
the dependency to spring boot is marked as optional, thus it is not
added as a transitive dependency to consumers which do not use spring
boot.

this needs to be added here until a more generic solution exists
directly within spring. see spring-projects/spring-boot#37936 for more
details.

the test coverage for this is a bit small since we currently don't have
access to the instanciated `OpenSearchClient` and would instead have to
create one on our own just for the test.

in the best case we'd be able to share some code with
[`spring-data-opensearch-testcontainers`] (or pull it in as a
dependency) to support [`@ServiceConnection`] usage. however, it seems
that this library hasn't yet been published to maven, thus this isn't
possible and copying over all the code might not make that much sense.

for more information see these links:
- [general information on spring auto-configuration](https://docs.spring.io/spring-boot/reference/using/auto-configuration.html)
- [creating your own auto-configuration](https://docs.spring.io/spring-boot/reference/features/developing-auto-configuration.html)

[`spring-data-opensearch-testcontainers`]: https://github.com/opensearch-project/spring-data-opensearch/tree/main/spring-data-opensearch-testcontainers
[`@ServiceConnection`]: https://docs.spring.io/spring-boot/reference/testing/testcontainers.html#testing.testcontainers.service-connections
no need to hand-roll this if there's a built-in alternative.
Copy link

sonarcloud bot commented Nov 22, 2024

<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.16</version>
<groupId>org.springframework.boot</groupId>
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like liquibase does not follow the convention, but it would be great to have spring-boot-liquibase-opensearch-starter / liquibase-opensearch-starter as a separate module

@@ -144,7 +145,7 @@ private void connect() {
try {
sslcontext = SSLContextBuilder
.create()
.loadTrustMaterial(null, (chains, authType) -> true)
.loadTrustMaterial(null, new TrustAllStrategy())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is fine for tests but not production, the `TrustAllStrategy is unsafe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is unrelated to this PR (sorry, i just snuck it in here, but at least as an atomic commit) - this commit doesn't change the behaviour at all, it's just making it more obvious what's happening here. there's #29 to improve this situation (but no clear idea on how to solve it yet).

@AutoConfiguration
@EnableConfigurationProperties(SpringLiquibaseOpenSearchProperties.class)
@ConditionalOnProperty("opensearch.uris")
public class LiquibaseOpenSearchAutoConfiguration {
Copy link
Collaborator

@reta reta Nov 22, 2024

Choose a reason for hiding this comment

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

I think we need to account for OpenSearch related beans (clients, etc) to be present (or not) in the context, I am happy to help you there (if it makes sense)

Copy link
Collaborator Author

@rursprung rursprung Nov 25, 2024

Choose a reason for hiding this comment

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

liquibase-opensearch already pulls in the opensearch client as a dependency, so the beans will always be here; thus i don't think that we need the conditional?
any help is welcome, of course! 👍 the faster we get this working the better for everyone

@reta
Copy link
Collaborator

reta commented Nov 22, 2024

@reta: do you know why spring-data-opensearch-testcontainers has not been released?

@rursprung hm ... it was released https://central.sonatype.com/artifact/org.opensearch.client/spring-data-opensearch-testcontainers, no?

we have nothing directly to do with spring-data but i think we could profit from the ServiceConnection implementation (maybe that'd need some refactoring on the spring-data-opensearch repo side to make sure that it's disentangled?)

I think we could, why not? (if it is helpful, and also it would be test only dependency)

@rursprung
Copy link
Collaborator Author

@rursprung
Copy link
Collaborator Author

as discussed this will most likely move to a dedicated repo, see #86 for further details

@rursprung rursprung linked an issue Nov 29, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add spring (boot) integration
2 participants