-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for local OpenSearch in development environment
Added a new development configuration for OpenSearch and adjusted production configuration accordingly. This change allows running the application locally with an instance of OpenSearch, which can be useful for local testing and development. Modifies application, development and production YAMLs.
- Loading branch information
Showing
7 changed files
with
77 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...n/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/OpenSearchLocalConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package no.nav.testnav.apps.oppsummeringsdokumentservice.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.opensearch.client.RestHighLevelClient; | ||
import org.opensearch.data.client.orhlc.AbstractOpenSearchConfiguration; | ||
import org.opensearch.data.client.orhlc.ClientConfiguration; | ||
import org.opensearch.data.client.orhlc.RestClients; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; | ||
|
||
import java.time.Duration; | ||
|
||
@Slf4j | ||
@Configuration | ||
@Profile("dev") | ||
public class OpenSearchLocalConfig extends AbstractOpenSearchConfiguration { | ||
|
||
@Value("${open.search.uri}") | ||
private String uri; | ||
|
||
@Override | ||
@SuppressWarnings("java:S2095") | ||
public RestHighLevelClient opensearchClient() { | ||
|
||
return RestClients.create(ClientConfiguration.builder() | ||
.connectedTo(uri.replace("http://", "")) | ||
.withConnectTimeout(Duration.ofSeconds(10)) | ||
.withSocketTimeout(Duration.ofSeconds(5)) | ||
.build()) | ||
.rest(); | ||
} | ||
} |
37 changes: 22 additions & 15 deletions
37
...c/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/OpensearchConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,39 @@ | ||
package no.nav.testnav.apps.oppsummeringsdokumentservice.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import no.nav.testnav.apps.oppsummeringsdokumentservice.config.credentials.ElasticSearchCredentials; | ||
import org.opensearch.client.RestHighLevelClient; | ||
import org.opensearch.data.client.orhlc.AbstractOpenSearchConfiguration; | ||
import org.opensearch.data.client.orhlc.ClientConfiguration; | ||
import org.opensearch.data.client.orhlc.RestClients; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
import java.time.Duration; | ||
|
||
@Profile("prod") | ||
@Configuration | ||
@RequiredArgsConstructor | ||
public class OpensearchConfig extends AbstractOpenSearchConfiguration { | ||
private final ElasticSearchCredentials elasticSearchCredentials; | ||
|
||
@Value("${open.search.username}") | ||
private String username; | ||
|
||
@Value("${open.search.password}") | ||
private String password; | ||
|
||
@Value("${open.search.uri}") | ||
private String uri; | ||
|
||
@Override | ||
@Bean | ||
@SuppressWarnings("java:S2095") | ||
public RestHighLevelClient opensearchClient() { | ||
ClientConfiguration clientConfiguration = ClientConfiguration.builder() | ||
.connectedTo(elasticSearchCredentials.getEndpoints().replace("https://", "")) | ||
.usingSsl() | ||
.withBasicAuth(elasticSearchCredentials.getUsername(), elasticSearchCredentials.getPassword()) | ||
.withConnectTimeout(Duration.ofSeconds(10)) | ||
.withSocketTimeout(Duration.ofSeconds(5)) | ||
.build(); | ||
|
||
return RestClients.create(clientConfiguration).rest(); | ||
|
||
return RestClients.create(ClientConfiguration.builder() | ||
.connectedTo(uri.replace("https://", "")) | ||
.usingSsl() | ||
.withBasicAuth(username, password) | ||
.withConnectTimeout(Duration.ofSeconds(10)) | ||
.withSocketTimeout(Duration.ofSeconds(5)) | ||
.build()) | ||
.rest(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
apps/oppsummeringsdokument-service/src/main/resources/application-dev.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
open: | ||
search: | ||
uri: http://localhost:9200 |
9 changes: 9 additions & 0 deletions
9
apps/oppsummeringsdokument-service/src/main/resources/application-prod.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
spring: | ||
security: | ||
oauth2: | ||
resourceserver: | ||
tokenx: | ||
issuer-uri: ${TOKEN_X_ISSUER} | ||
jwk-set-uri: ${TOKEN_X_JWKS_URI} | ||
accepted-audience: ${TOKEN_X_CLIENT_ID} |
17 changes: 0 additions & 17 deletions
17
apps/oppsummeringsdokument-service/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters