Commit 4db84250 authored by SGupta79's avatar SGupta79
Browse files

Remove SliLogger and make use of core JaxRsDpsLog logger

parent 0778af76
Pipeline #28999 failed with stages
in 2 minutes and 17 seconds
......@@ -6,13 +6,13 @@ import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.microsoft.azure.servicebus.IMessage;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.wks.config.ThreadDpsHeaders;
import org.opengroup.osdu.wks.config.ThreadJaxRsDpsLog;
import org.opengroup.osdu.wks.config.ThreadScopeContextHolder;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.exceptions.BadRequestException;
import org.opengroup.osdu.wks.logging.SliLogger;
import org.opengroup.osdu.wks.logging.SliLoggerPayload;
import org.opengroup.osdu.wks.model.RawRecordDetails;
import org.opengroup.osdu.wks.provider.azure.config.ThreadDpsHeaders;
import org.opengroup.osdu.wks.provider.azure.utils.MDCContextMap;
import org.opengroup.osdu.wks.service.WKSService;
import org.slf4j.Logger;
......@@ -30,6 +30,7 @@ public class ProcessWKSTransform {
private final static Logger LOGGER = LoggerFactory.getLogger(ProcessWKSTransform.class);
private static final String DATA = "data";
private static final String ID = "id";
private static final String SLI_LOG = "sli.log";
@Autowired
private WKSService wKSService;
......@@ -41,7 +42,7 @@ public class ProcessWKSTransform {
private ThreadDpsHeaders dpsHeaders;
@Autowired
private SliLogger sliLogger;
private ThreadJaxRsDpsLog log;
public void initiateWksTransformation(IMessage message) {
......@@ -78,33 +79,27 @@ public class ProcessWKSTransform {
} catch (BadRequestException e) {
LOGGER.warn("Bad Request Reason: {}, pubsub message id: {}", e.getErrorMsg(), message.getMessageId(), e);
sliLogger.writeLog(SliLoggerPayload.builder().status(false).recordId(message.getMessageId())
.correlationId(correlationId).dataPartitionId(dataPartitionId)
.statusCode(HttpStatus.BAD_REQUEST.value()).build());
log.info(SLI_LOG, SliLoggerPayload.builder().status(false).messageId(message.getMessageId())
.statusCode(HttpStatus.BAD_REQUEST.value()).build().toString());
} catch (ApplicationException e) {
LOGGER.warn("Application Error Reason: {}, pubsub message id: {}", e.getErrorMsg(), message.getMessageId(),
e);
sliLogger.writeLog(SliLoggerPayload.builder().status(false).recordId(message.getMessageId())
.correlationId(correlationId).dataPartitionId(dataPartitionId)
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build());
log.info(SLI_LOG, SliLoggerPayload.builder().status(false).messageId(message.getMessageId())
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build().toString());
} catch (NullPointerException e) {
LOGGER.error("Invalid format for message with id: {}", message.getMessageId(), e);
sliLogger.writeLog(SliLoggerPayload.builder().status(false).recordId(message.getMessageId())
.correlationId(correlationId).dataPartitionId(dataPartitionId)
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build());
log.info(SLI_LOG, SliLoggerPayload.builder().status(false).messageId(message.getMessageId())
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build().toString());
} catch (JsonSyntaxException e) {
LOGGER.error("Error occurred in payload parsing with id: {}", message.getMessageId(), e);
sliLogger.writeLog(SliLoggerPayload.builder().status(false).recordId(message.getMessageId())
.correlationId(correlationId).dataPartitionId(dataPartitionId)
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build());
log.info(SLI_LOG, SliLoggerPayload.builder().status(false).messageId(message.getMessageId())
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build().toString());
} catch (Exception e) {
LOGGER.error("Exception encountered processing the message with id: {}", message.getMessageId(), e);
sliLogger.writeLog(SliLoggerPayload.builder().status(false).recordId(message.getMessageId())
.correlationId(correlationId).dataPartitionId(dataPartitionId)
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build());
log.info(SLI_LOG, SliLoggerPayload.builder().status(false).messageId(message.getMessageId())
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build().toString());
}
......
......@@ -23,13 +23,14 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.wks.config.ThreadDpsHeaders;
import org.opengroup.osdu.wks.config.ThreadJaxRsDpsLog;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.exceptions.BadRequestException;
import org.opengroup.osdu.wks.logging.SliLogger;
import org.opengroup.osdu.wks.model.RawRecordDetails;
import org.opengroup.osdu.wks.provider.azure.config.ThreadDpsHeaders;
import org.opengroup.osdu.wks.provider.azure.utils.MDCContextMap;
import org.opengroup.osdu.wks.service.WKSService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collections;
......@@ -68,7 +69,7 @@ public class ProcessWKSTransformTest {
private ThreadDpsHeaders dpsHeaders;
@Mock
private SliLogger sliLogger;
private ThreadJaxRsDpsLog log;
@BeforeEach
......
package org.opengroup.osdu.wks.provider.azure.config;
package org.opengroup.osdu.wks.config;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.context.annotation.Primary;
......
package org.opengroup.osdu.wks.config;
import org.opengroup.osdu.core.common.logging.DefaultLogger;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
@Component
@Primary
@Scope(value = "ThreadScope", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class ThreadJaxRsDpsLog extends JaxRsDpsLog {
public ThreadJaxRsDpsLog(ILogger log, ThreadDpsHeaders headers) {
super(new DefaultLogger(), headers);
}
}
\ No newline at end of file
package org.opengroup.osdu.wks.logging;
import java.util.HashMap;
import java.util.Map;
import org.opengroup.osdu.core.common.logging.DefaultLogger;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.stereotype.Component;
import lombok.RequiredArgsConstructor;
@Component
@RequiredArgsConstructor
public class SliLogger {
private final DefaultLogger logger;
public void writeLog(SliLoggerPayload payload) {
this.logger.info("sli.log", getSliLog(payload), getHeader(payload));
}
private String getSliLog(SliLoggerPayload payload) {
Map<String, Object> jsonPayload = createSliPayload(payload);
return String.format("%s: ", jsonPayload.toString());
}
private Map<String, String> getHeader(SliLoggerPayload payload) {
Map<String, String> jsonPayload = new HashMap<>();
jsonPayload.put(DpsHeaders.DATA_PARTITION_ID, payload.getDataPartitionId());
jsonPayload.put(DpsHeaders.CORRELATION_ID, payload.getCorrelationId());
return jsonPayload;
}
private Map<String, Object> createSliPayload(SliLoggerPayload payload) {
Map<String, Object> jsonPayload = new HashMap<>();
jsonPayload.put("status", payload.getStatus());
jsonPayload.put("statusCode", payload.getStatusCode());
jsonPayload.put("id", payload.getRecordId());
jsonPayload.put(DpsHeaders.DATA_PARTITION_ID, payload.getDataPartitionId());
jsonPayload.put(DpsHeaders.CORRELATION_ID, payload.getCorrelationId());
return jsonPayload;
}
}
......@@ -2,14 +2,17 @@ package org.opengroup.osdu.wks.logging;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
@Data
@Builder
@ToString
public class SliLoggerPayload {
private String recordId;
private int statusCode;
private Boolean status;
private String dataPartitionId;
private String correlationId;
private String messageId;
}
......@@ -6,12 +6,12 @@ import java.util.*;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.opengroup.osdu.wks.config.RequestIdentity;
import org.opengroup.osdu.wks.config.ThreadJaxRsDpsLog;
import org.opengroup.osdu.wks.config.ThreadScopeContextHolder;
import org.opengroup.osdu.wks.constants.Constants;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.exceptions.BadRequestException;
import org.opengroup.osdu.wks.logging.SliLogger;
import org.opengroup.osdu.wks.logging.SliLoggerPayload;
import org.opengroup.osdu.wks.exceptions.NotFoundException;
......@@ -40,6 +40,7 @@ public class WKSServiceImpl implements WKSService {
private static final String CREATE = "create";
private static final String ID = "id";
private static final String KIND = "kind";
private static final String SLI_LOG = "sli.log";
@Autowired
private MappingService mappingService;
......@@ -57,7 +58,7 @@ public class WKSServiceImpl implements WKSService {
private StatusStoreService statusStoreService;
@Autowired
private SliLogger sliLogger;
private ThreadJaxRsDpsLog log;
/**
* This method applies the WKS transformation on the valid raw records
......@@ -142,33 +143,32 @@ public class WKSServiceImpl implements WKSService {
LOGGER.info(Constants.TRANFORMATION_SUCCESSFUL, rawRecord.getId(),
wksRecordTree.get(ID).asString(), wksRecordTree.get(KIND));
sliLogger.writeLog(SliLoggerPayload.builder().status(true).recordId(rawRecord.getId())
.correlationId(correlationId).dataPartitionId(dataPartitionId)
.statusCode(HttpStatus.OK.value()).build());
log.info(SLI_LOG, SliLoggerPayload.builder().status(true).recordId(rawRecord.getId())
.statusCode(HttpStatus.OK.value()).build().toString());
} catch (ApplicationException e) {
LOGGER.warn(Constants.TRANSFORMATION_FAILED_FOR_GIVEN_WKS_KIND, rawRecord.getId(),
e.getErrorMsg(), e);
sliLogger.writeLog(SliLoggerPayload.builder().status(false).recordId(rawRecord.getId())
.correlationId(correlationId).dataPartitionId(dataPartitionId)
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build());
log.info(SLI_LOG, SliLoggerPayload.builder().status(false).recordId(rawRecord.getId())
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build().toString());
} catch (NotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
LOGGER.warn(Constants.TRANSFORMATION_FAILED_FOR_GIVEN_WKS_KIND, rawRecord.getId(),
mappings.getMappingInfo().getTargetSchemaKind(), e.getMessage(), e);
log.info(SLI_LOG, SliLoggerPayload.builder().status(false).recordId(rawRecord.getId())
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build().toString());
}
}
} catch (ApplicationException e) {
LOGGER.warn(Constants.TRANFORMATION_FAILED, rawRecord.getId(), e.getErrorMsg(), e);
sliLogger.writeLog(SliLoggerPayload.builder().status(false).recordId(rawRecord.getId())
.correlationId(correlationId).dataPartitionId(dataPartitionId)
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build());
log.info(SLI_LOG, SliLoggerPayload.builder().status(false).recordId(rawRecord.getId())
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build().toString());
} catch (Exception e) {
LOGGER.warn(Constants.TRANFORMATION_FAILED, rawRecord.getId(), e.getMessage(), e);
log.info(SLI_LOG, SliLoggerPayload.builder().status(false).recordId(rawRecord.getId())
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).build().toString());
}
}
......
......@@ -11,7 +11,6 @@ import java.util.stream.Collectors;
import org.opengroup.osdu.wks.constants.Constants;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.exceptions.NotFoundException;
import org.opengroup.osdu.wks.model.*;
import org.opengroup.osdu.wks.model.mapping.MappingInfo;
import org.opengroup.osdu.wks.service.MappingService;
......@@ -110,7 +109,7 @@ public class RelationshipBlockHandler {
Relationship wksRelationship = null;
try {
wksRelationship = getRelationshipBlockWithWksIds(rawRelationship);
} catch (ApplicationException | NotFoundException e) {
} catch (ApplicationException e) {
LOGGER.info(e.getMessage(), e);
}
if (wksRelationship != null) {
......@@ -121,7 +120,7 @@ public class RelationshipBlockHandler {
}
private Relationship getRelationshipBlockWithWksIds(Relationship rawRelationship)
throws ApplicationException, NotFoundException {
throws ApplicationException {
List<String> rawIds = rawRelationship.getIds();
List<String> wksIds = getWksIds(rawIds);
......@@ -130,7 +129,7 @@ public class RelationshipBlockHandler {
}
private String getRelatedRecordIdUsingMapping(String relatedRecordId)
throws NotFoundException, ApplicationException {
throws ApplicationException {
Optional<String> rawRecordOption = storageService.getRecord(relatedRecordId);
if (rawRecordOption.isPresent()) {
......@@ -193,7 +192,7 @@ public class RelationshipBlockHandler {
return mappingInfos.stream().max(Comparator.comparing(MappingInfo::getTargetSchemaMajorVersion));
}
private List<String> getWksIds(List<String> relatedRawIds) throws NotFoundException, ApplicationException {
private List<String> getWksIds(List<String> relatedRawIds) throws ApplicationException {
List<String> wksIds = new ArrayList<>();
for (String relatedRawId : relatedRawIds) {
Optional<String> wksIdOptional = getWksId(relatedRawId);
......
......@@ -21,13 +21,11 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.opengroup.osdu.wks.config.RequestIdentity;
import org.opengroup.osdu.wks.config.ThreadJaxRsDpsLog;
import org.opengroup.osdu.wks.constants.Constants;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.exceptions.BadRequestException;
import org.opengroup.osdu.wks.logging.SliLogger;
import org.opengroup.osdu.wks.model.AttributeMappingModel;
import org.opengroup.osdu.wks.model.RawRecordDetails;
import org.opengroup.osdu.wks.model.TransformRequest;
import org.opengroup.osdu.wks.model.TransformationResult;
......@@ -35,6 +33,7 @@ import org.opengroup.osdu.wks.model.mapping.Mapping;
import org.opengroup.osdu.wks.model.mapping.MappingDefinition;
import org.opengroup.osdu.wks.model.mapping.operation.Operation;
import org.opengroup.osdu.wks.util.WksTransformator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import io.datatree.Tree;
......@@ -90,7 +89,7 @@ public class WKSServiceImplTest {
private WKSServiceImpl wksService;
@Mock
private SliLogger sliLogger;
private ThreadJaxRsDpsLog log;
@Rule
public ExpectedException expectedException = ExpectedException.none();
......
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