From e1886e3a021d44ac242445e64937d23345de1cde Mon Sep 17 00:00:00 2001 From: Prasad Settipalli Date: Tue, 26 Jul 2022 22:12:01 +0530 Subject: [PATCH 1/4] adding logging in Sol003 Driver --- pom.xml | 2 +- .../stratoss/common/utils/LoggingUtils.java | 39 ++++++++++++++++++ .../driver/VNFLifecycleManagementDriver.java | 40 ++++++++++++++----- .../vnfmdriver/model/MessageDirection.java | 9 +++++ 4 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/accantosystems/stratoss/vnfmdriver/model/MessageDirection.java diff --git a/pom.xml b/pom.xml index 85cee24..61a3a30 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ 4.5.13 2.13.3 0.8.4 - 11 + 1.8 2.4.1 2.5 2.17.1 diff --git a/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java b/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java index 30b62c4..c26325b 100644 --- a/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java +++ b/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java @@ -6,15 +6,33 @@ import java.util.UUID; import javax.servlet.http.HttpServletRequest; +import com.accantosystems.stratoss.vnfmdriver.driver.SOL003ResponseException; +import com.accantosystems.stratoss.vnfmdriver.model.MessageDirection; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.slf4j.MDC; import org.springframework.http.HttpHeaders; public class LoggingUtils { + private final static Logger logger = LoggerFactory.getLogger(LoggingUtils.class); + private static final String LOGGING_CONTEXT_KEY_PREFIX = "traceCtx.".toLowerCase(); private static final String LOGGING_CONTEXT_HEADER_PREFIX = "X-TraceCtx-".toLowerCase(); private static final String TRANSACTION_ID_HEADER_KEY = "TransactionId".toLowerCase(); + private static final String LOG_MESSAGE_DIRECTION_KEY = "message_direction"; + + private static final String LOG_EXTERNAL_REQUEST_ID_KEY = "tracectx.externalrequestid"; + + private static final String LOG_CONTENT_TYPE_KEY = "content_type"; + + private static final String LOG_PROTOCOL_KEY = "protocol"; + + private static final String LOG_PROTOCOL_METADATA_KEY = "protocol_metadata"; + public static Map getContextMapFromHttpHeaders(HttpServletRequest servletRequest) { final Map loggingContext = new HashMap<>(); final Enumeration headerNames = servletRequest.getHeaderNames(); @@ -38,6 +56,27 @@ public static Map getContextMapFromHttpHeaders(HttpServletReques return loggingContext; } + public static void logEnabledMDC(String message, MessageDirection messageDirection, String externalRequestId, String contentType, String protocol, Map protocolMetadata){ + try{ + MDC.put(LOG_MESSAGE_DIRECTION_KEY, messageDirection.SENT.toString()); + MDC.put(LOG_EXTERNAL_REQUEST_ID_KEY, externalRequestId); + MDC.put(LOG_CONTENT_TYPE_KEY, contentType); + MDC.put(LOG_PROTOCOL_KEY, protocol.toLowerCase()); + ObjectMapper jsonMapper = new ObjectMapper(); + try { + MDC.put(LOG_PROTOCOL_METADATA_KEY, jsonMapper.writeValueAsString(protocolMetadata)); + } catch (JsonProcessingException e) { + throw new SOL003ResponseException("Error in parsing protocol_metadata "+ protocolMetadata, e); + } + logger.info(message); + }finally{ + MDC.remove(LOG_MESSAGE_DIRECTION_KEY); + MDC.remove(LOG_EXTERNAL_REQUEST_ID_KEY); + MDC.remove(LOG_CONTENT_TYPE_KEY); + MDC.remove(LOG_PROTOCOL_KEY); + MDC.remove(LOG_PROTOCOL_METADATA_KEY); + } + } public static void setHttpHeadersFromMDC(final HttpHeaders httpHeaders) { Map mdcContext = MDC.getCopyOfContextMap(); diff --git a/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java b/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java index 698abdf..017e734 100644 --- a/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java +++ b/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java @@ -6,7 +6,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; +import com.accantosystems.stratoss.common.utils.LoggingUtils; +import com.accantosystems.stratoss.vnfmdriver.model.MessageDirection; import org.etsi.sol003.lifecyclemanagement.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,9 +101,10 @@ public String createVnfInstance(final ResourceManagerDeploymentLocation deployme final HttpHeaders headers = getHttpHeaders(deploymentLocation); headers.setContentType(MediaType.APPLICATION_JSON); final HttpEntity requestEntity = new HttpEntity<>(createVnfRequest, headers); - + UUID uuid = UUID.randomUUID(); + LoggingUtils.logEnabledMDC(createVnfRequest, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.POST, requestEntity, String.class); - + LoggingUtils.logEnabledMDC(responseEntity.getBody(), MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); // "Location" header also includes URI of the created instance checkResponseEntityMatches(responseEntity, HttpStatus.CREATED, true); return responseEntity.getBody(); @@ -127,9 +131,10 @@ public void deleteVnfInstance(final ResourceManagerDeploymentLocation deployment final HttpEntity requestEntity = new HttpEntity<>(headers); final Map uriVariables = new HashMap<>(); uriVariables.put("vnfInstanceId", vnfInstanceId); - + UUID uuid = UUID.randomUUID(); + LoggingUtils.logEnabledMDC(null, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.DELETE, requestEntity, Void.class, uriVariables); - + LoggingUtils.logEnabledMDC(null, MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); checkResponseEntityMatches(responseEntity, HttpStatus.NO_CONTENT, false); } @@ -348,9 +353,10 @@ private String callVnfLcmOperation(final ResourceManagerDeploymentLocation deplo final String url = deploymentLocation.getProperties().get(VNFM_SERVER_URL) + API_CONTEXT_ROOT + API_PREFIX_VNF_INSTANCES + "/" + vnfInstanceId + "/" + operationName; final HttpHeaders headers = getHttpHeaders(deploymentLocation); final HttpEntity requestEntity = new HttpEntity<>(operationRequest, headers); - + UUID uuid = UUID.randomUUID(); + LoggingUtils.logEnabledMDC(operationRequest, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.POST, requestEntity, String.class); - + LoggingUtils.logEnabledMDC(responseEntity.getBody(),MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); checkResponseEntityMatches(responseEntity, HttpStatus.ACCEPTED, false); // "Location" header contains URI of the created VnfLcmOpOcc record final URI location = responseEntity.getHeaders().getLocation(); @@ -422,10 +428,11 @@ public LccnSubscription createLifecycleSubscription(final ResourceManagerDeploym final String url = deploymentLocation.getProperties().get(VNFM_SERVER_URL) + API_CONTEXT_ROOT + API_PREFIX_SUBSCRIPTIONS; final HttpHeaders headers = getHttpHeaders(deploymentLocation); final HttpEntity requestEntity = new HttpEntity<>(lccnSubscriptionRequest, headers); - + UUID uuid = UUID.randomUUID(); + LoggingUtils.logEnabledMDC(lccnSubscriptionRequest.toString(), MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation) .exchange(url, HttpMethod.POST, requestEntity, LccnSubscription.class); - + LoggingUtils.logEnabledMDC(responseEntity.getBody().toString(), MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); // "Location" header also includes URI of the created instance checkResponseEntityMatches(responseEntity, HttpStatus.CREATED, true); return responseEntity.getBody(); @@ -482,9 +489,10 @@ public void deleteLifecycleSubscription(final ResourceManagerDeploymentLocation final HttpEntity requestEntity = new HttpEntity<>(headers); final Map uriVariables = new HashMap<>(); uriVariables.put("subscriptionId", subscriptionId); - + UUID uuid = UUID.randomUUID(); + LoggingUtils.logEnabledMDC(null, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.DELETE, requestEntity, Void.class, uriVariables); - + LoggingUtils.logEnabledMDC(null, MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); checkResponseEntityMatches(responseEntity, HttpStatus.NO_CONTENT, false); } @@ -523,4 +531,16 @@ private void checkResponseEntityMatches(final ResponseEntity responseEntity, fin } } + Map getProtocolMetaData(String url,ResponseEntity responseEntity){ + + Map protocolMetadata=new HashMap<>(); + + protocolMetadata.put("status_code",responseEntity.getStatusCode()); + protocolMetadata.put("status",responseEntity.getStatusCodeValue()); + protocolMetadata.put("url",url); + + return protocolMetadata; + + } + } diff --git a/src/main/java/com/accantosystems/stratoss/vnfmdriver/model/MessageDirection.java b/src/main/java/com/accantosystems/stratoss/vnfmdriver/model/MessageDirection.java new file mode 100644 index 0000000..f8eacfe --- /dev/null +++ b/src/main/java/com/accantosystems/stratoss/vnfmdriver/model/MessageDirection.java @@ -0,0 +1,9 @@ +package com.accantosystems.stratoss.vnfmdriver.model; + +public enum MessageDirection { + + RECEIVED("received"), SENT("sent"); + + MessageDirection(String sent) { + } +} From 5a3a5daddfe9d8715cc41f7376ff26939bf72809 Mon Sep 17 00:00:00 2001 From: Prasad Settipalli Date: Wed, 27 Jul 2022 17:19:48 +0530 Subject: [PATCH 2/4] adding Logging changes code for sol003 --- .../vnfmdriver/driver/VNFLifecycleManagementDriver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java b/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java index 017e734..731e09e 100644 --- a/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java +++ b/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java @@ -535,8 +535,8 @@ Map getProtocolMetaData(String url,ResponseEntity responseEntity) Map protocolMetadata=new HashMap<>(); - protocolMetadata.put("status_code",responseEntity.getStatusCode()); - protocolMetadata.put("status",responseEntity.getStatusCodeValue()); + protocolMetadata.put("status",responseEntity.getStatusCode()!=null?responseEntity.getStatusCode():null); + protocolMetadata.put("status_code",responseEntity.getStatusCodeValue()); protocolMetadata.put("url",url); return protocolMetadata; From 22dcc6ac613171618143af882ff1b329ba4906ff Mon Sep 17 00:00:00 2001 From: Prasad Settipalli Date: Wed, 27 Jul 2022 21:06:56 +0530 Subject: [PATCH 3/4] Added log info in sol003 driver --- .../stratoss/common/utils/LoggingUtils.java | 8 +++++-- .../driver/VNFLifecycleManagementDriver.java | 23 ++++++++++--------- .../vnfmdriver/model/MessageType.java | 9 ++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/accantosystems/stratoss/vnfmdriver/model/MessageType.java diff --git a/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java b/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java index c26325b..b6d4cc3 100644 --- a/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java +++ b/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java @@ -8,6 +8,7 @@ import com.accantosystems.stratoss.vnfmdriver.driver.SOL003ResponseException; import com.accantosystems.stratoss.vnfmdriver.model.MessageDirection; +import com.accantosystems.stratoss.vnfmdriver.model.MessageType; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; @@ -33,6 +34,8 @@ public class LoggingUtils { private static final String LOG_PROTOCOL_METADATA_KEY = "protocol_metadata"; + private static final String LOG_MSG_TYP_KEY= "message_type"; + public static Map getContextMapFromHttpHeaders(HttpServletRequest servletRequest) { final Map loggingContext = new HashMap<>(); final Enumeration headerNames = servletRequest.getHeaderNames(); @@ -56,9 +59,9 @@ public static Map getContextMapFromHttpHeaders(HttpServletReques return loggingContext; } - public static void logEnabledMDC(String message, MessageDirection messageDirection, String externalRequestId, String contentType, String protocol, Map protocolMetadata){ + public static void logEnabledMDC(String message, MessageType messageType, MessageDirection messageDirection, String externalRequestId, String contentType, String protocol, Map protocolMetadata){ try{ - MDC.put(LOG_MESSAGE_DIRECTION_KEY, messageDirection.SENT.toString()); + MDC.put(LOG_MESSAGE_DIRECTION_KEY, messageDirection.toString()); MDC.put(LOG_EXTERNAL_REQUEST_ID_KEY, externalRequestId); MDC.put(LOG_CONTENT_TYPE_KEY, contentType); MDC.put(LOG_PROTOCOL_KEY, protocol.toLowerCase()); @@ -68,6 +71,7 @@ public static void logEnabledMDC(String message, MessageDirection messageDirecti } catch (JsonProcessingException e) { throw new SOL003ResponseException("Error in parsing protocol_metadata "+ protocolMetadata, e); } + MDC.put(LOG_MSG_TYP_KEY,"messageType"); logger.info(message); }finally{ MDC.remove(LOG_MESSAGE_DIRECTION_KEY); diff --git a/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java b/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java index 731e09e..ab274e6 100644 --- a/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java +++ b/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java @@ -10,6 +10,7 @@ import com.accantosystems.stratoss.common.utils.LoggingUtils; import com.accantosystems.stratoss.vnfmdriver.model.MessageDirection; +import com.accantosystems.stratoss.vnfmdriver.model.MessageType; import org.etsi.sol003.lifecyclemanagement.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,9 +103,9 @@ public String createVnfInstance(final ResourceManagerDeploymentLocation deployme headers.setContentType(MediaType.APPLICATION_JSON); final HttpEntity requestEntity = new HttpEntity<>(createVnfRequest, headers); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(createVnfRequest, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(createVnfRequest, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.POST, requestEntity, String.class); - LoggingUtils.logEnabledMDC(responseEntity.getBody(), MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(responseEntity.getBody(), MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); // "Location" header also includes URI of the created instance checkResponseEntityMatches(responseEntity, HttpStatus.CREATED, true); return responseEntity.getBody(); @@ -132,9 +133,9 @@ public void deleteVnfInstance(final ResourceManagerDeploymentLocation deployment final Map uriVariables = new HashMap<>(); uriVariables.put("vnfInstanceId", vnfInstanceId); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(null, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(null, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.DELETE, requestEntity, Void.class, uriVariables); - LoggingUtils.logEnabledMDC(null, MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(null, MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); checkResponseEntityMatches(responseEntity, HttpStatus.NO_CONTENT, false); } @@ -354,9 +355,9 @@ private String callVnfLcmOperation(final ResourceManagerDeploymentLocation deplo final HttpHeaders headers = getHttpHeaders(deploymentLocation); final HttpEntity requestEntity = new HttpEntity<>(operationRequest, headers); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(operationRequest, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(operationRequest, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.POST, requestEntity, String.class); - LoggingUtils.logEnabledMDC(responseEntity.getBody(),MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(responseEntity.getBody(),MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); checkResponseEntityMatches(responseEntity, HttpStatus.ACCEPTED, false); // "Location" header contains URI of the created VnfLcmOpOcc record final URI location = responseEntity.getHeaders().getLocation(); @@ -429,10 +430,10 @@ public LccnSubscription createLifecycleSubscription(final ResourceManagerDeploym final HttpHeaders headers = getHttpHeaders(deploymentLocation); final HttpEntity requestEntity = new HttpEntity<>(lccnSubscriptionRequest, headers); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(lccnSubscriptionRequest.toString(), MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(lccnSubscriptionRequest.toString(),MessageType.REQUEST, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation) .exchange(url, HttpMethod.POST, requestEntity, LccnSubscription.class); - LoggingUtils.logEnabledMDC(responseEntity.getBody().toString(), MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(responseEntity.getBody().toString(),MessageType.RESPONSE, MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); // "Location" header also includes URI of the created instance checkResponseEntityMatches(responseEntity, HttpStatus.CREATED, true); return responseEntity.getBody(); @@ -490,9 +491,9 @@ public void deleteLifecycleSubscription(final ResourceManagerDeploymentLocation final Map uriVariables = new HashMap<>(); uriVariables.put("subscriptionId", subscriptionId); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(null, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(null, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.DELETE, requestEntity, Void.class, uriVariables); - LoggingUtils.logEnabledMDC(null, MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(null, MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); checkResponseEntityMatches(responseEntity, HttpStatus.NO_CONTENT, false); } @@ -535,7 +536,7 @@ Map getProtocolMetaData(String url,ResponseEntity responseEntity) Map protocolMetadata=new HashMap<>(); - protocolMetadata.put("status",responseEntity.getStatusCode()!=null?responseEntity.getStatusCode():null); + protocolMetadata.put("status",responseEntity.getStatusCode()); protocolMetadata.put("status_code",responseEntity.getStatusCodeValue()); protocolMetadata.put("url",url); diff --git a/src/main/java/com/accantosystems/stratoss/vnfmdriver/model/MessageType.java b/src/main/java/com/accantosystems/stratoss/vnfmdriver/model/MessageType.java new file mode 100644 index 0000000..0d2fea2 --- /dev/null +++ b/src/main/java/com/accantosystems/stratoss/vnfmdriver/model/MessageType.java @@ -0,0 +1,9 @@ +package com.accantosystems.stratoss.vnfmdriver.model; + +public enum MessageType { + + REQUEST("request"), RESPONSE("response"), MESSAGE("message"); + + MessageType(String request) { + } +} From 7b03f3e6cf445f574327ee4529f6be84aeb6ad43 Mon Sep 17 00:00:00 2001 From: Prasad Settipalli Date: Fri, 29 Jul 2022 10:26:30 +0530 Subject: [PATCH 4/4] adding driverRequestId filed inti log for Sol003 driver --- .../stratoss/common/utils/LoggingUtils.java | 10 ++++++++-- .../driver/VNFLifecycleManagementDriver.java | 20 +++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java b/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java index b6d4cc3..9a8c8f4 100644 --- a/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java +++ b/src/main/java/com/accantosystems/stratoss/common/utils/LoggingUtils.java @@ -36,6 +36,8 @@ public class LoggingUtils { private static final String LOG_MSG_TYP_KEY= "message_type"; + private static final String LOG_DRIVER_REQUEST_ID ="tracectx.driverrequestid"; + public static Map getContextMapFromHttpHeaders(HttpServletRequest servletRequest) { final Map loggingContext = new HashMap<>(); final Enumeration headerNames = servletRequest.getHeaderNames(); @@ -59,7 +61,7 @@ public static Map getContextMapFromHttpHeaders(HttpServletReques return loggingContext; } - public static void logEnabledMDC(String message, MessageType messageType, MessageDirection messageDirection, String externalRequestId, String contentType, String protocol, Map protocolMetadata){ + public static void logEnabledMDC(String message, MessageType messageType, MessageDirection messageDirection, String externalRequestId, String contentType, String protocol, Map protocolMetadata,String driverRequestId){ try{ MDC.put(LOG_MESSAGE_DIRECTION_KEY, messageDirection.toString()); MDC.put(LOG_EXTERNAL_REQUEST_ID_KEY, externalRequestId); @@ -71,7 +73,9 @@ public static void logEnabledMDC(String message, MessageType messageType, Messag } catch (JsonProcessingException e) { throw new SOL003ResponseException("Error in parsing protocol_metadata "+ protocolMetadata, e); } - MDC.put(LOG_MSG_TYP_KEY,"messageType"); + MDC.put(LOG_MSG_TYP_KEY,messageType.toString()); + MDC.put(LOG_DRIVER_REQUEST_ID,driverRequestId); + logger.info(message); }finally{ MDC.remove(LOG_MESSAGE_DIRECTION_KEY); @@ -79,6 +83,8 @@ public static void logEnabledMDC(String message, MessageType messageType, Messag MDC.remove(LOG_CONTENT_TYPE_KEY); MDC.remove(LOG_PROTOCOL_KEY); MDC.remove(LOG_PROTOCOL_METADATA_KEY); + MDC.remove(LOG_MSG_TYP_KEY); + MDC.remove(LOG_DRIVER_REQUEST_ID); } } diff --git a/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java b/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java index ab274e6..19bb8b6 100644 --- a/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java +++ b/src/main/java/com/accantosystems/stratoss/vnfmdriver/driver/VNFLifecycleManagementDriver.java @@ -103,9 +103,9 @@ public String createVnfInstance(final ResourceManagerDeploymentLocation deployme headers.setContentType(MediaType.APPLICATION_JSON); final HttpEntity requestEntity = new HttpEntity<>(createVnfRequest, headers); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(createVnfRequest, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(createVnfRequest, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null,uuid.toString()); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.POST, requestEntity, String.class); - LoggingUtils.logEnabledMDC(responseEntity.getBody(), MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(responseEntity.getBody(), MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity),uuid.toString()); // "Location" header also includes URI of the created instance checkResponseEntityMatches(responseEntity, HttpStatus.CREATED, true); return responseEntity.getBody(); @@ -133,9 +133,9 @@ public void deleteVnfInstance(final ResourceManagerDeploymentLocation deployment final Map uriVariables = new HashMap<>(); uriVariables.put("vnfInstanceId", vnfInstanceId); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(null, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(null, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null,uuid.toString()); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.DELETE, requestEntity, Void.class, uriVariables); - LoggingUtils.logEnabledMDC(null, MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(null, MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity),uuid.toString()); checkResponseEntityMatches(responseEntity, HttpStatus.NO_CONTENT, false); } @@ -355,9 +355,9 @@ private String callVnfLcmOperation(final ResourceManagerDeploymentLocation deplo final HttpHeaders headers = getHttpHeaders(deploymentLocation); final HttpEntity requestEntity = new HttpEntity<>(operationRequest, headers); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(operationRequest, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(operationRequest, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null,uuid.toString()); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.POST, requestEntity, String.class); - LoggingUtils.logEnabledMDC(responseEntity.getBody(),MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(responseEntity.getBody(),MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity),uuid.toString()); checkResponseEntityMatches(responseEntity, HttpStatus.ACCEPTED, false); // "Location" header contains URI of the created VnfLcmOpOcc record final URI location = responseEntity.getHeaders().getLocation(); @@ -430,10 +430,10 @@ public LccnSubscription createLifecycleSubscription(final ResourceManagerDeploym final HttpHeaders headers = getHttpHeaders(deploymentLocation); final HttpEntity requestEntity = new HttpEntity<>(lccnSubscriptionRequest, headers); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(lccnSubscriptionRequest.toString(),MessageType.REQUEST, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(lccnSubscriptionRequest.toString(),MessageType.REQUEST, MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null,uuid.toString()); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation) .exchange(url, HttpMethod.POST, requestEntity, LccnSubscription.class); - LoggingUtils.logEnabledMDC(responseEntity.getBody().toString(),MessageType.RESPONSE, MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(responseEntity.getBody().toString(),MessageType.RESPONSE, MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity),uuid.toString()); // "Location" header also includes URI of the created instance checkResponseEntityMatches(responseEntity, HttpStatus.CREATED, true); return responseEntity.getBody(); @@ -491,9 +491,9 @@ public void deleteLifecycleSubscription(final ResourceManagerDeploymentLocation final Map uriVariables = new HashMap<>(); uriVariables.put("subscriptionId", subscriptionId); UUID uuid = UUID.randomUUID(); - LoggingUtils.logEnabledMDC(null, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null); + LoggingUtils.logEnabledMDC(null, MessageType.REQUEST,MessageDirection.SENT, uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",null,uuid.toString()); final ResponseEntity responseEntity = authenticatedRestTemplateService.getRestTemplate(deploymentLocation).exchange(url, HttpMethod.DELETE, requestEntity, Void.class, uriVariables); - LoggingUtils.logEnabledMDC(null, MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity)); + LoggingUtils.logEnabledMDC(null, MessageType.RESPONSE,MessageDirection.RECEIVED,uuid.toString(),MediaType.APPLICATION_JSON.toString(), "http",getProtocolMetaData(url,responseEntity),uuid.toString()); checkResponseEntityMatches(responseEntity, HttpStatus.NO_CONTENT, false); }