Add execute resource recipe task script
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateE2EServiceInstance.groovy
index 518c30b..586364e 100644 (file)
@@ -3,6 +3,7 @@
  * 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.
 package org.openecomp.mso.bpmn.infrastructure.scripts;
 
 import static org.apache.commons.lang3.StringUtils.*;
+import org.apache.http.HttpResponse
 import groovy.xml.XmlUtil
 import groovy.json.*
 
 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
 import org.openecomp.mso.bpmn.core.domain.ModelInfo
+import org.openecomp.mso.bpmn.core.domain.Resource
+import org.openecomp.mso.bpmn.core.domain.AllottedResource
+import org.openecomp.mso.bpmn.core.domain.NetworkResource
+import org.openecomp.mso.bpmn.core.domain.VnfResource
+import org.openecomp.mso.bpmn.common.recipe.ResourceInput
+import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder;
+import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
 import org.openecomp.mso.bpmn.core.json.JsonUtils
 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
+import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
 import org.openecomp.mso.bpmn.core.RollbackData
 import org.openecomp.mso.bpmn.core.WorkflowException
 import org.openecomp.mso.rest.APIResponse;
 import org.openecomp.mso.rest.RESTClient
 import org.openecomp.mso.rest.RESTConfig
 
+import java.util.List;
 import java.util.UUID;
 
+import javax.mail.Quota.Resource;
+
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.runtime.Execution
 import org.json.JSONObject;
+import org.json.JSONArray;
 import org.apache.commons.lang3.*
 import org.apache.commons.codec.binary.Base64;
 import org.springframework.web.util.UriUtils;
@@ -76,35 +90,34 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
        String Prefix="DCRESI_"
        ExceptionUtil exceptionUtil = new ExceptionUtil()
        JsonUtils jsonUtil = new JsonUtils()
+       CatalogDbUtils cutils = new CatalogDbUtils()
 
        public void preProcessRequest (Execution execution) {
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
                String msg = ""
-               utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)
+               utils.log("INFO"," ***** preProcessRequest *****",  isDebugEnabled)
 
                try {
-                       String requestId = execution.getVariable("msoRequestId")
                        execution.setVariable("prefix", Prefix)
-                       
                        //Inputs
                        //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
                        String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
-
+                       utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId,  isDebugEnabled)
                        //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
-                       String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
-
+                       String serviceType = execution.getVariable("serviceType")
+                       utils.log("INFO"," ***** serviceType *****" + serviceType,  isDebugEnabled)
                        //requestDetails.requestParameters. for SDNC assignTopology
                        String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
 
                        if (isBlank(globalSubscriberId)) {
                                msg = "Input globalSubscriberId is null"
-                               utils.log("DEBUG", msg, isDebugEnabled)
+                               utils.log("INFO", msg, isDebugEnabled)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
                        }
                        
-                       if (isBlank(subscriptionServiceType)) {
-                               msg = "Input subscriptionServiceType is null"
-                               utils.log("DEBUG", msg, isDebugEnabled)
+                       if (isBlank(serviceType)) {
+                               msg = "Input serviceType is null"
+                               utils.log("INFO", msg, isDebugEnabled)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
                        }
                        
@@ -115,139 +128,27 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
                        String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
                        if (isBlank(sdncCallbackUrl)) {
                                msg = "URN_mso_workflow_sdncadapter_callback is null"
-                               utils.log("DEBUG", msg, isDebugEnabled)
+                               utils.log("INFO", msg, isDebugEnabled)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
                        }
                        execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
-                       utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
-
-                       //requestDetails.modelInfo.for AAI PUT servieInstanceData & SDNC assignTopology
-                       String modelInvariantUuid = ""
-                       String modelVersion = ""
-                       String modelUuid = ""
-                       String modelName = ""
-                       String serviceInstanceName = "" 
-                       //Generated in parent.for AAI PUT
-                       String serviceInstanceId = ""
-                       String serviceType = ""
-                       String serviceRole = ""
-                       
-                       ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
-                       if (serviceDecomp != null)
-                       {
-                               serviceType = serviceDecomp.getServiceType()
-                               if (serviceType == null)
-                               {
-                                       utils.log("DEBUG", "null serviceType", isDebugEnabled)
-                                       serviceType = ""
-                               }
-                               else
-                               {
-                                       utils.log("DEBUG", "serviceType:" + serviceType, isDebugEnabled)
-                               }
-                               serviceRole = serviceDecomp.getServiceRole()
-                               if (serviceRole == null)
-                               {
-                                       serviceRole = ""
-                               }
-                               
-                               ServiceInstance serviceInstance = serviceDecomp.getServiceInstance()
-                               if (serviceInstance != null)
-                               {
-                                       serviceInstanceId = serviceInstance.getInstanceId()
-                                       serviceInstanceName = serviceInstance.getInstanceName()
-                                       execution.setVariable("serviceInstanceId", serviceInstanceId)
-                                       execution.setVariable("serviceInstanceName", serviceInstanceName)
-                               }
-                               
-                               ModelInfo modelInfo = serviceDecomp.getModelInfo()
-                               if (modelInfo != null)
-                               {
-                                       modelInvariantUuid = modelInfo.getModelInvariantUuid()
-                                       modelVersion = modelInfo.getModelVersion()
-                                       modelUuid = modelInfo.getModelUuid()
-                                       modelName = modelInfo.getModelName()
-                               }
-                               else 
-                               {
-                                       msg = "Input serviceModelInfo is null"
-                                       utils.log("DEBUG", msg, isDebugEnabled)
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-                               }
-                       }
-                       else
-                       {
-                               //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData & SDNC assignToplology
-                               serviceInstanceName = execution.getVariable("serviceInstanceName")
-                               serviceInstanceId = execution.getVariable("serviceInstanceId")
-                               
-                               String serviceModelInfo = execution.getVariable("serviceModelInfo")
-                               if (isBlank(serviceModelInfo)) {
-                                       msg = "Input serviceModelInfo is null"
-                                       utils.log("DEBUG", msg, isDebugEnabled)
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-                               }
-                               modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
-                               modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
-                               modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
-                               modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
-                               //modelCustomizationUuid NA for SI
-       
-                       }
-                       execution.setVariable("serviceType", serviceType)
-                       execution.setVariable("serviceRole", serviceRole)
-                       
-                       if (serviceInstanceName == null) {
-                               execution.setVariable("serviceInstanceName", "")
-                               serviceInstanceName = ""
-                       }
-                       if (isBlank(serviceInstanceId)){
-                               msg = "Input serviceInstanceId is null"
-                               utils.log("DEBUG", msg, isDebugEnabled)
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-                       }
-                       
-                       if (modelInvariantUuid == null) {
-                               modelInvariantUuid = ""
-                       }
-                       if (modelUuid == null) {
-                               modelUuid = ""
-                       }
-                       if (modelVersion == null) {
-                               modelVersion = ""
-                       }
-                       if (modelName == null) {
-                               modelName = ""
-                       }
+                       utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
+
+                       //requestDetails.modelInfo.for AAI PUT servieInstanceData                       
+                       //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData 
+                       String serviceInstanceName = execution.getVariable("serviceInstanceName")
+                       String serviceInstanceId = execution.getVariable("serviceInstanceId")
+                       String uuiRequest = execution.getVariable("uuiRequest")
+                       String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceDefId")
+                       String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.templateId")
+                       String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
+                       execution.setVariable("serviceModelName", serviceModelName)
+                       //aai serviceType and Role can be setted as fixed value now.
+                       String aaiServiceType = "E2E Service"
+                       String aaiServiceRole = "E2E Service"
                        
                        execution.setVariable("modelInvariantUuid", modelInvariantUuid)
-                       execution.setVariable("modelVersion", modelVersion)
                        execution.setVariable("modelUuid", modelUuid)
-                       execution.setVariable("modelName", modelName)
-                       
-                       StringBuilder sbParams = new StringBuilder()
-                       Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
-                       if (paramsMap != null)
-                       {
-                               sbParams.append("<service-input-parameters>")
-                               for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
-                                       String paramsXml
-                                       String paramName = entry.getKey()
-                                       String paramValue = entry.getValue()
-                                       paramsXml =
-                                                       """     <param>
-                                                       <name>${paramName}</name>
-                                                       <value>${paramValue}</value>
-                                                       </param>
-                                                       """
-                                       sbParams.append(paramsXml)
-                               }
-                               sbParams.append("</service-input-parameters>")
-                       }
-                       String siParamsXml = sbParams.toString()
-                       if (siParamsXml == null)
-                               siParamsXml = ""
-                       execution.setVariable("siParamsXml", siParamsXml)
 
                        //AAI PUT
                        String oStatus = execution.getVariable("initialStatus") ?: ""
@@ -263,111 +164,79 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
                        String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
                        String serviceInstanceData =
                                        """<service-instance xmlns=\"${namespace}\">
-                                       <service-instance-name>${serviceInstanceName}</service-instance-name>
-                                       <service-type>${serviceType}</service-type>
-                                       <service-role>${serviceRole}</service-role>
+                               <service-instance-id>${serviceInstanceId}</service-instance-id>
+                               <service-instance-name>${serviceInstanceName}</service-instance-name>
+                                       <service-type>${aaiServiceType}</service-type>
+                                       <service-role>${aaiServiceRole}</service-role>
                                        ${statusLine}
                                    <model-invariant-id>${modelInvariantUuid}</model-invariant-id>
                                    <model-version-id>${modelUuid}</model-version-id>
-                                       </service-instance>""".trim()
-
+                                       </service-instance>""".trim()                                   
                        execution.setVariable("serviceInstanceData", serviceInstanceData)
                        utils.logAudit(serviceInstanceData)
-                       utils.log("DEBUG", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
+                       utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
+                       utils.log("INFO", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
 
                } catch (BpmnError e) {
                        throw e;
                } catch (Exception ex){
                        msg = "Exception in preProcessRequest " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
-               }
-               utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
-       }
-
-       //TODO: Will be able to replace with call to GenericGetService
-       public void getAAICustomerById (Execution execution) {
-               // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId}
-               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
-               String msg = ""
-               try {
-
-                       String globalCustomerId = execution.getVariable("globalSubscriberId") //VID to AAI name map
-                       utils.log("DEBUG"," ***** getAAICustomerById ***** globalCustomerId:" + globalCustomerId, isDebugEnabled)
-
-                       String aai_endpoint = execution.getVariable("URN_aai_endpoint")
-                       AaiUtil aaiUriUtil = new AaiUtil(this)
-                       String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
-                       if (isBlank(aai_endpoint) || isBlank(aai_uri))
-                       {
-                               msg = "AAI URL is invalid. Endpoint:" + aai_endpoint + aai_uri
-                               utils.log("DEBUG", msg, isDebugEnabled)
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
-                       }
-                       String getAAICustomerUrl = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8")
-
-                       utils.logAudit(getAAICustomerUrl)
-                       utils.log("DEBUG", "getAAICustomerById Url:" + getAAICustomerUrl, isDebugEnabled)
-                       APIResponse response = aaiUriUtil.executeAAIGetCall(execution, getAAICustomerUrl)
-                       String returnCode = response.getStatusCode()
-                       String aaiResponseAsString = response.getResponseBodyAsString()
-
-                       msg = "getAAICustomerById ResponseCode:" + returnCode + " ResponseString:" + aaiResponseAsString
-                       utils.log("DEBUG",msg, isDebugEnabled)
-                       utils.logAudit(msg)
-
-                       if (returnCode=='200') {
-                               // Customer found by ID. FLow to proceed.
-                               utils.log("DEBUG",msg, isDebugEnabled)
-
-                               //TODO Deferred
-                               //we might verify that service-subscription with matching name exists
-                               //and throw error if not. If not checked, we will get exception in subsequent step on Create call
-                               //in 1610 we assume both customer & service subscription were pre-created
-
-                       } else {
-                               if (returnCode=='404') {
-                                       msg = "GlobalCustomerId:" + globalCustomerId + " not found (404) in AAI"
-                                       utils.log("DEBUG", msg, isDebugEnabled)
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
-
-                               } else {
-                                       if (aaiResponseAsString.contains("RESTFault")) {
-                                               utils.log("ERROR", aaiResponseAsString)
-                                               WorkflowException workflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
-                                               execution.setVariable("WorkflowException", workflowException)
-                                               throw new BpmnError("MSOWorkflowException")
-
-                                       } else {
-                                               // aai all errors
-                                               msg = "Error in getAAICustomerById ResponseCode:" + returnCode
-                                               utils.log("DEBUG", msg, isDebugEnabled)
-                                               exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
-                                       }
-                               }
-                       }
-
-               } catch (BpmnError e) {
-                       throw e;
-               } catch (Exception ex) {
-                       msg = "Exception in getAAICustomerById. " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
+                       utils.log("INFO", msg, isDebugEnabled)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("DEBUG"," *****Exit getAAICustomerById *****", isDebugEnabled)
-
+               utils.log("INFO"," ***** Exit preProcessRequest *****",  isDebugEnabled)
        }
-
+       
+   public void prepareDecomposeService(Execution execution) {
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+
+        try {
+            utils.log("DEBUG", " ***** Inside prepareDecomposeService of create generic e2e service ***** ", isDebugEnabled)
+            String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
+            String modelUuid = execution.getVariable("modelUuid")
+            //here modelVersion is not set, we use modelUuid to decompose the service.
+            String serviceModelInfo = """{
+            "modelInvariantUuid":"${modelInvariantUuid}",
+            "modelUuid":"${modelUuid}",
+            "modelVersion":""
+             }"""
+            execution.setVariable("serviceModelInfo", serviceModelInfo)
+
+            utils.log("DEBUG", " ***** Completed prepareDecomposeService of  create generic e2e service ***** ", isDebugEnabled)
+        } catch (Exception ex) {
+            // try error in method block
+            String exceptionMessage = "Bpmn error encountered in  create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+        }
+     }
+
+    public void processDecomposition (Execution execution) {
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+    
+        utils.log("DEBUG", " ***** Inside processDecomposition() of  create generic e2e service flow ***** ", isDebugEnabled)    
+        try {
+            ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+        } catch (Exception ex) {
+            String exceptionMessage = "Bpmn error encountered in  create generic e2e service flow. processDecomposition() - " + ex.getMessage()
+            utils.log("DEBUG", exceptionMessage, isDebugEnabled)
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+        }
+    }
+    
+    public void doServiceHoming(Execution execution) {
+        //Now Homing is not clear. So to be implemented.
+    }
+    
        public void postProcessAAIGET(Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG"," ***** postProcessAAIGET ***** ", isDebugEnabled)
+               utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
                String msg = ""
 
                try {
                        String serviceInstanceName = execution.getVariable("serviceInstanceName")
                        boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
-                       if(succInAAI != true){
-                               utils.log("DEBUG","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled)
+                       if(!succInAAI){
+                               utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled)
                                WorkflowException workflowException = execution.getVariable("WorkflowException")
                                utils.logAudit("workflowException: " + workflowException)
                                if(workflowException != null){
@@ -376,17 +245,17 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
                                else
                                {
                                        msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
-                                       utils.log("DEBUG", msg, isDebugEnabled)
+                                       utils.log("INFO", msg, isDebugEnabled)
                                        exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
                                }
                        }
                        else
                        {
                                boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
-                               if(foundInAAI == true){
-                                       utils.log("DEBUG","Found Service-instance in AAI", isDebugEnabled)
+                               if(foundInAAI){
+                                       utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)
                                        msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
-                                       utils.log("DEBUG", msg, isDebugEnabled)
+                                       utils.log("INFO", msg, isDebugEnabled)
                                        exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
                                }
                        }
@@ -394,21 +263,21 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
                        throw e;
                } catch (Exception ex) {
                        msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
+                       utils.log("INFO", msg, isDebugEnabled)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("DEBUG"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
+               utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
        }
 
        public void postProcessAAIPUT(Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
+               utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
                String msg = ""
                try {
                        String serviceInstanceId = execution.getVariable("serviceInstanceId")
                        boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
-                       if(succInAAI != true){
-                               utils.log("DEBUG","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
+                       if(!succInAAI){
+                               utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
                                WorkflowException workflowException = execution.getVariable("WorkflowException")
                                utils.logAudit("workflowException: " + workflowException)
                                if(workflowException != null){
@@ -432,150 +301,22 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
                        throw e;
                } catch (Exception ex) {
                        msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
+                       utils.log("INFO", msg, isDebugEnabled)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("DEBUG"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
-       }
-
-       public void preProcessSDNCAssignRequest(Execution execution) {
-               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
-               String msg = ""
-               utils.log("DEBUG"," ***** preProcessSDNCAssignRequest *****", isDebugEnabled)
-
-               try {
-                       def serviceInstanceId = execution.getVariable("serviceInstanceId")
-                       def serviceInstanceName = execution.getVariable("serviceInstanceName")
-                       def callbackURL = execution.getVariable("sdncCallbackUrl")
-                       def requestId = execution.getVariable("msoRequestId")
-                       def serviceId = execution.getVariable("productFamilyId")
-                       def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
-                       def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
-                       def serviceType = execution.getVariable("serviceType")
-
-                       def modelInvariantUuid = execution.getVariable("modelInvariantUuid")
-                       def modelVersion = execution.getVariable("modelVersion")
-                       def modelUuid = execution.getVariable("modelUuid")
-                       def modelName = execution.getVariable("modelName")
-                       
-                       def sdncRequestId = UUID.randomUUID().toString()
-                       
-                       def siParamsXml = execution.getVariable("siParamsXml")
-                       
-                       String sdncAssignRequest =
-                                       """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
-                                                                                                       xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
-                                                                                                       xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
-                                  <sdncadapter:RequestHeader>
-                                                       <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
-                                                       <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
-                                                       <sdncadapter:SvcAction>assign</sdncadapter:SvcAction>
-                                                       <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
-                                                       <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
-                                                       <sdncadapter:MsoAction>${serviceType}</sdncadapter:MsoAction>
-                                       </sdncadapter:RequestHeader>
-                               <sdncadapterworkflow:SDNCRequestData>
-                                       <request-information>
-                                               <request-id>${requestId}</request-id>
-                                               <source>MSO</source>
-                                               <notification-url/>
-                                               <order-number/>
-                                               <order-version/>
-                                               <request-action>CreateServiceInstance</request-action>
-                                       </request-information>
-                                       <service-information>
-                                               <service-id>${serviceId}</service-id>
-                                               <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
-                                               <ecomp-model-information>
-                                                <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>
-                                                <model-uuid>${modelUuid}</model-uuid>
-                                                <model-version>${modelVersion}</model-version>
-                                                <model-name>${modelName}</model-name>
-                                           </ecomp-model-information>
-                                               <service-instance-id>${serviceInstanceId}</service-instance-id>
-                                               <subscriber-name/>
-                                               <global-customer-id>${globalSubscriberId}</global-customer-id>
-                                       </service-information>
-                                       <service-request-input>
-                                               <service-instance-name>${serviceInstanceName}</service-instance-name>
-                                               ${siParamsXml}
-                                       </service-request-input>
-                               </sdncadapterworkflow:SDNCRequestData>
-                               </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
-
-                       utils.log("DEBUG","sdncAssignRequest:\n" + sdncAssignRequest, isDebugEnabled)
-                       sdncAssignRequest = utils.formatXml(sdncAssignRequest)
-                       execution.setVariable("sdncAssignRequest", sdncAssignRequest)
-                       utils.logAudit("sdncAssignRequest:  " + sdncAssignRequest)
-
-                       def sdncRequestId2 = UUID.randomUUID().toString()
-                       String sdncDelete = sdncAssignRequest.replace(">assign<", ">delete<").replace(">CreateServiceInstance<", ">DeleteServiceInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
-                       def sdncRequestId3 = UUID.randomUUID().toString()
-                       String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId2}<", ">${sdncRequestId3}<")
-                       def rollbackData = execution.getVariable("rollbackData")
-                       rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate)
-                       rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete)
-                       execution.setVariable("rollbackData", rollbackData)
-                       
-                       utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled)
-
-               } catch (BpmnError e) {
-                       throw e;
-               } catch(Exception ex) {
-                       msg = "Exception in preProcessSDNCAssignRequest. " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
-               }
-               utils.log("DEBUG"," *****Exit preProcessSDNCAssignRequest *****", isDebugEnabled)
-       }
-       
-       public void postProcessSDNCAssign (Execution execution) {
-               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG"," ***** postProcessSDNCAssign ***** ", isDebugEnabled)
-               try {
-                       WorkflowException workflowException = execution.getVariable("WorkflowException")
-                       utils.logAudit("workflowException: " + workflowException)
-
-                       boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
-
-                       String response = execution.getVariable("sdncAdapterResponse")
-                       utils.logAudit("SDNCResponse: " + response)
-
-                       SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
-                       sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
-
-                       if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
-                               utils.log("DEBUG","Good response from SDNC Adapter for service-instance  topology assign: \n" + response, isDebugEnabled)
-
-                               def rollbackData = execution.getVariable("rollbackData")
-                               rollbackData.put("SERVICEINSTANCE", "rollbackSDNC", "true")
-                               execution.setVariable("rollbackData", rollbackData)
-
-                       }else{
-                               utils.log("DEBUG","Bad Response from SDNC Adapter for service-instance assign", isDebugEnabled)
-                               throw new BpmnError("MSOWorkflowException")
-                       }
-
-               } catch (BpmnError e) {
-                       throw e;
-               } catch(Exception ex) {
-                       msg = "Exception in postProcessSDNCAssign. " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
-               }
-               utils.log("DEBUG"," *** Exit postProcessSDNCAssign *** ", isDebugEnabled)
+               utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
        }
        
        public void postProcessAAIGET2(Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)
+               utils.log("INFO"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)
                String msg = ""
 
                try {
                        String serviceInstanceName = execution.getVariable("serviceInstanceName")
                        boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
-                       if(succInAAI != true){
-                               utils.log("DEBUG","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)
+                       if(!succInAAI){
+                               utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)
                                WorkflowException workflowException = execution.getVariable("WorkflowException")
                                utils.logAudit("workflowException: " + workflowException)
                                if(workflowException != null){
@@ -584,18 +325,18 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
                                else
                                {
                                        msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
-                                       utils.log("DEBUG", msg, isDebugEnabled)
+                                       utils.log("INFO", msg, isDebugEnabled)
                                        exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
                                }
                        }
                        else
                        {
                                boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
-                               if(foundInAAI == true){
+                               if(foundInAAI){
                                        String aaiService = execution.getVariable("GENGS_service")
                                        if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
                                                execution.setVariable("serviceInstanceName",  utils.getNodeText1(aaiService, "service-instance-name"))
-                                               utils.log("DEBUG","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
+                                               utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
                                        }
                                }
                        }
@@ -603,52 +344,240 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
                        throw e;
                } catch (Exception ex) {
                        msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
+                       utils.log("INFO", msg, isDebugEnabled)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("DEBUG"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)
+               utils.log("INFO"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)
        }
 
        public void preProcessRollback (Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG"," ***** preProcessRollback ***** ", isDebugEnabled)
+               utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
                try {
                        
                        Object workflowException = execution.getVariable("WorkflowException");
 
                        if (workflowException instanceof WorkflowException) {
-                               utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
+                               utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
                                execution.setVariable("prevWorkflowException", workflowException);
                                //execution.setVariable("WorkflowException", null);
                        }
                } catch (BpmnError e) {
-                       utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
+                       utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
                } catch(Exception ex) {
                        String msg = "Exception in preProcessRollback. " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
+                       utils.log("INFO", msg, isDebugEnabled)
                }
-               utils.log("DEBUG"," *** Exit preProcessRollback *** ", isDebugEnabled)
+               utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
        }
 
        public void postProcessRollback (Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG"," ***** postProcessRollback ***** ", isDebugEnabled)
+               utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
                String msg = ""
                try {
                        Object workflowException = execution.getVariable("prevWorkflowException");
                        if (workflowException instanceof WorkflowException) {
-                               utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
+                               utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
                                execution.setVariable("WorkflowException", workflowException);
                        }
                        execution.setVariable("rollbackData", null)
                } catch (BpmnError b) {
-                       utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
+                       utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
                        throw b;
                } catch(Exception ex) {
                        msg = "Exception in postProcessRollback. " + ex.getMessage()
-                       utils.log("DEBUG", msg, isDebugEnabled)
+                       utils.log("INFO", msg, isDebugEnabled)
                }
-               utils.log("DEBUG"," *** Exit postProcessRollback *** ", isDebugEnabled)
+               utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
+       }
+
+       public void preInitResourcesOperStatus(Execution execution){
+        def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+
+        utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
+        try{
+            String serviceId = execution.getVariable("serviceInstanceId")
+            String operationId = execution.getVariable("operationId")
+            String operationType = execution.getVariable("operationType")
+            String resourceTemplateUUIDs = ""
+            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 + " operationType:" + operationType, isDebugEnabled)
+            serviceId = UriUtils.encode(serviceId,"UTF-8")
+            execution.setVariable("serviceInstanceId", serviceId)
+            execution.setVariable("operationId", operationId)
+            execution.setVariable("operationType", operationType)
+            ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+            List<Resource>  resourceList = serviceDecomposition.getServiceResources()
+            
+            for(String resource : resourceList){
+                    resourceTemplateUUIDs  = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"                            
+            }           
+
+            def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
+            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:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
+                            <serviceId>${serviceId}</serviceId>
+                            <operationId>${operationId}</operationId>
+                            <operationType>${operationType}</operationType>
+                            <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
+                        </ns:initResourceOperationStatus>
+                    </soapenv:Body>
+                </soapenv:Envelope>"""
+
+            payload = utils.formatXml(payload)
+            execution.setVariable("CVFMI_initResOperStatusRequest", payload)
+            utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
+            utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
+
+        }catch(Exception e){
+            utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
+            execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
+        }
+        utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  
        }
+       
 
+       /**
+        * sequence resource. we should analyze resource sequence from service template
+        * Here we make VF first, and then network for E2E service.
+        */
+       public void sequenceResoure(execution){
+           def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+        utils.log("INFO", "======== Start sequenceResoure Process ======== ", isDebugEnabled)  
+           String serviceModelUUID = execution.getVariable("modelUuid")
+        JSONArray networks = cutils.getAllNetworksByServiceModelUuid(execution, serviceModelUUID)
+        utils.log("DEBUG", "obtained Network list: " + networks, isDebugEnabled)            
+        if (networks == null) {
+            utils.log("INFO", "No matching networks in Catalog DB for serviceModelUUID=" + serviceModelUUID, isDebugEnabled)
+        }
+        ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+                
+        //we use VF to define a network service
+        List<VnfResource>  vnfResourceList= serviceDecomposition.getServiceVnfs()
+        
+        //here wan is defined as a network resource        
+        List<NetworkResource> networkResourceList = serviceDecomposition.getServiceNetworks()
+
+        //allotted resource
+        List<AllottedResource> arResourceList= serviceDecomposition.getServiceAllottedResources()
+        //define sequenced resource list, we deploy vf first and then network and then ar
+        //this is defaule sequence
+        List<Resource>  sequencedResourceList = new ArrayList<Resource>();
+        if(null != vnfResourceList){
+            sequencedResourceList.addAll(vnfResourceList)
+        }
+        if(null != networkResourceList){
+            sequencedResourceList.addAll(networkResourceList)
+        }
+        if(null != arResourceList){
+            sequencedResourceList.addAll(arResourceList)
+        }
+
+        String isContainsWanResource = networkResourceList.isEmpty() ? "false" : "true"
+        execution.setVariable("isContainsWanResource", isContainsWanResource)
+        execution.setVariable("currentResourceIndex", 0)
+        execution.setVariable("sequencedResourceList", sequencedResourceList)
+        utils.log("INFO", "sequencedResourceList: " + sequencedResourceList, isDebugEnabled)  
+        utils.log("INFO", "======== COMPLETED sequenceResoure Process ======== ", isDebugEnabled)  
+       }
+       
+       public void getCurrentResoure(execution){
+           def isDebugEnabled=execution.getVariable("isDebugLogEnabled")   
+        utils.log("INFO", "======== Start getCurrentResoure Process ======== ", isDebugEnabled)    
+           def currentIndex = execution.getVariable("currentResourceIndex")
+           List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")  
+           Resource currentResource = sequencedResourceList.get(currentIndex)
+           utils.log("INFO", "Now we deal with resouce:" + currentResource.getModelInfo().getModelName(), isDebugEnabled)  
+        utils.log("INFO", "======== COMPLETED getCurrentResoure Process ======== ", isDebugEnabled)  
+    }
+
+          /**
+     * sequence resource
+     */
+    public void parseNextResource(execution){
+        def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+        utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)    
+        def currentIndex = execution.getVariable("currentResourceIndex")
+        def nextIndex =  currentIndex + 1
+        execution.setVariable("currentResourceIndex", nextIndex)
+        List<String> sequencedResourceList = execution.getVariable("sequencedResourceList")    
+        if(nextIndex >= sequencedResourceList.size()){
+            execution.setVariable("allResourceFinished", "true")
+        }else{
+            execution.setVariable("allResourceFinished", "false")
+        }
+        utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)       
+    }
+    
+      /**
+      * post config request.
+      */
+     public void postConfigRequest(execution){
+         //now do noting
+     } 
+     
+     public void prepareResourceRecipeRequest(execution){
+         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")                 
+         utils.log("INFO", "======== Start prepareResourceRecipeRequest Process ======== ", isDebugEnabled) 
+         ResourceInput resourceInput = new ResourceInput()         
+         String serviceInstanceName = execution.getVariable("serviceInstanceName")
+         String resourceInstanceName = resourceType + "_" + serviceInstanceName
+         resourceInput.setResourceInstanceName(resourceInstanceName)
+         utils.log("INFO", "Prepare Resource Request resourceInstanceName:" + resourceInstanceName, isDebugEnabled)
+         String globalSubscriberId = execution.getVariable("globalSubscriberId")
+         String serviceType = execution.getVariable("serviceType")
+         String serviceInstanceId = execution.getVariable("serviceInstanceId")
+         String operationId = execution.getVariable("operationId")
+         String operationType = execution.getVariable("operationType")
+         resourceInput.setGlobalSubscriberId(globalSubscriberId)
+         resourceInput.setServiceType(serviceType)
+         resourceInput.setServiceInstanceId(serviceInstanceId)
+         resourceInput.setOperationId(operationId)
+         resourceInput.setOperationType(operationType);
+         def currentIndex = execution.getVariable("currentResourceIndex")
+         List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")  
+         Resource currentResource = sequencedResourceList.get(currentIndex)
+         String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid()
+         resourceInput.setResourceCustomizationUuid(resourceCustomizationUuid);
+         String resourceInvariantUuid = currentResource.getModelInfo().getModelInvariantUuid()
+         resourceInput.setResourceInvariantUuid(resourceInvariantUuid)
+         String resourceUuid = currentResource.getModelInfo().getModelUuid()
+         resourceInput.setResourceUuid(resourceUuid)
+         
+         String incomingRequest = execution.getVariable("uuiRequest")
+         //set the requestInputs from tempalte  To Be Done
+         String serviceModelUuid = execution.getVariable("modelUuid")
+         String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
+         String resourceParameters = ResourceRequestBuilder.buildResourceRequestParameters(execution, serviceModelUuid, resourceCustomizationUuid, serviceParameters)
+         resourceInput.setResourceParameters(resourceParameters)
+         execution.setVariable("resourceInput", resourceInput)
+         utils.log("INFO", "======== COMPLETED prepareResourceRecipeRequest Process ======== ", isDebugEnabled)      
+     }
+     
+     public void executeResourceRecipe(Execution execution){
+         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")                 
+         utils.log("INFO", "======== Start executeResourceRecipe Process ======== ", isDebugEnabled) 
+         String requestId = execution.getVariable("msoRequestId")
+         String serviceInstanceId = execution.getVariable("serviceInstanceId")
+         String serviceType = execution.getVariable("serviceType")
+         ResourceInput resourceInput = execution.getVariable("resourceInput")
+         String requestAction = resourceInput.getOperationType()
+         JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceUuid(), requestAction)
+         String recipeUri = resourceRecipe.getString("orchestrationUri")
+         String recipeTimeOut = resourceRecipe.getString("recipeTimeout")
+         String recipeParamXsd = resourceRecipe.get("paramXSD")
+         HttpResponse resp = BpmnRestClient.post(recipeUri, requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
+         
+     }
 }