Skip to content
Snippets Groups Projects
Commit e370debb authored by Sviatoslav Nekhaienko's avatar Sviatoslav Nekhaienko
Browse files

add more methods

parent e5a93b9f
No related branches found
No related tags found
1 merge request!60Indexer to read from Schema Service as well as Storage Schema
...@@ -56,21 +56,17 @@ public class SchemaServiceImpl implements SchemaService { ...@@ -56,21 +56,17 @@ public class SchemaServiceImpl implements SchemaService {
@Override @Override
public String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { public String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException {
String schemaFromStorageService = storageService.getStorageSchema(kind); String schemaFromStorageService = getFromStorageService(kind);
if (schemaFromStorageService != null) { if (schemaFromStorageService != null) {
return schemaFromStorageService; return schemaFromStorageService;
} }
log.warning("Schema is not found on the Storage Service:" + kind); return getFromSchemaService(kind);
}
String url = String.format("%s/%s", SCHEMA_HOST, URLEncoder.encode(kind, StandardCharsets.UTF_8.toString())); private String getFromSchemaService(String kind) throws UnsupportedEncodingException, URISyntaxException {
FetchServiceHttpRequest request = FetchServiceHttpRequest.builder() HttpResponse response = getSchemaServiceResponse(kind);
.httpMethod(HttpMethods.GET)
.headers(this.requestInfo.getHeadersMap())
.url(url)
.build();
HttpResponse response = this.urlFetchService.sendRequest(request);
if (response.getResponseCode() == HttpStatus.SC_NOT_FOUND) { if (response.getResponseCode() == HttpStatus.SC_NOT_FOUND) {
log.warning("Schema is not found on the Schema Service:" + kind); log.warning("Schema is not found on the Schema Service:" + kind);
...@@ -80,4 +76,28 @@ public class SchemaServiceImpl implements SchemaService { ...@@ -80,4 +76,28 @@ public class SchemaServiceImpl implements SchemaService {
return response.getResponseCode() != HttpStatus.SC_OK ? null : return response.getResponseCode() != HttpStatus.SC_OK ? null :
schemaToStorageFormat.convertToString(response.getBody(), kind); schemaToStorageFormat.convertToString(response.getBody(), kind);
} }
private String getFromStorageService(String kind) throws URISyntaxException, UnsupportedEncodingException {
String schemaFromStorageService = storageService.getStorageSchema(kind);
if (schemaFromStorageService != null) {
return schemaFromStorageService;
}
log.warning("Schema is not found on the Storage Service:" + kind);
return null;
}
private HttpResponse getSchemaServiceResponse(String kind) throws UnsupportedEncodingException, URISyntaxException {
String url = String.format("%s/%s", SCHEMA_HOST, URLEncoder.encode(kind, StandardCharsets.UTF_8.toString()));
FetchServiceHttpRequest request = FetchServiceHttpRequest.builder()
.httpMethod(HttpMethods.GET)
.headers(this.requestInfo.getHeadersMap())
.url(url)
.build();
return this.urlFetchService.sendRequest(request);
}
} }
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