Commit 4c5c4f68 authored by Hema Vishnu Pola [Microsoft]'s avatar Hema Vishnu Pola [Microsoft]
Browse files

Merge branch 'haaggarw/FixingStorageURLForIT' into 'master'

Fixing Environment Variables and increasing logging coverage

See merge request osdu/platform/data-flow/enrichment/wks!13
parents 015f4336 e545e551
Pipeline #9968 failed with stages
in 0 seconds
......@@ -106,7 +106,7 @@ spec:
- name: server_port
value: "80"
- name: storage_service_endpoint
value: "http://osdu-flux-storage/api/storage/v2"
value: "http://storage/api/storage/v2"
- name: max_concurrent_calls
value: "1"
- name: executor_n_threads
......
......@@ -350,8 +350,9 @@ public class IntegrationTestStepDefs implements En {
JsonElement jsonBody = new Gson().fromJson(payload, JsonElement.class);
payload = new Gson().toJson(jsonBody);
this.context.setInputPayload(payload);
// Changing environment variable name to STORAGE_URL to maintain consistancy in naming
String storageURL = System.getProperty("STORAGE_URL", System.getenv("STORAGE_URL"));
// Changing environment variable name to STORAGE_URL to maintain consistency in naming
// Adding regex to removing any trailing slashes in Storage host url
String storageURL = System.getProperty("STORAGE_URL", System.getenv("STORAGE_URL")).replaceAll("/$", "");
HttpRequest httpRequest = HttpRequest.builder().url(storageURL + AutomationConstants.POST_ENDPOINT)
.body(jsonBody.toString()).httpMethod(HttpRequest.PUT).requestHeaders(this.context.getAuthHeaders())
.build();
......@@ -361,8 +362,9 @@ public class IntegrationTestStepDefs implements En {
}
private void deleteFromStorage(String recordId) {
String storageURL = System.getProperty("STORAGE_URL", System.getenv("STORAGE_URL"))
String storageURL = System.getProperty("STORAGE_URL", System.getenv("STORAGE_URL")).replaceAll("/$", "")
+ AutomationConstants.DELETE_ENDPOINT + recordId;
HttpRequest httpRequest = HttpRequest.builder().url(storageURL)
.httpMethod(HttpRequest.DELETE).requestHeaders(this.context.getAuthHeaders())
.build();
......@@ -377,7 +379,7 @@ public class IntegrationTestStepDefs implements En {
}
private String storageGetResponse(String recordId) {
String reqURI = System.getProperty("STORAGE_URL", System.getenv("STORAGE_URL"))
String reqURI = System.getProperty("STORAGE_URL", System.getenv("STORAGE_URL")).replaceAll("/$", "")
+ AutomationConstants.GET_ENDPOINT + recordId;
HttpRequest httpRequest = HttpRequest.builder().url(reqURI).httpMethod(HttpRequest.GET)
.requestHeaders(this.context.getAuthHeaders()).build();
......
......@@ -2,6 +2,7 @@ package org.opengroup.osdu.wks.service;
import java.util.Arrays;
import lombok.extern.java.Log;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
......@@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
@Log
@Service
public class StorageServiceImpl implements StorageService {
......@@ -92,6 +94,7 @@ public class StorageServiceImpl implements StorageService {
private void verifyResponseStatus(RestResponse response) throws ApplicationException {
if (response.getStatus() != HttpStatus.SC_CREATED) {
log.warning(response.getException());
throw new ApplicationException(response.getException());
}
}
......
......@@ -95,6 +95,7 @@ public class WKSServiceImpl implements WKSService {
throws ApplicationException {
MappingsModel mappings = mappingsMap.get(rawRecord.getKind());
if (isEmptyMappings(mappings)) {
log.warning(String.format(Constants.NO_MAPPING_FOR_KIND, rawRecord.getKind()));
throw new ApplicationException(String.format(Constants.NO_MAPPING_FOR_KIND, rawRecord.getKind()));
}
return mappings;
......@@ -102,6 +103,7 @@ public class WKSServiceImpl implements WKSService {
private void validateTransformRecord(Tree wksRecordTree) throws ApplicationException {
if (wksRecordTree == null || wksRecordTree.isEmpty()) {
log.warning(Constants.COULD_NOT_TRANSFORM);
throw new ApplicationException(Constants.COULD_NOT_TRANSFORM);
}
}
......@@ -118,6 +120,7 @@ public class WKSServiceImpl implements WKSService {
String rawRecordJsonStr = storageService.getRecord(rawRecord.getId(), dataPartitionId, correlationId);
Tree rawRecordTree = convertJsonStringToTree(rawRecordJsonStr);
if (rawRecordTree.isEmpty()) {
log.warning(Constants.RAW_RECORD_NOT_PRESENT + Constants.DASH + rawRecord.getId());
throw new ApplicationException(Constants.RAW_RECORD_NOT_PRESENT);
}
return rawRecordTree;
......@@ -146,12 +149,15 @@ public class WKSServiceImpl implements WKSService {
|| StringUtils.isBlank(rawRecordsDetails[0].getId())
|| StringUtils.isBlank(rawRecordsDetails[0].getKind())
|| StringUtils.isBlank(rawRecordsDetails[0].getOp())) {
log.warning(Constants.MISSING_RAW_RECORD_DETAILS);
throw new BadRequestException(Constants.MISSING_RAW_RECORD_DETAILS);
}
if (StringUtils.isBlank(dataPartitionId)) {
log.warning(Constants.DATA_PARTITION_ID_NEEDED);
throw new BadRequestException(Constants.DATA_PARTITION_ID_NEEDED);
}
if (StringUtils.isBlank(correlationId)) {
log.warning(Constants.CORRELATION_ID_NEEDED);
throw new BadRequestException(Constants.CORRELATION_ID_NEEDED);
}
}
......
......@@ -2,6 +2,7 @@ package org.opengroup.osdu.wks.util;
import java.util.concurrent.TimeUnit;
import lombok.extern.java.Log;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpException;
import org.opengroup.osdu.wks.constants.Constants;
......@@ -17,6 +18,7 @@ import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
@Log
@Component
public class RestClient {
......@@ -53,6 +55,7 @@ public class RestClient {
validate(requestParameters.getUrl());
submitRequest(requestParameters.getUrl(), requestParameters.getMethod(), request, retryCounter);
} catch (Exception e) {
log.warning(e.toString());
restResponse.setException(e.toString());
}
return restResponse;
......@@ -60,6 +63,7 @@ public class RestClient {
private void validate(String url) {
if (StringUtils.isBlank(url)) {
log.warning("URL is null or empty string.");
throw new RestClientException("'URL' is null or empty string.");
}
}
......@@ -107,6 +111,7 @@ public class RestClient {
} catch (HttpServerErrorException e) {
if (retryCounter == 0) {
log.warning("Error while processing request: " + e.getMessage());
throw new HttpException("Error while processing request: " + e.getMessage());
}
......@@ -114,6 +119,7 @@ public class RestClient {
submitRequest(url, method, request, retryCounter - 1);
} catch (RestClientException e) {
log.warning("Error while processing request: " + e.getMessage());
throw new HttpException("Error while processing request: " + e.getMessage());
}
}
......
......@@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.java.Log;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.opengroup.osdu.wks.constants.Constants;
......@@ -22,6 +23,7 @@ import io.datatree.Tree;
* This class do transformation of raw record to wks record
*
*/
@Log
@Component
public class WksTransformator {
......@@ -134,16 +136,19 @@ public class WksTransformator {
private void validateMappings(MappingsModel mappings) throws ApplicationException {
if (mappings == null || ArrayUtils.isEmpty(mappings.getAttributeMappings())) {
log.warning(MAPPING_NOT_PRESENT);
throw new ApplicationException(MAPPING_NOT_PRESENT);
}
if (StringUtils.isBlank(mappings.getWksSchemaKind())) {
log.warning(WKS_SCHEMA_KIND_NOT_PRESENT);
throw new ApplicationException(WKS_SCHEMA_KIND_NOT_PRESENT);
}
}
private void validateRawRecord(Tree rawRecordTree) throws ApplicationException {
if (rawRecordTree.isEmpty()) {
log.warning(RAW_RECORD_NOT_PRESENT);
throw new ApplicationException(RAW_RECORD_NOT_PRESENT);
}
validateForMandatoryAttributes(rawRecordTree);
......@@ -154,6 +159,7 @@ public class WksTransformator {
List<String> missingAttributes = retrieveMissingMandatoryAttributes(rawRecordTree, requiredAttributes);
if (ArrayUtils.isNotEmpty(missingAttributes.toArray())) {
log.warning(REQUIRED_ATTRIBUTES_ARE_MISSING_IN_RECORD + missingAttributes);
throw new ApplicationException(REQUIRED_ATTRIBUTES_ARE_MISSING_IN_RECORD + missingAttributes);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment