Shore up Logging Score on DGs 33/55233/3
authorvidhyasree <sn141y@att.com>
Thu, 21 Jun 2018 20:33:20 +0000 (16:33 -0400)
committerTakamune Cho <tc012c@att.com>
Fri, 22 Jun 2018 17:59:26 +0000 (17:59 +0000)
Modify TopologyService and DG calls to have all logging fields

Issue-ID: APPC-1020
Change-Id: I60078960ed0cfa8c70d0f4673c6d4a5026afc673
Signed-off-by: vidhyasree <sn141y@att.com>
appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/onap/appc/executor/impl/CommandTask.java

index 0784ffc..9656644 100644 (file)
@@ -45,6 +45,7 @@ import org.osgi.framework.ServiceReference;
 import org.slf4j.MDC;
 
 import java.net.InetAddress;
+import java.util.UUID;
 
 import static com.att.eelf.configuration.Configuration.*;
 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
@@ -169,7 +170,17 @@ public class CommandTask implements Runnable {
 
 
     private void setInitialLogProperties(CommandRequest request) {
-        MDC.put(MDC_KEY_REQUEST_ID, request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader().getRequestId());
+        String reqId = request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader().getRequestId();
+
+        try {
+            MDC.put(MDC_KEY_REQUEST_ID, UUID.fromString(reqId).toString());
+            //reaching here without exception means existing RequestId is
+            //valid UUID as per ECOMP logging standards
+        } catch (Exception e) {
+            String reqIdUUID = UUID.randomUUID().toString();
+            MDC.put(MDC_KEY_REQUEST_ID, reqIdUUID);
+            logger.info("Replaced invalid requestID of " + reqId + ".  New value is " + reqIdUUID + ".");
+        }
         if (request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getActionIdentifiers().getServiceInstanceId() != null)
             MDC.put(MDC_SERVICE_INSTANCE_ID, request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getActionIdentifiers().getServiceInstanceId());
         MDC.put(LoggingConstants.MDCKeys.PARTNER_NAME, request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader().getOriginatorId());