asdc controller treat distributionid as requestid 37/93637/1
authorBhatt, Prema <prema.bhatt@att.com>
Thu, 15 Aug 2019 19:54:22 +0000 (15:54 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Thu, 15 Aug 2019 19:54:23 +0000 (15:54 -0400)
Setting RequestId in MDC using DistributionID value in ASDC-controller
Setting RequestId in MDC using DistributionID value in ASDC-controller.
Cleaned up code.
Removing the log line as per the review comments.

Issue-ID: SO-2231
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I07880a80d479ad01411e0c5ece12d77722b8cb6c

asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
asdc-controller/src/test/java/org/onap/so/asdc/client/ASDCControllerITTest.java

index 3b9406a..0734121 100644 (file)
@@ -37,6 +37,7 @@ import java.nio.file.Paths;
 import java.util.List;
 import java.util.Optional;
 import org.onap.so.logger.LoggingAnchor;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.consumer.IDistributionStatusMessage;
 import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
@@ -71,6 +72,7 @@ import org.onap.so.logger.ErrorCode;
 import org.onap.so.logger.MessageEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.orm.ObjectOptimisticLockingFailureException;
 import org.springframework.stereotype.Component;
@@ -588,6 +590,10 @@ public class ASDCController {
         logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_RECEIVE_CALLBACK_NOTIF.toString(),
                 String.valueOf(noOfArtifacts), iNotif.getServiceUUID(), "ASDC");
         try {
+
+            if (iNotif.getDistributionID() != null && !iNotif.getDistributionID().isEmpty()) {
+                MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, iNotif.getDistributionID());
+            }
             logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
             logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), iNotif.getServiceUUID(),
                     "ASDC", "treatNotification");
index 0681cd8..055968c 100644 (file)
@@ -33,6 +33,7 @@ import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestName;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.onap.so.asdc.BaseTest;
 import org.onap.so.asdc.client.exceptions.ASDCControllerException;
 import org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl;
@@ -55,6 +56,7 @@ import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -277,6 +279,35 @@ public class ASDCControllerITTest extends BaseTest {
         }
     }
 
+    /**
+     * Test to check RequestId is being set using the DistributionID.
+     */
+    @Test
+    public void treatNotification_verifyRequestID() {
+
+        String serviceUuid = "efaea486-561f-4159-9191-a8d3cb346728";
+        String serviceInvariantUuid = "f2edfbf4-bb0a-4fe7-a57a-71362d4b0b23";
+        distributionId = "bb15de12-166d-4e45-9e5f-4b3f25200d7b";
+
+        initMockAaiServer(serviceUuid, serviceInvariantUuid);
+
+        NotificationDataImpl notificationData = new NotificationDataImpl();
+        notificationData.setServiceUUID(serviceUuid);
+        notificationData.setDistributionID(distributionId);
+        notificationData.setServiceInvariantUUID(serviceInvariantUuid);
+        notificationData.setServiceVersion("1.0");
+
+        try {
+            asdcController.treatNotification(notificationData);
+            logger.info("Verify RequestId : {}", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
+            assertEquals("bb15de12-166d-4e45-9e5f-4b3f25200d7b", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
+
+        } catch (Exception e) {
+            logger.info(e.getMessage(), e);
+            fail(e.getMessage());
+        }
+    }
+
     private ArtifactInfoImpl constructPnfServiceArtifact() {
         ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl();
         artifactInfo.setArtifactType(ASDCConfiguration.TOSCA_CSAR);