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 588e0ba2f62190d55169334f791eb5f52207faed..c27c76e6da5a71fdcc0b14901e160ad1dc9d8ff0 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 @@ -39,6 +39,8 @@ import org.springframework.stereotype.Service; import javax.inject.Inject; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; @@ -63,8 +65,6 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { private IndicesService indicesService; @Inject private ISchemaCache schemaCache; - @Inject - private SchemaService schemaService; public void processSchemaMessages(Map<String, OperationType> schemaMsgs) throws IOException { try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { @@ -131,7 +131,7 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { String schema = (String) this.schemaCache.get(kind); if (Strings.isNullOrEmpty(schema)) { // get from storage - schema = this.schemaService.getSchema(kind); + schema = getSchema(kind); if (Strings.isNullOrEmpty(schema)) { Schema basicSchema = Schema.builder().kind(kind).build(); return normalizeSchema(gson.toJson(basicSchema)); @@ -161,6 +161,10 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { } } + protected String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { + return this.storageService.getStorageSchema(kind); + } + public void syncIndexMappingWithStorageSchema(String kind) throws ElasticsearchException, IOException, AppException { String index = this.elasticIndexNameResolver.getIndexNameFromKind(kind); try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageService.java index 8d8e5b8359f389e543b9fbc856342daa96074658..ab8e9901294893255b0f00a7632ee0145c37f1fa 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageService.java @@ -28,4 +28,6 @@ public interface StorageService { Records getStorageRecords(List<String> ids) throws AppException, URISyntaxException; RecordQueryResponse getRecordsByKind(RecordReindexRequest request) throws URISyntaxException; + + String getStorageSchema(String kind) throws URISyntaxException, UnsupportedEncodingException; } \ No newline at end of file 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 cf62530ca9948422f7929b137af68bf61e0bc3d0..9b287fd5952dc47ff6ea19317a653d50359225dc 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 @@ -68,6 +68,9 @@ public class StorageServiceImpl implements StorageService { @Inject private JaxRsDpsLog jaxRsDpsLog; + @Value("${STORAGE_SCHEMA_HOST}") + private String STORAGE_SCHEMA_HOST; + @Value("${STORAGE_QUERY_RECORD_HOST}") private String STORAGE_QUERY_RECORD_HOST; @@ -207,4 +210,15 @@ public class StorageServiceImpl implements StorageService { return this.gson.fromJson(response.getBody(), RecordQueryResponse.class); } + @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())); + FetchServiceHttpRequest request = FetchServiceHttpRequest.builder() + .httpMethod(HttpMethods.GET) + .headers(this.requestInfo.getHeadersMap()) + .url(url) + .build(); + HttpResponse response = this.urlFetchService.sendRequest(request); + return response.getResponseCode() != HttpStatus.SC_OK ? null : response.getBody(); + } } \ No newline at end of file diff --git a/provider/indexer-aws/src/main/resources/application.properties b/provider/indexer-aws/src/main/resources/application.properties index 31706b87e72a40110e99a5aa237536675b54e1ad..6e7d9c6f32304d2fb255c95e63239ec8f2964a55 100644 --- a/provider/indexer-aws/src/main/resources/application.properties +++ b/provider/indexer-aws/src/main/resources/application.properties @@ -22,7 +22,7 @@ aws.es.serviceName=es GAE_SERVICE=indexer -SCHEMA_HOST=${SCHEMA_HOST}/api/schema-service/v1/schema +STORAGE_SCHEMA_HOST=${STORAGE_HOST}/api/storage/v2/schemas STORAGE_QUERY_RECORD_HOST=${STORAGE_HOST}/api/storage/v2/query/records STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=${STORAGE_HOST}/api/storage/v2/query/records:batch STORAGE_RECORDS_BATCH_SIZE=20 diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/IndexSchemaServiceOverrideImpl.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/IndexSchemaServiceOverrideImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..82a9a05841b69d7907a9e4b3f39320f1853d09b2 --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/IndexSchemaServiceOverrideImpl.java @@ -0,0 +1,29 @@ +package org.opengroup.osdu.indexer.azure.di; + +import lombok.AccessLevel; +import lombok.experimental.FieldDefaults; +import org.opengroup.osdu.indexer.service.IndexSchemaServiceImpl; +import org.opengroup.osdu.indexer.service.SchemaService; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; + +@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) +@Primary +@Service +public class IndexSchemaServiceOverrideImpl extends IndexSchemaServiceImpl { + + private SchemaService schemaService; + + @Inject + public IndexSchemaServiceOverrideImpl(SchemaService schemaService) { + this.schemaService = schemaService; + } + + protected String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { + return this.schemaService.getSchema(kind); + } +} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/SchemaServiceTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/SchemaServiceTest.java index 7aa916a6b89854d1018666f1c3c1781e5f866b8d..f03644ef5b2be81412a99499fa3a42f899524017 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/SchemaServiceTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/SchemaServiceTest.java @@ -14,17 +14,21 @@ package org.opengroup.osdu.indexer.azure.service; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.opengroup.osdu.core.common.http.IUrlFetchService; import org.opengroup.osdu.core.common.model.http.HttpResponse; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.indexer.schema.converter.SchemaToStorageFormatImpl; import org.opengroup.osdu.indexer.service.impl.SchemaServiceImpl; import org.springframework.http.HttpStatus; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.test.context.junit4.SpringRunner; import java.util.HashMap; @@ -36,6 +40,10 @@ import static org.powermock.api.mockito.PowerMockito.when; @RunWith(SpringRunner.class) public class SchemaServiceTest { + private ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build(); + + @Spy + private SchemaToStorageFormatImpl schemaToStorageFormatImpl = new SchemaToStorageFormatImpl(objectMapper); @Mock private IUrlFetchService urlFetchService; @Mock diff --git a/provider/indexer-gcp/src/main/resources/application-dev.properties b/provider/indexer-gcp/src/main/resources/application-dev.properties index bc78449e46c2bd7fbb72c8289f8732eda5fb5fdf..61da3c7139e0f8e834b2ec5b90173b2c517d075d 100644 --- a/provider/indexer-gcp/src/main/resources/application-dev.properties +++ b/provider/indexer-gcp/src/main/resources/application-dev.properties @@ -3,8 +3,7 @@ GOOGLE_CLOUD_PROJECT=opendes INDEXER_HOST=os-indexer-dot-opendes.appspot.com STORAGE_HOSTNAME=os-storage-dot-opendes.appspot.com -SCHEMA_HOST=https://os-schema-dot-opendes.appspot.com/api/schema-service/v1/schema - +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 diff --git a/provider/indexer-gcp/src/main/resources/application-kuber.properties b/provider/indexer-gcp/src/main/resources/application-kuber.properties index feec48270e63c78e1f1c79ab090aaac4ac31b1b4..bc2a5f9014fa1b406a008e2cc69f161a8e3a9a8b 100644 --- a/provider/indexer-gcp/src/main/resources/application-kuber.properties +++ b/provider/indexer-gcp/src/main/resources/application-kuber.properties @@ -3,8 +3,7 @@ GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT} INDEXER_HOST=os-indexer-service STORAGE_HOSTNAME=os-storage-service -SCHEMA_HOST=http://os-schema-service/api/schema-service/v1/schema - +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 diff --git a/provider/indexer-gcp/src/main/resources/application-testing.properties b/provider/indexer-gcp/src/main/resources/application-testing.properties index 4394b428e1ccbe644ae5e16423b76c507370e1d6..fb0c9e2d6ce29c87dca6f58d1afec0b420c1e663 100644 --- a/provider/indexer-gcp/src/main/resources/application-testing.properties +++ b/provider/indexer-gcp/src/main/resources/application-testing.properties @@ -3,8 +3,7 @@ GOOGLE_CLOUD_PROJECT=opendes-evt INDEXER_HOST=os-indexer-dot-opendes-evt.appspot.com STORAGE_HOSTNAME=os-storage-dot-opendes-evt.appspot.com -SCHEMA_HOST=https://os-schema-dot-opendes-evt.appspot.com/api/schema-service/v1/schema - +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 diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java index 4a5da036fecbaf6159a217e19e504bc80e51eb84..434e9bc803383e3034c65b4d8ea66fccd60fb25c 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java @@ -66,8 +66,6 @@ public class IndexerSchemaServiceTest { @Mock private IndicesService indicesService; @Mock - private SchemaService schemaService; - @Mock private ISchemaCache schemaCache; @InjectMocks private IndexSchemaServiceImpl sut; @@ -81,7 +79,7 @@ public class IndexerSchemaServiceTest { @Test public void should_returnNull_givenEmptySchema_getIndexerInputSchemaSchemaTest() throws Exception { - when(schemaService.getSchema(any())).thenReturn(emptySchema); + when(storageService.getStorageSchema(any())).thenReturn(emptySchema); IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); @@ -90,7 +88,7 @@ public class IndexerSchemaServiceTest { @Test public void should_returnValidResponse_givenValidSchema_getIndexerInputSchemaTest() throws Exception { - when(schemaService.getSchema(any())).thenReturn(someSchema); + when(storageService.getStorageSchema(any())).thenReturn(someSchema); IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); @@ -99,7 +97,7 @@ public class IndexerSchemaServiceTest { @Test public void should_returnValidResponse_givenValidSchemaWithCacheHit_getIndexerInputSchemaTest() throws Exception { - when(schemaService.getSchema(any())).thenReturn(someSchema); + when(storageService.getStorageSchema(any())).thenReturn(someSchema); when(this.schemaCache.get(kind + "_flattened")).thenReturn(someSchema); IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); @@ -111,7 +109,7 @@ public class IndexerSchemaServiceTest { public void should_throw500_givenInvalidSchemaCacheHit_getIndexerInputSchemaTest() { try { String invalidSchema = "{}}"; - when(schemaService.getSchema(any())).thenReturn(invalidSchema); + when(storageService.getStorageSchema(any())).thenReturn(invalidSchema); this.sut.getIndexerInputSchema(kind, false); fail("Should throw exception"); @@ -166,7 +164,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); this.sut.processSchemaMessages(schemaMessages); @@ -197,7 +195,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); this.sut.processSchemaMessages(schemaMessages); @@ -225,7 +223,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())).thenThrow(new AppException(HttpStatus.SC_BAD_REQUEST, reason, "")); try { @@ -258,7 +256,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())).thenThrow(new AppException(HttpStatus.SC_FORBIDDEN, reason, "blah")); try { @@ -284,7 +282,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); this.sut.processSchemaMessages(schemaMessages); @@ -338,7 +336,7 @@ public class IndexerSchemaServiceTest { when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); when(this.indicesService.deleteIndex(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); this.sut.syncIndexMappingWithStorageSchema(kind); diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/SchemaServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/SchemaServiceTest.java deleted file mode 100644 index 4bf2795e80c7ee2a27f0b4ee1bbfc70dc4238c2c..0000000000000000000000000000000000000000 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/SchemaServiceTest.java +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2017-2019, 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 -// -// http://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.service; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentMatchers; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Spy; -import org.opengroup.osdu.core.common.http.IUrlFetchService; -import org.opengroup.osdu.core.common.model.http.HttpResponse; -import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; -import org.opengroup.osdu.indexer.schema.converter.SchemaToStorageFormatImpl; -import org.opengroup.osdu.indexer.service.impl.SchemaServiceImpl; -import org.springframework.http.HttpStatus; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.HashMap; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(SpringRunner.class) -public class SchemaServiceTest { - - private ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build(); - - @Spy - private SchemaToStorageFormatImpl schemaToStorageFormat = new SchemaToStorageFormatImpl(objectMapper); - - @Mock - private IUrlFetchService urlFetchService; - @Mock - private IRequestInfo requestInfo; - @InjectMocks - private SchemaServiceImpl sut; - - @Before - public void setup() { - when(this.requestInfo.getHeadersMap()).thenReturn(new HashMap<>()); - } - - @Test - public void should_returnValidResponse_givenValidKind_getSchemaByKind() throws Exception { - - String validSchemaFromSchemaService = "{\n" + - " \"data\":{\n" + - " \"allOf\":[\n" + - " {\n" + - " \"type\":\"object\",\n" + - " \"properties\":{\n" + - " \"WellID\":{\n" + - " \"type\":\"string\",\n" + - " \"pattern\":\"^srn:<namespace>:master-data\\\\/Well:[^:]+:[0-9]*$\"\n" + - " }\n" + - " }\n" + - " }\n" + - " ]\n" + - " }\n" + - "}"; - String kind = "tenant:test:test:1.0.0"; - - HttpResponse httpResponse = new HttpResponse(); - httpResponse.setResponseCode(HttpStatus.OK.value()); - httpResponse.setBody(validSchemaFromSchemaService); - - when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); - - String recordSchemaResponse = this.sut.getSchema(kind); - - assertNotNull(recordSchemaResponse); - } - - @Test - public void should_returnNullResponse_givenAbsentKind_getSchemaByKind() throws Exception { - - String kind = "tenant:test:test:1.0.0"; - - HttpResponse httpResponse = new HttpResponse(); - httpResponse.setResponseCode(HttpStatus.NOT_FOUND.value()); - - when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); - - String recordSchemaResponse = this.sut.getSchema(kind); - - assertNull(recordSchemaResponse); - } - -} 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 6872aad5324ae2ef3934f29b5ca3e5b5e7f3baca..e868e50c842262a4eba35f2fa49cad1c2aae3cf6 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 @@ -172,6 +172,51 @@ public class StorageServiceTest { assertNull(recordQueryResponse.getResults()); } + @Test + public void should_returnValidResponse_givenValidKind_getSchemaByKind() throws Exception { + + String validSchemaFromStorage = "{" + + " \"kind\": \"tenant:test:test:1.0.0\"," + + " \"schema\": [" + + " {" + + " \"path\": \"msg\"," + + " \"kind\": \"string\"" + + " }," + + " {" + + " \"path\": \"references.entity\"," + + " \"kind\": \"string\"" + + " }" + + " ]," + + " \"ext\": null" + + "}"; + String kind = "tenant:test:test:1.0.0"; + + HttpResponse httpResponse = new HttpResponse(); + httpResponse.setResponseCode(HttpStatus.OK.value()); + httpResponse.setBody(validSchemaFromStorage); + + when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); + + String recordSchemaResponse = this.sut.getStorageSchema(kind); + + assertNotNull(recordSchemaResponse); + } + + @Test + public void should_returnNullResponse_givenAbsentKind_getSchemaByKind() throws Exception { + + String kind = "tenant:test:test:1.0.0"; + + HttpResponse httpResponse = new HttpResponse(); + httpResponse.setResponseCode(HttpStatus.NOT_FOUND.value()); + + when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); + + String recordSchemaResponse = this.sut.getStorageSchema(kind); + + assertNull(recordSchemaResponse); + } + @Test public void should_returnOneValidRecords_givenValidData_getValidStorageRecordsWithInvalidConversionTest() throws URISyntaxException { diff --git a/provider/indexer-ibm/src/main/resources/application.properties b/provider/indexer-ibm/src/main/resources/application.properties index d84c894a183ab22088b4d299e6355b1759a06a2b..9a7a16cc4942744aea51f9e54bc4bae855892b8d 100644 --- a/provider/indexer-ibm/src/main/resources/application.properties +++ b/provider/indexer-ibm/src/main/resources/application.properties @@ -26,11 +26,9 @@ KINDS_REDIS_DATABASE=1 CRON_INDEX_CLEANUP_THRESHOLD_DAYS=3 CRON_EMPTY_INDEX_CLEANUP_THRESHOLD_DAYS=7 -schema_service_url=http://localhost:8083 -SCHEMA_HOST=${schema_service_url}/api/schema-service/v1/schema - storage_service_url=http://localhost:8082 #storage_service_url=https://os-storage-ibm-osdu-r2.osduadev-a1c3eaf78a86806e299f5f3f207556f0-0000.us-south.containers.appdomain.cloud +STORAGE_SCHEMA_HOST=${storage_service_url}/api/storage/v2/schemas STORAGE_QUERY_RECORD_HOST=${storage_service_url}/api/storage/v2/query/records STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=${storage_service_url}/api/storage/v2/query/records:batch STORAGE_RECORDS_BATCH_SIZE=20 diff --git a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/IndexerSchemaServiceTest.java b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/IndexerSchemaServiceTest.java index 1f9a3c565366ad63074fa1a38af8d2203ae20a6e..db2eb01d13ab616671c3a6e855d13c67a4e7ed94 100644 --- a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/IndexerSchemaServiceTest.java +++ b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/IndexerSchemaServiceTest.java @@ -29,7 +29,6 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.opengroup.osdu.indexer.service.IndexSchemaServiceImpl; import org.opengroup.osdu.indexer.service.IndexerMappingService; -import org.opengroup.osdu.indexer.service.SchemaService; import org.opengroup.osdu.indexer.service.StorageService; import org.opengroup.osdu.core.common.model.http.RequestStatus; import org.opengroup.osdu.core.common.search.IndicesService; @@ -73,8 +72,6 @@ public class IndexerSchemaServiceTest { @Mock private IndicesService indicesService; @Mock - private SchemaService schemaService; - @Mock private ISchemaCache schemaCache; @InjectMocks private IndexSchemaServiceImpl sut; @@ -88,7 +85,7 @@ public class IndexerSchemaServiceTest { @Test public void should_returnNull_givenEmptySchema_getIndexerInputSchemaSchemaTest() throws Exception { - when(schemaService.getSchema(any())).thenReturn(emptySchema); + when(storageService.getStorageSchema(any())).thenReturn(emptySchema); IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); @@ -97,7 +94,7 @@ public class IndexerSchemaServiceTest { @Test public void should_returnValidResponse_givenValidSchema_getIndexerInputSchemaTest() throws Exception { - when(schemaService.getSchema(any())).thenReturn(someSchema); + when(storageService.getStorageSchema(any())).thenReturn(someSchema); IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); @@ -106,7 +103,7 @@ public class IndexerSchemaServiceTest { @Test public void should_returnValidResponse_givenValidSchemaWithCacheHit_getIndexerInputSchemaTest() throws Exception { - when(schemaService.getSchema(any())).thenReturn(someSchema); + when(storageService.getStorageSchema(any())).thenReturn(someSchema); when(this.schemaCache.get(kind + "_flattened")).thenReturn(someSchema); IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); @@ -118,7 +115,7 @@ public class IndexerSchemaServiceTest { public void should_throw500_givenInvalidSchemaCacheHit_getIndexerInputSchemaTest() { try { String invalidSchema = "{}}"; - when(schemaService.getSchema(any())).thenReturn(invalidSchema); + when(storageService.getStorageSchema(any())).thenReturn(invalidSchema); this.sut.getIndexerInputSchema(kind, false); fail("Should throw exception"); @@ -173,7 +170,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); this.sut.processSchemaMessages(schemaMessages); @@ -204,7 +201,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); this.sut.processSchemaMessages(schemaMessages); @@ -232,7 +229,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())).thenThrow(new AppException(HttpStatus.SC_BAD_REQUEST, reason, "")); try { @@ -265,7 +262,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())).thenThrow(new AppException(HttpStatus.SC_FORBIDDEN, reason, "blah")); try { @@ -291,7 +288,7 @@ public class IndexerSchemaServiceTest { when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); this.sut.processSchemaMessages(schemaMessages); @@ -345,7 +342,7 @@ public class IndexerSchemaServiceTest { when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); when(this.indicesService.deleteIndex(any(), any())).thenReturn(true); - when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); + when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); this.sut.syncIndexMappingWithStorageSchema(kind); diff --git a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/SchemaServiceTest.java b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/SchemaServiceTest.java deleted file mode 100644 index a2e0fbe02139e4b12ffac7334461ca673927f7d9..0000000000000000000000000000000000000000 --- a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/SchemaServiceTest.java +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2017-2019, 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 -// -// http://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.ibm.service; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentMatchers; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.opengroup.osdu.core.common.http.IUrlFetchService; -import org.opengroup.osdu.core.common.model.http.HttpResponse; -import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; -import org.opengroup.osdu.indexer.service.impl.SchemaServiceImpl; -import org.springframework.http.HttpStatus; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.HashMap; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(SpringRunner.class) -public class SchemaServiceTest { - @Mock - private IUrlFetchService urlFetchService; - @Mock - private IRequestInfo requestInfo; - @InjectMocks - private SchemaServiceImpl sut; - - @Before - public void setup() { - when(this.requestInfo.getHeadersMap()).thenReturn(new HashMap<>()); - } - - @Test - public void should_returnValidResponse_givenValidKind_getSchemaByKind() throws Exception { - - String validSchemaFromSchemaService = "{\n" + - " \"data\":{\n" + - " \"allOf\":[\n" + - " {\n" + - " \"type\":\"object\",\n" + - " \"properties\":{\n" + - " \"WellID\":{\n" + - " \"type\":\"string\",\n" + - " \"pattern\":\"^srn:<namespace>:master-data\\\\/Well:[^:]+:[0-9]*$\"\n" + - " }\n" + - " }\n" + - " }\n" + - " ]\n" + - " }\n" + - "}"; - String kind = "tenant:test:test:1.0.0"; - - HttpResponse httpResponse = new HttpResponse(); - httpResponse.setResponseCode(HttpStatus.OK.value()); - httpResponse.setBody(validSchemaFromSchemaService); - - when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); - - String recordSchemaResponse = this.sut.getSchema(kind); - - assertNotNull(recordSchemaResponse); - } - - @Test - public void should_returnNullResponse_givenAbsentKind_getSchemaByKind() throws Exception { - - String kind = "tenant:test:test:1.0.0"; - - HttpResponse httpResponse = new HttpResponse(); - httpResponse.setResponseCode(HttpStatus.NOT_FOUND.value()); - - when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); - - String recordSchemaResponse = this.sut.getSchema(kind); - - assertNull(recordSchemaResponse); - } -} diff --git a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/StorageServiceTest.java b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/StorageServiceTest.java index b0164281640b39b88f291a8a6db975dc0b58a954..013a5a7210806127947185924268cda94e7166cc 100644 --- a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/StorageServiceTest.java +++ b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/StorageServiceTest.java @@ -154,6 +154,51 @@ public class StorageServiceTest { verify(this.jobStatus).addOrUpdateRecordStatus(RECORDS_ID2, IndexingStatus.WARN, HttpStatus.BAD_REQUEST.value(), "crs conversion failed", String.format("record-id: %s | %s", "tenant1:doc:15e790a69beb4d789b1f979e2af2e813", "crs conversion failed")); } + @Test + public void should_returnValidResponse_givenValidKind_getSchemaByKind() throws Exception { + + String validSchemaFromStorage = "{" + + " \"kind\": \"tenant:test:test:1.0.0\"," + + " \"schema\": [" + + " {" + + " \"path\": \"msg\"," + + " \"kind\": \"string\"" + + " }," + + " {" + + " \"path\": \"references.entity\"," + + " \"kind\": \"string\"" + + " }" + + " ]," + + " \"ext\": null" + + "}"; + String kind = "tenant:test:test:1.0.0"; + + HttpResponse httpResponse = new HttpResponse(); + httpResponse.setResponseCode(HttpStatus.OK.value()); + httpResponse.setBody(validSchemaFromStorage); + + when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); + + String recordSchemaResponse = this.sut.getStorageSchema(kind); + + assertNotNull(recordSchemaResponse); + } + + @Test + public void should_returnNullResponse_givenAbsentKind_getSchemaByKind() throws Exception { + + String kind = "tenant:test:test:1.0.0"; + + HttpResponse httpResponse = new HttpResponse(); + httpResponse.setResponseCode(HttpStatus.NOT_FOUND.value()); + + when(this.urlFetchService.sendRequest(ArgumentMatchers.any())).thenReturn(httpResponse); + + String recordSchemaResponse = this.sut.getStorageSchema(kind); + + assertNull(recordSchemaResponse); + } + @Test public void should_returnOneValidRecords_givenValidData_getValidStorageRecordsWithInvalidConversionTest() throws URISyntaxException {