diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/IndexerConfigurationProperties.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/IndexerConfigurationProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..a139637e72da789c60d8f50bb4702098a2e2fa29 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/IndexerConfigurationProperties.java @@ -0,0 +1,123 @@ +package org.opengroup.osdu.indexer.config; + +import com.google.common.base.Strings; +import java.util.regex.PatternSyntaxException; +import lombok.Getter; +import lombok.Setter; +import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties +@Getter +@Setter +public class IndexerConfigurationProperties { + + //Search query properties + private Integer queryDefaultLimit = 10; + private Integer queryLimitMaximum = 1000; + private Integer aggregationSize = 1000; + + + private String elasticDatastoreKind; + private String elasticDatastoreId; + + //Default Cache Settings + private Integer schemaCacheExpiration = 60; + private Integer indexCacheExpiration = 60; + private Integer elasticCacheExpiration = 1440; + private Integer cursorCacheExpiration = 60; + + //Kinds Cache expiration 2*24*60 + private Integer kindsCacheExpiration = 2880; + + //Attributes Cache expiration 2*24*60 + private Integer attributesCacheExpiration = 2880; + + private Integer kindsRedisDatabase = 1; + private Integer cronIndexCleanupThresholdDays = 3; + private Integer cronEmptyIndexCleanupThresholdDays = 7; + + private String deploymentEnvironment = DeploymentEnvironment.CLOUD.name(); + private String environment; + private String indexerHost; + private String searchHost; + private String storageQueryRecordForConversionHost; + private String storageQueryRecordHost; + private Integer storageRecordsBatchSize; + private String storageSchemaHost; + private String entitlementsHost; + private String entitlementTargetAudience; + private String indexerQueueHost; + private String redisSearchHost; + private String redisSearchPort; + private String elasticHost; + private String elasticClusterName; + private String keyRing; + private String kmsKey; + private String cronIndexCleanupPattern; + private String cronIndexCleanupTenants; + private String smartSearchCcsDisabled; + + private String gaeService; + private String gaeVersion; + private String googleCloudProject; + private String googleCloudProjectRegion; + private String googleAudiences; + + public DeploymentEnvironment getDeploymentEnvironment(){ + return DeploymentEnvironment.valueOf(deploymentEnvironment); + } + + public String getDeploymentLocation() { + return googleCloudProjectRegion; + } + + public String getDeployedServiceId() { + return gaeService; + } + + public String getDeployedVersionId() { + return gaeVersion; + } + + + public boolean isLocalEnvironment() { + return "local".equalsIgnoreCase(environment); + } + + public boolean isPreP4d() { + return isLocalEnvironment() || "evd".equalsIgnoreCase(environment) || "evt".equalsIgnoreCase(environment); + } + + public boolean isPreDemo() { + return isPreP4d() || "p4d".equalsIgnoreCase(environment); + } + + public String[] getIndexCleanupPattern() { + if (!Strings.isNullOrEmpty(cronIndexCleanupPattern)) { + try { + return cronIndexCleanupPattern.split(","); + } catch (PatternSyntaxException var2) { + } + } + + return new String[0]; + } + + public String[] getIndexCleanupTenants() { + if (!Strings.isNullOrEmpty(cronIndexCleanupTenants)) { + try { + return cronIndexCleanupTenants.split(","); + } catch (PatternSyntaxException var2) { + } + } + + return new String[0]; + } + + public final Boolean isSmartSearchCcsDisabled() { + return Boolean.TRUE.toString().equalsIgnoreCase(smartSearchCcsDisabled); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/CronServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/CronServiceImpl.java index 03deefe99b233578e60634789ba4258444a6c17c..b6a61d47c0f41ec13cc9cbf3635a859d49baf4bb 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/CronServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/CronServiceImpl.java @@ -23,6 +23,7 @@ import org.opengroup.osdu.core.common.model.search.IndexInfo; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -44,16 +45,12 @@ public class CronServiceImpl implements CronService{ private IndicesService indicesService; @Inject private JaxRsDpsLog log; - - @Value("${CRON_INDEX_CLEANUP_THRESHOLD_DAYS}") - private String CRON_INDEX_CLEANUP_THRESHOLD_DAYS; - - @Value("${CRON_EMPTY_INDEX_CLEANUP_THRESHOLD_DAYS}") - private String CRON_EMPTY_INDEX_CLEANUP_THRESHOLD_DAYS; + @Inject + private IndexerConfigurationProperties configurationProperties; @Override public boolean cleanupIndices(String indexPattern) throws IOException { - long threshHoldTime = Instant.now().minus(Integer.parseInt(CRON_INDEX_CLEANUP_THRESHOLD_DAYS), ChronoUnit.DAYS).toEpochMilli(); + long threshHoldTime = Instant.now().minus(configurationProperties.getCronIndexCleanupThresholdDays(), ChronoUnit.DAYS).toEpochMilli(); try { try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { @@ -73,7 +70,7 @@ public class CronServiceImpl implements CronService{ @Override public boolean cleanupEmptyStaleIndices() throws IOException { - long threshHoldTime = Instant.now().minus(Integer.parseInt(CRON_EMPTY_INDEX_CLEANUP_THRESHOLD_DAYS), ChronoUnit.DAYS).toEpochMilli(); + long threshHoldTime = Instant.now().minus(configurationProperties.getCronEmptyIndexCleanupThresholdDays(), ChronoUnit.DAYS).toEpochMilli(); try { try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceImpl.java index aff7fa2c76761dc537f165ac14c7399b18cff758..6cefb9bca8b6090d3ff1f807da91050aab6ace3b 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceImpl.java @@ -22,7 +22,7 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository; import org.opengroup.osdu.core.common.provider.interfaces.IElasticCredentialsCache; import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; -import org.springframework.beans.factory.annotation.Value; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.stereotype.Service; import javax.inject.Inject; @@ -38,14 +38,13 @@ public class ElasticSettingServiceImpl implements IElasticSettingService { private IElasticCredentialsCache elasticCredentialCache; @Inject private JaxRsDpsLog log; - - @Value("${GAE_SERVICE}") - public String GAE_SERVICE; + @Inject + private IndexerConfigurationProperties configurationProperties; @Override public ClusterSettings getElasticClusterInformation() { - String cacheKey = String.format("%s-%s", GAE_SERVICE, tenantInfo.getName()); + String cacheKey = String.format("%s-%s", configurationProperties.getGaeService(), tenantInfo.getName()); ClusterSettings clusterInfo = (ClusterSettings) this.elasticCredentialCache.get(cacheKey); if (clusterInfo != null) { return clusterInfo; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java index 8882bd76e5f560f708c0b01b0caa69cbe39b192a..332fcb49608ec808673924efa3add582396223b6 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java @@ -46,15 +46,16 @@ import org.opengroup.osdu.core.common.search.Preconditions; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.indexer.Records; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.springframework.stereotype.Service; import javax.inject.Inject; -import static org.opengroup.osdu.core.common.search.Config.isPreDemo; - @Service public class IndexerMappingServiceImpl extends MappingServiceImpl implements IndexerMappingService { + @Inject + private IndexerConfigurationProperties configurationProperties; @Inject private JaxRsDpsLog log; @Inject @@ -126,7 +127,7 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements Ind if (schema.getDataSchema() != null) { for (Map.Entry<String, String> entry : schema.getDataSchema().entrySet()) { // Apply de_indexer_analyzer and de_search_analyzer to TEXT field - if (isPreDemo() && ElasticType.TEXT.getValue().equalsIgnoreCase(entry.getValue())) { + if (configurationProperties.isPreDemo() && ElasticType.TEXT.getValue().equalsIgnoreCase(entry.getValue())) { log.info(String.format("indexing %s with custom analyzer", entry.getKey())); dataMapping.put(entry.getKey(), Records.Analyzer.builder().type(entry.getValue()).analyzer(DEAnalyzerType.INDEXER_ANALYZER.getValue()).search_analyzer(DEAnalyzerType.SEARCH_ANALYZER.getValue()).build()); } else { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ReindexServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ReindexServiceImpl.java index ac471b3946609ec01facd3d23b926140a15a2e4e..013fcb6928d9f3a7a8d8ea27123b31bdd93d3832 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ReindexServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ReindexServiceImpl.java @@ -23,7 +23,7 @@ import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.search.Config; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.opengroup.osdu.core.common.model.indexer.RecordInfo; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; @@ -39,6 +39,8 @@ import java.util.stream.Collectors; @Component public class ReindexServiceImpl implements ReindexService { + @Inject + private IndexerConfigurationProperties configurationProperties; @Inject private StorageService storageService; @Inject @@ -81,7 +83,7 @@ public class ReindexServiceImpl implements ReindexService { // don't call reindex-worker endpoint if it's the last batch // previous storage query result size will be less then requested (limit param) - if (!Strings.isNullOrEmpty(recordQueryResponse.getCursor()) && recordQueryResponse.getResults().size() == Config.getStorageRecordsBatchSize()) { + if (!Strings.isNullOrEmpty(recordQueryResponse.getCursor()) && recordQueryResponse.getResults().size() == configurationProperties.getStorageRecordsBatchSize()) { String newPayLoad = gson.toJson(RecordReindexRequest.builder().cursor(recordQueryResponse.getCursor()).kind(recordReindexRequest.getKind()).build()); this.indexerQueueTaskBuilder.createReIndexTask(newPayLoad, initialDelayMillis, headers); return newPayLoad; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java index 9b287fd5952dc47ff6ea19317a653d50359225dc..3a9b59cea966ecd5ee5444920f4143bbed7d85b8 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java @@ -21,7 +21,6 @@ import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import org.opengroup.osdu.core.common.http.FetchServiceHttpRequest; -import lombok.extern.java.Log; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.HttpResponse; @@ -34,7 +33,7 @@ import org.opengroup.osdu.core.common.http.IUrlFetchService; import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.common.search.Config; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -67,18 +66,8 @@ public class StorageServiceImpl implements StorageService { private IRequestInfo requestInfo; @Inject private JaxRsDpsLog jaxRsDpsLog; - - @Value("${STORAGE_SCHEMA_HOST}") - private String STORAGE_SCHEMA_HOST; - - @Value("${STORAGE_QUERY_RECORD_HOST}") - private String STORAGE_QUERY_RECORD_HOST; - - @Value("${STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST}") - private String STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST; - - @Value("${STORAGE_RECORDS_BATCH_SIZE}") - private String STORAGE_RECORDS_BATCH_SIZE; + @Inject + private IndexerConfigurationProperties configurationProperties; @Override public Records getStorageRecords(List<String> ids) throws AppException, URISyntaxException { @@ -87,7 +76,7 @@ public class StorageServiceImpl implements StorageService { List<ConversionStatus> conversionStatuses = new ArrayList<>(); List<String> missingRetryRecordIds = new ArrayList<>(); - List<List<String>> batch = Lists.partition(ids, Integer.parseInt(STORAGE_RECORDS_BATCH_SIZE)); + List<List<String>> batch = Lists.partition(ids, configurationProperties.getStorageRecordsBatchSize()); for (List<String> recordsBatch : batch) { Records storageOut = this.getRecords(recordsBatch); valid.addAll(storageOut.getRecords()); @@ -108,7 +97,7 @@ public class StorageServiceImpl implements StorageService { FetchServiceHttpRequest request = FetchServiceHttpRequest .builder() .httpMethod(HttpMethods.POST) - .url(STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST) + .url(configurationProperties.getStorageQueryRecordForConversionHost()) .headers(headers) .body(body).build(); HttpResponse response = this.urlFetchService.sendRequest(request); @@ -191,7 +180,7 @@ public class StorageServiceImpl implements StorageService { public RecordQueryResponse getRecordsByKind(RecordReindexRequest reindexRequest) throws URISyntaxException { Map<String, String> queryParams = new HashMap<>(); queryParams.put(RecordMetaAttribute.KIND.getValue(), reindexRequest.getKind()); - queryParams.put("limit", STORAGE_RECORDS_BATCH_SIZE); + queryParams.put("limit", configurationProperties.getStorageRecordsBatchSize().toString()); if (!Strings.isNullOrEmpty(reindexRequest.getCursor())) { queryParams.put("cursor", reindexRequest.getCursor()); } @@ -202,7 +191,7 @@ public class StorageServiceImpl implements StorageService { FetchServiceHttpRequest request = FetchServiceHttpRequest.builder() .httpMethod(HttpMethods.GET) .headers(this.requestInfo.getHeadersMap()) - .url(STORAGE_QUERY_RECORD_HOST) + .url(configurationProperties.getStorageQueryRecordHost()) .queryParams(queryParams) .build(); @@ -212,7 +201,7 @@ public class StorageServiceImpl implements StorageService { @Override public String getStorageSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { - String url = String.format("%s/%s", STORAGE_SCHEMA_HOST, URLEncoder.encode(kind, StandardCharsets.UTF_8.toString())); + String url = String.format("%s/%s", configurationProperties.getStorageSchemaHost(), URLEncoder.encode(kind, StandardCharsets.UTF_8.toString())); FetchServiceHttpRequest request = FetchServiceHttpRequest.builder() .httpMethod(HttpMethods.GET) .headers(this.requestInfo.getHeadersMap()) diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/IndexerQueueTaskBuilder.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/IndexerQueueTaskBuilder.java index 845ec58d784c740017eaf6dfe68468ee00b284e9..6d0cf380a8065c749fe2a7bba6e8fc63ed8a7794 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/IndexerQueueTaskBuilder.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/IndexerQueueTaskBuilder.java @@ -23,6 +23,7 @@ import org.opengroup.osdu.core.common.model.search.CloudTaskRequest; import org.opengroup.osdu.core.common.model.http.HttpResponse; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.http.IUrlFetchService; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -43,9 +44,8 @@ import static org.opengroup.osdu.core.common.Constants.WORKER_RELATIVE_URL; private IUrlFetchService urlFetchService; @Inject private JaxRsDpsLog jaxRsDpsLog; - - @Value("${INDEXER_QUEUE_HOST}") - private String INDEXER_QUEUE_HOST; + @Inject + private IndexerConfigurationProperties configurationProperties; public void createWorkerTask(String payload, DpsHeaders headers) { createTask(WORKER_RELATIVE_URL, payload, 0l, headers); @@ -72,7 +72,7 @@ import static org.opengroup.osdu.core.common.Constants.WORKER_RELATIVE_URL; FetchServiceHttpRequest request = FetchServiceHttpRequest.builder() .httpMethod(HttpMethods.POST) - .url(INDEXER_QUEUE_HOST) + .url(configurationProperties.getIndexerQueueHost()) .body(new Gson().toJson(cloudTaskRequest)) .headers(headers) .build(); diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/CleanupIndiciesApiTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/CleanupIndiciesApiTest.java index 6a9f2ead5cf965f9e05f0e1d1782d97843ff7deb..e9e08994d97426370881c042f0665a569e7f91c1 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/CleanupIndiciesApiTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/CleanupIndiciesApiTest.java @@ -13,7 +13,6 @@ import org.opengroup.osdu.core.common.http.HeadersUtil; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; -import org.opengroup.osdu.core.common.search.Config; import org.opengroup.osdu.indexer.service.IndexerService; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -22,7 +21,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @RunWith(PowerMockRunner.class) -@PrepareForTest({HeadersUtil.class, IndexerQueueTaskBuilder.class, DpsHeaders.class, Config.class}) +@PrepareForTest({HeadersUtil.class, IndexerQueueTaskBuilder.class, DpsHeaders.class}) public class CleanupIndiciesApiTest { private final String messageValid = "{\"data\":\"[{\\\"id\\\":\\\"opendes:welldb:wellbore-d9033ae1-fb15-496c-9ba0-880fd1d2b2cf\\\",\\\"kind\\\":\\\"tenant1:welldb:wellbore:1.0.0\\\",\\\"op\\\":\\\"purge_schema\\\"}]\",\"attributes\":{\"account-id\":\"opendes\",\"correlation-id\":\"b5a281bd-f59d-4db2-9939-b2d85036fc7e\"},\"messageId\":\"75328163778221\",\"publishTime\":\"2018-05-08T21:48:56.131Z\"}"; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/RecordIndexerApiTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/RecordIndexerApiTest.java index 72fc5f925d859745ba37be0768bff2f43abeda01..1a3752139d2bbf9d642f85dbeb9f0f636aa8ba8a 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/RecordIndexerApiTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/RecordIndexerApiTest.java @@ -24,7 +24,6 @@ import org.mockito.Mock; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.search.Config; import org.opengroup.osdu.indexer.service.IndexerService; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; @@ -35,13 +34,10 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; import static org.mockito.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) -@PrepareForTest({HeadersUtil.class, IndexerQueueTaskBuilder.class, DpsHeaders.class, Config.class}) +@PrepareForTest({HeadersUtil.class, IndexerQueueTaskBuilder.class, DpsHeaders.class}) public class RecordIndexerApiTest { private final String messageValid = "{\"data\":\"[{\\\"id\\\":\\\"opendes:welldb:wellbore-d9033ae1-fb15-496c-9ba0-880fd1d2b2cf\\\",\\\"kind\\\":\\\"tenant1:welldb:wellbore:1.0.0\\\",\\\"op\\\":\\\"create\\\"}]\",\"attributes\":{\"account-id\":\"opendes\",\"correlation-id\":\"b5a281bd-f59d-4db2-9939-b2d85036fc7e\"},\"messageId\":\"75328163778221\",\"publishTime\":\"2018-05-08T21:48:56.131Z\"}"; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/ElasticClientHandlerTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/ElasticClientHandlerTest.java index dc7d6db42dded11847ccc7dce7b8dc3030161e70..e5782165553a1efd1a5a39a3ffa6891696371993 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/ElasticClientHandlerTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/ElasticClientHandlerTest.java @@ -26,10 +26,10 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.search.Config; import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; import org.opengroup.osdu.core.common.model.search.ClusterSettings; import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -39,9 +39,11 @@ import static org.mockito.MockitoAnnotations.initMocks; @Ignore @RunWith(SpringRunner.class) -@PrepareForTest({Config.class, RestClientBuilder.class, RestClient.class, RestHighLevelClient.class}) +@PrepareForTest({RestClientBuilder.class, RestClient.class, RestHighLevelClient.class}) public class ElasticClientHandlerTest { + @Mock + private IndexerConfigurationProperties configurationProperties; @Mock private IElasticSettingService elasticSettingService; @@ -60,14 +62,13 @@ public class ElasticClientHandlerTest { public void setup() { initMocks(this); -// mockStatic(Config.class); // mockStatic(RestClient.class); } @Test public void createRestClient_when_deployment_env_is_saas() { ClusterSettings clusterSettings = new ClusterSettings("H", 1, "U:P"); - when(Config.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); + when(configurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); when(elasticSettingService.getElasticClusterInformation()).thenReturn(clusterSettings); when(RestClient.builder(new HttpHost("H", 1, "https"))).thenReturn(builder); when(builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000).setSocketTimeout(60000))).thenReturn(builder); @@ -81,7 +82,7 @@ public class ElasticClientHandlerTest { @Test(expected = AppException.class) public void failed_createRestClientForSaaS_when_restclient_is_null() { ClusterSettings clusterSettings = new ClusterSettings("H", 1, "U:P"); - when(Config.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); + when(configurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); when(elasticSettingService.getElasticClusterInformation()).thenReturn(clusterSettings); when(RestClient.builder(new HttpHost("H", 1, "https"))).thenReturn(builder); when(builder.build()).thenReturn(null); @@ -91,7 +92,7 @@ public class ElasticClientHandlerTest { @Test(expected = AppException.class) public void failed_createRestClientForSaaS_when_getcluster_info_throws_exception() { - when(Config.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); + when(configurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); when(elasticSettingService.getElasticClusterInformation()).thenThrow(new AppException(1, "", "")); when(RestClient.builder(new HttpHost("H", 1, "https"))).thenReturn(builder); diff --git a/pom.xml b/pom.xml index c666a18e9ee25733866cbef13487413c3e6763f5..0bf363b5630407611fdd47070d23aa7fcde57d83 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ <java.version>1.8</java.version> <springfox-version>2.7.0</springfox-version> <spring-cloud.version>Greenwich.SR2</spring-cloud.version> - <os-core-common.version>0.3.6</os-core-common.version> + <os-core-common.version>0.3.19</os-core-common.version> <snakeyaml.version>1.26</snakeyaml.version> <hibernate-validator.version>6.1.5.Final</hibernate-validator.version> <jackson.version>2.11.2</jackson.version> diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/CronServiceImplTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/CronServiceImplTest.java index 67598b8831391746e4ca3951267c4b58180dad5a..2ec6cfdf20306468e69d78d70450c9def671bfe2 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/CronServiceImplTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/CronServiceImplTest.java @@ -24,11 +24,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.service.CronServiceImpl; import org.opengroup.osdu.core.common.model.search.IndexInfo; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.core.common.search.IndicesService; -import org.opengroup.osdu.core.common.search.Config; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -39,7 +39,6 @@ import java.time.temporal.ChronoUnit; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.powermock.api.mockito.PowerMockito.mockStatic; @Ignore @@ -47,6 +46,9 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic; @PrepareForTest({RestHighLevelClient.class}) public class CronServiceImplTest { + @Mock + private IndexerConfigurationProperties configurationProperties; + @Mock private RestHighLevelClient restHighLevelClient; @Mock @@ -65,12 +67,11 @@ public class CronServiceImplTest { @Before public void setup() { - mockStatic(Config.class); when(this.requestInfo.getHeaders()).thenReturn(dpsHeaders); - when(Config.getIndexCleanupThresholdDays()).thenReturn(3); - when(Config.getEmptyIndexCleanupThresholdDays()).thenReturn(7); + when(configurationProperties.getCronIndexCleanupThresholdDays()).thenReturn(3); + when(configurationProperties.getCronEmptyIndexCleanupThresholdDays()).thenReturn(7); } @Test diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/ReindexServiceTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/ReindexServiceTest.java index 5120f069f072945e85a569cb3d5b49a74251fab8..5165084ac11832bc7b60e3faa6fffb8f8b54fa9a 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/ReindexServiceTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/ReindexServiceTest.java @@ -27,12 +27,11 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.search.Config; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.service.ReindexServiceImpl; import org.opengroup.osdu.indexer.service.StorageService; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; -import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; import org.springframework.test.context.junit4.SpringRunner; @@ -47,7 +46,6 @@ import static org.powermock.api.mockito.PowerMockito.when; @Ignore @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({Config.class}) public class ReindexServiceTest { private final String cursor = "100"; @@ -57,6 +55,9 @@ public class ReindexServiceTest { @Mock private StorageService storageService; + @Mock + private IndexerConfigurationProperties configurationProperties; + @Mock private Map<String, String> httpHeaders; @Mock @@ -124,8 +125,7 @@ public class ReindexServiceTest { results.add("test1"); recordQueryResponse.setResults(results); - mockStatic(Config.class); - when(Config.getStorageRecordsBatchSize()).thenReturn(1); + when(configurationProperties.getStorageRecordsBatchSize()).thenReturn(1); when(storageService.getRecordsByKind(ArgumentMatchers.any())).thenReturn(recordQueryResponse); diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/AttributesCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/AttributesCache.java index b5789ec76026b8f7dc16737fe7cb3ae50301477d..889e4476794ea42013afbb1a0ecb49e09e5f0371 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/AttributesCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/AttributesCache.java @@ -14,8 +14,11 @@ package org.opengroup.osdu.indexer.cache; +import javax.inject.Inject; import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; import org.opengroup.osdu.core.common.provider.interfaces.IAttributesCache; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.Set; @@ -25,12 +28,10 @@ public class AttributesCache implements IAttributesCache<String,Set>, AutoClosea private RedisCache<String, Set> cache; - public AttributesCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, - @Value("${REDIS_SEARCH_PORT}") final String REDIS_SEARCH_PORT, - @Value("${INDEX_CACHE_EXPIRATION}") final String INDEX_CACHE_EXPIRATION) { - - cache = new RedisCache(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), - Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60, String.class, Boolean.class); + @Inject + public AttributesCache(final IndexerConfigurationProperties properties) { + cache = new RedisCache(properties.getRedisSearchHost(), Integer.parseInt(properties.getRedisSearchPort()), + properties.getElasticCacheExpiration() * 60, String.class, Boolean.class); } @Override diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/DatastoreCredentialCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/DatastoreCredentialCache.java index 1ec502fe6aa4ab1f2267e429eab0b3c066f8e3f4..0084dcb2c5e729066923b880108071e527e41b1d 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/DatastoreCredentialCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/DatastoreCredentialCache.java @@ -16,14 +16,16 @@ package org.opengroup.osdu.indexer.cache; import com.google.auth.oauth2.AccessToken; import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class DatastoreCredentialCache extends RedisCache<String, AccessToken> { - // Datastore credentials are only valid for 1hr, release the key 2 minutes before the expiration - public DatastoreCredentialCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, @Value("${REDIS_SEARCH_PORT}") final String REDIS_SEARCH_PORT) { - super(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), 58 * 60, String.class, AccessToken.class); + @Autowired + public DatastoreCredentialCache(final IndexerConfigurationProperties configurationProperties) { + super(configurationProperties.getRedisSearchHost(), Integer.parseInt(configurationProperties.getRedisSearchPort()), 58 * 60, String.class, AccessToken.class); } } \ No newline at end of file diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/ElasticCredentialsCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/ElasticCredentialsCache.java index 045b555c438d48bb44a700cda72c4f43df6332e0..8a5e763e783d01b0c4696d9ebc77a51e50ba3c7f 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/ElasticCredentialsCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/ElasticCredentialsCache.java @@ -1,8 +1,10 @@ package org.opengroup.osdu.indexer.cache; +import javax.inject.Inject; import org.opengroup.osdu.core.common.cache.RedisCache; import org.opengroup.osdu.core.common.model.search.ClusterSettings; import org.opengroup.osdu.core.common.provider.interfaces.IElasticCredentialsCache; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -11,11 +13,10 @@ public class ElasticCredentialsCache implements IElasticCredentialsCache<String, private RedisCache<String, ClusterSettings> cache; - public ElasticCredentialsCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, - @Value("${REDIS_SEARCH_PORT}") final String REDIS_SEARCH_PORT, - @Value("${ELASTIC_CACHE_EXPIRATION}") final String ELASTIC_CACHE_EXPIRATION) { - cache = new RedisCache<>(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), - Integer.parseInt(ELASTIC_CACHE_EXPIRATION) * 60, String.class, ClusterSettings.class); + @Inject + public ElasticCredentialsCache(final IndexerConfigurationProperties properties) { + cache = new RedisCache<>(properties.getRedisSearchHost(), Integer.parseInt(properties.getRedisSearchPort()), + properties.getElasticCacheExpiration() * 60, String.class, ClusterSettings.class); } @Override diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/IndexCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/IndexCache.java index c923ecc42ffcb1ea34d9fd0b06fe835b5e478168..2e8ead781a1f5e0b9b303ee411b953057696dbe2 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/IndexCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/IndexCache.java @@ -1,7 +1,10 @@ package org.opengroup.osdu.indexer.cache; +import javax.inject.Inject; import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -9,11 +12,10 @@ import org.springframework.stereotype.Component; public class IndexCache implements IIndexCache<String, Boolean>, AutoCloseable { private RedisCache<String, Boolean> cache; - public IndexCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, - @Value("${REDIS_SEARCH_PORT}") final String REDIS_SEARCH_PORT, - @Value("${INDEX_CACHE_EXPIRATION}") final String INDEX_CACHE_EXPIRATION) { - cache = new RedisCache<>(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), - Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60, String.class, Boolean.class); + @Inject + public IndexCache(final IndexerConfigurationProperties properties) { + cache = new RedisCache<>(properties.getRedisSearchHost(), Integer.parseInt(properties.getRedisSearchPort()), + properties.getElasticCacheExpiration() * 60, String.class, Boolean.class); } @Override diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/JwtCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/JwtCache.java index 3ae398125b9e5ffbbc859fdc319fbfa4faa0abed..a44747cd6426255bd90d3085e95b04c182b84186 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/JwtCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/JwtCache.java @@ -1,8 +1,10 @@ package org.opengroup.osdu.indexer.cache; +import javax.inject.Inject; import org.opengroup.osdu.core.common.cache.RedisCache; import org.opengroup.osdu.core.common.model.search.IdToken; import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -10,11 +12,12 @@ import org.springframework.stereotype.Component; public class JwtCache implements IJwtCache<String, IdToken>, AutoCloseable { RedisCache<String, IdToken> cache; + // google service account id_token can be requested only for 1 hr private final static int EXPIRED_AFTER = 59; - - public JwtCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, @Value("${REDIS_SEARCH_PORT}") final String REDIS_SEARCH_PORT) { - cache = new RedisCache<>(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), + @Inject + public JwtCache(final IndexerConfigurationProperties properties) { + cache = new RedisCache<>(properties.getRedisSearchHost(), Integer.parseInt(properties.getRedisSearchPort()), EXPIRED_AFTER * 60, String.class, IdToken.class); } diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/KindsCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/KindsCache.java index 68eb86f4afe07f05d478e43ad6cc78abb8386eba..92481f2418fd238c7c051d5c39a6d0b8becd50c0 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/KindsCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/KindsCache.java @@ -1,7 +1,9 @@ package org.opengroup.osdu.indexer.cache; +import javax.inject.Inject; import org.opengroup.osdu.core.common.cache.RedisCache; import org.opengroup.osdu.core.common.provider.interfaces.IKindsCache; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -11,13 +13,11 @@ import java.util.Set; public class KindsCache implements IKindsCache<String, Set>, AutoCloseable { private RedisCache<String, Set> cache; - public KindsCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, - @Value("${REDIS_SEARCH_PORT}") final String REDIS_SEARCH_PORT, - @Value("${KINDS_CACHE_EXPIRATION}") final String KINDS_CACHE_EXPIRATION, - @Value("${KINDS_REDIS_DATABASE}") final String KINDS_REDIS_DATABASE) { - cache = new RedisCache<>(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), - Integer.parseInt(KINDS_CACHE_EXPIRATION) * 60, - Integer.parseInt(KINDS_REDIS_DATABASE), String.class, Set.class); + @Inject + public KindsCache(final IndexerConfigurationProperties properties) { + cache = new RedisCache<>(properties.getRedisSearchHost(), Integer.parseInt(properties.getRedisSearchPort()), + properties.getKindsCacheExpiration() * 60, + properties.getKindsRedisDatabase(), String.class, Set.class); } @Override diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/SchemaCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/SchemaCache.java index ef7ba72ab5cdcf0ead81c0d66bf1b5d39fcdad7f..04f69cded8bea50fe3486349182a4d3e80a8bd01 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/SchemaCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/SchemaCache.java @@ -1,6 +1,9 @@ package org.opengroup.osdu.indexer.cache; +import javax.inject.Inject; import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -9,11 +12,10 @@ import org.springframework.stereotype.Component; public class SchemaCache implements ISchemaCache<String, String>, AutoCloseable { private RedisCache<String, String> cache; - public SchemaCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, - @Value("${REDIS_SEARCH_PORT}") final String REDIS_SEARCH_PORT, - @Value("${SCHEMA_CACHE_EXPIRATION}") final String SCHEMA_CACHE_EXPIRATION) { - cache = new RedisCache<>(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), - Integer.parseInt(SCHEMA_CACHE_EXPIRATION) * 60, String.class, String.class); + @Inject + public SchemaCache(final IndexerConfigurationProperties properties) { + cache = new RedisCache<>(properties.getRedisSearchHost(), Integer.parseInt(properties.getRedisSearchPort()), + properties.getElasticCacheExpiration() * 60, String.class, String.class); } @Override diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/EntitlementsClientFactory.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/EntitlementsClientFactory.java index 6630705facc5810952f23f2e29eca5eb3c6acfb0..debcc593970c05f7d4b7291de7519e99c7155890 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/EntitlementsClientFactory.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/EntitlementsClientFactory.java @@ -17,6 +17,8 @@ package org.opengroup.osdu.indexer.di; import org.opengroup.osdu.core.common.entitlements.EntitlementsAPIConfig; import org.opengroup.osdu.core.common.entitlements.EntitlementsFactory; import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; +import org.opengroup.osdu.core.common.http.json.HttpResponseBodyMapper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.context.annotation.Lazy; @@ -34,6 +36,9 @@ public class EntitlementsClientFactory extends AbstractFactoryBean<IEntitlements @Value("${AUTHORIZE_API_KEY:}") private String AUTHORIZE_API_KEY; + @Autowired + private HttpResponseBodyMapper mapper; + @Override protected IEntitlementsFactory createInstance() throws Exception { @@ -41,7 +46,8 @@ public class EntitlementsClientFactory extends AbstractFactoryBean<IEntitlements .builder() .rootUrl(AUTHORIZE_API) .apiKey(AUTHORIZE_API_KEY) - .build()); + .build(), + mapper); } @Override diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/middleware/IndexFilter.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/middleware/IndexFilter.java index 1eeb928ff5e8888a0053df66a2e451e7880fabad..5bdf78f04d24485d4678cb3cb227b42df62dfe62 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/middleware/IndexFilter.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/middleware/IndexFilter.java @@ -8,6 +8,7 @@ import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.http.ResponseHeaders; import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Component; @@ -31,8 +32,8 @@ public class IndexFilter implements Filter { @Inject private IRequestInfo requestInfo; - @Value("${DEPLOYMENT_ENVIRONMENT}") - private String DEPLOYMENT_ENVIRONMENT; + @Inject + private IndexerConfigurationProperties properties; private FilterConfig filterConfig; @@ -51,7 +52,7 @@ public class IndexFilter implements Filter { String uri = httpRequest.getRequestURI().toLowerCase(); if (httpRequest.getMethod().equalsIgnoreCase(HttpMethod.POST.name()) && uri.contains(PATH_TASK_HANDLERS)) { - if (DeploymentEnvironment.valueOf(DEPLOYMENT_ENVIRONMENT) != DeploymentEnvironment.LOCAL) { + if (properties.getDeploymentEnvironment() != DeploymentEnvironment.LOCAL) { checkWorkerApiAccess(requestInfo); } } diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/ElasticRepositoryDatastore.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/ElasticRepositoryDatastore.java index 3562fff40e6499e282e758bfb976d1f0c424bc4b..0c70475ae974c1fc47f52b926519b4a124ef20dd 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/ElasticRepositoryDatastore.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/ElasticRepositoryDatastore.java @@ -27,6 +27,7 @@ import org.opengroup.osdu.core.common.provider.interfaces.IKmsClient; import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository; import org.opengroup.osdu.core.common.search.Preconditions; import org.opengroup.osdu.core.gcp.multitenancy.DatastoreFactory; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.inject.Inject; @@ -44,17 +45,15 @@ public class ElasticRepositoryDatastore implements IElasticRepository { @Inject private DatastoreFactory datastoreFactory; - @Value("${ELASTIC_DATASTORE_KIND}") - private String ELASTIC_DATASTORE_KIND; + @Inject + private IndexerConfigurationProperties properties; - @Value("${ELASTIC_DATASTORE_ID}") - private String ELASTIC_DATASTORE_ID; @Override public ClusterSettings getElasticClusterSettings(TenantInfo tenantInfo) { Datastore googleDatastore = this.datastoreFactory.getDatastore(tenantInfo); - Key key = googleDatastore.newKeyFactory().setKind(ELASTIC_DATASTORE_KIND).newKey(ELASTIC_DATASTORE_ID); + Key key = googleDatastore.newKeyFactory().setKind(properties.getElasticDatastoreKind()).newKey(properties.getElasticDatastoreId()); Entity datastoreEntity = googleDatastore.get(key); if (datastoreEntity == null) { diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/publish/PublisherImpl.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/publish/PublisherImpl.java index cc7dcaabfc2d49cba5e57991854ca2b091ae787a..32d2dd6fc394eca3a11a95339cc9eca5599ddb2e 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/publish/PublisherImpl.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/publish/PublisherImpl.java @@ -33,6 +33,7 @@ import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.indexer.JobStatus; import org.opengroup.osdu.core.common.model.indexer.RecordStatus; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; import org.opengroup.osdu.core.gcp.PubSub.PubSubExtensions; import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; @@ -64,14 +65,14 @@ public class PublisherImpl implements IPublisher { @Inject private PubSubExtensions pubSubExtensions; - @Value("${DEPLOYMENT_ENVIRONMENT}") - private String DEPLOYMENT_ENVIRONMENT; + @Inject + private IndexerConfigurationProperties properties; @Override public void publishStatusChangedTagsToTopic(DpsHeaders headers, JobStatus indexerBatchStatus) throws Exception { // Don't publish to pubsub when testing locally - if (DeploymentEnvironment.valueOf(DEPLOYMENT_ENVIRONMENT) == DeploymentEnvironment.LOCAL) { + if (properties.getDeploymentEnvironment() == DeploymentEnvironment.LOCAL) { return; } diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/RequestInfoImpl.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/RequestInfoImpl.java index 8ab213d952a647db23ae61ab892fd12fbdb72d25..03fddbbfa7f3df968506a2c609f2818fe4c10130 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/RequestInfoImpl.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/RequestInfoImpl.java @@ -18,6 +18,7 @@ import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.core.gcp.model.CloudTaskHeaders; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -43,8 +44,8 @@ public class RequestInfoImpl implements IRequestInfo { @Inject private TenantInfo tenantInfo; - @Value("${DEPLOYMENT_ENVIRONMENT}") - private String DEPLOYMENT_ENVIRONMENT; + @Inject + private IndexerConfigurationProperties properties; @Value("${indexer.que.service.mail}") private String indexerQueServiceMail; @@ -132,7 +133,7 @@ public class RequestInfoImpl implements IRequestInfo { } public String checkOrGetAuthorizationHeader() { - if (DeploymentEnvironment.valueOf(DEPLOYMENT_ENVIRONMENT) == DeploymentEnvironment.LOCAL) { + if (properties.getDeploymentEnvironment() == DeploymentEnvironment.LOCAL) { String authHeader = this.dpsHeaders.getAuthorization(); if (Strings.isNullOrEmpty(authHeader)) { throw new AppException(HttpStatus.SC_UNAUTHORIZED, "Invalid authorization header", "Authorization token cannot be empty"); diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImpl.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImpl.java index fff6e78d0ec930ca03a4e2d6ec2326f7c84bb5ed..6e946ac37ab029c2d0b8b718776bd28da71ad6b1 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImpl.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImpl.java @@ -46,6 +46,7 @@ import org.opengroup.osdu.core.common.model.search.IdToken; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -75,12 +76,8 @@ public class ServiceAccountJwtGcpClientImpl implements IServiceAccountJwtClient private JaxRsDpsLog log; @Inject private DpsHeaders dpsHeaders; - - @Value("${GOOGLE_AUDIENCES}") - public String GOOGLE_AUDIENCES; - - @Value("${INDEXER_HOST}") - public String INDEXER_HOST; + @Inject + private IndexerConfigurationProperties properties; public String getIdToken(String tenantName) { this.log.info("Tenant name received for auth token is: " + tenantName); @@ -161,7 +158,7 @@ public class ServiceAccountJwtGcpClientImpl implements IServiceAccountJwtClient // Create IAM API object associated with the authenticated transport. this.iam = new Iam.Builder(httpTransport, JSON_FACTORY, credential) - .setApplicationName(INDEXER_HOST) + .setApplicationName(properties.getIndexerHost()) .build(); } @@ -171,7 +168,7 @@ public class ServiceAccountJwtGcpClientImpl implements IServiceAccountJwtClient private Map<String, Object> getJWTCreationPayload(TenantInfo tenantInfo) { Map<String, Object> payload = new HashMap<>(); - String googleAudience = GOOGLE_AUDIENCES; + String googleAudience = properties.getGoogleAudiences(); if (googleAudience.contains(",")) { googleAudience = googleAudience.split(",")[0]; } diff --git a/provider/indexer-gcp/src/main/resources/application-dev.properties b/provider/indexer-gcp/src/main/resources/application-dev.properties index 61da3c7139e0f8e834b2ec5b90173b2c517d075d..7ec1744f095c0ee84ad53abafae545ce7ad7bdfc 100644 --- a/provider/indexer-gcp/src/main/resources/application-dev.properties +++ b/provider/indexer-gcp/src/main/resources/application-dev.properties @@ -1,14 +1,14 @@ -GOOGLE_CLOUD_PROJECT=opendes +google-cloud-project=opendes -INDEXER_HOST=os-indexer-dot-opendes.appspot.com +indexer-host=os-indexer-dot-opendes.appspot.com STORAGE_HOSTNAME=os-storage-dot-opendes.appspot.com -STORAGE_SCHEMA_HOST=https://os-storage-dot-opendes.appspot.com/api/storage/v2/schemas -STORAGE_QUERY_RECORD_HOST=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records -STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records:batch -STORAGE_RECORDS_BATCH_SIZE=20 +storage-schema-host=https://os-storage-dot-opendes.appspot.com/api/storage/v2/schemas +storage-query-record-host=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records +storage-query-record-for-conversion-host=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records:batch +storage-records-batch-size=20 -INDEXER_QUEUE_HOST=https://os-indexer-queue-dot-opendes.appspot.com/_dps/task-handlers/enqueue +indexer-queue-host=https://os-indexer-queue-dot-opendes.appspot.com/_dps/task-handlers/enqueue AUTHORIZE_API=https://entitlements-dot-opendes.appspot.com/entitlements/v1 LEGALTAG_API=https://os-legal-dot-opendes.appspot.com/api/legal/v1 @@ -16,6 +16,6 @@ CRS_API=https://crs-converter-gae-dot-opendes.appspot.com/api/crs/v1 ## use below values for gcp: opendes REDIS_GROUP_HOST=10.0.16.28 -REDIS_SEARCH_HOST=10.0.16.20 +redis-search-host=10.0.16.20 -GOOGLE_AUDIENCES=245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com \ No newline at end of file +google-audiences=245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com \ No newline at end of file diff --git a/provider/indexer-gcp/src/main/resources/application-kuber.properties b/provider/indexer-gcp/src/main/resources/application-kuber.properties index bc2a5f9014fa1b406a008e2cc69f161a8e3a9a8b..22d3ba0253112794113a96f90fa094f5468902e1 100644 --- a/provider/indexer-gcp/src/main/resources/application-kuber.properties +++ b/provider/indexer-gcp/src/main/resources/application-kuber.properties @@ -1,14 +1,14 @@ -GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT} +google-cloud-project=${GOOGLE_CLOUD_PROJECT} -INDEXER_HOST=os-indexer-service +indexer-host=os-indexer-service STORAGE_HOSTNAME=os-storage-service -STORAGE_SCHEMA_HOST=http://os-storage-service/api/storage/v2/schemas -STORAGE_QUERY_RECORD_HOST=http://os-storage-service/api/storage/v2/query/records -STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=http://os-storage-service/api/storage/v2/query/records:batch -STORAGE_RECORDS_BATCH_SIZE=20 +storage-schema-host=http://os-storage-service/api/storage/v2/schemas +storage-query-record-host=http://os-storage-service/api/storage/v2/query/records +storage-query-record-for-conversion-host=http://os-storage-service/api/storage/v2/query/records:batch +storage-records-batch-size=20 -INDEXER_QUEUE_HOST=http://os-storage-service/_dps/task-handlers/enqueue +indexer-queue-host=http://os-storage-service/_dps/task-handlers/enqueue AUTHORIZE_API=http://os-entitlement-service/entitlements/v1 LEGALTAG_API=http://os-legal-service/api/legal/v1 @@ -16,9 +16,9 @@ CRS_API=${CRS_API} ## use below values for gcp: opendes REDIS_GROUP_HOST=${REDIS_GROUP_HOST} -REDIS_SEARCH_HOST=${REDIS_SEARCH_HOST} +redis-search-host=${REDIS_SEARCH_HOST} -GOOGLE_AUDIENCES=${GOOGLE_AUDIENCES} +google-audiences=${GOOGLE_AUDIENCES} -DEPLOYMENT_ENVIRONMENT=CLOUD +deployment-environment=cloud disable.appengine.log.factory=true \ No newline at end of file diff --git a/provider/indexer-gcp/src/main/resources/application-local.properties b/provider/indexer-gcp/src/main/resources/application-local.properties new file mode 100644 index 0000000000000000000000000000000000000000..a5511b15c0564250bca41b67c6c39646f9512e79 --- /dev/null +++ b/provider/indexer-gcp/src/main/resources/application-local.properties @@ -0,0 +1,21 @@ +google-cloud-project=osdu + +indexer-host=os-indexer-dot-opendes.appspot.com +STORAGE_HOSTNAME=os-storage-dot-opendes.appspot.com + +storage-schema-host=https://os-storage-dot-opendes.appspot.com/api/storage/v2/schemas +storage-query-record-host=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records +storage-query-record-for-conversion-host=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records:batch +storage-records-batch-size=20 + +indexer-queue-host=https://os-indexer-queue-dot-opendes.appspot.com/_dps/task-handlers/enqueue + +AUTHORIZE_API=https://entitlements-dot-opendes.appspot.com/entitlements/v1 +LEGALTAG_API=https://os-legal-dot-opendes.appspot.com/api/legal/v1 +CRS_API=https://crs-converter-gae-dot-opendes.appspot.com/api/crs/v1 + +## use below values for gcp: opendes +REDIS_GROUP_HOST=127.0.0.1 +redis-search-host=127.0.0.1 + +google-audiences=245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com diff --git a/provider/indexer-gcp/src/main/resources/application-testing.properties b/provider/indexer-gcp/src/main/resources/application-testing.properties index fb0c9e2d6ce29c87dca6f58d1afec0b420c1e663..67941ce47b5fd27c99e487fa59c935d0bcacd827 100644 --- a/provider/indexer-gcp/src/main/resources/application-testing.properties +++ b/provider/indexer-gcp/src/main/resources/application-testing.properties @@ -1,14 +1,14 @@ -GOOGLE_CLOUD_PROJECT=opendes-evt +google-cloud-project=opendes-evt -INDEXER_HOST=os-indexer-dot-opendes-evt.appspot.com +indexer-host=os-indexer-dot-opendes-evt.appspot.com STORAGE_HOSTNAME=os-storage-dot-opendes-evt.appspot.com -STORAGE_SCHEMA_HOST=https://os-storage-dot-opendes-evt.appspot.com/api/storage/v2/schemas -STORAGE_QUERY_RECORD_HOST=https://os-storage-dot-opendes-evt.appspot.com/api/storage/v2/query/records -STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=https://os-storage-dot-opendes-evt.appspot.com/api/storage/v2/query/records:batch -STORAGE_RECORDS_BATCH_SIZE=20 +storage-schema-host=https://os-storage-dot-opendes-evt.appspot.com/api/storage/v2/schemas +storage-query-record-host=https://os-storage-dot-opendes-evt.appspot.com/api/storage/v2/query/records +storage-query-record-for-conversion-host=https://os-storage-dot-opendes-evt.appspot.com/api/storage/v2/query/records:batch +storage-records-batch-size=20 -INDEXER_QUEUE_HOST=https://os-indexer-queue-dot-opendes-evt.appspot.com/_dps/task-handlers/enqueue +indexer-queue-host=https://os-indexer-queue-dot-opendes-evt.appspot.com/_dps/task-handlers/enqueue AUTHORIZE_API=https://entitlements-dot-opendes-evt.appspot.com/entitlements/v1 LEGALTAG_API=https://os-legal-dot-opendes-evt.appspot.com/api/legal/v1 @@ -16,6 +16,6 @@ CRS_API=https://crs-converter-gae-dot-opendes-evt.appspot.com/api/crs/v1 ## use below values for gcp: opendes REDIS_GROUP_HOST=10.253.209.196 -REDIS_SEARCH_HOST=10.118.2.140 +redis-search-host=10.118.2.140 -GOOGLE_AUDIENCES=833591776864-oobhqvmtdg9rpreubjvn44m5f8revglk.apps.googleusercontent.com \ No newline at end of file +google-audiences=833591776864-oobhqvmtdg9rpreubjvn44m5f8revglk.apps.googleusercontent.com \ No newline at end of file diff --git a/provider/indexer-gcp/src/main/resources/application.properties b/provider/indexer-gcp/src/main/resources/application.properties index e4391d77b133e71e5f52b8f39753a746fd85b5d6..06d81a1e4504e68c74c75c5e5c3caefd470b4eab 100644 --- a/provider/indexer-gcp/src/main/resources/application.properties +++ b/provider/indexer-gcp/src/main/resources/application.properties @@ -6,32 +6,37 @@ server.port=8080 JAVA_OPTS=-Xms3072m -Xmx3072m JAVA_GC_OPTS=-XX:+UseG1GC -XX:+UseStringDeduplication -XX:InitiatingHeapOccupancyPercent=45 -DEPLOYMENT_ENVIRONMENT=CLOUD +deployment-environment=CLOUD REDIS_GROUP_PORT=6379 -REDIS_SEARCH_PORT=6379 DEFAULT_DATA_COUNTRY=US +redis-search-port=6379 + #Default Cache Settings -SCHEMA_CACHE_EXPIRATION=60 -INDEX_CACHE_EXPIRATION=60 -ELASTIC_CACHE_EXPIRATION=1440 -CURSOR_CACHE_EXPIRATION=60 +schema-cache-expiration=60 +index-cache-expiration=60 +elastic-cache-expiration=1440 +cursor-cache-expiration=60 # Kinds Cache expiration 2*24*60 -KINDS_CACHE_EXPIRATION=2880 +kinds-cache-expiration=2880 # Attributes Cache expiration 2*24*60 -ATTRIBUTES_CACHE_EXPIRATION=2880 +attributes-cache-expiration=2880 + +kinds-redis-database=1 +cron-index-cleanup-threshold-days=3 +cron-empty-index-cleanup-threshold-days=7 -KINDS_REDIS_DATABASE=1 -CRON_INDEX_CLEANUP_THRESHOLD_DAYS=3 -CRON_EMPTY_INDEX_CLEANUP_THRESHOLD_DAYS=7 +gae-service=indexer +key-ring=csqp +kms-key=searchService -GAE_SERVICE=indexer -KEY_RING=csqp -KMS_KEY=searchService +KEY_RING=${key-ring} +KMS_KEY=${kms-key} +GOOGLE_CLOUD_PROJECT=${google-cloud-project} -ELASTIC_DATASTORE_KIND=SearchSettings -ELASTIC_DATASTORE_ID=indexer-service +elastic-datastore-kind=SearchSettings +elastic-datastore-id=indexer-service security.https.certificate.trust=false indexer.que.service.mail=default@iam.gserviceaccount.com diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/CronServiceImplTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/CronServiceImplTest.java index 39ad6fb0eebd03b8540c606318bc5e29eb007aab..f839c8d2f25e550df8ee3e631a1c96c6b826ff66 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/CronServiceImplTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/CronServiceImplTest.java @@ -26,10 +26,10 @@ import org.opengroup.osdu.core.common.model.search.IndexInfo; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.util.ReflectionTestUtils; import java.io.IOException; import java.time.Instant; @@ -49,6 +49,8 @@ public class CronServiceImplTest { @Mock private ElasticClientHandler elasticClientHandler; @Mock + private IndexerConfigurationProperties configurationProperties; + @Mock private IRequestInfo requestInfo; @Mock private JaxRsDpsLog log; @@ -63,8 +65,8 @@ public class CronServiceImplTest { when(this.requestInfo.getHeaders()).thenReturn(dpsHeaders); - ReflectionTestUtils.setField(this.sut, "CRON_INDEX_CLEANUP_THRESHOLD_DAYS", "3"); - ReflectionTestUtils.setField(this.sut, "CRON_EMPTY_INDEX_CLEANUP_THRESHOLD_DAYS", "7"); + when(configurationProperties.getCronIndexCleanupThresholdDays()).thenReturn(3); + when(configurationProperties.getCronEmptyIndexCleanupThresholdDays()).thenReturn(3); } @Test diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceTest.java index 44bade56c4d25dc98dfe95bd6e844d6ea9d09fe1..ffdfde118a63472e22e142523e0715dc1d6aa506 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceTest.java @@ -27,6 +27,7 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.provider.interfaces.IElasticCredentialsCache; import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository; import org.opengroup.osdu.core.common.multitenancy.ITenantInfoService; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.test.context.junit4.SpringRunner; import static org.junit.Assert.assertEquals; @@ -43,6 +44,8 @@ public class ElasticSettingServiceTest { @Mock private IElasticCredentialsCache elasticCredentialCache; @Mock + private IndexerConfigurationProperties configurationProperties; + @Mock private TenantInfo tenantInfo; @InjectMocks private ElasticSettingServiceImpl sut; @@ -69,7 +72,7 @@ public class ElasticSettingServiceTest { when(tenantInfo.getName()).thenReturn("tenant1"); when(this.headersInfo.getPartitionId()).thenReturn("tenant1"); when(this.tenantInfoService.getTenantInfo()).thenReturn(tenantInfo); - sut.GAE_SERVICE = "indexer"; + when(configurationProperties.getGaeService()).thenReturn("indexer"); clusterSettings = ClusterSettings.builder().host(host).port(port).userNameAndPassword(credentials).build(); cacheKey = String.format("%s-%s", GAE_SERVICE, tenantInfo.getName()); } diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java index d28e1c2746ee215e10c1c460c799f7dda39e2fa8..ac48c1ac516308b045206b2c33595fc10914ce13 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java @@ -35,7 +35,7 @@ import org.mockito.Mock; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; -import org.opengroup.osdu.core.common.search.Config; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.opengroup.osdu.indexer.util.TypeMapper; import org.powermock.api.mockito.PowerMockito; @@ -51,12 +51,11 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.mockStatic; import static org.powermock.api.mockito.PowerMockito.when; @Ignore @RunWith(SpringRunner.class) -@PrepareForTest({ RestHighLevelClient.class, IndicesClient.class, Config.class }) +@PrepareForTest({ RestHighLevelClient.class, IndicesClient.class}) public class IndexerMappingServiceTest { private final String kind = "tenant:test:test:1.0.0"; @@ -64,6 +63,8 @@ public class IndexerMappingServiceTest { private final String type = "test"; private final String mappingValid = "{\"dynamic\":false,\"properties\":{\"data\":{\"properties\":{\"Msg\":{\"type\":\"text\",\"analyzer\":\"de_indexer_analyzer\",\"search_analyzer\":\"de_search_analyzer\"},\"Location\":{\"type\":\"geo_point\"}}},\"id\":{\"type\":\"keyword\"},\"acl\":{\"properties\":{\"viewers\":{\"type\":\"keyword\"},\"owners\":{\"type\":\"keyword\"}}}}}"; + @Mock + private IndexerConfigurationProperties configurationProperties; @Mock private RestClient restClient; @Mock @@ -91,8 +92,7 @@ public class IndexerMappingServiceTest { @Before public void setup() throws IOException { initMocks(this); - mockStatic(Config.class); - when(Config.isPreDemo()).thenReturn(true); + when(configurationProperties.isPreDemo()).thenReturn(true); Map<String, String> dataMapping = new HashMap<>(); dataMapping.put("Location", "geo_point"); dataMapping.put("Msg", "text"); diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ReindexServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ReindexServiceTest.java index bf2465ed8bc18d41f66d373e4e048e050e3b53ca..4ba73dacf1b815eec6856720c51d1e109b53c067 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ReindexServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ReindexServiceTest.java @@ -26,9 +26,8 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; -import org.opengroup.osdu.core.common.search.Config; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; -import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; import org.springframework.test.context.junit4.SpringRunner; @@ -43,13 +42,14 @@ import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({Config.class}) public class ReindexServiceTest { private final String cursor = "100"; private final String correlationId = UUID.randomUUID().toString(); + @Mock + private IndexerConfigurationProperties configurationProperties; @Mock private StorageService storageService; @Mock @@ -120,8 +120,7 @@ public class ReindexServiceTest { results.add("test1"); recordQueryResponse.setResults(results); - mockStatic(Config.class); - when(Config.getStorageRecordsBatchSize()).thenReturn(1); + when(configurationProperties.getStorageRecordsBatchSize()).thenReturn(1); when(storageService.getRecordsByKind(any())).thenReturn(recordQueryResponse); diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/StorageServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/StorageServiceTest.java index e868e50c842262a4eba35f2fa49cad1c2aae3cf6..3ffbbbd4cdd40f018ba41288a6fdf4e67a044d3a 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/StorageServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/StorageServiceTest.java @@ -36,9 +36,9 @@ import org.opengroup.osdu.core.common.http.IUrlFetchService; import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; import org.opengroup.osdu.core.common.model.indexer.Records; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.springframework.http.HttpStatus; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.util.ReflectionTestUtils; import java.lang.reflect.Type; import java.net.URISyntaxException; @@ -64,6 +64,8 @@ public class StorageServiceTest { private JaxRsDpsLog log; @Mock private IRequestInfo requestInfo; + @Mock + private IndexerConfigurationProperties configurationProperties; @InjectMocks private StorageServiceImpl sut; @@ -86,7 +88,7 @@ public class StorageServiceTest { jobStatus.initialize(msgs); ids = Arrays.asList(RECORD_ID1, RECORDS_ID2); - ReflectionTestUtils.setField(this.sut, "STORAGE_RECORDS_BATCH_SIZE", "20"); + when(configurationProperties.getStorageRecordsBatchSize()).thenReturn(20); } @Test diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImplTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImplTest.java index b25cf1fc4e62590d9589179917e713c6bc30dd36..1089d7dba57f8f2cdc1ac1642289e7946b8cc892 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImplTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImplTest.java @@ -38,7 +38,7 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; import org.opengroup.osdu.core.common.model.search.IdToken; import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; -import org.opengroup.osdu.core.common.search.Config; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -49,11 +49,13 @@ import static org.powermock.api.mockito.PowerMockito.when; @Ignore @RunWith(SpringRunner.class) -@PrepareForTest({GoogleNetHttpTransport.class, GoogleCredential.class, NetHttpTransport.class, SignJwtResponse.class, Iam.Builder.class, HttpClients.class, EntityUtils.class, Config.class}) +@PrepareForTest({GoogleNetHttpTransport.class, GoogleCredential.class, NetHttpTransport.class, SignJwtResponse.class, Iam.Builder.class, HttpClients.class, EntityUtils.class, IndexerConfigurationProperties.class}) public class ServiceAccountJwtGcpClientImplTest { private static final String JWT_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik1UVXlPREE0TXpFd09BPT0ifQ.eyJzdWIiOiJtemh1OUBzbGIuY29tIiwiaXNzIjoic2F1dGgtcHJldmlldy5zbGIuY29tIiwiYXVkIjoidGVzdC1zbGJkZXYtZGV2cG9ydGFsLnNsYmFwcC5jb20iLCJpYXQiOjE1MjgxNDg5MTUsImV4cCI6MTUyODIzNTMxNSwicHJvdmlkZXIiOiJzbGIuY29tIiwiY2xpZW50IjoidGVzdC1zbGJkZXYtZGV2cG9ydGFsLnNsYmFwcC5jb20iLCJ1c2VyaWQiOiJtemh1OUBzbGIuY29tIiwiZW1haWwiOiJtemh1OUBzbGIuY29tIiwiYXV0aHoiOiJ7XCJhY2NvdW50Q291bnRyeVwiOntcImNvZGVcIjpcInVzXCIsXCJpZFwiOjU3MTU5OTkxMDE4MTI3MzYsXCJuYW1lXCI6XCJVbml0ZWQgU3RhdGVzIG9mIEFtZXJpY2FcIn0sXCJhY2NvdW50SWRcIjo1NjkxODc4ODMzOTEzODU2LFwiYWNjb3VudE5hbWVcIjpcIlNJUyBJbnRlcm5hbCBIUVwiLFwiY3JlYXRlZFwiOlwiMjAxOC0wNS0wM1QxNzoyNTo1NS40NDNaXCIsXCJkZXBhcnRtZW50TWFuYWdlclwiOm51bGwsXCJzdWJzY3JpcHRpb25zXCI6W3tcImFjY291bnRJZFwiOjU2OTE4Nzg4MzM5MTM4NTYsXCJjb250cmFjdElkXCI6NTc1MTcwMDIxMjE1NDM2OCxcImNyZWF0ZWRcIjpcIjIwMTgtMDUtMDNUMTc6MzM6MDkuNTczWlwiLFwiY3JtQ29udHJhY3RJZFwiOlwiU0lTLUlOVEVSTkFMLUhRLVFBXCIsXCJjcm1Db250cmFjdEl0ZW1JZFwiOlwiZGV2bGlcIixcImV4cGlyYXRpb25cIjpcIjE5NzAtMDEtMDFUMDA6MDA6MDAuMDAwWlwiLFwiaWRcIjo1MDc5Mjg4NTA0MTIzMzkyLFwicHJvZHVjdFwiOntcImNvZGVcIjpcImRldmVsb3Blci1saWdodFwiLFwiY29tY2F0TmFtZVwiOlwiTm90IGluIENvbUNhdFwiLFwiZmVhdHVyZVNldHNcIjpbe1wiYXBwbGljYXRpb25cIjp7XCJjb2RlXCI6XCJhcGlkZXZlbG9wZXJwb3J0YWxcIixcImlkXCI6NTE2ODkzMDY5NTkzODA0OCxcIm5hbWVcIjpcIkFQSSBEZXZlbG9wZXIgUG9ydGFsXCIsXCJ0eXBlXCI6XCJXZWJBcHBcIn0sXCJjbGFpbXNcIjpudWxsLFwiaWRcIjo1MTkxNTcyMjg3MTI3NTUyLFwibmFtZVwiOlwiRGV2ZWxvcGVyXCIsXCJ0eXBlXCI6XCJCQVNFXCJ9XSxcImlkXCI6NTE1MDczMDE1MTI2NDI1NixcIm5hbWVcIjpcIkRldmVsb3BlciBQb3J0YWxcIixcInBhcnROdW1iZXJcIjpcIlNERUwtUEItU1VCVVwifX1dLFwidXNlckVtYWlsXCI6XCJtemh1OUBzbGIuY29tXCIsXCJ1c2VyTmFtZVwiOlwiTWluZ3lhbmcgWmh1XCJ9XG4iLCJsYXN0bmFtZSI6IlpodSIsImZpcnN0bmFtZSI6Ik1pbmd5YW5nIiwiY291bnRyeSI6IiIsImNvbXBhbnkiOiIiLCJqb2J0aXRsZSI6IiIsInN1YmlkIjoiNDE3YjczMjktYmMwNy00OTFmLWJiYzQtZTQ1YjRhMWFiYjVjLVd3U0c0dyIsImlkcCI6ImNvcnAyIiwiaGQiOiJzbGIuY29tIn0.WQfGr1Xu-6IdaXdoJ9Fwzx8O2el1UkFPWo1vk_ujiAfdOjAR46UG5SrBC7mzC7gYRyK3a4fimBmbv3uRVJjTNXdxXRLZDw0SvXUMIOqjUGLom491ESbrtka_Xz7vGO-tWyDcEQDTfFzQ91LaVN7XdzL18_EDTXZoPhKb-zquyk9WLQxP9Mw-3Yh-UrbvC9nl1-GRn1IVbzp568kqkpOVUFM9alYSGw-oMGDZNt1DIYOJnpGaw2RB5B3AKvNivZH_Xdac7ZTzQbsDOt8B8DL2BphuxcJ9jshCJkM2SHQ15uErv8sfnzMwdF08e_0QcC_30I8eX9l8yOu6TnwwqlXunw"; + @Mock + private IndexerConfigurationProperties indexerConfigurationProperties; @Mock private JaxRsDpsLog log; @Mock @@ -98,8 +100,8 @@ public class ServiceAccountJwtGcpClientImplTest { when(credential.createScoped(any())).thenReturn(credential); when(HttpClients.createDefault()).thenReturn(httpClient); when(httpClient.execute(any())).thenReturn(httpResponse); - when(Config.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.LOCAL); - when(Config.getGoogleAudiences()).thenReturn("aud"); + when(indexerConfigurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.LOCAL); + when(indexerConfigurationProperties.getGoogleAudiences()).thenReturn("aud"); // when(this.tenantInfoServiceProvider).thenReturn(this.tenantInfoService); diff --git a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/CronServiceImplTest.java b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/CronServiceImplTest.java index a51f2d8bf2bb95f8afd53db6cac16d81faa8b17f..356744e6b8654b2cc6c1f6b92cb4302d41d94dd6 100644 --- a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/CronServiceImplTest.java +++ b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/CronServiceImplTest.java @@ -24,11 +24,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.service.CronServiceImpl; import org.opengroup.osdu.core.common.model.search.IndexInfo; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.core.common.search.IndicesService; -import org.opengroup.osdu.core.common.search.Config; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -39,7 +39,6 @@ import java.time.temporal.ChronoUnit; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.powermock.api.mockito.PowerMockito.mockStatic; @Ignore @@ -47,6 +46,8 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic; @PrepareForTest({RestHighLevelClient.class}) public class CronServiceImplTest { + @Mock + private IndexerConfigurationProperties configurationProperties; @Mock private RestHighLevelClient restHighLevelClient; @Mock @@ -65,12 +66,10 @@ public class CronServiceImplTest { @Before public void setup() { - mockStatic(Config.class); - when(this.requestInfo.getHeaders()).thenReturn(dpsHeaders); - when(Config.getIndexCleanupThresholdDays()).thenReturn(3); - when(Config.getEmptyIndexCleanupThresholdDays()).thenReturn(7); + when(configurationProperties.getCronIndexCleanupThresholdDays()).thenReturn(3); + when(configurationProperties.getCronEmptyIndexCleanupThresholdDays()).thenReturn(7); } @Test diff --git a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/ReindexServiceTest.java b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/ReindexServiceTest.java index 1db13bb3827d6b691075b4ab089b5457e53b6b37..3b81ef8e1e135982ebadc2c00752d6fe0d7333d2 100644 --- a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/ReindexServiceTest.java +++ b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/ReindexServiceTest.java @@ -26,7 +26,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.search.Config; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.service.ReindexServiceImpl; import org.opengroup.osdu.indexer.service.StorageService; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; @@ -46,13 +46,16 @@ import static org.powermock.api.mockito.PowerMockito.when; @Ignore @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({Config.class}) +@PrepareForTest({IndexerConfigurationProperties.class}) public class ReindexServiceTest { private final String cursor = "100"; private final String correlationId = UUID.randomUUID().toString(); + @Mock + private IndexerConfigurationProperties indexerConfigurationProperties; + @Mock private StorageService storageService; @@ -123,8 +126,7 @@ public class ReindexServiceTest { results.add("test1"); recordQueryResponse.setResults(results); - mockStatic(Config.class); - when(Config.getStorageRecordsBatchSize()).thenReturn(1); + when(indexerConfigurationProperties.getStorageRecordsBatchSize()).thenReturn(1); when(storageService.getRecordsByKind(ArgumentMatchers.any())).thenReturn(recordQueryResponse); diff --git a/testing/indexer-test-core/pom.xml b/testing/indexer-test-core/pom.xml index 0052017fa37e2ab67779269c72328e4969d0f8d9..1a31fdd1830f64cf62cbdc471981ad9a36087a23 100644 --- a/testing/indexer-test-core/pom.xml +++ b/testing/indexer-test-core/pom.xml @@ -19,7 +19,7 @@ <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> <cucumber.version>1.2.5</cucumber.version> - <os-core-common.version>0.3.6</os-core-common.version> + <os-core-common.version>0.3.19</os-core-common.version> </properties> <dependencies>