Commit 9ecbfbdf authored by harshit aggarwal's avatar harshit aggarwal
Browse files

adding logging changes

parent b5b2c088
Pipeline #21772 passed with stages
in 12 minutes and 37 seconds
......@@ -101,8 +101,8 @@ spec:
- name: default_tenant
value: {{ .Values.default_tenant }}
- name: max_concurrent_calls
value: "16"
value: "32"
- name: executor_n_threads
value: "16"
value: "32"
- name: max_lock_renew_duration_seconds
value: "600"
package org.opengroup.osdu.wks;
import java.util.logging.Level;
import org.opengroup.osdu.wks.config.ThreadScopeBeanFactoryPostProcessor;
import org.opengroup.osdu.wks.provider.interfaces.SubscriptionManager;
import org.opengroup.osdu.wks.service.SchemaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......@@ -12,15 +13,13 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;
import lombok.extern.java.Log;
@Log
@SpringBootApplication
@ComponentScan(value = {
"org.opengroup.osdu"
})
public class WksServiceApplication {
private final static Logger LOGGER = LoggerFactory.getLogger(SchemaService.class);
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(WksServiceApplication.class, args);
try {
......@@ -29,8 +28,7 @@ public class WksServiceApplication {
}
catch (Exception e)
{
log.severe(e.getMessage());
log.log(Level.FINE, e.getMessage(), e);
LOGGER.error(e.getMessage(), e);
}
}
......
......@@ -17,6 +17,8 @@ import org.opengroup.osdu.wks.model.SchemaInfoResponse;
import org.opengroup.osdu.wks.provider.interfaces.UserCredential;
import org.opengroup.osdu.wks.util.KindUtil;
import org.opengroup.osdu.wks.util.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
......@@ -28,6 +30,7 @@ import java.util.List;
@Component
public class SchemaService implements ISchemaService{
private final static Logger LOGGER = LoggerFactory.getLogger(SchemaService.class);
private static final String SCHEMA_SERVICE_ERROR_MESSAGE = "Schema service status code %s and message %s";
@Autowired
......@@ -94,6 +97,7 @@ public class SchemaService implements ISchemaService{
return kinds;
}
catch (JsonProcessingException exception) {
LOGGER.warn(exception.getMessage(), exception);
throw new ApplicationException(exception.getMessage(), exception.getCause());
}
}
......@@ -113,6 +117,7 @@ public class SchemaService implements ISchemaService{
return uriBuilder.build().toString();
}
catch (URISyntaxException exception) {
LOGGER.warn(exception.getMessage(), exception);
throw new ApplicationException(exception.getMessage(), exception.getCause());
}
......
......@@ -13,16 +13,16 @@ import org.opengroup.osdu.wks.model.RequestParameters;
import org.opengroup.osdu.wks.model.RestResponse;
import org.opengroup.osdu.wks.provider.interfaces.UserCredential;
import org.opengroup.osdu.wks.util.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import lombok.extern.java.Log;
@Log
@Service
public class StorageServiceImpl implements StorageService {
private final static Logger LOGGER = LoggerFactory.getLogger(StorageServiceImpl.class);
@Autowired
private RestClient restClient;
......@@ -96,13 +96,14 @@ private String getAuthKey(TenantInfo tenantInfo) {
try {
return userCrendential.getIdToken(tenantInfo);
} catch(ApplicationException e) {
LOGGER.warn(e.getErrorMsg(), e);
throw new AuthorizationException(e);
}
}
private void verifyResponseStatus(RestResponse response) throws ApplicationException {
if (response.getStatus() != HttpStatus.SC_CREATED) {
log.warning(response.getException());
LOGGER.warn(response.getException());
throw new ApplicationException(response.getException());
}
}
......
......@@ -6,8 +6,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -24,18 +22,19 @@ import org.opengroup.osdu.wks.model.TransformationResult;
import org.opengroup.osdu.wks.provider.interfaces.StatusStoreService;
import org.opengroup.osdu.wks.util.KindUtil;
import org.opengroup.osdu.wks.util.WksTransformator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.datatree.Tree;
import lombok.extern.java.Log;
@Log
@Service("wKSService")
public class WKSServiceImpl implements WKSService {
private final static Logger LOGGER = LoggerFactory.getLogger(WKSServiceImpl.class);
private static final int SOURCE_INDEX = 1;
private static final String UPDATE = "update";
private static final String CREATE = "create";
......@@ -106,13 +105,12 @@ public class WKSServiceImpl implements WKSService {
}
if (invalidOpCodeCount > 0) {
log.log(Level.INFO, String.format(Constants.NOT_CREATE_OR_UPDATE_OPERATION, invalidOpCodeCount,
LOGGER.info(String.format(Constants.NOT_CREATE_OR_UPDATE_OPERATION, invalidOpCodeCount,
rawRecordsDetails.length));
}
if (invalidSourceCount > 0) {
log.log(Level.INFO,
String.format(Constants.TRANFORMATION_ALREADY_DONE, invalidSourceCount, rawRecordsDetails.length));
LOGGER.info(String.format(Constants.TRANFORMATION_ALREADY_DONE, invalidSourceCount, rawRecordsDetails.length));
}
return rawRecordsDetailsList.toArray(new RawRecordDetails[0]);
......@@ -144,19 +142,17 @@ public class WKSServiceImpl implements WKSService {
}
wksRecordTreeList.add(wksRecordTree);
log.log(Level.INFO, String.format(Constants.TRANFORMATION_SUCCESSFUL, rawRecord.getId(),
LOGGER.info(String.format(Constants.TRANFORMATION_SUCCESSFUL, rawRecord.getId(),
wksRecordTree.get(ID).asString(), wksRecordTree.get(KIND)));
}
catch (ApplicationException e) {
log.log(Level.WARNING,
String.format(Constants.TRANSFORMATION_FAILED_FOR_GIVEN_WKS_KIND, rawRecord.getId(), mappings.getTargetSchemaKind(), e.getErrorMsg()));
LOGGER.warn(String.format(Constants.TRANSFORMATION_FAILED_FOR_GIVEN_WKS_KIND, rawRecord.getId(), mappings.getTargetSchemaKind(), e.getErrorMsg()), e);
}
}
} catch (ApplicationException e) {
log.log(Level.WARNING,
String.format(Constants.TRANFORMATION_FAILED, rawRecord.getId(), e.getErrorMsg()));
LOGGER.warn(String.format(Constants.TRANFORMATION_FAILED, rawRecord.getId(), e.getErrorMsg()), e);
}
}
......@@ -166,7 +162,7 @@ public class WKSServiceImpl implements WKSService {
statusStoreService.createOrUpdateStoreEntry(relationshipStatusList);
}
}
log.log(Level.INFO, Constants.TRANFORMATION_PROCESS_COMPLETED);
LOGGER.info(Constants.TRANFORMATION_PROCESS_COMPLETED);
}
private List<MappingsModel> updateMappingsWithLatestMinorAndPatchVersions(List<MappingsModel> mappingsList) throws ApplicationException {
......@@ -175,7 +171,7 @@ public class WKSServiceImpl implements WKSService {
List<String> schemaKindsWithLatestMinorAndPatchVersions = schemaService.getSchemas(mappingsModel.getTargetSchemaKind());
mappingsModel.setTargetSchemaKind(schemaKindsWithLatestMinorAndPatchVersions.get(0));
}
log.log(Level.INFO, "Schemas for WKS fetched with latest minor and patch versions");
LOGGER.info("Schemas for WKS fetched with latest minor and patch versions");
return mappingsList;
}
......@@ -188,7 +184,7 @@ public class WKSServiceImpl implements WKSService {
throws ApplicationException {
List<MappingsModel> mappings = mappingsMap.get(rawRecord.getKind());
if (isEmptyMappings(mappings)) {
log.warning(String.format(Constants.NO_MAPPING_FOR_KIND, rawRecord.getKind()));
LOGGER.warn(String.format(Constants.NO_MAPPING_FOR_KIND, rawRecord.getKind()));
throw new ApplicationException(String.format(Constants.NO_MAPPING_FOR_KIND, rawRecord.getKind()));
}
return mappings;
......@@ -196,7 +192,7 @@ public class WKSServiceImpl implements WKSService {
private void validateTransformRecord(Tree wksRecordTree) throws ApplicationException {
if (wksRecordTree == null || wksRecordTree.isEmpty()) {
log.warning(Constants.COULD_NOT_TRANSFORM);
LOGGER.warn(Constants.COULD_NOT_TRANSFORM);
throw new ApplicationException(Constants.COULD_NOT_TRANSFORM);
}
}
......@@ -205,7 +201,7 @@ public class WKSServiceImpl implements WKSService {
throws ApplicationException {
String message = this.storageService.putRecords(convertTreeListToJsonStrArr(wksRecordTreeList),
dataPartitionId, correlationId);
log.info(message);
LOGGER.info(message);
}
private Tree retrieveRawRecordTree(RawRecordDetails rawRecord)
......@@ -213,14 +209,14 @@ public class WKSServiceImpl implements WKSService {
Optional<String> optionalRawRecord = storageService.getRecord(rawRecord.getId());
if (!optionalRawRecord.isPresent()) {
log.severe(Constants.RAW_RECORD_NOT_PRESENT);
LOGGER.warn(Constants.RAW_RECORD_NOT_PRESENT);
throw new BadRequestException(Constants.RAW_RECORD_NOT_PRESENT);
}
String rawRecordJsonStr = optionalRawRecord.get();
Tree rawRecordTree = convertJsonStringToTree(rawRecordJsonStr);
if (rawRecordTree.isEmpty()) {
log.severe(Constants.RAW_RECORD_NOT_PRESENT);
LOGGER.warn(Constants.RAW_RECORD_NOT_PRESENT);
throw new ApplicationException(Constants.RAW_RECORD_NOT_PRESENT);
}
return rawRecordTree;
......@@ -249,15 +245,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);
LOGGER.warn(Constants.MISSING_RAW_RECORD_DETAILS);
throw new BadRequestException(Constants.MISSING_RAW_RECORD_DETAILS);
}
if (StringUtils.isBlank(dataPartitionId)) {
log.warning(Constants.DATA_PARTITION_ID_NEEDED);
LOGGER.warn(Constants.DATA_PARTITION_ID_NEEDED);
throw new BadRequestException(Constants.DATA_PARTITION_ID_NEEDED);
}
if (StringUtils.isBlank(correlationId)) {
log.warning(Constants.CORRELATION_ID_NEEDED);
LOGGER.warn(Constants.CORRELATION_ID_NEEDED);
throw new BadRequestException(Constants.CORRELATION_ID_NEEDED);
}
}
......@@ -280,7 +276,7 @@ public class WKSServiceImpl implements WKSService {
try {
map = mapper.readValue(jsonStr, Map.class);
} catch (IOException e) {
log.warning("Could not convert json string to map");
LOGGER.warn("Could not convert json string to map", e);
}
}
return new Tree(map);
......
......@@ -8,11 +8,12 @@ import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.datatree.Tree;
import lombok.extern.java.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Log
public class JsonTreeUtil {
private final static Logger LOGGER = LoggerFactory.getLogger(JsonTreeUtil.class);
private JsonTreeUtil(){
throw new IllegalStateException("JsonTreeUtil should not be instantiated");
}
......@@ -25,7 +26,7 @@ public class JsonTreeUtil {
try {
map = mapper.readValue(jsonStr, Map.class);
} catch (IOException e) {
log.warning("Could not convert json string to map");
LOGGER.warn("Could not convert json string to map", e);
}
}
return new Tree(map);
......
......@@ -8,9 +8,7 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.opengroup.osdu.wks.constants.Constants;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
......@@ -26,6 +24,8 @@ import org.opengroup.osdu.wks.model.UpdatedRelationshipBlock;
import org.opengroup.osdu.wks.provider.interfaces.MappingStore;
import org.opengroup.osdu.wks.service.SearchService;
import org.opengroup.osdu.wks.service.StorageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -33,12 +33,12 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.datatree.Tree;
import lombok.extern.java.Log;
@Component
@Log
public class RelationshipBlockHandler {
private final static Logger LOGGER = LoggerFactory.getLogger(RelationshipBlockHandler.class);
private final StorageService storageService;
private final SearchService searchService;
......@@ -107,7 +107,7 @@ public class RelationshipBlockHandler {
try {
wksRelationship = getRelationshipBlockWithWksIds(rawRelationship);
} catch (ApplicationException e) {
log.log(Level.INFO, e.getMessage(), e);
LOGGER.info(e.getMessage(), e);
}
if(wksRelationship != null) {
wksRelationships.add(wksRelationship);
......@@ -142,7 +142,7 @@ public class RelationshipBlockHandler {
// on authority name are lifted search results will be unique every time and caching won't be required
searchResults = searchService.query(searchRequestPayload.getJsonString());
} catch(ApplicationException e) {
log.info("WKS not found from search service");
LOGGER.info("WKS not found from search service", e);
}
Kind rawKind = new Kind(JsonTreeUtil.toTree(rawRecordJson).get("kind").asString());
......@@ -152,7 +152,7 @@ public class RelationshipBlockHandler {
private String extractWksIdFromSearchResults(String searchResults, String rawId, Kind rawKind) {
List<WksInfo> wksInfos = getWksInfos(searchResults);
if (noWksFound(wksInfos)) {
log.log(Level.INFO, "No matching WKS found for record id");
LOGGER.info("No matching WKS found for record id");
return rawId;
}
return getUniqueWksId(rawId, wksInfos, rawKind);
......@@ -164,10 +164,10 @@ public class RelationshipBlockHandler {
// 2. Choose records having same universe as that of the mapping file
// 3. Choose the one with highest major version
log.log(Level.INFO, String.format("Total %s Records found having %s in ancestry block", wksInfos.size(), rawId));
LOGGER.info(String.format("Total %s Records found having %s in ancestry block", wksInfos.size(), rawId));
List<WksInfo> wksGeneratedByWKSService = getWKSRecordsCreatedByWKSService(rawId, wksInfos, rawKind);
log.log(Level.INFO, String.format("Total %s Records created by WKS service", wksGeneratedByWKSService.size()));
LOGGER.info(String.format("Total %s Records created by WKS service", wksGeneratedByWKSService.size()));
if(wksGeneratedByWKSService.isEmpty()) {
return rawId;
}
......@@ -175,7 +175,7 @@ public class RelationshipBlockHandler {
String targetSchemaAuthority = targetSchemaKindValue.split(Constants.COLON_SEPARATOR)[0];
List<WksInfo> wksFromGivenAuthority = getWKSRecordsFromGivenAuthority(targetSchemaAuthority, wksGeneratedByWKSService);
log.log(Level.INFO, String.format("Total %s Records have same authority as that of target schema", wksGeneratedByWKSService.size()));
LOGGER.info(String.format("Total %s Records have same authority as that of target schema", wksGeneratedByWKSService.size()));
if(wksFromGivenAuthority.isEmpty()) {
return rawId;
......@@ -187,7 +187,7 @@ public class RelationshipBlockHandler {
List<WksInfo> wksSortedOnMajorVersion = wksFromGivenAuthority.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
log.log(Level.INFO, String.format("Unique WKS Record with id: %s found for relationship with Record %s", wksSortedOnMajorVersion.get(0).getId(), rawId));
LOGGER.info(String.format("Unique WKS Record with id: %s found for relationship with Record %s", wksSortedOnMajorVersion.get(0).getId(), rawId));
return wksSortedOnMajorVersion.get(0).getId();
}
......@@ -299,7 +299,7 @@ public class RelationshipBlockHandler {
return (new ObjectMapper()).readValue(results, new TypeReference<List<WksInfo>>() {
});
} catch (Exception e) {
log.warning("Error parsing wks info from search result");
LOGGER.warn("Error parsing wks info from search result", e);
}
return new ArrayList<>();
}
......
......@@ -3,12 +3,13 @@ package org.opengroup.osdu.wks.util;
import java.util.Collections;
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;
import org.opengroup.osdu.wks.model.RequestParameters;
import org.opengroup.osdu.wks.model.RestResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
......@@ -20,10 +21,11 @@ import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
@Log
@Component
public class RestClient {
private final static Logger LOGGER = LoggerFactory.getLogger(RestClient.class);
@Autowired
private RestTemplate restTemplate;
private int retryCounter = 3;
......@@ -57,7 +59,7 @@ public class RestClient {
validate(requestParameters.getUrl());
submitRequest(requestParameters.getUrl(), requestParameters.getMethod(), request, retryCounter);
} catch (Exception e) {
log.warning(e.toString());
LOGGER.warn(e.toString(), e);
restResponse.setException(e.toString());
}
return restResponse;
......@@ -65,7 +67,7 @@ public class RestClient {
private void validate(String url) {
if (StringUtils.isBlank(url)) {
log.warning("URL is null or empty string.");
LOGGER.warn("URL is null or empty string.");
throw new RestClientException("'URL' is null or empty string.");
}
}
......@@ -113,7 +115,7 @@ public class RestClient {
} catch (HttpServerErrorException e) {
if (retryCounter == 0) {
log.warning("Error while processing request: " + e.getMessage());
LOGGER.warn("Error while processing request: " + e.getMessage(), e);
throw new HttpException("Error while processing request: " + e.getMessage());
}
......@@ -121,7 +123,7 @@ public class RestClient {
submitRequest(url, method, request, retryCounter - 1);
} catch (RestClientException e) {
log.warning("Error while processing request: " + e.getMessage());
LOGGER.warn("Error while processing request: " + e.getMessage(), e);
throw new HttpException("Error while processing request: " + e.getMessage());
}
}
......
......@@ -17,20 +17,21 @@ import org.opengroup.osdu.wks.model.RelationshipStatus;
import org.opengroup.osdu.wks.model.TransformRequest;
import org.opengroup.osdu.wks.model.TransformationResult;
import org.opengroup.osdu.wks.model.UpdatedRelationshipBlock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import io.datatree.Tree;
import lombok.extern.java.Log;
/**
* This class do transformation of raw record to wks record
*
*/
@Log
@Component
public class WksTransformator {
private final static Logger LOGGER = LoggerFactory.getLogger(WksTransformator.class);
private static final char DOT_CHAR = '.';
private static final String DATA = "data";
private static final String PROPERTY_NAMES = "propertyNames";
......@@ -167,19 +168,19 @@ public class WksTransformator {
private void validateMappings(MappingsModel mappings) throws ApplicationException {
if (mappings == null || ArrayUtils.isEmpty(mappings.getAttributeMappings())) {
log.warning(MAPPING_NOT_PRESENT);
LOGGER.warn(MAPPING_NOT_PRESENT);
throw new ApplicationException(MAPPING_NOT_PRESENT);
}
if (StringUtils.isBlank(mappings.getTargetSchemaKind())) {
log.warning(WKS_SCHEMA_KIND_NOT_PRESENT);
LOGGER.warn(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);
LOGGER.warn(RAW_RECORD_NOT_PRESENT);
throw new ApplicationException(RAW_RECORD_NOT_PRESENT);
}
validateForMandatoryAttributes(rawRecordTree);
......@@ -190,7 +191,7 @@ public class WksTransformator {
List<String> missingAttributes = retrieveMissingMandatoryAttributes(rawRecordTree, requiredAttributes);
if (ArrayUtils.isNotEmpty(missingAttributes.toArray())) {
log.warning(REQUIRED_ATTRIBUTES_ARE_MISSING_IN_RECORD + missingAttributes);
LOGGER.warn(REQUIRED_ATTRIBUTES_ARE_MISSING_IN_RECORD + missingAttributes);
throw new ApplicationException(REQUIRED_ATTRIBUTES_ARE_MISSING_IN_RECORD + missingAttributes);
}
}
......
Supports Markdown
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