Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoUpdateE2EServiceInstance.groovy
index 0372d95..74c991e 100644 (file)
@@ -22,10 +22,12 @@ package org.openecomp.mso.bpmn.infrastructure.scripts;
 import static org.apache.commons.lang3.StringUtils.*;\r
 import groovy.xml.XmlUtil\r
 import groovy.json.*\r
+import groovy.util.XmlParser\r
 \r
 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition\r
 import org.openecomp.mso.bpmn.core.domain.ServiceInstance\r
 import org.openecomp.mso.bpmn.core.domain.ModelInfo\r
+import org.openecomp.mso.bpmn.core.domain.Resource\r
 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
 import org.openecomp.mso.bpmn.common.scripts.AaiUtil\r
 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
@@ -49,35 +51,28 @@ import org.apache.commons.lang3.*
 import org.apache.commons.codec.binary.Base64;\r
 import org.springframework.web.util.UriUtils;\r
 \r
-import org.w3c.dom.Document\r
-import org.w3c.dom.Element\r
-import org.w3c.dom.Node\r
-import org.w3c.dom.NodeList\r
-import org.xml.sax.InputSource\r
+\r
 /**\r
- * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.\r
+ * This groovy class supports the <class>DoUpdateE2EServiceInstance.bpmn</class> process.\r
  *\r
  * Inputs:\r
  * @param - msoRequestId\r
  * @param - globalSubscriberId\r
- * @param - subscriptionServiceType\r
+ * @param - serviceType\r
  * @param - serviceInstanceId\r
- * @param - serviceInstanceName - O\r
+ * @param - serviceInstanceName\r
  * @param - serviceModelInfo\r
  * @param - productFamilyId\r
- * @param - disableRollback\r
- * @param - failExists - TODO\r
- * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)\r
- * @param - sdncVersion ("1610")\r
- * @param - serviceDecomposition - Decomposition for R1710 \r
- * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)\r
- *\r
+ * @param - uuiRequest\r
+ * @param - serviceDecomposition_Target\r
+ * @param - serviceDecomposition_Original\r
+ * @param - addResourceList\r
+ * @param - delResourceList\r
+ * \r
  * Outputs:\r
  * @param - rollbackData (localRB->null)\r
  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)\r
  * @param - WorkflowException\r
- * @param - serviceInstanceName - (GET from AAI if null in input)\r
- *\r
  */\r
 public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {\r
 \r
@@ -88,31 +83,23 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {
        JsonUtils jsonUtil = new JsonUtils()\r
 \r
        public void preProcessRequest (DelegateExecution execution) {\r
-           //only for dug\r
-               execution.setVariable("isDebugLogEnabled","true")\r
-               execution.setVariable("unit_test", "true")\r
-               execution.setVariable("skipVFC", "true")\r
-               \r
-               def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'\r
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
-               utils.log("INFO","Entered " + method, isDebugEnabled)\r
-               String msg = ""\r
                utils.log("INFO"," ***** Enter DoUpdateE2EServiceInstance preProcessRequest *****",  isDebugEnabled)\r
                \r
-               utils.log("INFO","  unit test : " + execution.getVariable("unit_test"),  isDebugEnabled)        \r
+               String msg = "" \r
 \r
                try {\r
                        execution.setVariable("prefix", Prefix)\r
                        //Inputs\r
-                       //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology\r
+                       //for AAI GET & PUT & SDNC assignToplology\r
                        String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId\r
                        utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId,  isDebugEnabled)\r
                        \r
-                       //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology\r
+                       //for AAI PUT & SDNC assignTopology\r
                        String serviceType = execution.getVariable("serviceType")\r
                        utils.log("INFO"," ***** serviceType *****" + serviceType,  isDebugEnabled)\r
                        \r
-                       //requestDetails.requestParameters. for SDNC assignTopology\r
+                       //for SDNC assignTopology\r
                        String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId\r
 \r
                        if (isBlank(globalSubscriberId)) {\r
@@ -134,93 +121,22 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {
                                utils.log("INFO", msg, isDebugEnabled)\r
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
                        }\r
-                       \r
-                       if (productFamilyId == null) {\r
-                               execution.setVariable("productFamilyId", "")\r
-                       }\r
-                       \r
-                       String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')\r
-                       if (isBlank(sdncCallbackUrl)) {\r
-                               msg = "URN_mso_workflow_sdncadapter_callback is null"\r
-                               utils.log("INFO", msg, isDebugEnabled)\r
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
-                       }\r
-                       execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)\r
-                       utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)\r
 \r
-                       //requestDetails.modelInfo.for AAI PUT servieInstanceData                       \r
-                       //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData \r
                        String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
-                       //String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
-                       String uuiRequest = execution.getVariable("uuiRequest")\r
-                       utils.log("INFO","uuiRequest: " + uuiRequest, isDebugEnabled)\r
-                       \r
-                       String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceDefId")\r
-                       utils.log("INFO","modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)\r
-                       \r
-                       String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.templateId")\r
-                       utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)\r
-                       \r
-                       String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")\r
-                       utils.log("INFO","serviceModelName: " + serviceModelName, isDebugEnabled)\r
-                       execution.setVariable("serviceModelName", serviceModelName)\r
-                       \r
-            //aai serviceType and Role can be setted as fixed value now.\r
-                       String aaiServiceType = serviceType\r
-                       String aaiServiceRole = serviceType+"Role"\r
                        \r
-                       execution.setVariable("modelInvariantUuid", modelInvariantUuid)\r
-                       execution.setVariable("model-invariant-id-target", modelInvariantUuid)\r
-                       execution.setVariable("modelUuid", modelUuid)\r
-                       execution.setVariable("model-version-id-target", modelUuid_target)\r
-\r
-                       //AAI PUT\r
-                       String oStatus = execution.getVariable("initialStatus") ?: ""\r
-                       utils.log("INFO","oStatus: " + oStatus, isDebugEnabled)\r
-                       if ("TRANSPORT".equalsIgnoreCase(serviceType))\r
-                       {\r
-                               oStatus = "Update"\r
-                       }\r
-\r
-                       String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${oStatus}</orchestration-status>"\r
-                       utils.log("INFO","statusLine: " + statusLine, isDebugEnabled)   \r
-                       AaiUtil aaiUriUtil = new AaiUtil(this)\r
-                       utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled) \r
-                       String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
-                       utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)\r
-                       String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)\r
-                       utils.log("INFO","namespace: " + namespace, isDebugEnabled)\r
-                       /*\r
-                       String serviceInstanceData =\r
-                                       """<service-instance xmlns=\"${namespace}\">\r
-                               <service-instance-id>${serviceInstanceId}</service-instance-id>\r
-                               <service-instance-name>${serviceInstanceName}</service-instance-name>\r
-                                       <service-type>${aaiServiceType}</service-type>\r
-                                       <service-role>${aaiServiceRole}</service-role>\r
-                                       ${statusLine}\r
-                                   <model-invariant-id>${modelInvariantUuid}</model-invariant-id>\r
-                                   <model-version-id>${modelUuid}</model-version-id>\r
-                                       </service-instance>""".trim()\r
-            */\r
-            //begin only for test\r
-                       String serviceInstanceData =\r
-                                       """<service-instance xmlns=\"${namespace}\">\r
-                               <service-instance-id>${serviceInstanceId}</service-instance-id>\r
-                               <service-instance-name>${serviceInstanceName}</service-instance-name>\r
-                                       <service-type>${aaiServiceType}</service-type>\r
-                                       <service-role>${aaiServiceRole}</service-role>\r
-                                       ${statusLine}\r
-                                       </service-instance>""".trim()\r
-                       //end only for test\r
-                       execution.setVariable("serviceInstanceData", serviceInstanceData)\r
-                       utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)\r
-                       utils.logAudit(serviceInstanceData)\r
-                       utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)\r
-                       utils.log("INFO", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)\r
-                       \r
-                       execution.setVariable("serviceSDNCCreate", "false")\r
-                       execution.setVariable("operationStatus", "Waiting deploy resource...")                  \r
-\r
+                       // user params\r
+                       String uuiRequest = execution.getVariable("uuiRequest")\r
+            \r
+                       // target model Invariant uuid\r
+                       String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")\r
+                       execution.setVariable("modelInvariantUuid", modelInvariantUuid)            \r
+                       utils.log("INFO", "modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)            \r
+            \r
+                       // target model uuid\r
+                       String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")\r
+                       execution.setVariable("modelUuid", modelUuid)                   \r
+                       utils.log("INFO", "modelUuid: " + modelUuid, isDebugEnabled)\r
+                               \r
                } catch (BpmnError e) {\r
                        throw e;\r
                } catch (Exception ex){\r
@@ -228,155 +144,9 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {
                        utils.log("INFO", msg, isDebugEnabled)\r
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
                }\r
-               utils.log("INFO", "Exited " + method, isDebugEnabled)\r
+               utils.log("INFO", "======== COMPLETED preProcessRequest Process ======== ", isDebugEnabled)  \r
        }\r
-       \r
-       public void postProcessAAIGET(DelegateExecution execution) {\r
-               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
-               utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)\r
-               String msg = ""\r
-\r
-               try {\r
-                       String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
-                       boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")\r
-                       String serviceType = ""\r
-\r
-                       if(foundInAAI){\r
-                               utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)\r
 \r
-                               String siData = execution.getVariable("GENGS_service")\r
-                               utils.log("INFO", "SI Data", isDebugEnabled)\r
-                               if (isBlank(siData))\r
-                               {\r
-                                       msg = "Could not retrive ServiceInstance data from AAI, Id:" + serviceInstanceId\r
-                                       utils.log("INFO", msg, isDebugEnabled)\r
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)\r
-                               }\r
-                               else\r
-                               {\r
-                                       utils.log("INFO", "SI Data" + siData, isDebugEnabled)\r
-                                       \r
-                                       InputSource source = new InputSource(new StringReader(siData));\r
-                                       DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();\r
-                                       DocumentBuilder docBuilder = docFactory.newDocumentBuilder()\r
-                                       Document serviceXml = docBuilder.parse(source)\r
-                                       serviceXml.getDocumentElement().normalize()\r
-                                       \r
-                                       // Get Template uuid and version\r
-                                       if (utils.nodeExists(siData, "model-invariant-id") && utils.nodeExists(siData, "model-version-id") ) {\r
-                                           utils.log("INFO", "SI Data model-invariant-id and model-version-id exist:", isDebugEnabled)\r
-                                           def modelInvariantId  = serviceXml.getElementsByTagName("model-invariant-id").item(0).getTextContent()\r
-                                           def modelVersionId  = serviceXml.getElementsByTagName("model-version-id").item(0).getTextContent()\r
-                                           \r
-                                           // Set Original Template info\r
-                                           execution.setVariable("model-invariant-id-original", modelInvariantId)\r
-                                           execution.setVariable("model-version-id-original", modelVersionId)                                  \r
-                                       }\r
-                                       \r
-                                       //Confirm there are no related service instances (vnf/network or volume)\r
-                                       if (utils.nodeExists(siData, "relationship-list")) {\r
-                                               utils.log("INFO", "SI Data relationship-list exists:", isDebugEnabled)\r
-                                               \r
-                                               //test(siData)\r
-                                               NodeList nodeList = serviceXml.getElementsByTagName("relationship")\r
-                           JSONArray jArray = new JSONArray()\r
-                                               for (int x = 0; x < nodeList.getLength(); x++) {\r
-                                                       Node node = nodeList.item(x)\r
-                                                       if (node.getNodeType() == Node.ELEMENT_NODE) {\r
-                                                               Element eElement = (Element) node\r
-                                                               def e = eElement.getElementsByTagName("related-to").item(0).getTextContent()                                                                    //for ns\r
-                                                               if(e.equals("service-instance")){\r
-                                                                   def relatedObject = eElement.getElementsByTagName("related-link").item(0).getTextContent()\r
-                                                                       utils.log("INFO", "ServiceInstance Related NS :" + relatedObject, isDebugEnabled)\r
-                                    NodeList dataList = node.getChildNodes()\r
-                                    if(null != dataList) {\r
-                                        JSONObject jObj = new JSONObject()\r
-                                        for (int i = 0; i < dataList.getLength(); i++) {\r
-                                            Node dNode = dataList.item(i)\r
-                                            if(dNode.getNodeName() == "relationship-data") {\r
-                                                Element rDataEle = (Element)dNode\r
-                                                def eKey =  rDataEle.getElementsByTagName("relationship-key").item(0).getTextContent()\r
-                                                def eValue = rDataEle.getElementsByTagName("relationship-value").item(0).getTextContent()\r
-                                                if(eKey.equals("service-instance.service-instance-id")){\r
-                                                    jObj.put("resourceInstanceId", eValue)\r
-                                                }\r
-                                            }\r
-                                            else if(dNode.getNodeName() == "related-to-property"){\r
-                                                 Element rDataEle = (Element)dNode\r
-                                                 def eKey =  rDataEle.getElementsByTagName("property-key").item(0).getTextContent()\r
-                                                 def eValue = rDataEle.getElementsByTagName("property-value").item(0).getTextContent()\r
-                                                 if(eKey.equals("service-instance.service-instance-name")){\r
-                                                        jObj.put("resourceType", eValue)\r
-                                                    }\r
-                                            }\r
-                                        }\r
-                                        utils.log("INFO", "Relationship related to Resource:" + jObj.toString(), isDebugEnabled)\r
-                                        jArray.put(jObj)\r
-                                    }\r
-                                                       //for overlay/underlay\r
-                                                               }else if (e.equals("configuration")){\r
-                                    def relatedObject = eElement.getElementsByTagName("related-link").item(0).getTextContent()\r
-                                    utils.log("INFO", "ServiceInstance Related Configuration :" + relatedObject, isDebugEnabled)\r
-                                                                       NodeList dataList = node.getChildNodes()\r
-                                                                       if(null != dataList) {\r
-                                                                               JSONObject jObj = new JSONObject()\r
-                                                                               for (int i = 0; i < dataList.getLength(); i++) {\r
-                                                                                       Node dNode = dataList.item(i)\r
-                                                                                       if(dNode.getNodeName() == "relationship-data") {\r
-                                                                                               Element rDataEle = (Element)dNode\r
-                                                                                               def eKey =  rDataEle.getElementsByTagName("relationship-key").item(0).getTextContent()\r
-                                                                                               def eValue = rDataEle.getElementsByTagName("relationship-value").item(0).getTextContent()\r
-                                                                                               if(eKey.equals("configuration.configuration-id")){\r
-                                                                                                   jObj.put("resourceInstanceId", eValue)\r
-                                                                                               }\r
-                                                                                       }\r
-                                                                                       else if(dNode.getNodeName() == "related-to-property"){\r
-                                                    Element rDataEle = (Element)dNode\r
-                                                    def eKey =  rDataEle.getElementsByTagName("property-key").item(0).getTextContent()\r
-                                                    def eValue = rDataEle.getElementsByTagName("property-value").item(0).getTextContent()\r
-                                                    if(eKey.equals("configuration.configuration-type")){\r
-                                                           jObj.put("resourceType", eValue)\r
-                                                       }\r
-                                                                                       }\r
-                                                                               }\r
-                                                                               utils.log("INFO", "Relationship related to Resource:" + jObj.toString(), isDebugEnabled)\r
-                                        jArray.put(jObj)\r
-                                                                       }                                                                       \r
-                                                               }\r
-                                                       }\r
-                                               }\r
-                        execution.setVariable("serviceRelationShip", jArray.toString())\r
-                                       }\r
-                               }\r
-                       }else{\r
-                               boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")\r
-                               if(!succInAAI){\r
-                                       utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled)\r
-                                       WorkflowException workflowException = execution.getVariable("WorkflowException")\r
-                                       utils.logAudit("workflowException: " + workflowException)\r
-                                       if(workflowException != null){\r
-                                               exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI\r
-                                               utils.log("INFO", msg, isDebugEnabled)\r
-                                               exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
-                                       }\r
-                               }\r
-\r
-                               utils.log("INFO","Service-instance NOT found in AAI. Silent Success", isDebugEnabled)\r
-                       }\r
-               }catch (BpmnError e) {\r
-                       throw e;\r
-               } catch (Exception ex) {\r
-                       msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage()\r
-                       utils.log("INFO", msg, isDebugEnabled)\r
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
-               }\r
-               utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)\r
-       }\r
-       \r
        \r
        public void preInitResourcesOperStatus(DelegateExecution execution){\r
         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
@@ -396,145 +166,295 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor {
             execution.setVariable("serviceInstanceId", serviceId)\r
             execution.setVariable("operationId", operationId)\r
             execution.setVariable("operationType", operationType)\r
-            \r
-            String serviceRelationShip = execution.getVariable("serviceRelationShip")\r
-            \r
-            def jsonSlurper = new JsonSlurper()\r
-            def jsonOutput = new JsonOutput()         \r
-            List relationShipList =  jsonSlurper.parseText(serviceRelationShip)\r
-                    \r
-            if (relationShipList != null) {\r
-                relationShipList.each {\r
-                    resourceTemplateUUIDs  = resourceTemplateUUIDs + it.resourceInstanceId + ":"\r
-                }\r
-            }           \r
-            execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")\r
-\r
-            String payload =\r
-                """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
-                        xmlns:ns="http://org.openecomp.mso/requestsdb">\r
-                        <soapenv:Header/>\r
-                        <soapenv:Body>\r
-                            <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
-                            <serviceId>${serviceId}</serviceId>\r
-                            <operationId>${operationId}</operationId>\r
-                            <operationType>${operationType}</operationType>\r
-                            <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>\r
-                        </ns:initResourceOperationStatus>\r
-                    </soapenv:Body>\r
-                </soapenv:Envelope>"""\r
-\r
-            payload = utils.formatXml(payload)\r
-            execution.setVariable("CVFMI_initResOperStatusRequest", payload)\r
-            utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)\r
-            utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)\r
 \r
-        }catch(Exception e){\r
-            utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)\r
-            execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())\r
-        }\r
-        utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  \r
-    }\r
-    \r
-    /**\r
-        * Init the service Operation Status\r
-        */\r
-       public void preUpdateServiceOperationStatus(DelegateExecution execution){\r
-        def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'\r
-               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
-               utils.log("INFO","Entered " + method, isDebugEnabled)\r
-        \r
-        try{\r
-            String serviceId = execution.getVariable("serviceInstanceId")\r
-            String operationId = execution.getVariable("operationId")\r
-            String serviceName = execution.getVariable("serviceInstanceName")\r
-            String userId = ""\r
-            String result = "processing"\r
-            String progress = execution.getVariable("progress")\r
-                       utils.log("INFO", "progress: " + progress , isDebugEnabled)\r
-                       if ("100".equalsIgnoreCase(progress))\r
-                       {\r
-                               result = "finished"\r
+                       List<Resource> resourceList = new ArrayList<String>()\r
+                       List<Resource> addResourceList =  execution.getVariable("addResourceList")\r
+                       List<Resource> delResourceList =  execution.getVariable("delResourceList")\r
+                       resourceList.addAll(addResourceList)\r
+                       resourceList.addAll(delResourceList)\r
+                       for(Resource resource : resourceList){\r
+                               resourceTemplateUUIDs  = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"\r
                        }\r
-            String reason = ""\r
-            String operationContent = "Prepare service : " + execution.getVariable("operationStatus")\r
                        \r
-            utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)\r
-            serviceId = UriUtils.encode(serviceId,"UTF-8")\r
-            execution.setVariable("serviceInstanceId", serviceId)\r
-            execution.setVariable("operationId", operationId)\r
-            execution.setVariable("operationType", operationType)\r
+                       def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"\r
+                       execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
+                       utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
 \r
-            def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"\r
-            execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)\r
-            utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)\r
-\r
-            execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")\r
                        String payload =\r
-                """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
+                               """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\r
                         xmlns:ns="http://org.openecomp.mso/requestsdb">\r
                         <soapenv:Header/>\r
                         <soapenv:Body>\r
-                            <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
-                            <serviceId>${serviceId}</serviceId>\r
-                            <operationId>${operationId}</operationId>\r
-                            <serviceName>${serviceName}</serviceName>\r
-                            <operationType>${operationType}</operationType>\r
-                            <userId>${userId}</userId>\r
-                            <result>${result}</result>\r
-                            <operationContent>${operationContent}</operationContent>\r
-                            <progress>${progress}</progress>\r
-                            <reason>${reason}</reason>\r
-                        </ns:updateServiceOperationStatus>\r
-                    </soapenv:Body>\r
-                </soapenv:Envelope>"""\r
-\r
-            payload = utils.formatXml(payload)\r
-            execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)\r
-            utils.log("INFO", "Outgoing preUpdateServiceOperationStatus: \n" + payload, isDebugEnabled)\r
-           \r
+                            <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">\r
+                                                               <serviceId>${serviceId}</serviceId>\r
+                                                               <operationId>${operationId}</operationId>\r
+                                                               <operationType>${operationType}</operationType>\r
+                                                               <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>\r
+                            </ns:initResourceOperationStatus>\r
+                       </soapenv:Body>\r
+                       </soapenv:Envelope>"""\r
+\r
+                       payload = utils.formatXml(payload)\r
+                       execution.setVariable("CVFMI_initResOperStatusRequest", payload)\r
+                       utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)\r
+                       utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)\r
 \r
         }catch(Exception e){\r
-            utils.log("ERROR", "Exception Occured Processing preUpdateServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)\r
-            execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())\r
+            utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)\r
+            execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())\r
         }\r
-        utils.log("INFO", "======== COMPLETED preUpdateServiceOperationStatus Process ======== ", isDebugEnabled)  \r
-        utils.log("INFO", "Exited " + method, isDebugEnabled)\r
-       }\r
-    \r
-    public void postResourcesOperStatus(DelegateExecution execution) {\r
-        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
-    \r
+        utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  \r
     }\r
     \r
-    public void preCompareModelVersions(DelegateExecution execution) {\r
-        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
-\r
-    }\r
 \r
-    public void postCompareModelVersions(DelegateExecution execution) {\r
-        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
-    }\r
-    \r
     public void preProcessForAddResource(DelegateExecution execution) {\r
         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
-\r
+               utils.log("INFO"," ***** preProcessForAddResource ***** ", isDebugEnabled)\r
+               \r
+           execution.setVariable("operationType", "create")\r
+               \r
+               execution.setVariable("hasResourcetoAdd", false)\r
+               List<Resource> addResourceList =  execution.getVariable("addResourceList")\r
+               if(addResourceList != null && !addResourceList.isEmpty()) {\r
+                       execution.setVariable("hasResourcetoAdd", true)                 \r
+               }\r
+       \r
+               utils.log("INFO"," *** Exit preProcessForAddResource *** ", isDebugEnabled)\r
     }\r
 \r
     public void postProcessForAddResource(DelegateExecution execution) {\r
         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
-    \r
+               utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled)\r
+               \r
+               execution.setVariable("operationType", "update")\r
+\r
+               utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled)\r
     }\r
     \r
-    public void preProcessForDeleteResource(DelegateExecution execution) {\r
-        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+       public void preProcessForDeleteResource(DelegateExecution execution) {\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("INFO"," ***** preProcessForDeleteResource ***** ", isDebugEnabled)\r
 \r
-    }\r
+               execution.setVariable("operationType", "delete")\r
+\r
+               def  hasResourcetoDelete = false\r
+               List<Resource> delResourceList =  execution.getVariable("delResourceList")\r
+               if(delResourceList != null && !delResourceList.isEmpty()) {\r
+                       hasResourcetoDelete = true\r
+               }\r
+               execution.setVariable("hasResourcetoDelete", hasResourcetoDelete)\r
+\r
+               if(hasResourcetoDelete) {\r
+                       def jsonSlurper = new JsonSlurper()\r
+                       String serviceRelationShip = execution.getVariable("serviceRelationShip")                       \r
+                       List relationShipList =  jsonSlurper.parseText(serviceRelationShip)\r
+\r
+                       //Set the real resource instance id to the decomosed resource list\r
+                       for(Resource resource: delResourceList){\r
+                               //reset the resource instance id , because in the decompose flow ,its a random one.\r
+                               resource.setResourceId("");\r
+                               //match the resource-instance-name and the model name\r
+                               if (relationShipList != null) {\r
+                                       relationShipList.each {\r
+                                               if(StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())){\r
+                                                       resource.setResourceId(it.resourceInstanceId);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               execution.setVariable("deleteResourceList", delResourceList)\r
+\r
+               utils.log("INFO"," *** Exit preProcessForDeleteResource *** ", isDebugEnabled)\r
+       }\r
 \r
     public void postProcessForDeleteResource(DelegateExecution execution) {\r
         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("INFO"," ***** postProcessForDeleteResource ***** ", isDebugEnabled)\r
+               \r
+               execution.setVariable("operationType", "update")\r
+\r
+               utils.log("INFO"," *** Exit postProcessForDeleteResource *** ", isDebugEnabled)\r
+    } \r
     \r
-    }    \r
+       public void preProcessAAIGET(DelegateExecution execution) {\r
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")  \r
+       }\r
+       \r
+       public void postProcessAAIGET(DelegateExecution execution) {\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)\r
+               String msg = ""\r
+\r
+               try {\r
+                       String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
+                       boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")\r
+                       if(!succInAAI){\r
+                               utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName, isDebugEnabled)\r
+                               WorkflowException workflowException = execution.getVariable("WorkflowException")\r
+                               utils.logAudit("workflowException: " + workflowException)\r
+                               if(workflowException != null){\r
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
+                               }\r
+                               else\r
+                               {\r
+                                       msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI\r
+                                       utils.log("INFO", msg, isDebugEnabled)\r
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")\r
+                               if(foundInAAI){\r
+                                       String aaiService = execution.getVariable("GENGS_service")\r
+                                       if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {\r
+                                               execution.setVariable("serviceInstanceVersion",  utils.getNodeText1(aaiService, "resource-version"))\r
+                                               utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)\r
+                                       }\r
+                               }\r
+                       }\r
+               } catch (BpmnError e) {\r
+                       throw e;\r
+               } catch (Exception ex) {\r
+                       msg = "Exception in DoUpdateE2EServiceInstance.postProcessAAIGET " + ex.getMessage()\r
+                       utils.log("INFO", msg, isDebugEnabled)\r
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
+               }\r
+               utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)\r
+       }\r
+\r
+       public void preProcessAAIPUT(DelegateExecution execution) {             \r
+               def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'\r
+               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+               utils.log("INFO","Entered " + method, isDebugEnabled)\r
+               String msg = ""\r
+               utils.log("INFO"," ***** preProcessAAIPUT *****",  isDebugEnabled)\r
+\r
+\r
+               String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion")\r
+               //execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)\r
+        \r
+               //requestDetails.modelInfo.for AAI PUT servieInstanceData\r
+               //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData\r
+               String serviceInstanceName = execution.getVariable("serviceInstanceName")\r
+               String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
+               //aai serviceType and Role can be setted as fixed value now.\r
+               String aaiServiceType = "E2E Service"\r
+               String aaiServiceRole = "E2E Service"\r
+               String modelInvariantUuid = execution.getVariable("modelInvariantUuid")\r
+               String modelUuid = execution.getVariable("modelUuid")\r
+\r
+\r
+               AaiUtil aaiUriUtil = new AaiUtil(this)\r
+               utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled) \r
+               String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
+               utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)\r
+               String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)\r
+               utils.log("INFO","namespace: " + namespace, isDebugEnabled)\r
+\r
+               //update target model to aai\r
+               String serviceInstanceData =\r
+                               """<service-instance xmlns=\"${namespace}\">\r
+                    <service-instance-id>${serviceInstanceId}</service-instance-id>\r
+                    <service-instance-name>${serviceInstanceName}</service-instance-name>\r
+                    <service-type>${aaiServiceType}</service-type>\r
+                    <service-role>${aaiServiceRole}</service-role>\r
+                    <resource-version>${serviceInstanceVersion}</resource-version>\r
+                    <model-invariant-id>${modelInvariantUuid}</model-invariant-id>\r
+                    <model-version-id>${modelUuid}</model-version-id>                    \r
+                                </service-instance>""".trim()\r
+\r
+               execution.setVariable("serviceInstanceData", serviceInstanceData)\r
+               utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)\r
+               utils.logAudit(serviceInstanceData)\r
+               utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)\r
+               utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)\r
+       \r
+               utils.log("INFO", "Exited " + method, isDebugEnabled)\r
+       }       \r
+       \r
+       public void postProcessAAIPUT(DelegateExecution execution) {\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)\r
+               String msg = ""\r
+               try {\r
+                       String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
+                       boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")\r
+                       if(!succInAAI){\r
+                               utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)\r
+                               WorkflowException workflowException = execution.getVariable("WorkflowException")\r
+                               utils.logAudit("workflowException: " + workflowException)\r
+                               if(workflowException != null){\r
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               //start rollback set up\r
+                               RollbackData rollbackData = new RollbackData()\r
+                               def disableRollback = execution.getVariable("disableRollback")\r
+                               rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())\r
+                               rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")\r
+                               rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)\r
+                               rollbackData.put("SERVICEINSTANCE", "serviceType", execution.getVariable("serviceType"))\r
+                               rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))\r
+                               execution.setVariable("rollbackData", rollbackData)\r
+                       }\r
+\r
+               } catch (BpmnError e) {\r
+                       throw e;\r
+               } catch (Exception ex) {\r
+                       msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()\r
+                       utils.log("INFO", msg, isDebugEnabled)\r
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
+               }\r
+               utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)\r
+       }       \r
+\r
+       public void preProcessRollback (DelegateExecution execution) {\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)\r
+               try {\r
+                       \r
+                       Object workflowException = execution.getVariable("WorkflowException");\r
+\r
+                       if (workflowException instanceof WorkflowException) {\r
+                               utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)\r
+                               execution.setVariable("prevWorkflowException", workflowException);\r
+                               //execution.setVariable("WorkflowException", null);\r
+                       }\r
+               } catch (BpmnError e) {\r
+                       utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)\r
+               } catch(Exception ex) {\r
+                       String msg = "Exception in preProcessRollback. " + ex.getMessage()\r
+                       utils.log("INFO", msg, isDebugEnabled)\r
+               }\r
+               utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)\r
+       }\r
+\r
+       public void postProcessRollback (DelegateExecution execution) {\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)\r
+               String msg = ""\r
+               try {\r
+                       Object workflowException = execution.getVariable("prevWorkflowException");\r
+                       if (workflowException instanceof WorkflowException) {\r
+                               utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)\r
+                               execution.setVariable("WorkflowException", workflowException);\r
+                       }\r
+                       execution.setVariable("rollbackData", null)\r
+               } catch (BpmnError b) {\r
+                       utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)\r
+                       throw b;\r
+               } catch(Exception ex) {\r
+                       msg = "Exception in postProcessRollback. " + ex.getMessage()\r
+                       utils.log("INFO", msg, isDebugEnabled)\r
+               }\r
+               utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)\r
+       }\r
+\r
         \r
        public void postConfigRequest(execution){\r
            //now do noting\r