Fix to pass transaction id to AAI 89/8389/2
authoranupmarathe <anup.marathe@amdocs.com>
Wed, 23 Aug 2017 05:40:27 +0000 (11:10 +0530)
committeranupmarathe <anup.marathe@amdocs.com>
Thu, 24 Aug 2017 07:25:21 +0000 (12:55 +0530)
When SO is calling AAI REST API in groovy code, it is always passing new
X-TransactionID. As per EELF logging guidelines, this id is used for
tracking transaction across components. This fix checks if there is
already an existing transaction id in MDC, if yes then pass same. If not
found, then create one and set in MDC for use in next API calls in same
transaction.

Change-Id: If6e33b77d9615f4887e1c1fc367de4268eecc340
Issue-ID: SO-78
Signed-off-by: anupmarathe <anup.marathe@amdocs.com>
bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/AaiUtil.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DeleteAAIVfModule.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/MsoUtils.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/PrepareUpdateAAIVfModule.groovy

index b50bf68..af650b4 100644 (file)
@@ -296,7 +296,7 @@ class AaiUtil {
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
                taskProcessor.logDebug(" ======== STARTED Execute AAI Get Process ======== ", isDebugEnabled)\r
                try{\r
-                       String uuid = UUID.randomUUID()\r
+                       String uuid = utils.getRequestID()\r
                        taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)\r
                        taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)\r
                        \r
@@ -335,7 +335,7 @@ class AaiUtil {
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
                taskProcessor.logDebug( " ======== Started Execute AAI Put Process ======== ", isDebugEnabled)\r
                try{\r
-                       String uuid = UUID.randomUUID()\r
+                       String uuid = utils.getRequestID()\r
                        taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)\r
                        taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)\r
                        \r
@@ -371,7 +371,7 @@ class AaiUtil {
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
                taskProcessor.logDebug( " ======== Started Execute AAI Patch Process ======== ", isDebugEnabled)\r
                try{\r
-                       String uuid = UUID.randomUUID()\r
+                       String uuid = utils.getRequestID()\r
                        taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)\r
 \r
                        taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)\r
@@ -408,7 +408,7 @@ class AaiUtil {
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
                taskProcessor.logDebug( " ======== Started Execute AAI Delete Process ======== ", isDebugEnabled)\r
                try{\r
-                       String uuid = UUID.randomUUID()\r
+                       String uuid = utils.getRequestID()\r
                        taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)\r
                        taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)\r
 \r
@@ -445,7 +445,7 @@ class AaiUtil {
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
                taskProcessor.logDebug( " ======== Started Execute AAI Delete Process ======== ", isDebugEnabled)\r
                try{\r
-                       String uuid = UUID.randomUUID()\r
+                       String uuid = utils.getRequestID()\r
                        taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)\r
 \r
                        taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)\r
@@ -483,7 +483,7 @@ class AaiUtil {
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
                taskProcessor.logDebug( " ======== Started Execute AAI Post Process ======== ", isDebugEnabled)\r
                try{\r
-                       String uuid = UUID.randomUUID()\r
+                       String uuid = utils.getRequestID()\r
                        taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)\r
                        taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)\r
 \r
index 72ad140..aaac86c 100644 (file)
@@ -29,7 +29,8 @@ import org.openecomp.mso.rest.RESTConfig;
 public class DeleteAAIVfModule extends AbstractServiceTaskProcessor{\r
        \r
        def Prefix="DAAIVfMod_"\r
-       ExceptionUtil exceptionUtil = new ExceptionUtil()       \r
+       ExceptionUtil exceptionUtil = new ExceptionUtil()\r
+    private MsoUtils utils = new MsoUtils()\r
        public void initProcessVariables(Execution execution) {\r
                execution.setVariable("prefix",Prefix)\r
                execution.setVariable("DAAIVfMod_vnfId",null)\r
@@ -83,7 +84,7 @@ public class DeleteAAIVfModule extends AbstractServiceTaskProcessor{
                def delModuleId = execution.getVariable("DAAIVfMod_vfModuleId")\r
                def endPoint = execution.getVariable("URN_aai_endpoint") + execution.getVariable("DAAIVfMod_genericVnfEndpoint") + "?depth=1"\r
                utils.logAudit("DeleteAAIVfModule endPoint: " + endPoint)\r
-               def aaiRequestId = UUID.randomUUID().toString()\r
+               def aaiRequestId = utils.getRequestID()\r
 \r
                RESTConfig config = new RESTConfig(endPoint);\r
                utils.log("DEBUG","queryAAIForGenericVnf() endpoint-" + endPoint, isDebugEnabled)\r
@@ -118,7 +119,7 @@ public class DeleteAAIVfModule extends AbstractServiceTaskProcessor{
        // note: to get here, all the modules associated with the Generic Vnf must already be deleted\r
        public void deleteGenericVnf(Execution execution) {\r
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
-               def aaiRequestId = UUID.randomUUID().toString()\r
+               def aaiRequestId = utils.getRequestID()\r
                def endPoint = execution.getVariable("URN_aai_endpoint") + execution.getVariable("DAAIVfMod_genericVnfEndpoint") +\r
                        "/?resource-version=" + execution.getVariable("DAAIVfMod_genVnfRsrcVer")\r
                utils.logAudit("AAI endPoint: " + endPoint)\r
@@ -153,7 +154,7 @@ public class DeleteAAIVfModule extends AbstractServiceTaskProcessor{
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
                def endPoint = execution.getVariable("URN_aai_endpoint") + execution.getVariable("DAAIVfMod_vfModuleEndpoint") +\r
                        "/?resource-version=" + execution.getVariable("DAAIVfMod_vfModRsrcVer")\r
-               def aaiRequestId = UUID.randomUUID().toString()\r
+               def aaiRequestId = utils.getRequestID()\r
 \r
                RESTConfig config = new RESTConfig(endPoint);\r
                utils.log("DEBUG","deleteVfModule() endpoint-" + endPoint, isDebugEnabled)\r
index a0256d3..26c3049 100644 (file)
@@ -30,6 +30,7 @@ import org.openecomp.mso.bpmn.core.xml.XmlTool
 import org.openecomp.mso.logger.MessageEnum\r
 import org.openecomp.mso.logger.MsoLogger\r
 import org.openecomp.mso.utils.CryptoUtils\r
+import org.slf4j.MDC\r
 import org.w3c.dom.Element\r
 \r
 class MsoUtils {\r
@@ -947,5 +948,25 @@ class MsoUtils {
                 }\r
                 return sortedModuleIndexList.size().toString()\r
         }\r
+       /**\r
+        * This utility checks if there is transaction id already present in MDC.\r
+        * If found, it returns same else creates new, sets in MDC for future use before returning\r
+        * @return String RequestId in UUID format.\r
+        */\r
+       public String getRequestID()\r
+       {\r
+               String requestId = MDC.get("RequestId")\r
+               if(requestId == null || requestId.isEmpty())\r
+               {\r
+                       requestId = java.util.UUID.randomUUID()\r
+                       MDC.put("RequestId",requestId)\r
+                       log("DEBUG","MsoUtils - Created new RequestId: " + requestId)\r
+               }\r
+               else\r
+               {\r
+                       log("DEBUG","MsoUtils - Using existing RequestId: " + requestId)\r
+               }\r
 \r
+               return requestId\r
+       }\r
 }\r
index f30692c..14732fb 100644 (file)
@@ -31,6 +31,7 @@ import org.springframework.web.util.UriUtils
 public class PrepareUpdateAAIVfModule extends VfModuleBase {\r
        \r
        ExceptionUtil exceptionUtil = new ExceptionUtil()\r
+       private MsoUtils utils = new MsoUtils()\r
        /**\r
         * Initialize the flow's variables.\r
         * \r
@@ -116,7 +117,7 @@ public class PrepareUpdateAAIVfModule extends VfModuleBase {
                        try {\r
                                RESTConfig config = new RESTConfig(endPoint);\r
                                def responseData = ''\r
-                               def aaiRequestId = UUID.randomUUID().toString()\r
+                               String aaiRequestId = utils.getRequestID()\r
                                RESTClient client = new RESTClient(config).\r
                                        addHeader('X-TransactionId', aaiRequestId).\r
                                        addHeader('X-FromAppId', 'MSO').\r
@@ -255,7 +256,7 @@ public class PrepareUpdateAAIVfModule extends VfModuleBase {
                        try {\r
                                RESTConfig config = new RESTConfig(endPoint);\r
                                def responseData = ''\r
-                               def aaiRequestId = UUID.randomUUID().toString()\r
+                def aaiRequestId = utils.getRequestID()\r
                                RESTClient client = new RESTClient(config).\r
                                        addHeader('X-TransactionId', aaiRequestId).\r
                                        addHeader('X-FromAppId', 'MSO').\r