AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoDeleteVFCNetworkServiceInstance.groovy
index f3659ed..c71cb05 100644 (file)
@@ -32,7 +32,7 @@ import org.openecomp.mso.rest.APIResponse
 import java.util.UUID;\r
 \r
 import org.camunda.bpm.engine.delegate.BpmnError \r
-import org.camunda.bpm.engine.runtime.Execution\r
+import org.camunda.bpm.engine.delegate.DelegateExecution\r
 import org.apache.commons.lang3.*\r
 import org.apache.commons.codec.binary.Base64;\r
 import org.springframework.web.util.UriUtils \r
@@ -41,16 +41,15 @@ import org.openecomp.mso.rest.RESTConfig
 import org.openecomp.mso.rest.APIResponse;\r
 \r
 /**\r
- * This groovy class supports the <class>DODeleteVFCNetworkServiceInstance.bpmn</class> process.\r
+ * This groovy class supports the <class>DoDeleteVFCNetworkServiceInstance.bpmn</class> process.\r
  * flow for E2E ServiceInstance Delete\r
  */\r
-public class DODeleteVFCNetworkServiceInstance extends AbstractServiceTaskProcessor {\r
+public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProcessor {\r
 \r
-    String deleteUrl = "/vfc/vfcadapters/v1/ns/{nsInstanceId}"\r
             \r
-    String terminateUrl = "/vfcvfcadatpers/v1/ns/{nsInstanceId}/terminate"\r
+    String vfcUrl = "/vfc/rest/v1/vfcadapter"\r
     \r
-    String queryJobUrl = "/vfc/vfcadatpers/v1/jobs/{jobId}"\r
+    String host = "http://mso.mso.testlab.openecomp.org:8080"\r
     \r
     ExceptionUtil exceptionUtil = new ExceptionUtil()\r
 \r
@@ -61,102 +60,118 @@ public class DODeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
      * Inclouds:\r
      * generate the nsOperationKey\r
      */\r
-    public void preProcessRequest (Execution execution) {\r
+    public void preProcessRequest (DelegateExecution execution) {\r
         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
         String msg = ""\r
-        utils.log("DEBUG", " *** preProcessRequest() *** ", isDebugEnabled)\r
+        utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)\r
         try {\r
             //deal with operation key\r
             String globalSubscriberId = execution.getVariable("globalSubscriberId")\r
-            utils.log("DEBUG", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)\r
+            utils.log("INFO", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)\r
             String serviceType = execution.getVariable("serviceType")\r
-            utils.log("DEBUG", "serviceType:" + serviceType, isDebugEnabled)\r
+            utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)\r
             String serviceId = execution.getVariable("serviceId")\r
-            utils.log("DEBUG", "serviceId:" + serviceId, isDebugEnabled)\r
+            utils.log("INFO", "serviceId:" + serviceId, isDebugEnabled)\r
             String operationId = execution.getVariable("operationId")\r
-            utils.log("DEBUG", "serviceType:" + serviceType, isDebugEnabled)\r
-            String nodeTemplateUUID = execution.getVariable("nodeTemplateUUID")\r
-            utils.log("DEBUG", "nodeTemplateUUID:" + nodeTemplateUUID, isDebugEnabled)\r
-            String nsInstanceId = execution.getVariable("nsInstanceId")\r
-            utils.log("DEBUG", "nsInstanceId:" + nsInstanceId, isDebugEnabled)\r
-            String nsOperationKey = "{\"globalSubscriberId\":\"" + globalSubscriberId + "\",\"serviceType:\""\r
-                  + serviceType + "\",\"serviceId\":\"" + serviceId + "\",\"operationId\":\"" + operationId\r
-                  +"\",\"nodeTemplateUUID\":\"" + nodeTemplateUUID + "\"}";\r
+            utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)\r
+            String nodeTemplateUUID = execution.getVariable("resourceTemplateId")\r
+            utils.log("INFO", "nodeTemplateUUID:" + nodeTemplateUUID, isDebugEnabled)\r
+            String nsInstanceId = execution.getVariable("resourceInstanceId")\r
+            utils.log("INFO", "nsInstanceId:" + nsInstanceId, isDebugEnabled)\r
+            execution.setVariable("nsInstanceId",nsInstanceId)\r
+            String nsOperationKey = """{\r
+            "globalSubscriberId":"${globalSubscriberId}",\r
+            "serviceType":"${serviceType}",\r
+            "serviceId":"${serviceId}",\r
+            "operationId":"${operationId}",\r
+            "nodeTemplateUUID":"${nodeTemplateUUID}"\r
+             }"""\r
             execution.setVariable("nsOperationKey", nsOperationKey);\r
+            utils.log("INFO", "nsOperationKey:" + nsOperationKey, isDebugEnabled)\r
         } catch (BpmnError e) {\r
             throw e;\r
         } catch (Exception ex){\r
             msg = "Exception in preProcessRequest " + ex.getMessage()\r
-            utils.log("DEBUG", msg, isDebugEnabled)\r
+            utils.log("INFO", msg, isDebugEnabled)\r
             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
         }\r
-        utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
+        utils.log("INFO"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
        }\r
 \r
     /**\r
      * delete NS task\r
      */\r
-    public void deleteNetworkService(Execution execution) {\r
-        String nsOperationKey = excution.getVariable("nsOperationKey");\r
-        String url = deleteUrl.replaceAll("{nsInstanceId}", execution.getVariable("nsInstanceId")) \r
-        APIResponse apiResponse = deleteRequest(url, reqBody)\r
+    public void deleteNetworkService(DelegateExecution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO", " *** deleteNetworkService  start *** ", isDebugEnabled)\r
+        String nsOperationKey = execution.getVariable("nsOperationKey");\r
+        String url = host + vfcUrl + "/ns/" + execution.getVariable("nsInstanceId") \r
+        APIResponse apiResponse = deleteRequest(execution, url, nsOperationKey)\r
         String returnCode = apiResponse.getStatusCode()\r
-        String aaiResponseAsString = apiResponse.getResponseBodyAsString()\r
+        String apiResponseAsString = apiResponse.getResponseBodyAsString()\r
         String operationStatus = "error";\r
-        if(returnCode== "200"){\r
+        if(returnCode== "200" || returnCode== "202"){\r
             operationStatus = "finished"\r
         }\r
         execution.setVariable("operationStatus", operationStatus)\r
+        \r
+        utils.log("INFO", " *** deleteNetworkService  end *** ", isDebugEnabled)\r
     }\r
 \r
     /**\r
      * instantiate NS task\r
      */\r
-    public void terminateNetworkService(Execution execution) {\r
+    public void terminateNetworkService(DelegateExecution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO", " *** terminateNetworkService  start *** ", isDebugEnabled)\r
         String nsOperationKey = execution.getVariable("nsOperationKey") \r
-        String url = terminateUrl.replaceAll("{nsInstanceId}", execution.getVariable("nsInstanceId")) \r
-        APIResponse apiResponse = postRequest(url, reqBody)\r
+        String url =  host + vfcUrl + "/ns/" + execution.getVariable("nsInstanceId") + "/terminate"\r
+        APIResponse apiResponse = postRequest(execution, url, nsOperationKey)\r
         String returnCode = apiResponse.getStatusCode()\r
         String aaiResponseAsString = apiResponse.getResponseBodyAsString()\r
         String jobId = "";\r
-        if(returnCode== "200"){\r
+        if(returnCode== "200" || returnCode== "202"){\r
             jobId =  jsonUtil.getJsonValue(aaiResponseAsString, "jobId")\r
         }\r
-        execution.setVariable("jobId", nsInstanceId)   \r
+        execution.setVariable("jobId", jobId)   \r
+        utils.log("INFO", " *** terminateNetworkService  end *** ", isDebugEnabled)\r
     }\r
 \r
     /**\r
      * query NS task\r
      */\r
-    public void queryNSProgress(Execution execution) {\r
+    public void queryNSProgress(DelegateExecution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+        utils.log("INFO", " *** queryNSProgress  start *** ", isDebugEnabled)\r
         String jobId = execution.getVariable("jobId")\r
-        String nsOperationKey = excution.getVariable("nsOperationKey");\r
-        String url = queryJobUrl.replaceAll("{jobId}", execution.getVariable("jobId")\r
-        APIResponse createRsp = postRequest(url, nsOperationKey)\r
+        String nsOperationKey = execution.getVariable("nsOperationKey");\r
+        String url =  host + vfcUrl + "/jobs/" +  execution.getVariable("jobId"\r
+        APIResponse apiResponse = postRequest(execution, url, nsOperationKey)\r
         String returnCode = apiResponse.getStatusCode()\r
-        String aaiResponseAsString = apiResponse.getResponseBodyAsString()\r
+        String apiResponseAsString = apiResponse.getResponseBodyAsString()\r
         String operationProgress = "100"\r
         if(returnCode== "200"){\r
-            operationProgress = jsonUtil.getJsonValue(aaiResponseAsString, "responseDescriptor.progress")\r
+            operationProgress = jsonUtil.getJsonValue(apiResponseAsString, "responseDescriptor.progress")\r
         }\r
-        exection.setVariable("operationProgress", operationProgress)\r
+        execution.setVariable("operationProgress", operationProgress)\r
+        utils.log("INFO", " *** queryNSProgress  end *** ", isDebugEnabled)\r
     }\r
 \r
     /**\r
      * delay 5 sec \r
      */\r
-    public void timeDelay(Execution execution) {\r
+    public void timeDelay(DelegateExecution execution) {\r
         try {\r
             Thread.sleep(5000);\r
         } catch(InterruptedException e) {           \r
-            taskProcessor.utils.log("ERROR", "Time Delay exception" + e , isDebugEnabled)\r
+            utils.log("INFO", "Time Delay exception" + e, isDebugEnabled)\r
         }\r
     }\r
 \r
     /**\r
      * finish NS task\r
      */\r
-    public void finishNSDelete(Execution execution) {\r
+    public void finishNSDelete(DelegateExecution execution) {\r
         //no need to do anything util now\r
     }\r
 \r
@@ -165,19 +180,19 @@ public class DODeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
      * url: the url of the request\r
      * requestBody: the body of the request\r
      */\r
-    private APIResponse postRequest(String url, String requestBody){\r
+    private APIResponse postRequest(DelegateExecution execution, String url, String requestBody){\r
         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
-        taskProcessor.logDebug( " ======== Started Execute VFC adapter Post Process ======== ", isDebugEnabled)\r
-        taskProcessor.logDebug( "url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)\r
+        utils.log("INFO", " ======== Started Execute VFC adapter Post Process ======== ", isDebugEnabled)\r
+        utils.log("INFO", "url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)\r
         APIResponse apiResponse = null\r
         try{\r
             RESTConfig config = new RESTConfig(url);\r
-            RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/json");\r
+            RESTClient client = new RESTClient(config).addHeader("Content-Type", "application/json").addHeader("Accept","application/json").addHeader("Authorization","Basic QlBFTENsaWVudDpwYXNzd29yZDEk");;\r
             apiResponse = client.httpPost(requestBody)\r
-            taskProcessor.logDebug( "response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled)\r
-            taskProcessor.logDebug( "======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled)\r
+            utils.log("INFO", "response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled)\r
+            utils.log("INFO", "======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled)\r
         }catch(Exception e){\r
-            taskProcessor.utils.log("ERROR", "Exception occured while executing VF-C Post Call. Exception is: \n" + e, isDebugEnabled)\r
+            utils.log("ERROR", "Exception occured while executing VF-C Post Call. Exception is: \n" + e, isDebugEnabled)\r
             throw new BpmnError("MSOWorkflowException")\r
         }        \r
         return apiResponse\r
@@ -187,19 +202,19 @@ public class DODeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
      * url: the url of the request\r
      * requestBody: the body of the request\r
      */\r
-    private APIResponse deleteRequest(String url, String requestBody){\r
+    private APIResponse deleteRequest(DelegateExecution execution, String url, String requestBody){\r
         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
-        taskProcessor.logDebug( " ======== Started Execute VFC adapter Delete Process ======== ", isDebugEnabled)\r
-        taskProcessor.logDebug( "url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)\r
+        utils.log("INFO", " ======== Started Execute VFC adapter Delete Process ======== ", isDebugEnabled)       \r
+        utils.log("INFO", "url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)\r
         APIResponse apiResponse = null\r
         try{\r
             RESTConfig config = new RESTConfig(url);\r
-            RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/json");\r
+            RESTClient client = new RESTClient(config).addHeader("Content-Type", "application/json").addHeader("Accept","application/json").addHeader("Authorization","Basic QlBFTENsaWVudDpwYXNzd29yZDEk");\r
             apiResponse = client.httpDelete(requestBody)\r
-            taskProcessor.logDebug( "response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled)\r
-            taskProcessor.logDebug( "======== Completed Execute VF-C adapter Delete Process ======== ", isDebugEnabled)\r
+            utils.log("INFO", "response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled) \r
+            utils.log("INFO", "======== Completed Execute VF-C adapter Delete Process ======== ", isDebugEnabled) \r
         }catch(Exception e){\r
-            taskProcessor.utils.log("ERROR", "Exception occured while executing VF-C Post Call. Exception is: \n" + e, isDebugEnabled)\r
+            utils.log("ERROR", "Exception occured while executing VF-C Post Call. Exception is: \n" + e, isDebugEnabled) \r
             throw new BpmnError("MSOWorkflowException")\r
         }        \r
         return apiResponse\r