Skip to content
Snippets Groups Projects
Commit 9fdd1459 authored by Pavel Bachyla's avatar Pavel Bachyla
Browse files

Merge remote-tracking branch 'osdu-delfi/schema-adoption' into use-schema-for-it

parents 13b1c83e cdfca88f
No related branches found
No related tags found
1 merge request!60Indexer to read from Schema Service as well as Storage Schema
......@@ -17,6 +17,8 @@ package org.opengroup.osdu.indexer.schema.converter;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import lombok.extern.java.Log;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.search.Preconditions;
import org.opengroup.osdu.indexer.schema.converter.tags.AllOfItem;
import org.opengroup.osdu.indexer.schema.converter.tags.Definition;
......@@ -97,7 +99,9 @@ class PropertiesProcessor {
}
Definition definition = definitions.getDefinition(definitionSubRef);
Optional.ofNullable(definition).orElseThrow(() -> new RuntimeException("Failed to find definition"));
Optional.ofNullable(definition).orElseThrow(() ->
new AppException(HttpStatus.SC_NOT_FOUND, "Failed to find definition:" + definitionSubRef,
"Unknown definition:" + definitionSubRef));
return definition.getProperties().entrySet().stream().flatMap(this::processPropertyEntry);
}
......
......@@ -19,6 +19,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import lombok.extern.java.Log;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.search.Preconditions;
import org.opengroup.osdu.indexer.schema.converter.interfaces.SchemaToStorageFormat;
import org.opengroup.osdu.indexer.schema.converter.tags.*;
......@@ -64,7 +66,7 @@ public class SchemaToStorageFormatImpl implements SchemaToStorageFormat {
try {
return objectMapper.readValue(schemaServiceFormat, SchemaRoot.class);
} catch (JsonProcessingException e) {
throw new RuntimeException("Failed to load schema", e);
throw new AppException(HttpStatus.SC_BAD_REQUEST, "Loading shchem error", "Failed to load schema", e);
}
}
......@@ -72,7 +74,7 @@ public class SchemaToStorageFormatImpl implements SchemaToStorageFormat {
try {
return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(schemaServiceFormat);
} catch (JsonProcessingException e) {
throw new RuntimeException("Failed to save JSON file", e);
throw new AppException(HttpStatus.SC_UNPROCESSABLE_ENTITY, "Saving JSON error", "Failed to save a JSON file", e);
}
}
......
......@@ -15,6 +15,7 @@
package org.opengroup.osdu.indexer.service.impl;
import com.google.api.client.http.HttpMethods;
import lombok.extern.java.Log;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.http.FetchServiceHttpRequest;
import org.opengroup.osdu.core.common.http.IUrlFetchService;
......@@ -36,6 +37,7 @@ import java.nio.charset.StandardCharsets;
* Provides implementation of the client service that retrieves schemas from the Schema Service
*/
@Component
@Log
public class SchemaServiceImpl implements SchemaService {
@Inject
private IUrlFetchService urlFetchService;
......@@ -63,9 +65,12 @@ public class SchemaServiceImpl implements SchemaService {
HttpResponse response = this.urlFetchService.sendRequest(request);
if (response.getResponseCode() == HttpStatus.SC_NOT_FOUND) {
log.info("Schema is not found on Schema Service:" + kind);
return storageService.getStorageSchema(kind);
}
log.info("Schema is found on the Schema Service:" + kind);
return response.getResponseCode() != HttpStatus.SC_OK ? null :
schemaToStorageFormat.convertToString(response.getBody(), kind);
}
......
......@@ -34,6 +34,7 @@ KINDS_REDIS_DATABASE=1
CRON_INDEX_CLEANUP_THRESHOLD_DAYS=3
CRON_EMPTY_INDEX_CLEANUP_THRESHOLD_DAYS=7
schema_service_endpoint=https://evd-mvp.managed-osdu.cloud.slb-ds.com/api/schema-service/v1
schema_service_url=${schema_service_endpoint}
SCHEMA_HOST=${schema_service_url}/schema
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment