Skip to content
Snippets Groups Projects
Commit 53307511 authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

add config for schema event listener

parent 4e65a216
Branches
Tags
2 merge requests!346Merge branch 'aws-integration' into 'master',!222Add endpoint to consume schema service events
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;
}
......@@ -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 {
......
......@@ -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 =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment