Merge "Fix AAI Service Delete failed issue."
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / CreateCustomE2EServiceInstance.groovy
index f376c44..450c5b1 100644 (file)
@@ -1,8 +1,9 @@
 /*-
  * ============LICENSE_START=======================================================
- * OPENECOMP - MSO
+ * ONAP - SO
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. 
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,11 +26,12 @@ import groovy.xml.XmlUtil
 import groovy.json.*
 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
-import org.openecomp.mso.bpmn.common.scripts.VidUtils
+
 import org.openecomp.mso.bpmn.core.WorkflowException
 import org.openecomp.mso.bpmn.core.json.JsonUtils
 import org.openecomp.mso.rest.APIResponse
 
+import java.util.List;
 import java.util.UUID;
 
 import org.camunda.bpm.engine.delegate.BpmnError
@@ -47,13 +49,13 @@ public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
        String Prefix="CRESI_"
        ExceptionUtil exceptionUtil = new ExceptionUtil()
        JsonUtils jsonUtil = new JsonUtils()
-       VidUtils vidUtils = new VidUtils()
+
 
        public void preProcessRequest (Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix",Prefix)
                String msg = ""
-               utils.log("DEBUG", " *** preProcessRequest() *** ", isDebugEnabled)
+               utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)
 
                try {
 
@@ -62,81 +64,16 @@ public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
                        String requestId = execution.getVariable("mso-request-id")
                        execution.setVariable("msoRequestId", requestId)
-                       utils.log("DEBUG", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
+                       utils.log("INFO", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
 
                        String serviceInstanceId = execution.getVariable("serviceInstanceId")
                        if (isBlank(serviceInstanceId)) {
                                serviceInstanceId = UUID.randomUUID().toString()
                        }
-                       utils.log("DEBUG", "Generated new Service Instance:" + serviceInstanceId, isDebugEnabled)
+                       utils.log("INFO", "Generated new Service Instance:" + serviceInstanceId, isDebugEnabled)
                        serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
                        execution.setVariable("serviceInstanceId", serviceInstanceId)
 
-                       //parameters
-                       String p_domainHost = jsonUtil.getJsonValue(siRequest, "service.parameters.domainHost")
-                       if (isBlank(p_domainHost)) {
-                               msg = "Input parameters domainHost is null"
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-                       } else {
-                               execution.setVariable("p_domainHost", p_domainHost)
-                       }
-
-                       String p_nodeTemplateName = jsonUtil.getJsonValue(siRequest, "service.parameters.nodeTemplateName")
-                       if (isBlank(p_nodeTemplateName)) {
-                               msg = "Input parameters nodeTemplateName is null"
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-                       } else {
-                               execution.setVariable("p_nodeTemplateName", p_nodeTemplateName)
-                       }
-                       
-                       String p_nodeType = jsonUtil.getJsonValue(siRequest, "service.parameters.nodeType")
-                       if (isBlank(p_nodeType)) {
-                               msg = "Input parameters nodeType is null"
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-                       } else {
-                               execution.setVariable("p_nodeType", p_nodeType)
-                       }
-
-                       //segments
-                       def jsonSlurper = new JsonSlurper()
-                       //def jsonOutput = new JsonOutput()
-
-                       Map reqMap = jsonSlurper.parseText(siRequest)           
-                       
-                       def p_segments = reqMap.service?.parameters?.segments
-                       
-                       //List<Segment> segList = []
-                       //if (p_segments) {
-                       //    p_segments.each {
-                       //              p_segment -> segList.add(p_segment)
-                       //              //p_segment.domainHost
-                       //      }
-                       //}
-                       //execution.setVariable("segments", segList)
-                       
-                       //location Constraints
-                       def p_locationConstraints = reqMap.service?.parameters?.nsParameters?.locationConstraints
-                       if(p_locationConstraints){
-                       //Copy data. no data available now so ignoring
-                       }
-                       
-                       //additionalParamForNs
-                       String p_param1 = jsonUtil.getJsonValue(siRequest, "service.parameters.nsParameters.additionalParamForNs.E2EServcie.param1")
-                       if (isBlank(p_param1)) {
-                               msg = "Input parameters p_param1 is null"
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-                       } else {
-                               execution.setVariable("p_param1", p_param1)
-                       }
-                       
-                       String p_param2 = jsonUtil.getJsonValue(siRequest, "service.parameters.nsParameters.additionalParamForNs.E2EServcie.param2")
-                       if (isBlank(p_param2)) {
-                               msg = "Input parameters p_param2 is null"
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-                       } else {
-                               execution.setVariable("p_param2", p_param2)
-                       }
-
                        //subscriberInfo
                        String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
                        if (isBlank(globalSubscriberId)) {
@@ -154,74 +91,73 @@ public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        if (isBlank(productFamilyId))
                        {
                                msg = "Input productFamilyId is null"
-                               utils.log("DEBUG", msg, isDebugEnabled)
+                               utils.log("INFO", msg, isDebugEnabled)
                                //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
                        } else {
                                execution.setVariable("productFamilyId", productFamilyId)
                        }
-
+                String userParams = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams")      
+             utils.log("INFO", "userParams:" + userParams, isDebugEnabled)
+                List<String> paramList = jsonUtil.StringArrayToList(execution, userParams)
+                String uuiRequest = jsonUtil.getJsonValue(paramList.get(0), "UUIRequest")
                        //modelInfo
-                       String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
-                       if (isBlank(serviceModelInfo)) {
-                               msg = "Input serviceModelInfo is null"
-                               utils.log("DEBUG", msg, isDebugEnabled)
+                       if (isBlank(uuiRequest)) {
+                               msg = "Input uuiRequest is null"
+                               utils.log("INFO", msg, isDebugEnabled)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
                        } else
                        {
-                               execution.setVariable("serviceModelInfo", serviceModelInfo)
+                               execution.setVariable("uuiRequest", uuiRequest)
                        }
 
-                       utils.log("DEBUG", "modelInfo" + serviceModelInfo,  isDebugEnabled)
+                       utils.log("INFO", "uuiRequest:\n" + uuiRequest,  isDebugEnabled)
 
                        //requestParameters
-                       String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
-                       if (isBlank(subscriptionServiceType)) {
-                               msg = "Input subscriptionServiceType is null"
-                               utils.log("DEBUG", msg, isDebugEnabled)
+                       String serviceType = jsonUtil.getJsonValue(uuiRequest, "service.parameters.serviceType")
+                       if (isBlank(serviceType)) {
+                               msg = "Input serviceType is null"
+                               utils.log("INFO", msg, isDebugEnabled)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
                        } else {
-                               execution.setVariable("subscriptionServiceType", subscriptionServiceType)
+                               execution.setVariable("serviceType", serviceType)
                        }
-
-                       //TODO
-                       //execution.setVariable("serviceInputParams", jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams"))
-                       //execution.setVariable("failExists", true)
+                       execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
 
                } catch (BpmnError e) {
                        throw e;
                } catch (Exception ex){
                        msg = "Exception in preProcessRequest " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
+                       utils.log("INFO", msg, isDebugEnabled)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
+               utils.log("INFO"," ***** Exit preProcessRequest *****",  isDebugEnabled)
        }
 
        public void sendSyncResponse (Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
+               utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
 
                try {
-                       String requestId = execution.getVariable("msoRequestId")
+                       String operationId = execution.getVariable("operationId")
                        String serviceInstanceId = execution.getVariable("serviceInstanceId")
                        // RESTResponse for API Handler (APIH) Reply Task
-                       String createServiceRestRequest = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${requestId}"}}""".trim()
-                       utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + createServiceRestRequest, isDebugEnabled)
+                       String createServiceRestRequest = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${operationId}"}}""".trim()
+                       utils.log("INFO", " sendSyncResponse to APIH:" + "\n" + createServiceRestRequest, isDebugEnabled)
                        sendWorkflowResponse(execution, 202, createServiceRestRequest)
                        execution.setVariable("sentSyncResponse", true)
 
                } catch (Exception ex) {
                        String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
+                       utils.log("INFO", msg, isDebugEnabled)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("DEBUG"," ***** Exit sendSyncResopnse *****",  isDebugEnabled)
+               utils.log("INFO"," ***** Exit sendSyncResopnse *****",  isDebugEnabled)
        }
 
 
        public void sendSyncError (Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG", " *** sendSyncError *** ", isDebugEnabled)
+               utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
 
                try {
                        String errorMessage = ""
@@ -242,14 +178,14 @@ public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        sendWorkflowResponse(execution, 500, buildworkflowException)
 
                } catch (Exception ex) {
-                       utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
+                       utils.log("INFO", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
                }
 
        }
 
        public void prepareCompletionRequest (Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
+               utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
 
                try {
                        String requestId = execution.getVariable("msoRequestId")
@@ -273,23 +209,23 @@ public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
 
                        execution.setVariable("completionRequest", xmlMsoCompletionRequest)
-                       utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
+                       utils.log("INFO", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
 
                } catch (Exception ex) {
                        String msg = " Exception in prepareCompletion:" + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
+                       utils.log("INFO", msg, isDebugEnabled)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
+               utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
        }
 
        public void prepareFalloutRequest(Execution execution){
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
+               utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)
 
                try {
                        WorkflowException wfex = execution.getVariable("WorkflowException")
-                       utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
+                       utils.log("INFO", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
                        String requestId = execution.getVariable("msoRequestId")
                        String source = execution.getVariable("source")
                        String requestInfo =
@@ -302,7 +238,7 @@ public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
                        execution.setVariable("falloutRequest", falloutRequest)
                } catch (Exception ex) {
-                       utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
+                       utils.log("INFO", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
                        String errorException = "  Bpmn error encountered in CreateGenericALaCarteServiceInstance flow. FalloutHandlerRequest,  buildErrorResponse() - " + ex.getMessage()
                        String requestId = execution.getVariable("msoRequestId")
                        String falloutRequest =
@@ -312,7 +248,7 @@ public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                                           <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
                                              <request-id>${requestId}</request-id>
                                              <action>CREATE</action>
-                                             <source>VID</source>
+                                             <source>UUI</source>
                                           </request-info>
                                                <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
                                                        <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
@@ -322,6 +258,64 @@ public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
                        execution.setVariable("falloutRequest", falloutRequest)
                }
-               utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
+               utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
+       }
+       
+       /**
+        * Init the service Operation Status
+        */
+       public void prepareInitServiceOperationStatus(Execution execution){
+        def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+        utils.log("INFO", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
+        try{
+            String serviceId = execution.getVariable("serviceInstanceId")
+            String operationId = UUID.randomUUID().toString()
+            String serviceName = execution.getVariable("serviceInstanceName")
+            String operationType = "CREATE"
+            String userId = ""
+            String result = "processing"
+            String progress = "0"
+            String reason = ""
+            String operationContent = "Prepare service creation"
+            utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
+            serviceId = UriUtils.encode(serviceId,"UTF-8")
+            execution.setVariable("serviceInstanceId", serviceId)
+            execution.setVariable("operationId", operationId)
+            execution.setVariable("operationType", operationType)
+
+            def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
+            execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
+            utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
+
+            String payload =
+                """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+                        xmlns:ns="http://org.openecomp.mso/requestsdb">
+                        <soapenv:Header/>
+                        <soapenv:Body>
+                            <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
+                            <serviceId>${serviceId}</serviceId>
+                            <operationId>${operationId}</operationId>
+                            <serviceName>${serviceName}</serviceName>
+                            <operationType>${operationType}</operationType>
+                            <userId>${userId}</userId>
+                            <result>${result}</result>
+                            <operationContent>${operationContent}</operationContent>
+                            <progress>${progress}</progress>
+                            <reason>${reason}</reason>
+                        </ns:updateServiceOperationStatus>
+                    </soapenv:Body>
+                </soapenv:Envelope>"""
+
+            payload = utils.formatXml(payload)
+            execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
+            utils.log("INFO", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
+            utils.logAudit("CreateVfModuleInfra Outgoing updateServiceOperStatusRequest Request: " + payload)
+
+        }catch(Exception e){
+            utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
+            execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
+        }
+        utils.log("INFO", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)    
        }
-}
\ No newline at end of file
+       
+}