[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateVfModule.groovy
  * ============LICENSE_END=========================================================
  */
 
-package com.att.bpm.scripts;
-
-import org.camunda.bpm.engine.delegate.BpmnError
-import org.camunda.bpm.engine.runtime.Execution
-import org.apache.commons.lang3.*
+package org.openecomp.mso.bpmn.infrastructure.scripts;
 
 import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.DocumentBuilderFactory
 
-import org.apache.commons.codec.binary.Base64
-import org.springframework.web.util.UriUtils
-
+import org.apache.commons.lang3.*
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.runtime.Execution
+import org.openecomp.mso.bpmn.common.scripts.AaiUtil
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
+import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
+import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
+import org.openecomp.mso.bpmn.common.scripts.VfModuleBase
 import org.openecomp.mso.bpmn.core.RollbackData
 import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.bpmn.core.json.JsonUtils
 import org.openecomp.mso.rest.APIResponse
 import org.openecomp.mso.rest.RESTClient
 import org.openecomp.mso.rest.RESTConfig
-
+import org.springframework.web.util.UriUtils
 import org.w3c.dom.Document
 import org.w3c.dom.Element
 import org.w3c.dom.NamedNodeMap
 import org.w3c.dom.Node
-import org.w3c.dom.NodeList;
+import org.w3c.dom.NodeList
 import org.xml.sax.InputSource
 
 
@@ -49,6 +51,7 @@ public class DoCreateVfModule extends VfModuleBase {
 
        String Prefix="DCVFM_"
        ExceptionUtil exceptionUtil = new ExceptionUtil()
+       JsonUtils jsonUtil = new JsonUtils()
 
        /**
         * Validates the request message and sets up the workflow.
@@ -62,213 +65,353 @@ public class DoCreateVfModule extends VfModuleBase {
                logDebug('Entered ' + method, isDebugLogEnabled)
 
                execution.setVariable('prefix', Prefix)
-try{
-               String request = execution.getVariable("DoCreateVfModuleRequest")
-               utils.logAudit("DoCreateVfModule request: " + request)
-
-               def rollbackData = execution.getVariable("RollbackData")
-               if (rollbackData == null) {
-                       rollbackData = new RollbackData()
-               }
-
-               execution.setVariable ("CreateAAIVfModuleRequest", request)
-               execution.setVariable("DCVFM_vnfParamsExistFlag", false)
-               //tenantId
-               def tenantId = ""
-               if (utils.nodeExists(request, "tenant-id")) {
-                       tenantId = utils.getNodeText(request, "tenant-id")
-               }
-               execution.setVariable("DCVFM_tenantId", tenantId)
-               rollbackData.put("VFMODULE", "tenantid", tenantId)
-               //volumeGroupId
-               def volumeGroupId = ""
-               if (utils.nodeExists(request, "volume-group-id")) {
-                       volumeGroupId = utils.getNodeText(request, "volume-group-id")
-               }
-               execution.setVariable("DCVFM_volumeGroupId", volumeGroupId)
-               //volumeGroupId
-               def volumeGroupName = ""
-               if (utils.nodeExists(request, "volume-group-name")) {
-                       volumeGroupName = utils.getNodeText(request, "volume-group-name")
-               }
-               execution.setVariable("DCVFM_volumeGroupName", volumeGroupName)
-               //cloudSiteId
-               def cloudSiteId = ""
-               if (utils.nodeExists(request, "aic-cloud-region")) {
-                       cloudSiteId = utils.getNodeText(request, "aic-cloud-region")
-               }
-               execution.setVariable("DCVFM_cloudSiteId", cloudSiteId)
-               rollbackData.put("VFMODULE", "aiccloudregion", cloudSiteId)
-               logDebug("cloudSiteId: " + cloudSiteId, isDebugLogEnabled)
-               //vnfType
-               def vnfType = ""
-               if (utils.nodeExists(request, "vnf-type")) {
-                       vnfType = utils.getNodeText(request, "vnf-type")
-               }
-               execution.setVariable("DCVFM_vnfType", vnfType)
-               rollbackData.put("VFMODULE", "vnftype", vnfType)
-               logDebug("vnfType: " + vnfType, isDebugLogEnabled)
-               //vnfName
-               def vnfName = ""
-               if (utils.nodeExists(request, "vnf-name")) {
-                       vnfName = utils.getNodeText(request, "vnf-name")
-               }
-               execution.setVariable("DCVFM_vnfName", vnfName)
-               rollbackData.put("VFMODULE", "vnfname", vnfName)
-               logDebug("vnfName: " + vnfName, isDebugLogEnabled)
-               //vnfId
-               def vnfId = ""
-               if (utils.nodeExists(request, "vnf-id")) {
-                       vnfId = utils.getNodeText(request, "vnf-id")
-               }
-               execution.setVariable("DCVFM_vnfId", vnfId)
-               rollbackData.put("VFMODULE", "vnfid", vnfId)
-               logDebug("vnfId: " + vnfId, isDebugLogEnabled)
-               //vfModuleName
-               def vfModuleName = ""
-               if (utils.nodeExists(request, "vf-module-name")) {
-                       vfModuleName = utils.getNodeText(request, "vf-module-name")
-               }
-               execution.setVariable("DCVFM_vfModuleName", vfModuleName)
-               rollbackData.put("VFMODULE", "vfmodulename", vfModuleName)
-               logDebug("vfModuleName: " + vfModuleName, isDebugLogEnabled)
-               //vfModuleModelName
-               def vfModuleModelName = ""
-               if (utils.nodeExists(request, "vf-module-model-name")) {
-                       vfModuleModelName = utils.getNodeText(request, "vf-module-model-name")
-               }
-               execution.setVariable("DCVFM_vfModuleModelName", vfModuleModelName)
-               rollbackData.put("VFMODULE", "vfmodulemodelname", vfModuleModelName)
-               logDebug("vfModuleModelName: " + vfModuleModelName, isDebugLogEnabled)
-               //vfModuleId
-               def vfModuleId = ""
-               if (utils.nodeExists(request, "vf-module-id")) {
-                       vfModuleId = utils.getNodeText(request, "vf-module-id")
-               }
-               execution.setVariable("DCVFM_vfModuleId", vfModuleId)
-               logDebug("vfModuleId: " + vfModuleId, isDebugLogEnabled)
-               def requestId = ""
-               if (utils.nodeExists(request, "request-id")) {
-                       requestId = utils.getNodeText(request, "request-id")
-               }
-               execution.setVariable("DCVFM_requestId", requestId)
-               logDebug("requestId: " + requestId, isDebugLogEnabled)
-               //serviceId
-               def serviceId = ""
-               if (utils.nodeExists(request, "service-id")) {
-                       serviceId = utils.getNodeText(request, "service-id")
-               }
-               execution.setVariable("DCVFM_serviceId", serviceId)
-               logDebug("serviceId: " + serviceId, isDebugLogEnabled)
-               //serviceInstanceId
-               def serviceInstanceId = ""
-               if (utils.nodeExists(request, "service-instance-id")) {
-                       serviceInstanceId = utils.getNodeText(request, "service-instance-id")
-               }
-               execution.setVariable("DCVFM_serviceInstanceId", serviceInstanceId)
-               rollbackData.put("VFMODULE", "serviceInstanceId", serviceInstanceId)
-               logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled)
-               //source
-               def source = ""
-               if (utils.nodeExists(request, "source")) {
-                       source = utils.getNodeText(request, "source")
-               }
-               execution.setVariable("DCVFM_source", source)
-               rollbackData.put("VFMODULE", "source", source)
-               logDebug("source: " + source, isDebugLogEnabled)
-               //backoutOnFailure
-               NetworkUtils networkUtils = new NetworkUtils()
-               def backoutOnFailure = networkUtils.isRollbackEnabled(execution,request)
-               execution.setVariable("DCVFM_backoutOnFailure", backoutOnFailure)
-               logDebug("backoutOnFailure: " + backoutOnFailure, isDebugLogEnabled)
-               //isBaseVfModule
-               def isBaseVfModule = "false"
-               if (utils.nodeExists(request, "is-base-vf-module")) {
-                       isBaseVfModule = utils.getNodeText(request, "is-base-vf-module")
-               }
-               execution.setVariable("DCVFM_isBaseVfModule", isBaseVfModule)
-               logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
-
-               //asdcServiceModelVersion
-               def asdcServiceModelVersion = ""
-               if (utils.nodeExists(request, "asdc-service-model-version")) {
-                       asdcServiceModelVersion = utils.getNodeText(request, "asdc-service-model-version")
-               }
-               execution.setVariable("DCVFM_asdcServiceModelVersion", asdcServiceModelVersion)
-               logDebug("asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugLogEnabled)
-
-               //Get or Generate UUID
-               String uuid = execution.getVariable("DCVFM_uuid")
-               if(uuid == null){
-                       uuid = UUID.randomUUID()
-                       logDebug("Generated messageId (UUID) is: " + uuid, isDebugLogEnabled)
-               }else{
-                       logDebug("Found messageId (UUID) is: " + uuid, isDebugLogEnabled)
-               }
-               execution.setVariable("DCVFM_uuid", uuid)
-               execution.setVariable("DCVFM_baseVfModuleId", "")
-               execution.setVariable("DCVFM_baseVfModuleHeatStackId", "")
-               execution.setVariable("DCVFM_heatStackId", "")
-               execution.setVariable("DCVFM_contrailServiceInstanceFqdn", "")
-               execution.setVariable("DCVFM_volumeGroupStackId", "")
-               execution.setVariable("DCVFM_cloudRegionForVolume", "")
-               rollbackData.put("VFMODULE", "rollbackPrepareUpdateVfModule", "false")
-               rollbackData.put("VFMODULE", "rollbackUpdateAAIVfModule", "false")
-               rollbackData.put("VFMODULE", "rollbackVnfAdapterCreate", "false")
-               rollbackData.put("VFMODULE", "rollbackSDNCRequestActivate", "false")
-               rollbackData.put("VFMODULE", "rollbackSDNCRequestAssign", "false")
-               rollbackData.put("VFMODULE", "rollbackCreateAAIVfModule", "false")
-
-               String sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
-                       if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
-                               def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
-                               logError(msg)
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+               try{                    
+                       def rollbackData = execution.getVariable("RollbackData")
+                       if (rollbackData == null) {
+                               rollbackData = new RollbackData()
                        }
-                       execution.setVariable("DCVFM_sdncCallbackUrl", sdncCallbackUrl)
-                       utils.logAudit("SDNC Callback URL: " + sdncCallbackUrl)
-                   logDebug("SDNC Callback URL is: " + sdncCallbackUrl, isDebugLogEnabled)
-                       String vnfCallbackUrl = (String) execution.getVariable('URN_mso_workflow_vnfadapter_rest_callback')
-                       if (vnfCallbackUrl == null || vnfCallbackUrl.trim().isEmpty()) {
-                               def msg = 'Required variable \'URN_mso_workflow_vnfadapter_rest_callback\' is missing'
-                               logError(msg)
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                       
+                       execution.setVariable("DCVFM_vnfParamsExistFlag", false)
+                       execution.setVariable("DCVFM_oamManagementV4Address", "")
+                       execution.setVariable("DCVFM_oamManagementV6Address", "")
+                                                               
+                       String request = execution.getVariable("DoCreateVfModuleRequest")
+                               
+                       if (request == null || request.isEmpty()) {
+                               // Building Block-type request
+                               
+                               String cloudConfiguration = execution.getVariable("cloudConfiguration")
+                               String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
+                               
+                               //tenantId
+                               def tenantId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.tenantId")
+                               execution.setVariable("DCVFM_tenantId", tenantId)
+                               rollbackData.put("VFMODULE", "tenantid", tenantId)
+                               //volumeGroupId
+                               def volumeGroupId = execution.getVariable("volumeGroupId")                              
+                               execution.setVariable("DCVFM_volumeGroupId", volumeGroupId)
+                               //volumeGroupName
+                               def volumeGroupName = execution.getVariable("volumeGroupName")                          
+                               execution.setVariable("DCVFM_volumeGroupName", volumeGroupName)
+                               //cloudSiteId
+                               def cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "cloudConfiguration.lcpCloudRegionId")
+                               execution.setVariable("DCVFM_cloudSiteId", cloudSiteId)
+                               rollbackData.put("VFMODULE", "aiccloudregion", cloudSiteId)
+                               logDebug("cloudSiteId: " + cloudSiteId, isDebugLogEnabled)
+                               //vnfType
+                               def vnfType = execution.getVariable("vnfType")
+                               execution.setVariable("DCVFM_vnfType", vnfType)
+                               rollbackData.put("VFMODULE", "vnftype", vnfType)
+                               logDebug("vnfType: " + vnfType, isDebugLogEnabled)
+                               //vnfName
+                               def vnfName = execution.getVariable("vnfName")                          
+                               execution.setVariable("DCVFM_vnfName", vnfName)
+                               rollbackData.put("VFMODULE", "vnfname", vnfName)
+                               logDebug("vnfName: " + vnfName, isDebugLogEnabled)
+                               //vnfId
+                               def vnfId = execution.getVariable("vnfId")                              
+                               execution.setVariable("DCVFM_vnfId", vnfId)
+                               rollbackData.put("VFMODULE", "vnfid", vnfId)
+                               logDebug("vnfId: " + vnfId, isDebugLogEnabled)
+                               //vfModuleName
+                               def vfModuleName = execution.getVariable("vfModuleName")                                
+                               execution.setVariable("DCVFM_vfModuleName", vfModuleName)
+                               rollbackData.put("VFMODULE", "vfmodulename", vfModuleName)
+                               logDebug("vfModuleName: " + vfModuleName, isDebugLogEnabled)
+                               //vfModuleModelName
+                               def vfModuleModelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelInfo.modelName")                         
+                               execution.setVariable("DCVFM_vfModuleModelName", vfModuleModelName)
+                               rollbackData.put("VFMODULE", "vfmodulemodelname", vfModuleModelName)
+                               logDebug("vfModuleModelName: " + vfModuleModelName, isDebugLogEnabled)
+                               //modelCustomizationUuid
+                               def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelInfo.modelCustomizationId")
+                               execution.setVariable("DCVFM_modelCustomizationUuid", modelCustomizationUuid)
+                               rollbackData.put("VFMODULE", "modelcustomizationuuid", modelCustomizationUuid)
+                               logDebug("modelCustomizationUuid: " + modelCustomizationUuid, isDebugLogEnabled)
+                               //vfModuleId
+                               def vfModuleId = execution.getVariable("vfModuleId")                            
+                               execution.setVariable("DCVFM_vfModuleId", vfModuleId)
+                               logDebug("vfModuleId: " + vfModuleId, isDebugLogEnabled)
+                               def requestId = execution.getVariable("requestId")                              
+                               execution.setVariable("DCVFM_requestId", requestId)
+                               logDebug("requestId: " + requestId, isDebugLogEnabled)
+                               // Set mso-request-id to request-id for VNF Adapter interface                           
+                               execution.setVariable("mso-request-id", requestId)
+                               //serviceId
+                               def serviceId = execution.getVariable("serviceId")                              
+                               execution.setVariable("DCVFM_serviceId", serviceId)
+                               logDebug("serviceId: " + serviceId, isDebugLogEnabled)
+                               //serviceInstanceId
+                               def serviceInstanceId = execution.getVariable("serviceInstanceId")                              
+                               execution.setVariable("DCVFM_serviceInstanceId", serviceInstanceId)
+                               rollbackData.put("VFMODULE", "serviceInstanceId", serviceInstanceId)
+                               logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled)
+                               //source - HARDCODED
+                               def source = "VID"                              
+                               execution.setVariable("DCVFM_source", source)
+                               rollbackData.put("VFMODULE", "source", source)
+                               logDebug("source: " + source, isDebugLogEnabled)
+                               //backoutOnFailure
+                               def disableRollback = execution.getVariable("disableRollback")
+                               def backoutOnFailure = true
+                               if (disableRollback != null && disableRollback.equals("true")) {
+                                       backoutOnFailure = false
+                               }                               
+                               execution.setVariable("DCVFM_backoutOnFailure", backoutOnFailure)
+                               logDebug("backoutOnFailure: " + backoutOnFailure, isDebugLogEnabled)
+                               //isBaseVfModule
+                               def isBaseVfModule = execution.getVariable("isBaseVfModule")                            
+                               execution.setVariable("DCVFM_isBaseVfModule", isBaseVfModule)
+                               logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)                
+                               //asdcServiceModelVersion
+                               def asdcServiceModelVersion = execution.getVariable("asdcServiceModelVersion")                          
+                               execution.setVariable("DCVFM_asdcServiceModelVersion", asdcServiceModelVersion)
+                               logDebug("asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugLogEnabled)                              
+                               //personaModelId
+                               execution.setVariable("DCVFM_personaModelId", jsonUtil.getJsonValue(vfModuleModelInfo, "modelInfo.modelInvariantId"))
+                               //personaModelVersion
+                               execution.setVariable("DCVFM_personaModelVersion", jsonUtil.getJsonValue(vfModuleModelInfo, "modelInfo.modelVersion"))          
+                               //Get or Generate UUID
+                               String uuid = execution.getVariable("DCVFM_uuid")
+                               if(uuid == null){
+                                       uuid = UUID.randomUUID()
+                                       logDebug("Generated messageId (UUID) is: " + uuid, isDebugLogEnabled)
+                               }else{
+                                       logDebug("Found messageId (UUID) is: " + uuid, isDebugLogEnabled)
+                               }
+                               //isVidRequest
+                               String isVidRequest = execution.getVariable("isVidRequest")
+                               // default to true
+                               if (isVidRequest == null || isVidRequest.isEmpty()) {
+                                       execution.setVariable("isVidRequest", "true")
+                               }
+                               
+                               String vnfParamsChildNodes = execution.getVariable("vfModuleInputParams")
+                               
                        }
-
-               // Process the parameters
-
-               String vnfParamsChildNodes = utils.getChildNodes(request, "vnf-params")
-               if(vnfParamsChildNodes == null || vnfParamsChildNodes.length() < 1){
-                               utils.log("DEBUG", "Request contains NO VNF Params", isDebugLogEnabled)
-               }else{
-                               utils.log("DEBUG", "Request does contain VNF Params", isDebugLogEnabled)
-                               execution.setVariable("DCVFM_vnfParamsExistFlag", true)
-
-                               InputSource xmlSource = new InputSource(new StringReader(request));
-                               DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
-                               docFactory.setNamespaceAware(true)
-                               DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
-                               Document xml = docBuilder.parse(xmlSource)
-                               //Get params, build map
-                               Map<String, String> paramsMap = new HashMap<String, String>()
-                               NodeList paramsList = xml.getElementsByTagNameNS("*", "param")
-
-                               for (int z = 0; z < paramsList.getLength(); z++) {
-                                       Node node = paramsList.item(z)
-                                       String paramValue = node.getTextContent()
-                                       NamedNodeMap e = node.getAttributes()
-                                       String paramName = e.getNamedItem("name").getTextContent()
-                                       paramsMap.put(paramName, paramValue)
+                       else {
+                               // The info is inside the request
+                               utils.logAudit("DoCreateVfModule request: " + request)
+                                                               
+                               //tenantId
+                               def tenantId = ""
+                               if (utils.nodeExists(request, "tenant-id")) {
+                                       tenantId = utils.getNodeText(request, "tenant-id")
+                               }
+                               execution.setVariable("DCVFM_tenantId", tenantId)
+                               rollbackData.put("VFMODULE", "tenantid", tenantId)
+                               //volumeGroupId
+                               def volumeGroupId = ""
+                               if (utils.nodeExists(request, "volume-group-id")) {
+                                       volumeGroupId = utils.getNodeText(request, "volume-group-id")
                                }
-                               execution.setVariable("DCVFM_vnfParamsMap", paramsMap)
+                               execution.setVariable("DCVFM_volumeGroupId", volumeGroupId)
+                               //volumeGroupId
+                               def volumeGroupName = ""
+                               if (utils.nodeExists(request, "volume-group-name")) {
+                                       volumeGroupName = utils.getNodeText(request, "volume-group-name")
+                               }
+                               execution.setVariable("DCVFM_volumeGroupName", volumeGroupName)
+                               //cloudSiteId
+                               def cloudSiteId = ""
+                               if (utils.nodeExists(request, "aic-cloud-region")) {
+                                       cloudSiteId = utils.getNodeText(request, "aic-cloud-region")
+                               }
+                               execution.setVariable("DCVFM_cloudSiteId", cloudSiteId)
+                               rollbackData.put("VFMODULE", "aiccloudregion", cloudSiteId)
+                               logDebug("cloudSiteId: " + cloudSiteId, isDebugLogEnabled)
+                               //vnfType
+                               def vnfType = ""
+                               if (utils.nodeExists(request, "vnf-type")) {
+                                       vnfType = utils.getNodeText(request, "vnf-type")
+                               }
+                               execution.setVariable("DCVFM_vnfType", vnfType)
+                               rollbackData.put("VFMODULE", "vnftype", vnfType)
+                               logDebug("vnfType: " + vnfType, isDebugLogEnabled)
+                               //vnfName
+                               def vnfName = ""
+                               if (utils.nodeExists(request, "vnf-name")) {
+                                       vnfName = utils.getNodeText(request, "vnf-name")
+                               }
+                               execution.setVariable("DCVFM_vnfName", vnfName)
+                               rollbackData.put("VFMODULE", "vnfname", vnfName)
+                               logDebug("vnfName: " + vnfName, isDebugLogEnabled)
+                               //vnfId
+                               def vnfId = ""
+                               if (utils.nodeExists(request, "vnf-id")) {
+                                       vnfId = utils.getNodeText(request, "vnf-id")
+                               }
+                               execution.setVariable("DCVFM_vnfId", vnfId)
+                               rollbackData.put("VFMODULE", "vnfid", vnfId)
+                               logDebug("vnfId: " + vnfId, isDebugLogEnabled)
+                               //vfModuleName
+                               def vfModuleName = ""
+                               if (utils.nodeExists(request, "vf-module-name")) {
+                                       vfModuleName = utils.getNodeText(request, "vf-module-name")
+                               }
+                               execution.setVariable("DCVFM_vfModuleName", vfModuleName)
+                               rollbackData.put("VFMODULE", "vfmodulename", vfModuleName)
+                               logDebug("vfModuleName: " + vfModuleName, isDebugLogEnabled)
+                               //vfModuleModelName
+                               def vfModuleModelName = ""
+                               if (utils.nodeExists(request, "vf-module-model-name")) {
+                                       vfModuleModelName = utils.getNodeText(request, "vf-module-model-name")
+                               }
+                               execution.setVariable("DCVFM_vfModuleModelName", vfModuleModelName)
+                               rollbackData.put("VFMODULE", "vfmodulemodelname", vfModuleModelName)
+                               logDebug("vfModuleModelName: " + vfModuleModelName, isDebugLogEnabled)
+                               //modelCustomizationUuid
+                               def modelCustomizationUuid = ""
+                               if (utils.nodeExists(request, "model-customization-id")) {
+                                       modelCustomizationUuid = utils.getNodeText(request, "model-customization-id")
+                               }
+                               execution.setVariable("DCVFM_modelCustomizationUuid", modelCustomizationUuid)
+                               rollbackData.put("VFMODULE", "modelcustomizationuuid", modelCustomizationUuid)
+                               logDebug("modelCustomizationUuid: " + modelCustomizationUuid, isDebugLogEnabled)
+                               //vfModuleId
+                               def vfModuleId = ""
+                               if (utils.nodeExists(request, "vf-module-id")) {
+                                       vfModuleId = utils.getNodeText(request, "vf-module-id")
+                               }
+                               execution.setVariable("DCVFM_vfModuleId", vfModuleId)
+                               logDebug("vfModuleId: " + vfModuleId, isDebugLogEnabled)
+                               def requestId = ""
+                               if (utils.nodeExists(request, "request-id")) {
+                                       requestId = utils.getNodeText(request, "request-id")
+                               }
+                               execution.setVariable("DCVFM_requestId", requestId)
+                               logDebug("requestId: " + requestId, isDebugLogEnabled)
+                               //serviceId
+                               def serviceId = ""
+                               if (utils.nodeExists(request, "service-id")) {
+                                       serviceId = utils.getNodeText(request, "service-id")
+                               }
+                               execution.setVariable("DCVFM_serviceId", serviceId)
+                               logDebug("serviceId: " + serviceId, isDebugLogEnabled)
+                               //serviceInstanceId
+                               def serviceInstanceId = ""
+                               if (utils.nodeExists(request, "service-instance-id")) {
+                                       serviceInstanceId = utils.getNodeText(request, "service-instance-id")
+                               }
+                               execution.setVariable("DCVFM_serviceInstanceId", serviceInstanceId)
+                               rollbackData.put("VFMODULE", "serviceInstanceId", serviceInstanceId)
+                               logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled)
+                               //source
+                               def source = ""
+                               if (utils.nodeExists(request, "source")) {
+                                       source = utils.getNodeText(request, "source")
+                               }
+                               execution.setVariable("DCVFM_source", source)
+                               rollbackData.put("VFMODULE", "source", source)
+                               logDebug("source: " + source, isDebugLogEnabled)
+                               //backoutOnFailure
+                               NetworkUtils networkUtils = new NetworkUtils()
+                               def backoutOnFailure = networkUtils.isRollbackEnabled(execution,request)
+                               execution.setVariable("DCVFM_backoutOnFailure", backoutOnFailure)
+                               logDebug("backoutOnFailure: " + backoutOnFailure, isDebugLogEnabled)
+                               //isBaseVfModule
+                               def isBaseVfModule = "false"
+                               if (utils.nodeExists(request, "is-base-vf-module")) {
+                                       isBaseVfModule = utils.getNodeText(request, "is-base-vf-module")
+                               }
+                               execution.setVariable("DCVFM_isBaseVfModule", isBaseVfModule)
+                               logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
+               
+                               //asdcServiceModelVersion
+                               def asdcServiceModelVersion = ""
+                               if (utils.nodeExists(request, "asdc-service-model-version")) {
+                                       asdcServiceModelVersion = utils.getNodeText(request, "asdc-service-model-version")
+                               }
+                               execution.setVariable("DCVFM_asdcServiceModelVersion", asdcServiceModelVersion)
+                               logDebug("asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugLogEnabled)      
+                               
+                               //personaModelId
+                               def personaModelId = ""
+                               if (utils.nodeExists(request, "persona-model-id")) {
+                                       personaModelId = utils.getNodeText(request, "persona-model-id")
+                               }
+                               execution.setVariable("DCVFM_personaModelId", personaModelId)
+                               logDebug("personaModelId: " + personaModelId, isDebugLogEnabled)
+                               
+                               //personaModelVersion
+                               def personaModelVersion = ""
+                               if (utils.nodeExists(request, "persona-model-version")) {
+                                       personaModelVersion = utils.getNodeText(request, "persona-model-version")
+                               }
+                               execution.setVariable("DCVFM_personaModelVersion", personaModelVersion)
+                               logDebug("personaModelVersion: " + personaModelVersion, isDebugLogEnabled)
+                               
+                               // Process the parameters
+                               
+                                               String vnfParamsChildNodes = utils.getChildNodes(request, "vnf-params")
+                                               if(vnfParamsChildNodes == null || vnfParamsChildNodes.length() < 1){
+                                                               utils.log("DEBUG", "Request contains NO VNF Params", isDebugLogEnabled)
+                                               }else{
+                                                               utils.log("DEBUG", "Request does contain VNF Params", isDebugLogEnabled)
+                                                               execution.setVariable("DCVFM_vnfParamsExistFlag", true)
+                               
+                                                               InputSource xmlSource = new InputSource(new StringReader(request));
+                                                               DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+                                                               docFactory.setNamespaceAware(true)
+                                                               DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
+                                                               Document xml = docBuilder.parse(xmlSource)
+                                                               //Get params, build map
+                                                               Map<String, String> paramsMap = new HashMap<String, String>()
+                                                               NodeList paramsList = xml.getElementsByTagNameNS("*", "param")
+                               
+                                                               for (int z = 0; z < paramsList.getLength(); z++) {
+                                                                       Node node = paramsList.item(z)
+                                                                       String paramValue = node.getTextContent()
+                                                                       NamedNodeMap e = node.getAttributes()
+                                                                       String paramName = e.getNamedItem("name").getTextContent()
+                                                                       paramsMap.put(paramName, paramValue)
+                                                               }
+                                                               execution.setVariable("DCVFM_vnfParamsMap", paramsMap)
+                                                       }
                        }
-
-               execution.setVariable("RollbackData", rollbackData)
-}catch(BpmnError b){
+                       
+                       //Get or Generate UUID
+                       String uuid = execution.getVariable("DCVFM_uuid")
+                       if(uuid == null){
+                               uuid = UUID.randomUUID()
+                               logDebug("Generated messageId (UUID) is: " + uuid, isDebugLogEnabled)
+                       }else{
+                               logDebug("Found messageId (UUID) is: " + uuid, isDebugLogEnabled)
+                       }
+                       execution.setVariable("DCVFM_uuid", uuid)
+                       execution.setVariable("DCVFM_baseVfModuleId", "")
+                       execution.setVariable("DCVFM_baseVfModuleHeatStackId", "")
+                       execution.setVariable("DCVFM_heatStackId", "")
+                       execution.setVariable("DCVFM_contrailServiceInstanceFqdn", "")
+                       execution.setVariable("DCVFM_volumeGroupStackId", "")
+                       execution.setVariable("DCVFM_cloudRegionForVolume", "")
+                       execution.setVariable("DCVFM_contrailNetworkPolicyFqdnList", "")
+                       rollbackData.put("VFMODULE", "rollbackPrepareUpdateVfModule", "false")
+                       rollbackData.put("VFMODULE", "rollbackUpdateAAIVfModule", "false")
+                       rollbackData.put("VFMODULE", "rollbackVnfAdapterCreate", "false")
+                       rollbackData.put("VFMODULE", "rollbackSDNCRequestActivate", "false")
+                       rollbackData.put("VFMODULE", "rollbackSDNCRequestAssign", "false")
+                       rollbackData.put("VFMODULE", "rollbackCreateAAIVfModule", "false")
+                       rollbackData.put("VFMODULE", "rollbackCreateNetworkPoliciesAAI", "false")
+                       rollbackData.put("VFMODULE", "rollbackUpdateVnfAAI", "false")
+       
+                       String sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
+                               if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
+                                       def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
+                                       logError(msg)
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                               }
+                               execution.setVariable("DCVFM_sdncCallbackUrl", sdncCallbackUrl)
+                               utils.logAudit("SDNC Callback URL: " + sdncCallbackUrl)
+                           logDebug("SDNC Callback URL is: " + sdncCallbackUrl, isDebugLogEnabled)     
+                       
+       
+                       execution.setVariable("RollbackData", rollbackData)
+               }catch(BpmnError b){
                        throw b
-}catch(Exception e){
-       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
-}
+               }catch(Exception e){
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
+               }
 
                logDebug('Exited ' + method, isDebugLogEnabled)
        }
@@ -375,11 +518,9 @@ try{
                        String  aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
                        logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
 
-                       String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8")
+                       String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
                        utils.logAudit("AAI endPoint: " + endPoint)
 
-                       String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
-
                        try {
                                RESTConfig config = new RESTConfig(endPoint);
                                def responseData = ''
@@ -389,11 +530,6 @@ try{
                                        addHeader('X-FromAppId', 'MSO').
                                        addHeader('Content-Type', 'application/xml').
                                        addHeader('Accept','application/xml');
-
-                               if (basicAuthCred != null && !"".equals(basicAuthCred)) {
-                                       client.addAuthorizationHeader(basicAuthCred)
-                               }
-
                                logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
                                APIResponse response = client.httpGet()
                                utils.logAudit("createVfModule - invoking httpGet() to AAI")
@@ -502,7 +638,7 @@ try{
 
                        String uuid = execution.getVariable('testReqId') // for junits
                        if(uuid==null){
-                               uuid = execution.getVariable("att-mso-request-id") + "-" +      System.currentTimeMillis()
+                               uuid = execution.getVariable("mso-request-id") + "-" +          System.currentTimeMillis()
                        }
 
                        String serviceOperation = "/VNF-API:vnfs/vnf-list/" + vfModuleId
@@ -521,9 +657,9 @@ try{
                        sleep(5000)
 
                        String SDNCGetRequest =
-                                       """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://ecomp.att.com/mso/request/types/v1"
-                                                                                       xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
-                                                                                       xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
+                                       """<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>${uuid}</sdncadapter:RequestId>
                                        <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
@@ -592,11 +728,13 @@ try{
                def asdcServiceModelVersion = execution.getVariable("DCVFM_asdcServiceModelVersion")
                //volumeGroupStackId
                def volumeGroupStackId = execution.getVariable("DCVFM_volumeGroupStackId")
+               //modelCustomizationUuid
+               def modelCustomizationUuid = execution.getVariable("DCVFM_modelCustomizationUuid")
 
-               def messageId = execution.getVariable('att-mso-request-id') + '-' +
+               def messageId = execution.getVariable('mso-request-id') + '-' +
                                 System.currentTimeMillis()
 
-               def notificationUrl = execution.getVariable("URN_mso_workflow_vnfadapter_rest_callback")
+               def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
                def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
 
                utils.logAudit("notificationUrl: " + notificationUrl)
@@ -655,6 +793,7 @@ try{
                <vnfType>${vnfType}</vnfType>
                <vfModuleType>${vfModuleModelName}</vfModuleType>
                <vnfVersion>${asdcServiceModelVersion}</vnfVersion>
+               <modelCustomizationUuid>${modelCustomizationUuid}</modelCustomizationUuid>
                <requestType></requestType>
                <volumeGroupId>${volumeGroupId}</volumeGroupId>
        <volumeGroupStackId>${volumeGroupStackId}</volumeGroupStackId>
@@ -722,16 +861,16 @@ try{
 
                        /*
 
-                       def requestId = execution.getVariable("att-mso-request-id")
+                       def requestId = execution.getVariable("mso-request-id")
 
                        if (requestId == null) {
-                               createWorkflowException(execution, 1002, processKey + " request has no att-mso-request-id")
+                               createWorkflowException(execution, 1002, processKey + " request has no mso-request-id")
                        }
 
-                       def serviceInstanceId = execution.getVariable("att-mso-service-instance-id")
+                       def serviceInstanceId = execution.getVariable("mso-service-instance-id")
 
                        if (serviceInstanceId == null) {
-                               createWorkflowException(execution, 1002, processKey + " request message has no att-mso-service-instance-id")
+                               createWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")
                        }
 
                        utils.logContext(requestId, serviceInstanceId)
@@ -793,7 +932,7 @@ try{
 
                String uuid = execution.getVariable('testReqId') // for junits
                if(uuid==null){
-                       uuid = execution.getVariable("att-mso-request-id") + "-" +      System.currentTimeMillis()
+                       uuid = execution.getVariable("mso-request-id") + "-" +          System.currentTimeMillis()
                }
                def callbackURL = execution.getVariable("DCVFM_sdncCallbackUrl")
                def requestId = execution.getVariable("DCVFM_requestId")
@@ -818,9 +957,9 @@ try{
                }
 
                String sdncRequest =
-               """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://ecomp.att.com/mso/request/types/v1"
-                                                                                                       xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
-                                                                                                       xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
+               """<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>${requestId}</sdncadapter:RequestId>
                                <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
@@ -927,6 +1066,7 @@ try{
                        Document outputsXml = docBuilder.parse(source)
 
                                        NodeList entries = outputsXml.getElementsByTagNameNS("*", "entry")
+                                       List contrailNetworkPolicyFqdnList = []
                                        for (int i = 0; i< entries.getLength(); i++) {
                                                Node node = entries.item(i)
                                                if (node.getNodeType() == Node.ELEMENT_NODE) {
@@ -937,7 +1077,26 @@ try{
                                                                logDebug("Obtained contrailServiceInstanceFqdn: " + contrailServiceInstanceFqdn, isDebugLogEnabled)
                                                                execution.setVariable("DCVFM_contrailServiceInstanceFqdn", contrailServiceInstanceFqdn)
                                                        }
-                                               }
+                                                       else if (key.endsWith("contrail_network_policy_fqdn")) {
+                                                               String contrailNetworkPolicyFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
+                                                               logDebug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn, isDebugLogEnabled)
+                                                               contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)                                                            
+                                                       }
+                                                       else if (key.equals("oam_management_v4_address")) {
+                                                               String oamManagementV4Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
+                                                               logDebug("Obtained oamManagementV4Address: " + oamManagementV4Address, isDebugLogEnabled)
+                                                               execution.setVariable("DCVFM_oamManagementV4Address", oamManagementV4Address)                                                   
+                                                       }
+                                                       else if (key.equals("oam_management_v6_address")) {
+                                                               String oamManagementV6Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
+                                                               logDebug("Obtained oamManagementV6Address: " + oamManagementV6Address, isDebugLogEnabled)
+                                                               execution.setVariable("DCVFM_oamManagementV6Address", oamManagementV6Address)
+                                                       }
+                                               
+                                               }                                               
+                                       }
+                                       if (!contrailNetworkPolicyFqdnList.isEmpty()) {
+                                               execution.setVariable("DCVFM_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
                                        }
                                }
                        }else{
@@ -1073,7 +1232,7 @@ try{
 
                        String uuid = execution.getVariable('testReqId') // for junits
                        if(uuid==null){
-                               uuid = execution.getVariable("att-mso-request-id") + "-" +      System.currentTimeMillis()
+                               uuid = execution.getVariable("mso-request-id") + "-" +          System.currentTimeMillis()
                        }
 
                        String serviceOperation = "/VNF-API:vnfs/vnf-list/" + vnfId
@@ -1081,9 +1240,9 @@ try{
                        utils.logAudit("callbackUrl: " + callbackUrl)
 
                        String SDNCGetRequest =
-                                       """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://ecomp.att.com/mso/request/types/v1"
-                                                                                       xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"
-                                                                                       xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1">
+                                       """<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>${uuid}</sdncadapter:RequestId>
                                        <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
@@ -1216,6 +1375,7 @@ try{
        }
 
    /**
+    *
     *This method occurs when an MSOWorkflowException is caught.  It logs the
     *variables and ensures that the "WorkflowException" Variable is set.
     *
@@ -1275,7 +1435,244 @@ try{
                logDebug("======== COMPLETED  prepareCreateAAIVfModuleVolumeGroupRequest ======== ", isDebugLogEnabled)
 
        }
+   
+   public void createNetworkPoliciesInAAI(Execution execution) {
+          def method = getClass().getSimpleName() + '.createNetworkPoliciesInAAI(' +
+          'execution=' + execution.getId() +
+          ')'
+          def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+          logDebug('Entered ' + method, isDebugLogEnabled)
+          execution.setVariable("prefix", Prefix)
+          logDebug(" ======== STARTED createNetworkPoliciesInAAI ======== ", isDebugLogEnabled)
+         
+          try {
+                  // get variables
+                  List fqdnList = execution.getVariable("DCVFM_contrailNetworkPolicyFqdnList")
+                  int fqdnCount = fqdnList.size()
+                  def rollbackData = execution.getVariable("RollbackData")
+                 
+                  execution.setVariable("DCVFM_networkPolicyFqdnCount", fqdnCount)
+                  logDebug("DCVFM_networkPolicyFqdnCount - " + fqdnCount, isDebugLogEnabled)
+
+                  String aai_endpoint = execution.getVariable("URN_aai_endpoint")
+                  AaiUtil aaiUriUtil = new AaiUtil(this)
+                  String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
+
+                  if (fqdnCount > 0) {                                   
+                          
+                          // AII loop call over contrail network policy fqdn list
+                          for (i in 0..fqdnCount-1) {
+
+                                  int counting = i+1
+                                  String fqdn = fqdnList[i]
+
+                                  // Query AAI for this network policy FQDN
+                                 
+                                  String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
+                                  utils.logAudit("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
+                                  
+                                  def aaiRequestId = UUID.randomUUID().toString()
+                                  RESTConfig config = new RESTConfig(queryNetworkPolicyByFqdnAAIRequest);
+                                  RESTClient client = new RESTClient(config).addHeader("X-TransactionId", aaiRequestId)
+                                                                                                                        .addHeader("X-FromAppId", "MSO")
+                                                                                                                        .addHeader("Content-Type", "application/xml")
+                                                                                                                        .addHeader("Accept","application/xml");
+                                  APIResponse response = client.get()
+                                  int returnCode = response.getStatusCode()
+                                  execution.setVariable("DCVFM_aaiQqueryNetworkPolicyByFqdnReturnCode", returnCode)
+                                  logDebug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugLogEnabled)
+
+                                  String aaiResponseAsString = response.getResponseBodyAsString()
+
+                                  if (isOneOf(returnCode, 200, 201)) {
+                                          logDebug("The return code is: "  + returnCode, isDebugLogEnabled)
+                                          // This network policy FQDN already exists in AAI
+                                          utils.logAudit(aaiResponseAsString)
+                                          execution.setVariable("DCVFM_queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
+                                          logDebug(" QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugLogEnabled)                                   
+
+                                  } else {
+                                          if (returnCode == 404) {
+                                                  // This network policy FQDN is not in AAI yet. Add it now
+                                                  logDebug("The return code is: "  + returnCode, isDebugLogEnabled)
+                                                  logDebug("This network policy FQDN is not in AAI yet: " + fqdn, isDebugLogEnabled)
+                                                  utils.logAudit("Network policy FQDN is not in AAI yet")                                                 
+                                                  // Add the network policy with this FQDN to AAI
+                                                  def networkPolicyId = UUID.randomUUID().toString()
+                                                  logDebug("Adding network-policy with network-policy-id " + networkPolicyId, isDebugLogEnabled)                                               
+                                                                                                  
+                                                  String aaiNamespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
+                                                  logDebug('AAI namespace is: ' + aaiNamespace, isDebugLogEnabled)
+                                                  String payload = """<network-policy xmlns="${aaiNamespace}">
+                                                               <network-policy-id>${networkPolicyId}</network-policy-id>
+                                                               <network-policy-fqdn>${fqdn}</network-policy-fqdn>
+                                                               <heat-stack-id>${execution.getVariable("DCVFM_heatStackId")}</heat-stack-id>                                                            
+                                                               </network-policy>""" as String
+                                                               
+                                                  execution.setVariable("DCVFM_addNetworkPolicyAAIRequestBody", payload)
+                                                  
+                                                  String addNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8")
+                                                  utils.logAudit("AAI request endpoint: " + addNetworkPolicyAAIRequest)
+                                                  logDebug("AAI request endpoint: " + addNetworkPolicyAAIRequest, isDebugLogEnabled)
+                                                  
+                                                  def aaiRequestIdPut = UUID.randomUUID().toString()
+                                                  RESTConfig configPut = new RESTConfig(addNetworkPolicyAAIRequest);
+                                                  RESTClient clientPut = new RESTClient(configPut).addHeader("X-TransactionId", aaiRequestIdPut)
+                                                                                                                                        .addHeader("X-FromAppId", "MSO")
+                                                                                                                                        .addHeader("Content-Type", "application/xml")
+                                                                                                                                        .addHeader("Accept","application/xml");
+                                                  logDebug("invoking PUT call to AAI with payload:"+System.lineSeparator()+payload, isDebugLogEnabled)
+                                                  utils.logAudit("Sending PUT call to AAI with Endpoint /n" + addNetworkPolicyAAIRequest + " with payload /n" + payload)
+                                                  APIResponse responsePut = clientPut.httpPut(payload)
+                                                  int returnCodePut = responsePut.getStatusCode()
+                                                  execution.setVariable("DCVFM_aaiAddNetworkPolicyReturnCode", returnCodePut)
+                                                  logDebug(" ***** AAI add network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodePut, isDebugLogEnabled)
+               
+                                                  String aaiResponseAsStringPut = responsePut.getResponseBodyAsString()        
+                                                  if (isOneOf(returnCodePut, 200, 201)) {
+                                                          logDebug("The return code from adding network policy is: "  + returnCodePut, isDebugLogEnabled)
+                                                          // This network policy was created in AAI successfully
+                                                          utils.logAudit(aaiResponseAsStringPut)
+                                                          execution.setVariable("DCVFM_addNetworkPolicyAAIResponse", aaiResponseAsStringPut)
+                                                          logDebug(" AddAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsStringPut, isDebugLogEnabled)
+                                                          rollbackData.put("VFMODULE", "rollbackCreateNetworkPoliciesAAI", "true")
+                                                          rollbackData.put("VFMODULE", "contrailNetworkPolicyFqdn" + i, fqdn)
+                                                          execution.setVariable("RollbackData", rollbackData)
+                                                                       
+                                                  } else {
+                                                               // aai all errors
+                                                               String putErrorMessage = "Unable to add network-policy to AAI createNetworkPoliciesInAAI - " + returnCodePut
+                                                               logDebug(putErrorMessage, isDebugLogEnabled)
+                                                               exceptionUtil.buildAndThrowWorkflowException(execution, 2500, putErrorMessage)                                     
+                                                  }
+                                                                                                  
+                                          } else {
+                                                 if (aaiResponseAsString.contains("RESTFault")) {
+                                                         WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
+                                                         execution.setVariable("WorkflowException", exceptionObject)
+                                                         throw new BpmnError("MSOWorkflowException")
+
+                                                         } else {
+                                                                  // aai all errors
+                                                                  String dataErrorMessage = "Unexpected Response from createNetworkPoliciesInAAI - " + returnCode
+                                                                  logDebug(dataErrorMessage, isDebugLogEnabled)
+                                                                  exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
+
+                                                        }
+                                          }
+                                  }
+
+                          } // end loop
+
+                         
+                  } else {
+                          logDebug("No contrail network policies to query/create", isDebugLogEnabled)
 
+                  }
 
-}
+          } catch (BpmnError e) {
+                  throw e;
 
+          } catch (Exception ex) {
+                  String exceptionMessage = "Bpmn error encountered in DoCreateVfModule flow. createNetworkPoliciesInAAI() - " + ex.getMessage()
+                  logDebug(exceptionMessage, isDebugLogEnabled)
+                  exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+          }
+
+   }
+   
+   /**
+       * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
+       *
+       * @param execution The flow's execution instance.
+       */
+   public void prepUpdateAAIGenericVnf(Execution execution) {
+          def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
+                  'execution=' + execution.getId() +
+                  ')'
+          def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+          logDebug('Entered ' + method, isDebugLogEnabled)
+
+          try {
+                  def rollbackData = execution.getVariable("RollbackData")
+                  def vnfId = execution.getVariable('DCVFM_vnfId')
+                  def oamManagementV4Address = execution.getVariable("DCVFM_oamManagementV4Address")
+                  def oamManagementV6Address = execution.getVariable("DCVFM_oamManagementV6Address")
+                  def ipv4OamAddressElement = ''
+                  def managementV6AddressElement = ''
+                  
+                  if (oamManagementV4Address != null && !oamManagementV4Address.isEmpty()) {
+                          ipv4OamAddressElement = '<ipv4-oam-address>' + oamManagementV4Address + '</ipv4-oam-address>'                          
+                  }
+                  
+                  if (oamManagementV6Address != null && !oamManagementV6Address.isEmpty()) {
+                          managementV6AddressElement = '<management-v6-address>' + oamManagementV6Address + '</management-v6-address>'
+                  }
+                  
+                  rollbackData.put("VFMODULE", "oamManagementV4Address", oamManagementV4Address)
+                  
+                          
+                  String updateAAIGenericVnfRequest = """
+                                       <UpdateAAIGenericVnfRequest>
+                                               <vnf-id>${vnfId}</vnf-id>
+                                               ${ipv4OamAddressElement}
+                                               ${managementV6AddressElement}
+                                       </UpdateAAIGenericVnfRequest>
+                               """
+                          updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
+                          execution.setVariable('DCVM_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
+                          utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
+                          logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
+               
+
+                  logDebug('Exited ' + method, isDebugLogEnabled)
+          } catch (BpmnError e) {
+                  throw e;
+          } catch (Exception e) {
+                  logError('Caught exception in ' + method, e)
+                  createWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
+          }
+   }
+   
+   /**
+       * Post process a result from invoking the UpdateAAIGenericVnf subflow.
+       *
+       * @param execution The flow's execution instance.
+       */
+   public void postProcessUpdateAAIGenericVnf(Execution execution) {
+          def method = getClass().getSimpleName() + '.postProcessUpdateAAIGenericVnf(' +
+                  'execution=' + execution.getId() +
+                  ')'
+          def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+          logDebug('Entered ' + method, isDebugLogEnabled)
+
+          try {
+                  def rollbackData = execution.getVariable("RollbackData")
+                  
+                  rollbackData.put("VFMODULE", "rollbackUpdateVnfAAI", "true")
+                  
+                  def vnfId = execution.getVariable('DCVFM_vnfId')
+                  def oamManagementV4Address = execution.getVariable("DCVFM_oamManagementV4Address")
+                  def oamManagementV6Address = execution.getVariable("DCVFM_oamManagementV6Address")
+                  def ipv4OamAddressElement = ''
+                  def managementV6AddressElement = ''
+                  
+                  if (oamManagementV4Address != null && !oamManagementV4Address.isEmpty()) {                      
+                          rollbackData.put("VFMODULE", "oamManagementV4Address", oamManagementV4Address)
+                  }
+                  
+                  if (oamManagementV6Address != null && !oamManagementV6Address.isEmpty()) {
+                          rollbackData.put("VFMODULE", "oamManagementV6Address", oamManagementV6Address)                          
+                  }
+                  
+                  execution.setVariable("RollbackData", rollbackData)             
+                       
+                  logDebug('Exited ' + method, isDebugLogEnabled)
+          } catch (BpmnError e) {
+                  throw e;
+          } catch (Exception e) {
+                  logError('Caught exception in ' + method, e)
+                  createWorkflowException(execution, 1002, 'Error in postProcessUpdateAAIGenericVnf(): ' + e.getMessage())
+          }
+   }
+}