From 533075119a39e9ecb3e6a56d213e89688cf07732 Mon Sep 17 00:00:00 2001 From: NThakur4 <nthakur4@slb.com> Date: Wed, 13 Apr 2022 15:05:37 -0500 Subject: [PATCH] add config for schema event listener --- .../SchemaEventsListenerConfiguration.java | 16 +++++++++++++ .../indexer/service/SchemaProviderImpl.java | 24 ++++++++++++++----- .../service/SchemaProviderImplTest.java | 11 ++++++++- 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 indexer-core/src/main/java/org/opengroup/osdu/indexer/config/SchemaEventsListenerConfiguration.java diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/SchemaEventsListenerConfiguration.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/SchemaEventsListenerConfiguration.java new file mode 100644 index 000000000..7f4bddefe --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/SchemaEventsListenerConfiguration.java @@ -0,0 +1,16 @@ +package org.opengroup.osdu.indexer.config; + +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Getter +public class SchemaEventsListenerConfiguration { + + @Value("${listner.schema.event.create:true}") + private boolean listenCreateEvent; + + @Value("${listner.schema.event.update:true}") + private boolean listenUpdateEvent; +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java index 825361548..c82d538a2 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java @@ -28,6 +28,7 @@ import org.opengroup.osdu.core.common.model.indexer.SchemaInfo; import org.opengroup.osdu.core.common.model.indexer.SchemaOperationType; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; +import org.opengroup.osdu.indexer.config.SchemaEventsListenerConfiguration; import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.schema.converter.interfaces.SchemaToStorageFormat; import org.opengroup.osdu.indexer.util.ElasticClientHandler; @@ -76,6 +77,10 @@ public class SchemaProviderImpl implements SchemaService { @Inject private AuditLogger auditLogger; + @Inject + private SchemaEventsListenerConfiguration schemaEventsListenerConfiguration; + + @Override public String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { String schemaServiceSchema = getFromSchemaService(kind); @@ -85,16 +90,23 @@ public class SchemaProviderImpl implements SchemaService { @Override public void processSchemaMessages(List<SchemaInfo> schemaInfos) throws IOException { Map<String, SchemaOperationType> messages = new HashMap<>(); - Map<String, SchemaOperationType> createSchemaMessages = SchemaInfo.getCreateSchemaEvents(schemaInfos); - if (createSchemaMessages != null && !createSchemaMessages.isEmpty()) { - messages.putAll(createSchemaMessages); + + if (schemaEventsListenerConfiguration.isListenCreateEvent()) { + Map<String, SchemaOperationType> createSchemaMessages = SchemaInfo.getCreateSchemaEvents(schemaInfos); + if (createSchemaMessages != null && !createSchemaMessages.isEmpty()) { + messages.putAll(createSchemaMessages); + } } - Map<String, SchemaOperationType> updateSchemaMessages = SchemaInfo.getUpdateSchemaEvents(schemaInfos); - if (updateSchemaMessages != null && !updateSchemaMessages.isEmpty()) { - messages.putAll(updateSchemaMessages); + if (schemaEventsListenerConfiguration.isListenUpdateEvent()) { + Map<String, SchemaOperationType> updateSchemaMessages = SchemaInfo.getUpdateSchemaEvents(schemaInfos); + if (updateSchemaMessages != null && !updateSchemaMessages.isEmpty()) { + messages.putAll(updateSchemaMessages); + } } + if (messages.isEmpty()) return; + try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { messages.entrySet().forEach(msg -> { try { diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/SchemaProviderImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/SchemaProviderImplTest.java index 2d1ab4aea..3c40aa24c 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/SchemaProviderImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/SchemaProviderImplTest.java @@ -21,6 +21,7 @@ import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.rest.RestStatus; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.*; @@ -31,6 +32,7 @@ import org.opengroup.osdu.core.common.model.http.HttpResponse; import org.opengroup.osdu.core.common.model.indexer.SchemaInfo; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; +import org.opengroup.osdu.indexer.config.SchemaEventsListenerConfiguration; import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.schema.converter.SchemaToStorageFormatImpl; import org.opengroup.osdu.indexer.util.ElasticClientHandler; @@ -77,12 +79,19 @@ public class SchemaProviderImplTest { private AuditLogger auditLogger; @Mock private IndexSchemaService indexSchemaService; - + @Mock + private SchemaEventsListenerConfiguration schemaEventsListenerConfiguration; @InjectMocks private SchemaProviderImpl sut; private RestHighLevelClient restClient; + @Before + public void setup() { + when(this.schemaEventsListenerConfiguration.isListenCreateEvent()).thenReturn(true); + when(this.schemaEventsListenerConfiguration.isListenUpdateEvent()).thenReturn(true); + } + @Test public void test_empty_schema() throws UnsupportedEncodingException, URISyntaxException { org.opengroup.osdu.core.common.model.http.HttpResponse httpResponse = -- GitLab