diff --git a/devops/gc/deploy/README.md b/devops/gc/deploy/README.md index eca88b9b059252c218980123b147d5bd137ec915..40a0e4a4e51a4eb82d0bb659046fc782f1aa527b 100644 --- a/devops/gc/deploy/README.md +++ b/devops/gc/deploy/README.md @@ -79,6 +79,7 @@ First you need to set variables in **values.yaml** file using any code editor. S **istio.proxyCPULimit** | CPU limit for Envoy sidecars | string | 200m | yes **istio.proxyMemory** | memory request for Envoy sidecars | string | 100Mi | yes **istio.proxyMemoryLimit** | memory limit for Envoy sidecars | string | 256Mi | yes +**istio.sidecarInject** | whether Istio sidecar will be injected. Setting to "false" reduces security, because disables authorization policy. | boolean | true | yes ### Install the helm chart diff --git a/devops/gc/deploy/templates/deployment.yaml b/devops/gc/deploy/templates/deployment.yaml index 06855a6c7b586f3bdb1b9b75d68488d4dce2c456..54df76f61d38457796aaf926bec43e0d4330bdfc 100644 --- a/devops/gc/deploy/templates/deployment.yaml +++ b/devops/gc/deploy/templates/deployment.yaml @@ -14,6 +14,7 @@ spec: metadata: labels: app: {{ .Values.conf.appName | quote }} + sidecar.istio.io/inject: {{ .Values.istio.sidecarInject | quote }} annotations: rollme: {{ randAlphaNum 5 | quote }} sidecar.istio.io/proxyCPU: {{ .Values.istio.proxyCPU | quote }} diff --git a/devops/gc/deploy/values.yaml b/devops/gc/deploy/values.yaml index 96f0648927b09fdf48f165b4ce272180f4882862..a5e0dd84cf454af10a67f9d29a73281d1da99315 100644 --- a/devops/gc/deploy/values.yaml +++ b/devops/gc/deploy/values.yaml @@ -43,3 +43,4 @@ istio: proxyCPULimit: "200m" proxyMemory: "100Mi" proxyMemoryLimit: "256Mi" + sidecarInject: true diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/RecordIndexerApi.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/RecordIndexerApi.java index 93d09b0da1f98686c1bb88bbd0c2157bfa6cc481..4f08bbc5489e121e5405b926257522c79516ef54 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/RecordIndexerApi.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/RecordIndexerApi.java @@ -16,7 +16,6 @@ package org.opengroup.osdu.indexer.api; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; - import com.google.gson.JsonParseException; import io.swagger.v3.oas.annotations.Operation; import lombok.extern.java.Log; @@ -28,14 +27,17 @@ import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; import org.opengroup.osdu.core.common.model.indexer.SchemaChangedMessages; import org.opengroup.osdu.core.common.model.indexer.SchemaInfo; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.indexer.SwaggerDoc; import org.opengroup.osdu.indexer.service.IndexerService; import org.opengroup.osdu.indexer.service.ReindexService; import org.opengroup.osdu.indexer.service.SchemaEventsProcessor; -import org.opengroup.osdu.indexer.service.SchemaService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; @@ -51,34 +53,29 @@ import java.util.List; @RequestScope public class RecordIndexerApi { + @Inject + private IRequestInfo requestInfo; @Inject private IndexerService indexerService; @Inject private ReindexService reIndexService; @Inject - private SchemaService schemaService; - @Inject private SchemaEventsProcessor eventsProcessingService; // THIS IS AN INTERNAL USE API ONLY // THAT MEANS WE DON'T DOCUMENT IT IN SWAGGER, ACCESS IS LIMITED TO CLOUD TASK QUEUE CALLS ONLY @PostMapping(path = "/index-worker", consumes = "application/json") @Operation(hidden = true, summary = "", description = "") - public ResponseEntity<JobStatus> indexWorker ( + public ResponseEntity<JobStatus> indexWorker( @NotNull(message = SwaggerDoc.REQUEST_VALIDATION_NOT_NULL_BODY) @Valid @RequestBody RecordChangedMessages recordChangedMessages) throws Exception { - if (recordChangedMessages.missingAccountId()) { - throw new AppException(org.apache.http.HttpStatus.SC_BAD_REQUEST, "Invalid tenant", - String.format("Required header: '%s' not found", DpsHeaders.DATA_PARTITION_ID)); - } - try { - if (recordChangedMessages == null) { - log.info("record change messages is null"); - } + populateCorrelationIdIfExist(recordChangedMessages); + + verifyDataPartitionId(recordChangedMessages); - Type listType = new TypeToken<List<RecordInfo>>() { - }.getType(); + try { + Type listType = new TypeToken<List<RecordInfo>>() {}.getType(); List<RecordInfo> recordInfos = new Gson().fromJson(recordChangedMessages.getData(), listType); if (recordInfos.size() == 0) { @@ -96,6 +93,19 @@ public class RecordIndexerApi { } } + private void verifyDataPartitionId(RecordChangedMessages recordChangedMessages) { + if (recordChangedMessages.missingAccountId()) { + throw new AppException(org.apache.http.HttpStatus.SC_BAD_REQUEST, "Invalid tenant", + String.format("Required header: '%s' not found", DpsHeaders.DATA_PARTITION_ID)); + } + } + + private void populateCorrelationIdIfExist(RecordChangedMessages recordChangedMessages) { + if (recordChangedMessages.hasCorrelationId()) { + this.requestInfo.getHeaders().put(DpsHeaders.CORRELATION_ID, recordChangedMessages.getCorrelationId()); + } + } + // THIS IS AN INTERNAL USE API ONLY // THAT MEANS WE DON'T DOCUMENT IT IN SWAGGER, ACCESS IS LIMITED TO CLOUD TASK QUEUE CALLS ONLY @PostMapping("/reindex-worker") diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurations.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurations.java index ab20d8755d9cfd8989ce9ec7fa64a1a7a97fd958..6fbb00c7727610df9912cdfca75ae315bb409a95 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurations.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurations.java @@ -60,4 +60,40 @@ public class PropertyConfigurations { } return new ArrayList<>(relatedObjectKinds); } + + public boolean hasValidCode() { + // It is just basic test to detect mistake + if(Strings.isNullOrEmpty(this.code)) { + return false; + } + + String[] parts = this.code.split(":"); + if(parts.length != 4) { + return false; + } + // Version must be ended with dot and major version only + // e.g. "Code": "osdu:wks:master-data--Well:1." + String version = parts[3]; + return (version.length() > 1 && version.indexOf(".") == version.length() - 1); + } + + public boolean hasValidConfigurations() { + if(configurations == null || configurations.isEmpty()) { + return false; + } + + return configurations.stream().anyMatch(config -> config.isValid()); + } + + public boolean hasInvalidConfigurations() { + if(configurations == null || configurations.isEmpty()) { + return false; + } + + return configurations.stream().anyMatch(config -> !config.isValid()); + } + + public boolean isValid() { + return hasValidCode() && hasValidConfigurations(); + } } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java index ab3cebb80195698fe9d3b280c801f95b31281c16..31b63bafb3fe19b1ad5a6302b94953c56c7f5c4f 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java @@ -167,10 +167,15 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { return this.getEmptySchema(kind); } else { if(augmenterSetting.isEnabled()) { - // Merge schema of the extended properties if needed - PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(kind); - if (propertyConfigurations != null) { - schema = mergeSchemaFromPropertyConfiguration(schema, propertyConfigurations); + try { + // Merge schema of the extended properties if needed + PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(kind); + if (propertyConfigurations != null) { + schema = mergeSchemaFromPropertyConfiguration(schema, propertyConfigurations); + } + } + catch(Exception ex) { + log.error(String.format("Augmenter: Failed to merge schema of the extended properties for kind: '%s'", kind), ex); } } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java index cdae2cb43b3c99b3cbc3376867f7c1e7cd142218..65d8c9f2bfaafe979800468590efa6109a4a6747 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java @@ -129,7 +129,7 @@ public class IndexerServiceImpl implements IndexerService { try { auditLogger.indexStarted(recordInfos.stream() - .map(RecordInfo::getKind) + .map(entry -> String.format("id=%s kind=%s operationType=%s", entry.getId(), entry.getKind(), entry.getOp())) .collect(Collectors.toList())); // get upsert records @@ -157,11 +157,16 @@ public class IndexerServiceImpl implements IndexerService { retryAndEnqueueFailedRecords(recordInfos, retryRecordIds, message); } - if(this.augmenterSetting.isEnabled()) { - Map<String, List<String>> upsertKindIds = getUpsertRecordIdsForConfigurationsEnabledKinds(upsertRecordMap, retryRecordIds); - Map<String, List<String>> deleteKindIds = getDeleteRecordIdsForConfigurationsEnabledKinds(deleteRecordMap, retryRecordIds); - if (!upsertKindIds.isEmpty() || !deleteKindIds.isEmpty()) { - propertyConfigurationsService.updateAssociatedRecords(message, upsertKindIds, deleteKindIds); + if (this.augmenterSetting.isEnabled()) { + try { + Map<String, List<String>> upsertKindIds = getUpsertRecordIdsForConfigurationsEnabledKinds(upsertRecordMap, retryRecordIds); + Map<String, List<String>> deleteKindIds = getDeleteRecordIdsForConfigurationsEnabledKinds(deleteRecordMap, retryRecordIds); + if (!upsertKindIds.isEmpty() || !deleteKindIds.isEmpty()) { + propertyConfigurationsService.updateAssociatedRecords(message, upsertKindIds, deleteKindIds); + } + } + catch(Exception ex) { + jaxRsDpsLog.error("Augmenter: Failed to update associated records", ex); } } } catch (IOException e) { @@ -346,14 +351,19 @@ public class IndexerServiceImpl implements IndexerService { } if(this.augmenterSetting.isEnabled()) { - if(propertyConfigurationsService.isPropertyConfigurationsEnabled(storageRecord.getKind())) { - PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(storageRecord.getKind()); - if (propertyConfigurations != null) { - // Merge extended properties - dataMap = mergeDataFromPropertyConfiguration(storageRecord.getId(), dataMap, propertyConfigurations); + try { + if (propertyConfigurationsService.isPropertyConfigurationsEnabled(storageRecord.getKind())) { + PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(storageRecord.getKind()); + if (propertyConfigurations != null) { + // Merge extended properties + dataMap = mergeDataFromPropertyConfiguration(storageRecord.getId(), dataMap, propertyConfigurations); + } + // We cache the dataMap in case the update of this object will trigger update of the related objects. + propertyConfigurationsService.cacheDataRecord(storageRecord.getId(), storageRecord.getKind(), dataMap); } - // We cache the dataMap in case the update of this object will trigger update of the related objects. - propertyConfigurationsService.cacheDataRecord(storageRecord.getId(), storageRecord.getKind(), dataMap); + } + catch(Exception ex) { + jaxRsDpsLog.error(String.format("Augmenter: Failed to merge extended properties of the record with id: '%s' and kind: '%s'", storageRecord.getId(), storageRecord.getKind()), ex); } } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java index de45b4db3aaa1a6809bf200b422db530625617ff..d7aa52e00e73505535dbac9d423168fa1744ec5b 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java @@ -126,6 +126,30 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations if (configuration == null) { configuration = searchConfigurations(kind); if (configuration != null) { + if(configuration.isValid()) { + // Log for debug + if(configuration.hasInvalidConfigurations()) { + String msg = String.format("PropertyConfigurations: it has invalid PropertyConfiguration for configurations with name '%s':", configuration.getName()); + this.jaxRsDpsLog.warning(msg); + } + } + else { + // Log for debug + StringBuilder msgBuilder = new StringBuilder(); + msgBuilder.append(String.format("PropertyConfigurations: it is invalid for configurations with name '%s':", configuration.getName())); + if(!configuration.hasValidCode()) { + msgBuilder.append(System.lineSeparator()); + msgBuilder.append(String.format("The code '%s' is invalid. It should be a valid kind with major version ended with '.'", configuration.getCode())); + } + if(!configuration.hasValidConfigurations()) { + msgBuilder.append(System.lineSeparator()); + msgBuilder.append("It does not have any valid PropertyConfiguration"); + } + this.jaxRsDpsLog.warning(msgBuilder.toString()); + + configuration = EMPTY_CONFIGURATIONS; // reset + } + propertyConfigurationCache.put(kind, configuration); } else { // It is common that a kind does not have extended property. So we need to cache an empty configuration diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java index f21e0968d976de22c1f2f35daf4e33b17cbe7406..b21bbb47aec44f2774bc2cec8486a9c4b77bb5cf 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/BooleanFeatureFlagClient.java @@ -55,7 +55,11 @@ public class BooleanFeatureFlagClient { PartitionInfo partitionInfo = partitionProvider.get(dataPartitionId); return partitionInfo; } catch (PartitionException e) { - logger.error(String.format("Error getting partition info for data-partition: %s", dataPartitionId), e); + if (e.getResponse() != null) { + logger.error(String.format("Error getting partition info for data-partition: %s. Message: %s. ResponseCode: %s.", dataPartitionId, e.getResponse().getBody(), e.getResponse().getResponseCode()), e); + } else { + logger.error(String.format("Error getting partition info for data-partition: %s.", dataPartitionId), e); + } throw e; } } 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 4c008d8646ded0eaf6d247d7f55d283a2e90d29e..fd5940d16d90b59844aea1d6d5f4ac64a23405ac 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 @@ -17,22 +17,23 @@ package org.opengroup.osdu.indexer.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.MockitoAnnotations.initMocks; - +import static org.mockito.Mockito.when; import com.google.gson.Gson; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.opengroup.osdu.core.common.http.HeadersUtil; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; 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.indexer.SchemaChangedMessages; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.indexer.service.IndexerService; import org.opengroup.osdu.indexer.service.SchemaEventsProcessor; -import org.opengroup.osdu.indexer.service.SchemaService; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -59,7 +60,7 @@ public class RecordIndexerApiTest { @Mock private IndexerService indexService; @Mock - private SchemaService schemaService; + private IRequestInfo requestInfo; @Mock private SchemaEventsProcessor eventsProcessingService; @@ -72,6 +73,7 @@ public class RecordIndexerApiTest { dpsHeaders.put(DpsHeaders.ACCOUNT_ID, this.ACCOUNT_ID); dpsHeaders.put(DpsHeaders.DATA_PARTITION_ID, this.DATA_PARTITION_ID); + when(this.requestInfo.getHeaders()).thenReturn(dpsHeaders); } @Test @@ -89,6 +91,12 @@ public class RecordIndexerApiTest { should_return400_indexerWorkerTest(messageEmpty, String.format("Required header: '%s' not found", DpsHeaders.DATA_PARTITION_ID)); } + @Test + public void should_addCorrelationIdToHeader_IfExists_indexWorkerTest() throws Exception { + this.sut.indexWorker(createRecordChangedMessage(recordMessageValid)); + Mockito.verify(this.requestInfo.getHeaders()).put("correlation-id", "b5a281bd-f59d-4db2-9939-b2d85036fc7e"); + } + @Test public void should_return400_given_incorrectJsonFormatMessage_indexWorkerTest() { should_return400_indexerWorkerTest(messageWithIncorrectJsonFormat, "Unable to parse request payload."); diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurationsTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurationsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c5856c89befb04ce78865ec16f3f299671290f3f --- /dev/null +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurationsTest.java @@ -0,0 +1,117 @@ +/* + * Copyright © Schlumberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.osdu.indexer.model.indexproperty; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.SneakyThrows; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +@RunWith(SpringRunner.class) +public class PropertyConfigurationsTest { + private PropertyConfigurations configurations; + + @Before + public void setup() throws JsonProcessingException { + String jsonText = getJsonFromFile("well_configuration_record.json"); + ObjectMapper objectMapper = new ObjectMapper(); + configurations = objectMapper.readValue(jsonText, PropertyConfigurations.class); + } + + @Test + public void isValid() { + Assert.assertTrue(configurations.hasValidCode()); + Assert.assertTrue(configurations.hasValidConfigurations()); + Assert.assertFalse(configurations.hasInvalidConfigurations()); + Assert.assertTrue(configurations.isValid()); + } + + @Test + public void hasInvalidCode() { + String code = configurations.getCode(); + + configurations.setCode(code + "0.0"); + Assert.assertFalse(configurations.hasValidCode()); + Assert.assertFalse(configurations.isValid()); + + configurations.setCode("a:b:1."); + Assert.assertFalse(configurations.hasValidCode()); + Assert.assertFalse(configurations.isValid()); + + configurations.setCode(""); + Assert.assertFalse(configurations.hasValidCode()); + Assert.assertFalse(configurations.isValid()); + + configurations.setCode(null); + Assert.assertFalse(configurations.hasValidCode()); + Assert.assertFalse(configurations.isValid()); + } + + @Test + public void hasNoValidConfigurations() { + List<PropertyConfiguration> propertyConfigurations = configurations.getConfigurations(); + + configurations.setConfigurations(new ArrayList<>()); + Assert.assertFalse(configurations.hasValidConfigurations()); + Assert.assertFalse(configurations.hasInvalidConfigurations()); + Assert.assertFalse(configurations.isValid()); + + configurations.setConfigurations(null); + Assert.assertFalse(configurations.hasValidConfigurations()); + Assert.assertFalse(configurations.hasInvalidConfigurations()); + Assert.assertFalse(configurations.isValid()); + + propertyConfigurations.forEach(p -> p.setPolicy("")); + configurations.setConfigurations(propertyConfigurations); + Assert.assertFalse(configurations.hasValidConfigurations()); + Assert.assertTrue(configurations.hasInvalidConfigurations()); + Assert.assertFalse(configurations.isValid()); + } + + @Test + public void hasPartialValidConfigurations() { + List<PropertyConfiguration> propertyConfigurations = configurations.getConfigurations(); + Assert.assertEquals(2, propertyConfigurations.size()); + + propertyConfigurations.get(0).setPolicy(""); + Assert.assertTrue(configurations.hasValidConfigurations()); + Assert.assertTrue(configurations.hasInvalidConfigurations()); + Assert.assertTrue(configurations.isValid()); + } + + @SneakyThrows + private String getJsonFromFile(String file) { + InputStream inStream = this.getClass().getResourceAsStream("/indexproperty/" + file); + BufferedReader br = new BufferedReader(new InputStreamReader(inStream)); + StringBuilder stringBuilder = new StringBuilder(); + String sCurrentLine; + while ((sCurrentLine = br.readLine()) != null) + { + stringBuilder.append(sCurrentLine).append("\n"); + } + return stringBuilder.toString(); + } +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java index 17b8d526b78fba8ce7819d73bce2302515ebaaf6..2546e920b63a4445370f291bed95036f2e81fe6d 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java @@ -39,8 +39,8 @@ public class AzureBootstrapConfig { @Value("${azure.servicebus.reindex.topic-name}") private String serviceBusReindexTopicName; - @Value("${publish.indexing.progress}") - private boolean publishIndexingProgress; + @Value("${publish.to.azure.servicebus.topic.enabled}") + private boolean shouldPublishToServiceBusTopic; @Value("${ELASTIC_CACHE_EXPIRATION}") private Integer elasticCacheExpiration; @@ -67,10 +67,8 @@ public class AzureBootstrapConfig { } @Bean - @Named("PUBLISH_TO_INDEXING_PROGRESS_TOPIC") - public Boolean publishIndexingProgress() { - return publishIndexingProgress; - } + @Named("PUBLISH_TO_SERVICE_BUS_INDEXERSTATUS_TOPIC_ENABLED") + public boolean shouldPublishToServiceBusTopic() { return shouldPublishToServiceBusTopic;} @Bean @Named("ELASTIC_CACHE_EXPIRATION") diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/publish/PublisherImpl.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/publish/PublisherImpl.java index 4d29f6d3c96bc08c68352c0e636890e289819181..4b8bc2730357f1a4ffe167a2541080a7fe56e0ad 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/publish/PublisherImpl.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/publish/PublisherImpl.java @@ -57,8 +57,8 @@ public class PublisherImpl implements IPublisher { private String serviceBusTopic; @Inject - @Named("PUBLISH_TO_INDEXING_PROGRESS_TOPIC") - private boolean publishToIndexingProgressTopic; + @Named("PUBLISH_TO_SERVICE_BUS_INDEXERSTATUS_TOPIC_ENABLED") + private boolean shouldPublishToServiceBusTopic; @Override public void publishStatusChangedTagsToTopic(DpsHeaders headers, JobStatus indexerBatchStatus) throws Exception { @@ -76,7 +76,7 @@ public class PublisherImpl implements IPublisher { message.setContentType("application/json"); try { - if(publishToIndexingProgressTopic) { + if(shouldPublishToServiceBusTopic) { logger.debug("Indexer publishes message " + headers.getCorrelationId()); topicClientFactory.getClient(headers.getPartitionId(), serviceBusTopic).send(message); } diff --git a/provider/indexer-azure/src/main/resources/application.properties b/provider/indexer-azure/src/main/resources/application.properties index 2e870669aa046452a3d94e847578089fd3a3afe6..c510590320ff79871298500f3bbda69eee26e10e 100644 --- a/provider/indexer-azure/src/main/resources/application.properties +++ b/provider/indexer-azure/src/main/resources/application.properties @@ -69,7 +69,7 @@ azure.cosmosdb.database=${cosmosdb_database} #AzureServiceBusconfiguration azure.servicebus.topic-name=${servicebus_topic_name} azure.servicebus.reindex.topic-name=${reindex_topic_name} -publish.indexing.progress=false +publish.to.azure.servicebus.topic.enabled=false #Indexer-Queue-header indexer.queue.key=abcd diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/publish/PublisherImplTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/publish/PublisherImplTest.java index 565b99dc8cb70b8ceaebe695ef1600954d5ed325..d130ea279a2bc445944a2af2af10e0f9f810d5cb 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/publish/PublisherImplTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/publish/PublisherImplTest.java @@ -23,8 +23,8 @@ public class PublisherImplTest { private static String serviceBusTopicField = "serviceBusTopic"; private static String serviceBusTopicValue = "recordChangeTopic"; - private static String publishToIndexingProgressTopicField = "publishToIndexingProgressTopic"; - private static Boolean publishToIndexingProgressTopicValue = true; + private static String shouldPublishToServiceBusTopicField = "shouldPublishToServiceBusTopic"; + private static Boolean shouldPublishToServiceBusTopicValue = true; private static String partitionId = "opendes"; @Mock @@ -45,7 +45,7 @@ public class PublisherImplTest { @Test public void should_invoke_getPartitionIdOfdpsHeaders_when_publishStatusChangedTagsToTopic_isCalled() throws Exception { ReflectionTestUtils.setField(sut,serviceBusTopicField,serviceBusTopicValue); - ReflectionTestUtils.setField(sut,publishToIndexingProgressTopicField,publishToIndexingProgressTopicValue); + ReflectionTestUtils.setField(sut,shouldPublishToServiceBusTopicField,shouldPublishToServiceBusTopicValue); when(dpsHeaders.getPartitionId()).thenReturn(partitionId); sut.publishStatusChangedTagsToTopic(dpsHeaders, jobStatus); @@ -56,7 +56,7 @@ public class PublisherImplTest { @Test public void should_invoke_getAccountIdOfDpsHeaders_when_publishStatusChangedTagsToTopic_isCalledWithGetPartitionIdReturningEmptyString() throws Exception { ReflectionTestUtils.setField(sut,serviceBusTopicField,serviceBusTopicValue); - ReflectionTestUtils.setField(sut,publishToIndexingProgressTopicField,publishToIndexingProgressTopicValue); + ReflectionTestUtils.setField(sut,shouldPublishToServiceBusTopicField,shouldPublishToServiceBusTopicValue); when(dpsHeaders.getPartitionId()).thenReturn(""); sut.publishStatusChangedTagsToTopic(dpsHeaders, jobStatus); @@ -67,7 +67,7 @@ public class PublisherImplTest { @Test public void should_invoke_getClientOftopicClientFactory_when_publishStatusChangedTagsToTopic_isCalled() throws Exception { ReflectionTestUtils.setField(sut,serviceBusTopicField,serviceBusTopicValue); - ReflectionTestUtils.setField(sut,publishToIndexingProgressTopicField,publishToIndexingProgressTopicValue); + ReflectionTestUtils.setField(sut,shouldPublishToServiceBusTopicField,shouldPublishToServiceBusTopicValue); when(dpsHeaders.getPartitionId()).thenReturn(partitionId); sut.publishStatusChangedTagsToTopic(dpsHeaders, jobStatus);