Add Relationship for e2e service and NS
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateVFCNetworkServiceInstance.groovy
index 8354798..2e62abd 100644 (file)
@@ -53,7 +53,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
     ExceptionUtil exceptionUtil = new ExceptionUtil()\r
 \r
     JsonUtils jsonUtil = new JsonUtils()\r
-\r
+    \r
     /**\r
      * Pre Process the BPMN Flow Request\r
      * Inclouds:\r
@@ -118,7 +118,8 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
      * create NS task\r
      */\r
     public void createNetworkService(Execution execution) {\r
-        \r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO"," *****  createNetworkService *****",  isDebugEnabled)\r
         String nsOperationKey = execution.getVariable("nsOperationKey");\r
         String nsParameters = execution.getVariable("nsParameters");\r
         String nsServiceName = execution.getVariable("nsServiceName")\r
@@ -137,13 +138,15 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
             nsInstanceId =  jsonUtil.getJsonValue(aaiResponseAsString, "nsInstanceId")\r
         }\r
         execution.setVariable("nsInstanceId", nsInstanceId)\r
-        \r
+        utils.log("INFO"," *****Exit  createNetworkService *****",  isDebugEnabled)\r
     }\r
 \r
     /**\r
      * instantiate NS task\r
      */\r
     public void instantiateNetworkService(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO"," *****  instantiateNetworkService *****",  isDebugEnabled)\r
         String nsOperationKey = execution.getVariable("nsOperationKey");\r
         String nsParameters = execution.getVariable("nsParameters");\r
         String nsServiceName = execution.getVariable("nsServiceName")\r
@@ -163,13 +166,16 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
         if(returnCode== "200"){\r
             jobId =  jsonUtil.getJsonValue(aaiResponseAsString, "jobId")\r
         }\r
-        execution.setVariable("jobId", nsInstanceId)\r
+        execution.setVariable("jobId", jobId)\r
+        utils.log("INFO"," *****Exit  instantiateNetworkService *****",  isDebugEnabled)\r
     }\r
 \r
     /**\r
      * query NS task\r
      */\r
     public void queryNSProgress(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO"," *****  queryNSProgress *****",  isDebugEnabled)\r
         String jobId = execution.getVariable("jobId")\r
         String nsOperationKey = execution.getVariable("nsOperationKey");\r
         String url = host + vfcUrl + "/jobs/" + jobId\r
@@ -181,24 +187,81 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
             operationStatus = jsonUtil.getJsonValue(aaiResponseAsString, "responseDescriptor.status")\r
         }\r
         execution.setVariable("operationStatus", operationStatus)\r
+        utils.log("INFO"," *****Exit  queryNSProgress *****",  isDebugEnabled)\r
     }\r
 \r
     /**\r
      * delay 5 sec \r
      */\r
     public void timeDelay(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
         try {\r
             Thread.sleep(5000);\r
         } catch(InterruptedException e) {           \r
-            taskProcessor.utils.log("ERROR", "Time Delay exception" + e , isDebugEnabled)\r
+            utils.log("ERROR", "Time Delay exception" + e , isDebugEnabled)\r
         }\r
     }\r
 \r
     /**\r
      * finish NS task\r
      */\r
-    public void finishNSCreate(Execution execution) {\r
-        //no need to do anything util now\r
+    public void addNSRelationship(Execution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO"," ***** addNSRelationship *****",  isDebugEnabled)\r
+        String operationStatus = execution.getVariable("operationStatus")\r
+        if(operationStatus != "finished"){\r
+            utils.log("INFO"," create NS failed, so do not need to add relationship",  isDebugEnabled)\r
+            return\r
+        }\r
+        String globalSubscriberId = execution.getVariable("globalSubscriberId")\r
+        String serviceType = execution.getVariable("serviceType")\r
+        String serviceId = execution.getVariable("serviceId")\r
+        String nsInstanceId = execution.getVariable("nsInstanceId")\r
+        String addRelationPayload = """<relationship xmlns="http://org.openecomp.aai.inventory/v11">\r
+                                            <related-to>service-instance</related-to>\r
+                                            <related-link>/aai/v11/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${nsInstanceId}</related-link>\r
+                                            <relationship-data>\r
+                                                <relationship-key>customer.global-customer-id</relationship-key>\r
+                                                <relationship-value>${globalSubscriberId}</relationship-value>\r
+                                            </relationship-data>\r
+                                            <relationship-data>\r
+                                                <relationship-key>service-subscription.service-type</relationship-key>\r
+                                                <relationship-value>${serviceType}</relationship-value>\r
+                                            </relationship-data>\r
+                                           <relationship-data>\r
+                                                <relationship-key>service-instance.service-instance-id</relationship-key>\r
+                                                <relationship-value>${nsInstanceId}</relationship-value>\r
+                                            </relationship-data>           \r
+                                        </relationship>"""\r
+        String endpoint = execution.getVariable("URN_aai_endpoint")  \r
+        String url = endpoint + "/aai/v11/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + serviceType + "/service-instances/service-instance/" + serviceId + "/relationship-list/relationship"\r
+        executeAAIPutCall(execution, url, addRelationPayload)\r
+        utils.log("INFO"," *****Exit addNSRelationship *****",  isDebugEnabled)\r
+    }\r
+    \r
+    public APIResponse executeAAIPutCall(Execution execution, String url, String payload){\r
+        def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO", " ======== Started Execute AAI Put Process ======== ",  isDebugEnabled) \r
+        APIResponse apiResponse = null\r
+        try{\r
+            String uuid = utils.getRequestID()\r
+            utils.log("INFO","Generated uuid is: " + uuid,  isDebugEnabled) \r
+            utils.log("INFO","URL to be used is: " + url,  isDebugEnabled) \r
+            String userName = execution.getVariable("URN_aai_auth")\r
+            String password = execution.getVariable("URN_mso_msoKey")\r
+            String basicAuthCred = utils.getBasicAuth(userName,password)\r
+            RESTConfig config = new RESTConfig(url);\r
+            RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/xml").addHeader("Accept","application/xml");\r
+            if (basicAuthCred != null && !"".equals(basicAuthCred)) {\r
+                client.addAuthorizationHeader(basicAuthCred)\r
+            }\r
+            apiResponse = client.httpPut(payload)\r
+            utils.log("INFO","======== Completed Execute AAI Put Process ======== ",  isDebugEnabled) \r
+        }catch(Exception e){\r
+            utils.log("ERROR","Exception occured while executing AAI Put Call. Exception is: \n" + e,  isDebugEnabled) \r
+            throw new BpmnError("MSOWorkflowException")\r
+        }\r
+        return apiResponse\r
     }\r
     \r
     /**\r