Merge "Merge 'origin/casablanca' into master"
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateVfModule.groovy
index e32d6a8..53e3525 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
 package org.onap.so.bpmn.infrastructure.scripts
 
+import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
+import org.onap.so.client.HttpClientFactory
+
+import javax.ws.rs.core.MediaType
+import javax.ws.rs.core.Response
 import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.DocumentBuilderFactory
 
@@ -27,6 +32,8 @@ import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.json.JSONArray
 import org.json.JSONObject
+import org.onap.aai.domain.yang.GenericVnf
+import org.onap.aai.domain.yang.NetworkPolicy
 import org.onap.so.bpmn.common.scripts.AaiUtil
 import org.onap.so.bpmn.common.scripts.CatalogDbUtils
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
@@ -34,24 +41,28 @@ import org.onap.so.bpmn.common.scripts.MsoUtils
 import org.onap.so.bpmn.common.scripts.NetworkUtils
 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
 import org.onap.so.bpmn.common.scripts.VfModuleBase
+import org.onap.so.bpmn.common.util.OofInfraUtils
 import org.onap.so.bpmn.core.RollbackData
 import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.WorkflowException
-
 import org.onap.so.bpmn.core.domain.VnfResource
 import org.onap.so.bpmn.core.json.DecomposeJsonUtil
 import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.client.HttpClient
+import org.onap.so.client.aai.AAIObjectPlurals
 import org.onap.so.client.aai.AAIObjectType;
 import org.onap.so.client.aai.AAIResourcesClient
 import org.onap.so.client.aai.entities.AAIResultWrapper
+import org.onap.so.client.aai.entities.uri.AAIResourceUri
 import org.onap.so.client.aai.entities.uri.AAIUri
 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.client.graphinventory.entities.uri.Depth
+import org.onap.so.constants.Defaults
+import org.onap.so.db.catalog.beans.HomingInstance
 import org.onap.so.logger.MessageEnum
 import org.onap.so.logger.MsoLogger
-import org.onap.so.rest.APIResponse
-import org.onap.so.rest.RESTClient
-import org.onap.so.rest.RESTConfig
-import org.springframework.web.util.UriUtils
+
+import org.onap.so.utils.TargetEntity
 import org.w3c.dom.Document
 import org.w3c.dom.Element
 import org.w3c.dom.NamedNodeMap
@@ -65,13 +76,15 @@ import com.fasterxml.jackson.databind.ObjectMapper
 
 public class DoCreateVfModule extends VfModuleBase {
        private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVfModule.class);
-       
+
        String Prefix="DCVFM_"
        ExceptionUtil exceptionUtil = new ExceptionUtil()
        JsonUtils jsonUtil = new JsonUtils()
        SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
-       CatalogDbUtils catalog = new CatalogDbUtils()
+       OofInfraUtils oofInfraUtils = new OofInfraUtils()
+       CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
        DecomposeJsonUtil decomposeJsonUtils = new DecomposeJsonUtil()
+       private final HttpClientFactory httpClientFactory = new HttpClientFactory()
 
        /**
         * Validates the request message and sets up the workflow.
@@ -81,7 +94,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.preProcessRequest(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
 
                execution.setVariable('prefix', Prefix)
@@ -100,13 +113,13 @@ public class DoCreateVfModule extends VfModuleBase {
                        if (request == null || request.isEmpty()) {
                                // Building Block-type request
 
-                               String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")           
-                               
+                               String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
+
                                def serviceModelInfo = execution.getVariable("serviceModelInfo")
                                msoLogger.debug("serviceModelInfo: " + serviceModelInfo)
                                String modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
                                msoLogger.debug("modelInvariantUuid: " + modelInvariantUuid)
-                               
+
                                def vnfModelInfo = execution.getVariable("vnfModelInfo")
 
                                //tenantId
@@ -124,6 +137,11 @@ public class DoCreateVfModule extends VfModuleBase {
                                execution.setVariable("DCVFM_cloudSiteId", cloudSiteId)
                                rollbackData.put("VFMODULE", "aiccloudregion", cloudSiteId)
                                msoLogger.debug("cloudSiteId: " + cloudSiteId)
+                               //cloudOwner
+                               def cloudOwner = execution.getVariable("cloudOwner")
+                               execution.setVariable("DCVFM_cloudOwner", cloudOwner)
+                               rollbackData.put("VFMODULE", "cloudOwner", cloudOwner)
+                               msoLogger.debug("cloudOwner: " + cloudOwner)
                                //vnfType
                                def vnfType = execution.getVariable("vnfType")
                                execution.setVariable("DCVFM_vnfType", vnfType)
@@ -173,12 +191,6 @@ public class DoCreateVfModule extends VfModuleBase {
                                execution.setVariable("DCVFM_serviceInstanceId", serviceInstanceId)
                                rollbackData.put("VFMODULE", "serviceInstanceId", serviceInstanceId)
                                msoLogger.debug("serviceInstanceId: " + serviceInstanceId)
-                               //OofDirectives
-                               String oofDirectives = execution.getVariable(cloudSiteId + "_oofDirectives")
-                               if (flavorList != null) {
-                                       execution.setVariable("DCVFM_flavorList", flavorList)
-                                       logDebug("flavorList is: " + flavorList, isDebugLogEnabled)
-                               }
                                //source - HARDCODED
                                def source = "VID"
                                execution.setVariable("DCVFM_source", source)
@@ -201,7 +213,7 @@ public class DoCreateVfModule extends VfModuleBase {
                                execution.setVariable("DCVFM_asdcServiceModelVersion", asdcServiceModelVersion)
                                msoLogger.debug("asdcServiceModelVersion: " + asdcServiceModelVersion)
                                //personaModelId
-                               execution.setVariable("DCVFM_personaModelId", jsonUtil.getJsonValue(vfModuleModelInfo, "modelInvariantUuid"))                   
+                               execution.setVariable("DCVFM_personaModelId", jsonUtil.getJsonValue(vfModuleModelInfo, "modelInvariantUuid"))
                                //personaModelVersion
                                execution.setVariable("DCVFM_personaModelVersion", jsonUtil.getJsonValue(vfModuleModelInfo, "modelUuid"))
                                //vfModuleLabel
@@ -227,8 +239,39 @@ public class DoCreateVfModule extends VfModuleBase {
                                //globalSubscriberId
                                String globalSubscriberId = execution.getVariable("globalSubscriberId")
                                execution.setVariable("DCVFM_globalSubscriberId", globalSubscriberId)
-                               msoLogger.debug("globalSubsrciberId: " + globalSubscriberId)                            
+                               msoLogger.debug("globalSubsrciberId: " + globalSubscriberId)
+
+                               // Set Homing Info
+                               String oofDirectives = null
+                               try {
+                                       HomingInstance homingInstance = oofInfraUtils.getHomingInstance(serviceInstanceId, execution)
+                                       if (homingInstance != null) {
+                                               execution.setVariable("DCVFM_cloudSiteId", homingInstance.getCloudRegionId())
+                                               rollbackData.put("VFMODULE", "aiccloudregion", homingInstance.getCloudRegionId())
+                                               msoLogger.debug("Overwriting cloudSiteId with homing cloudSiteId: " +
+                                                               homingInstance.getCloudRegionId())
+                                               execution.setVariable("DCVFM_cloudOwner", homingInstance.getCloudOwner())
+                                               rollbackData.put("VFMODULE", "cloudOwner", homingInstance.getCloudOwner())
+                                               msoLogger.debug("Overwriting cloudOwner with homing cloudOwner: " +
+                                                               homingInstance.getCloudOwner())
+                                               oofDirectives = homingInstance.getOofDirectives()
+                                               execution.setVariable("DCVFM_oofDirectives", oofDirectives)
+                                       }
+                               } catch (Exception exception) {
+                                       msoLogger.debug("Could not find homing information for service instance: " + serviceInstanceId +
+                                                       "... continuing")
+                                       msoLogger.debug("Could not find homing information for service instance error: " + exception)
+                               }
+                               //OofDirectives to Input Params
                                Map<String,String> vfModuleInputParams = execution.getVariable("vfModuleInputParams")
+                               if (oofDirectives != null && vfModuleInputParams != null) {
+                                       vfModuleInputParams.put("oof_directives", oofDirectives)
+                                       vfModuleInputParams.put("sdnc_directives", "{}")
+                                       msoLogger.debug("OofDirectives are: " + oofDirectives)
+                               } else if (vfModuleInputParams != null) {
+                                       vfModuleInputParams.put("oof_directives", "{}")
+                                       vfModuleInputParams.put("sdnc_directives", "{}")
+                               }
                                if (vfModuleInputParams != null) {
                                        execution.setVariable("DCVFM_vnfParamsMap", vfModuleInputParams)
                                        execution.setVariable("DCVFM_vnfParamsExistFlag", true)
@@ -238,17 +281,17 @@ public class DoCreateVfModule extends VfModuleBase {
                                execution.setVariable("DCVFM_usePreload", usePreload)
                                msoLogger.debug("usePreload: " + usePreload)
                                //aLaCarte
-                               def aLaCarte = execution.getVariable("aLaCarte")                                
+                               def aLaCarte = execution.getVariable("aLaCarte")
                                execution.setVariable("DCVFM_aLaCarte", aLaCarte)
                                msoLogger.debug("aLaCarte: " + aLaCarte)
-                               
+
                                //get workload and environment context from parent SI
                                String environmentContext = ""
                                String workloadContext =""
                                String serviceType =""
-                               
+
                                try{
-                                       String json = catalog.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
+                                       String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
                                        serviceType = jsonUtil.getJsonValue(json, "serviceResources.serviceType")
                                }catch(BpmnError e){
                                        throw e
@@ -257,7 +300,7 @@ public class DoCreateVfModule extends VfModuleBase {
                                        msoLogger.debug(msg)
                                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                                }
-                               
+
                                try{
                                        AAIUri serviceInstanceURI = AAIUriFactory.create(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId,serviceType,serviceInstanceId)
                                        AAIResourcesClient aaiRC = new AAIResourcesClient()
@@ -265,14 +308,14 @@ public class DoCreateVfModule extends VfModuleBase {
                                        Map<String, Object> aaiJson = aaiRW.asMap()
                                        environmentContext = aaiJson.getOrDefault("environment-context","")
                                        workloadContext = aaiJson.getOrDefault("workload-context","")
-                                       
+
                                }catch (Exception ex) {
                                        msoLogger.debug("Error retreiving parent service instance information")
                                }
-                               
+
                                execution.setVariable("DCVFM_environmentContext",environmentContext)
                                execution.setVariable("DCVFM_workloadContext",workloadContext)
-                                                                                         
+
                        }
                        else {
                                // The info is inside the request - DEAD CODE
@@ -400,7 +443,7 @@ public class DoCreateVfModule extends VfModuleBase {
                                        isBaseVfModule = utils.getNodeText(request, "is-base-vf-module")
                                }
                                execution.setVariable("DCVFM_isBaseVfModule", isBaseVfModule)
-                               msoLogger.debug("isBaseVfModule: " + isBaseVfModule)                            
+                               msoLogger.debug("isBaseVfModule: " + isBaseVfModule)
                                //asdcServiceModelVersion
                                def asdcServiceModelVersion = ""
                                if (utils.nodeExists(request, "asdc-service-model-version")) {
@@ -452,8 +495,37 @@ public class DoCreateVfModule extends VfModuleBase {
                                                                }
                                                                execution.setVariable("DCVFM_vnfParamsMap", paramsMap)
                                                        }
+
+                               //OofDirectives
+                               String oofDirectives = null
+                               try {
+                                       HomingInstance homingInstance = oofInfraUtils.getHomingInstance(serviceInstanceId, execution)
+                                       if (homingInstance != null) {
+                                               execution.setVariable("DCVFM_cloudSiteId", homingInstance.getCloudRegionId())
+                                               rollbackData.put("VFMODULE", "aiccloudregion", homingInstance.getCloudRegionId())
+                                               msoLogger.debug("Overwriting cloudSiteId with homing cloudSiteId: " +
+                                                               homingInstance.getCloudRegionId())
+                                               execution.setVariable("DCVFM_cloudOwner", homingInstance.getCloudOwner())
+                                               rollbackData.put("VFMODULE", "cloudOwner", homingInstance.getCloudOwner())
+                                               msoLogger.debug("Overwriting cloudOwner with homing cloudOwner: " +
+                                                               homingInstance.getCloudOwner())
+                                               oofDirectives = homingInstance.getOofDirectives()
+                                               execution.setVariable("DCVFM_oofDirectives", oofDirectives)
+                                       }
+                               } catch (Exception exception) {
+                                       msoLogger.debug("Could not find homing information for service instance: " + serviceInstanceId +
+                                                       "... continuing")
+                                       msoLogger.debug("Could not find homing information for service instance error: " + exception)
+                               }
+                               if (oofDirectives != null) {
+                                       Map<String, String> paramsMap = execution.getVariable("DCVFM_vnfParamsMap")
+                                       paramsMap.put("oofDirectives", oofDirectives)
+                                       msoLogger.debug("OofDirectives are: " + oofDirectives)
+                                       execution.setVariable("DCVFM_vnfParamsMap", paramsMap)
+                               }
                        }
 
+
                        //Get or Generate UUID
                        String uuid = execution.getVariable("DCVFM_uuid")
                        if(uuid == null){
@@ -469,7 +541,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        }
                        msoLogger.debug("sdncVersion: " + sdncVersion)
                        execution.setVariable("DCVFM_sdncVersion", sdncVersion)
-                       
+
                        execution.setVariable("DCVFM_uuid", uuid)
                        execution.setVariable("DCVFM_baseVfModuleId", "")
                        execution.setVariable("DCVFM_baseVfModuleHeatStackId", "")
@@ -534,7 +606,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.sendResponse(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
 
                try {
@@ -544,7 +616,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        throw e;
                } catch (Exception e) {
                        msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
-                       
+
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Internal Error')
                }
        }
@@ -560,7 +632,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.getVfModule(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
 
                try {
@@ -604,7 +676,7 @@ public class DoCreateVfModule extends VfModuleBase {
         * @param execution The flow's execution instance.
         */
        public void queryAAIVfModule(DelegateExecution execution) {
-               
+
                def method = getClass().getSimpleName() + '.getVfModule(' +
                        'execution=' + execution.getId() +
                        ')'
@@ -615,34 +687,30 @@ public class DoCreateVfModule extends VfModuleBase {
                        def vfModuleId = execution.getVariable('DCVFM_vfModuleId')
 
                        AaiUtil aaiUriUtil = new AaiUtil(this)
-                       String  aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
-                       msoLogger.debug('AAI URI is: ' + aai_uri)
-
-                       String endPoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
+                       AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
+                       String endPoint = aaiUriUtil.createAaiUri(uri)
 
                        try {
-                               RESTConfig config = new RESTConfig(endPoint);
-                               def responseData = ''
-                               def aaiRequestId = UUID.randomUUID().toString()
-                               RESTClient client = new RESTClient(config).
-                                       addHeader('X-TransactionId', aaiRequestId).
-                                       addHeader('X-FromAppId', 'MSO').
-                                       addHeader('Content-Type', 'application/xml').
-                                       addHeader('Accept','application/xml');
+                               HttpClient client = httpClientFactory.newXmlClient(new URL(endPoint), TargetEntity.AAI)
+                               client.addAdditionalHeader('X-TransactionId', UUID.randomUUID().toString())
+                               client.addAdditionalHeader('X-FromAppId', 'MSO')
+                               client.addAdditionalHeader('Content-Type', MediaType.APPLICATION_XML)
+                               client.addAdditionalHeader('Accept', MediaType.APPLICATION_XML)
+
                                msoLogger.debug('sending GET to AAI endpoint \'' + endPoint + '\'')
-                               APIResponse response = client.httpGet()
+                               Response response = client.get()
 
-                               responseData = response.getResponseBodyAsString()
+                               String responseData = response.readEntity(String.class)
                                if (responseData != null) {
                                        msoLogger.debug("Received generic VNF data: " + responseData)
 
                                }
 
-                               execution.setVariable('DCVFM_queryAAIVfModuleResponseCode', response.getStatusCode())
+                               execution.setVariable('DCVFM_queryAAIVfModuleResponseCode', response.getStatus())
                                execution.setVariable('DCVFM_queryAAIVfModuleResponse', responseData)
-                               msoLogger.debug('Response code:' + response.getStatusCode())
+                               msoLogger.debug('Response code:' + response.getStatus())
                                msoLogger.debug('Response:' + System.lineSeparator() + responseData)
-                               if (response.getStatusCode() == 200) {
+                               if (response.getStatus() == 200) {
                                        // Parse the VNF record from A&AI to find base module info
                                        msoLogger.debug('Parsing the VNF data to find base module info')
                                        if (responseData != null) {
@@ -678,23 +746,23 @@ public class DoCreateVfModule extends VfModuleBase {
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())
                }
        }
-       
+
        /**
-        * Using the vnfId and vfModuleName provided in the inputs, 
+        * Using the vnfId and vfModuleName provided in the inputs,
         * query AAI to get the corresponding VF Module info.
-        * A 200 response is expected with the VF Module info in the response body, 
-        * or a 404 response if the module does not exist yet. Will determine VF Module's 
+        * A 200 response is expected with the VF Module info in the response body,
+        * or a 404 response if the module does not exist yet. Will determine VF Module's
         * orchestration status if one exists
         *
         * @param execution The flow's execution instance.
         */
        public void queryAAIVfModuleForStatus(DelegateExecution execution) {
-               
+
                def method = getClass().getSimpleName() + '.queryAAIVfModuleForStatus(' +
                        'execution=' + execution.getId() +
                        ')'
                msoLogger.trace('Entered ' + method)
-               
+
                execution.setVariable('DCVFM_orchestrationStatus', '')
 
                try {
@@ -702,38 +770,34 @@ public class DoCreateVfModule extends VfModuleBase {
                        def vfModuleName = execution.getVariable('DCVFM_vfModuleName')
 
                        AaiUtil aaiUriUtil = new AaiUtil(this)
-                       String  aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
-                       msoLogger.debug('AAI URI is: ' + aai_uri)
+                       AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, vnfId).queryParam("vf-module-name",vfModuleName)
+                       String endPoint = aaiUriUtil.createAaiUri(uri)
 
-                       String endPoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") +
-                                       "/vf-modules/vf-module?vf-module-name=" + UriUtils.encode(vfModuleName, "UTF-8")
-                       msoLogger.debug("AAI endPoint: " + endPoint)
+                       HttpClient client = httpClientFactory.newXmlClient(new URL(endPoint), TargetEntity.AAI)
+                       client.addAdditionalHeader('X-TransactionId', UUID.randomUUID().toString())
+                       client.addAdditionalHeader('X-FromAppId', 'MSO')
+                       client.addAdditionalHeader('Content-Type', MediaType.APPLICATION_XML)
+                       client.addAdditionalHeader('Accept', MediaType.APPLICATION_XML)
 
                        try {
-                               RESTConfig config = new RESTConfig(endPoint);
                                def responseData = ''
-                               def aaiRequestId = UUID.randomUUID().toString()
-                               RESTClient client = new RESTClient(config).
-                                       addHeader('X-TransactionId', aaiRequestId).
-                                       addHeader('X-FromAppId', 'MSO').
-                                       addHeader('Content-Type', 'application/xml').
-                                       addHeader('Accept','application/xml');
+
                                msoLogger.debug('sending GET to AAI endpoint \'' + endPoint + '\'')
-                               APIResponse response = client.httpGet()
+                               Response response = client.get()
                                msoLogger.debug("createVfModule - invoking httpGet() to AAI")
 
-                               responseData = response.getResponseBodyAsString()
+                               responseData = response.readEntity(String.class)
                                if (responseData != null) {
                                        msoLogger.debug("Received generic VNF data: " + responseData)
 
                                }
 
-                               execution.setVariable('DCVFM_queryAAIVfModuleForStatusResponseCode', response.getStatusCode())
+                               execution.setVariable('DCVFM_queryAAIVfModuleForStatusResponseCode', response.getStatus())
                                execution.setVariable('DCVFM_queryAAIVfModuleForStatusResponse', responseData)
-                               msoLogger.debug('Response code:' + response.getStatusCode())
+                               msoLogger.debug('Response code:' + response.getStatus())
                                msoLogger.debug('Response:' + System.lineSeparator() + responseData)
                                // Retrieve VF Module info and its orchestration status; if not found, do nothing
-                               if (response.getStatusCode() == 200) {
+                               if (response.getStatus() == 200) {
                                        // Parse the VNF record from A&AI to find base module info
                                        msoLogger.debug('Parsing the VNF data to find orchestration status')
                                        if (responseData != null) {
@@ -745,7 +809,7 @@ public class DoCreateVfModule extends VfModuleBase {
                                                def vfModuleId = utils.getNodeText(vfModuleText, "vf-module-id")
                                                execution.setVariable("DCVFM_vfModuleId", vfModuleId)
                                                msoLogger.debug("Received orchestration status from A&AI: " + orchestrationStatus)
-                                               
+
                                        }
                                }
                        } catch (Exception ex) {
@@ -764,7 +828,7 @@ public class DoCreateVfModule extends VfModuleBase {
 
 
        public void preProcessSDNCAssignRequest(DelegateExecution execution){
-               
+
                execution.setVariable("prefix", Prefix)
                msoLogger.trace("STARTED preProcessSDNCAssignRequest")
                def vnfId = execution.getVariable("DCVFM_vnfId")
@@ -791,30 +855,30 @@ public class DoCreateVfModule extends VfModuleBase {
                        msoLogger.debug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
 
                }catch(Exception e){
-                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, " Exception Occurred Processing preProcessSDNCAssignRequest", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);                      
+                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, " Exception Occurred Processing preProcessSDNCAssignRequest", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareProvision Method:\n" + e.getMessage())
                }
                msoLogger.trace("COMPLETED preProcessSDNCAssignRequest")
        }
 
        public void preProcessSDNCGetRequest(DelegateExecution execution, String element){
-               
+
                String sdncVersion = execution.getVariable("DCVFM_sdncVersion")
                execution.setVariable("prefix", Prefix)
                msoLogger.trace("STARTED preProcessSDNCGetRequest Process")
                try{
                        def serviceInstanceId = execution.getVariable('DCVFM_serviceInstanceId')
-                       
+
                        String uuid = execution.getVariable('testReqId') // for junits
                        if(uuid==null){
                                uuid = execution.getVariable("mso-request-id") + "-" +  System.currentTimeMillis()
                        }
-                                       
+
                        def callbackUrl = execution.getVariable("DCVFM_sdncCallbackUrl")
                        msoLogger.debug("callbackUrl:" + callbackUrl)
-                       
+
                        def vfModuleId = execution.getVariable('DCVFM_vfModuleId')
-                       
+
                        def svcInstId = ""
                        if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
                                svcInstId = vfModuleId
@@ -822,7 +886,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        else {
                                svcInstId = serviceInstanceId
                        }
-                       
+
                        def msoAction = ""
                        if (!sdncVersion.equals("1707")) {
                                msoAction = "mobility"
@@ -830,33 +894,36 @@ public class DoCreateVfModule extends VfModuleBase {
                        else {
                                msoAction = "vfmodule"
                        }
-                       // For VNF, serviceOperation (URI for topology GET) will be retrieved from "selflink" element 
-                       // in the response from GenericGetVnf
+                       // For VNF, serviceOperation (URI for topology GET) will be retrieved from "selflink" element
                        // For VF Module, in 1707 serviceOperation will be retrieved from "object-path" element
                        // in SDNC Assign Response
                        // For VF Module for older versions, serviceOperation is constructed using vfModuleId
-                       
+
                        String serviceOperation = ""
                        if (element.equals("vnf")) {
-                               def vnfQueryResponse = execution.getVariable("DCVFM_vnfQueryResponse")
-                               serviceOperation = utils.getNodeText(vnfQueryResponse, "selflink")
+                               AAIResourcesClient resourceClient = new AAIResourcesClient()
+                               AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, execution.getVariable('DCVFM_vnfId'))
+                               AAIResultWrapper wrapper = resourceClient.get(uri)
+
+                               Optional<GenericVnf> vnf = wrapper.asBean(GenericVnf.class)
+                               serviceOperation = vnf.get().getSelflink()
                                msoLogger.debug("VNF - service operation: " + serviceOperation)
                        }
                        else if (element.equals("vfmodule")) {
                                String response = execution.getVariable("DCVFM_assignSDNCAdapterResponse")
-                               msoLogger.debug("DCVFM_assignSDNCAdapterResponse is: \n" + response)                                                    
-                       
+                               msoLogger.debug("DCVFM_assignSDNCAdapterResponse is: \n" + response)
+
                                if (!sdncVersion.equals("1707")) {
                                        serviceOperation = "/VNF-API:vnfs/vnf-list/" + vfModuleId
                                        msoLogger.debug("VF Module with sdncVersion before 1707 - service operation: " + serviceOperation)
                                }
-                               else {                          
-                                       String data = utils.getNodeXml(response, "response-data")                                       
+                               else {
+                                       String data = utils.getNodeXml(response, "response-data")
                                        msoLogger.debug("responseData: " + data)
                                        serviceOperation = utils.getNodeText(data, "object-path")
                                        msoLogger.debug("VF Module with sdncVersion of 1707 - service operation: " + serviceOperation)
-                               }                               
-                       }               
+                               }
+                       }
 
                        //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
                        sleep(5000)
@@ -880,7 +947,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        msoLogger.debug("Outgoing GetSDNCRequest is: \n" + SDNCGetRequest)
 
                }catch(Exception e){
-                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);                  
+                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
                }
                msoLogger.trace("COMPLETED preProcessSDNCGetRequest Process")
@@ -891,7 +958,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.VNFAdapterCreateVfModule(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
 
                //def xml = execution.getVariable("DoCreateVfModuleRequest")
@@ -922,8 +989,6 @@ public class DoCreateVfModule extends VfModuleBase {
                def serviceId = execution.getVariable("DCVFM_serviceId")
                //serviceInstanceId
                def serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId")
-               //OofDirectives
-               String oofDirectives = execution.getVariable("DCVFM_oofDirectives")
                //backoutOnFailure
                def backoutOnFailure = execution.getVariable("DCVFM_backoutOnFailure")
                //volumeGroupId
@@ -944,7 +1009,7 @@ public class DoCreateVfModule extends VfModuleBase {
                String workloadContext = execution.getVariable("DCVFM_workloadContext")
                msoLogger.debug("workloadContext: " + workloadContext)
                msoLogger.debug("environmentContext: " + environmentContext)
-               
+
                def messageId = execution.getVariable('mso-request-id') + '-' +
                                 System.currentTimeMillis()
 
@@ -959,18 +1024,14 @@ public class DoCreateVfModule extends VfModuleBase {
                }
 
                Map<String, String> vnfParamsMap = execution.getVariable("DCVFM_vnfParamsMap")
-               // Add flavorLabel List to vnfParamsMap
-               flavorList.each { cloudFlavor ->
-                       vnfParamsMap.put("label_" + cloudFlavor.getFlavorLabel(), cloudFlavor.getFlavor())
-               }
                String vfModuleParams = ""
                //Get SDNC Response Data for VF Module Topology
                String vfModuleSdncGetResponse = execution.getVariable('DCVFM_getSDNCAdapterResponse')
                msoLogger.debug("sdncGetResponse: " + vfModuleSdncGetResponse)
                def sdncVersion = execution.getVariable("sdncVersion")
-               
+
                if (!sdncVersion.equals("1707")) {
-                                               
+
                        vfModuleParams = buildVfModuleParams(vnfParamsMap, vfModuleSdncGetResponse, vnfId, vnfName,
                                vfModuleId, vfModuleName, vfModuleIndex, environmentContext, workloadContext)
                }
@@ -978,9 +1039,9 @@ public class DoCreateVfModule extends VfModuleBase {
                        //Get SDNC Response Data for Vnf Topology
                        String vnfSdncGetResponse = execution.getVariable('DCVFM_getVnfSDNCAdapterResponse')
                        msoLogger.debug("vnfSdncGetResponse: " + vnfSdncGetResponse)
-                       
+
                        vfModuleParams = buildVfModuleParamsFromCombinedTopologies(vnfParamsMap, vnfSdncGetResponse, vfModuleSdncGetResponse, vnfId, vnfName,
-                               vfModuleId, vfModuleName, vfModuleIndex, environmentContext, workloadContext)                   
+                               vfModuleId, vfModuleName, vfModuleIndex, environmentContext, workloadContext)
                }
 
                def svcInstId = ""
@@ -991,7 +1052,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        svcInstId = serviceInstanceId
                }
 
-               def createVnfARequest = """
+               String createVnfARequest = """
                <createVfModuleRequest>
                <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
                <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
@@ -1037,7 +1098,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.validateInfraRequest(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
 
                String processKey = getProcessKey(execution);
@@ -1099,7 +1160,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.isVolumeGroupIdPresent(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
 
                def request = execution.getVariable('DoCreateVfModuleRequest')
@@ -1120,7 +1181,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.isVolumeGroupNamePresent(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
 
                def request = execution.getVariable('DoCreateVfModuleRequest')
@@ -1183,9 +1244,9 @@ public class DoCreateVfModule extends VfModuleBase {
                }else{
                        sdncVNFParamsXml = ""
                }
-               
+
                String sdncRequest = ""
-               
+
                if (!sdncVersion.equals("1707")) {
 
                        sdncRequest =
@@ -1227,10 +1288,10 @@ public class DoCreateVfModule extends VfModuleBase {
                </vnf-request-information>
        </sdncadapterworkflow:SDNCRequestData>
        </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
-               
+
                }
-               else {  
-                       
+               else {
+
                        sdncRequest =
                        """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
                                                                                                        xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
@@ -1255,28 +1316,28 @@ public class DoCreateVfModule extends VfModuleBase {
                        <subscription-service-type>${MsoUtils.xmlEscape(serviceId)}</subscription-service-type>
                        ${serviceEcompModelInformation}
                        <service-instance-id>${MsoUtils.xmlEscape(svcInstId)}</service-instance-id>
-                       <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>                      
-               </service-information>          
+                       <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
+               </service-information>
                <vnf-information>
                        <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
                        <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
-                       ${vnfEcompModelInformation}                     
+                       ${vnfEcompModelInformation}
                </vnf-information>
                <vf-module-information>
                        <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
                        <vf-module-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vf-module-type>
-                       ${vfModuleEcompModelInformation}                        
+                       ${vfModuleEcompModelInformation}
                </vf-module-information>
-               <vf-module-request-input>                       
+               <vf-module-request-input>
                        <vf-module-name>${MsoUtils.xmlEscape(vfModuleName)}</vf-module-name>
                        <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
-                       <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>                 
+                       <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
                ${sdncVNFParamsXml}
                </vf-module-request-input>
          </sdncadapterworkflow:SDNCRequestData>
        </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
-                       
-                       
+
+
                        /*
                        sdncRequest =
                        """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
@@ -1299,30 +1360,30 @@ public class DoCreateVfModule extends VfModuleBase {
                <service-information>
                        <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
                        <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
-                       ${serviceEcompModelInformation}                 
+                       ${serviceEcompModelInformation}
                        <service-instance-id>${MsoUtils.xmlEscape(svcInstId)}</service-instance-id>
                        <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
                </service-information>
                <vnf-information>
                        <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
                        <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
-                       ${vnfEcompModelInformation}                     
+                       ${vnfEcompModelInformation}
                </vnf-information>
                <vf-module-information>
                        <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
                        <vf-module-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vf-module-type>
-                       ${vfModuleEcompModelInformation}                        
+                       ${vfModuleEcompModelInformation}
                </vf-module-information>
-               <vf-module-request-input>                       
+               <vf-module-request-input>
                        <vf-module-name>${MsoUtils.xmlEscape(vfModuleName)}</vf-module-name>
                        <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
-                       <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>                         
+                       <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
                ${sdncVNFParamsXml}
-               </vf-module-request-input>              
+               </vf-module-request-input>
        </sdncadapterworkflow:SDNCRequestData>
        </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
                        */
-                       
+
                }
 
        msoLogger.debug("sdncRequest:  " + sdncRequest)
@@ -1334,7 +1395,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
                execution.setVariable("prefix", Prefix)
                msoLogger.trace("STARTED preProcessSDNCActivateRequest Process")
@@ -1366,7 +1427,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
                execution.setVariable("prefix",Prefix)
                try{
@@ -1454,7 +1515,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.preProcessUpdateAAIVfModuleRequestOrch(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
                execution.setVariable("prefix", Prefix)
                msoLogger.trace("STARTED preProcessUpdateAAIVfModuleRequestOrch")
@@ -1467,7 +1528,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        if (!contrailServiceInstanceFqdn.equals("")) {
                                setContrailServiceInstanceFqdn = true
                        }
-                       
+
                        execution.setVariable("DCVFM_orchestrationStatus", "Created")
 
                        String updateAAIVfModuleRequest = buildUpdateAAIVfModuleRequest(execution, false, true, true, setContrailServiceInstanceFqdn)
@@ -1477,18 +1538,18 @@ public class DoCreateVfModule extends VfModuleBase {
                        msoLogger.debug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest)
 
                }catch(Exception e){
-                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessUpdateAAIVfModuleRequestOrch", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);                     
+                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessUpdateAAIVfModuleRequestOrch", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestOrch Method:\n" + e.getMessage())
                }
                msoLogger.trace("COMPLETED preProcessUpdateAAIVfModuleRequestOrch")
 
        }
-       
+
        public void preProcessUpdateAAIVfModuleRequestStatus(DelegateExecution execution, String status) {
                def method = getClass().getSimpleName() + '.preProcessUpdateAAIVfModuleStatus(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
                execution.setVariable("prefix", Prefix)
                msoLogger.trace("STARTED preProcessUpdateAAIVfModuleStatus")
@@ -1517,7 +1578,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.preProcessUpdateAAIVfModuleRequestGroup(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
                execution.setVariable("prefix", Prefix)
                msoLogger.trace("STARTED preProcessUpdateAAIVfModuleRequestGroup")
@@ -1533,7 +1594,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        msoLogger.debug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest)
 
                }catch(Exception e){
-                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessUpdateAAIVfModuleRequestGroup", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);                    
+                       msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessUpdateAAIVfModuleRequestGroup", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestGroup Method:\n" + e.getMessage())
                }
                msoLogger.trace("COMPLETED  preProcessUpdateAAIVfModuleRequestGroup")
@@ -1541,7 +1602,7 @@ public class DoCreateVfModule extends VfModuleBase {
        }
 
        public void validateSDNCResponse(DelegateExecution execution, String response, String method){
-               
+
                execution.setVariable("prefix",Prefix)
                msoLogger.debug("STARTED ValidateSDNCResponse Process")
 
@@ -1574,7 +1635,7 @@ public class DoCreateVfModule extends VfModuleBase {
        }
 
        public void preProcessUpdateAfterCreateRequest(DelegateExecution execution){
-               
+
                execution.setVariable("prefix", Prefix)
                msoLogger.trace("STARTED preProcessRequest Process")
                try{
@@ -1680,25 +1741,25 @@ public class DoCreateVfModule extends VfModuleBase {
                }
                return params
        }
-       
+
        public String buildCompleteSDNCParamsXml(DelegateExecution execution){
-               
+
                String params = ""
                StringBuilder sb = new StringBuilder()
                Map<String, String> paramsMap = execution.getVariable("DCVFM_vnfParamsMap")
-               
+
                for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
                        String paramsXml
-                       String key = entry.getKey();                                    
+                       String key = entry.getKey();
                        String value = entry.getValue()
-                       paramsXml =     """<${key}>$value</$key>"""     
+                       paramsXml =     """<${key}>$value</$key>"""
                        params = sb.append(paramsXml)
                }
                return params
        }
 
    public void queryCloudRegion (DelegateExecution execution) {
-               
+
                execution.setVariable("prefix", Prefix)
                msoLogger.trace("STARTED queryCloudRegion")
 
@@ -1706,13 +1767,12 @@ public class DoCreateVfModule extends VfModuleBase {
                        String cloudRegion = execution.getVariable("DCVFM_cloudSiteId")
 
                        // Prepare AA&I url
-                       String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
                        AaiUtil aaiUtil = new AaiUtil(this)
-                       String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
-                       String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
+
+                       AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, Defaults.CLOUD_OWNER.toString(), cloudRegion)
+                       def queryCloudRegionRequest = aaiUtil.createAaiUri(uri)
 
                        execution.setVariable("DCVFM_queryCloudRegionRequest", queryCloudRegionRequest)
-                       msoLogger.debug("DCVFM_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest)
 
                        cloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
 
@@ -1769,7 +1829,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def method = getClass().getSimpleName() + '.prepareCreateAAIVfModuleVolumeGroupRequest(' +
                        'execution=' + execution.getId() +
                        ')'
-               
+
                msoLogger.trace('Entered ' + method)
                execution.setVariable("prefix", Prefix)
                msoLogger.trace("STARTED prepareCreateAAIVfModuleVolumeGroupRequest")
@@ -1783,12 +1843,14 @@ public class DoCreateVfModule extends VfModuleBase {
                        def volumeGroupId = execution.getVariable("DCVFM_volumeGroupId")
                        //def aicCloudRegion = execution.getVariable("DCVFM_cloudSiteId")
                        def aicCloudRegion = execution.getVariable("DCVFM_cloudRegionForVolume")
+                       def cloudOwner = execution.getVariable("DCVFM_cloudOwner")
                        String createAAIVfModuleVolumeGroupRequest =
                        """<CreateAAIVfModuleVolumeGroupRequest>
                                <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
                                <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
                                <volume-group-id>${MsoUtils.xmlEscape(volumeGroupId)}</volume-group-id>
                                <aic-cloud-region>${MsoUtils.xmlEscape(aicCloudRegion)}</aic-cloud-region>
+                               <cloud-owner>${MsoUtils.xmlEscape(cloudOwner)}</cloud-owner>
                        </CreateAAIVfModuleVolumeGroupRequest>"""
 
                        createAAIVfModuleVolumeGroupRequest = utils.formatXml(createAAIVfModuleVolumeGroupRequest)
@@ -1807,7 +1869,7 @@ public class DoCreateVfModule extends VfModuleBase {
           def method = getClass().getSimpleName() + '.createNetworkPoliciesInAAI(' +
           'execution=' + execution.getId() +
           ')'
-          
+
           msoLogger.trace('Entered ' + method)
           execution.setVariable("prefix", Prefix)
           msoLogger.trace("STARTED createNetworkPoliciesInAAI")
@@ -1821,109 +1883,48 @@ public class DoCreateVfModule extends VfModuleBase {
                   execution.setVariable("DCVFM_networkPolicyFqdnCount", fqdnCount)
                   msoLogger.debug("DCVFM_networkPolicyFqdnCount - " + fqdnCount)
 
-                  String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
                   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")
-
-                                  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)
-                                  msoLogger.debug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
-
-                                  String aaiResponseAsString = response.getResponseBodyAsString()
-
-                                  if (isOneOf(returnCode, 200, 201)) {
-                                          msoLogger.debug("The return code is: "  + returnCode)
-                                          // This network policy FQDN already exists in AAI
-                                          execution.setVariable("DCVFM_queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
-                                          msoLogger.debug(" QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
-
-                                  } else {
-                                          if (returnCode == 404) {
-                                                  // This network policy FQDN is not in AAI yet. Add it now
-                                                  msoLogger.debug("The return code is: "  + returnCode)
-                                                  msoLogger.debug("This network policy FQDN is not in AAI yet: " + fqdn)
-                                                  // Add the network policy with this FQDN to AAI
-                                                  def networkPolicyId = UUID.randomUUID().toString()
-                                                  msoLogger.debug("Adding network-policy with network-policy-id " + networkPolicyId)
-
-                                                  String aaiNamespace = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
-                                                  msoLogger.debug('AAI namespace is: ' + aaiNamespace)
-                                                  String payload = """<network-policy xmlns="${aaiNamespace}">
-                                                               <network-policy-id>${MsoUtils.xmlEscape(networkPolicyId)}</network-policy-id>
-                                                               <network-policy-fqdn>${MsoUtils.xmlEscape(fqdn)}</network-policy-fqdn>
-                                                               <heat-stack-id>${MsoUtils.xmlEscape(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")
-                                                  msoLogger.debug("AAI request endpoint: " + addNetworkPolicyAAIRequest)
-
-                                                  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");
-                                                  msoLogger.debug("invoking PUT call to AAI with payload:"+System.lineSeparator()+payload)
-                                                  APIResponse responsePut = clientPut.httpPut(payload)
-                                                  int returnCodePut = responsePut.getStatusCode()
-                                                  execution.setVariable("DCVFM_aaiAddNetworkPolicyReturnCode", returnCodePut)
-                                                  msoLogger.debug(" ***** AAI add network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodePut)
-
-                                                  String aaiResponseAsStringPut = responsePut.getResponseBodyAsString()
-                                                  if (isOneOf(returnCodePut, 200, 201)) {
-                                                          msoLogger.debug("The return code from adding network policy is: "  + returnCodePut)
-                                                          // This network policy was created in AAI successfully
-                                                          execution.setVariable("DCVFM_addNetworkPolicyAAIResponse", aaiResponseAsStringPut)
-                                                          msoLogger.debug(" AddAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsStringPut)
-                                                          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
-                                                               msoLogger.debug(putErrorMessage)
-                                                               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
-                                                                  msoLogger.debug(dataErrorMessage)
-                                                                  exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
-
-                                                        }
-                                          }
-                                  }
 
-                          } // end loop
+                       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
+                                       AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
+                                       uri.queryParam("network-policy-fqdn", fqdn)
+
+                                       AAIResourcesClient resourceClient = new AAIResourcesClient()
+
+
+                                       if (resourceClient.exists(uri)) {
+
+                                               msoLogger.debug(" QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting)
+
+                                       } else {
+                                               // This network policy FQDN is not in AAI yet. Add it now
+                                               msoLogger.debug("This network policy FQDN is not in AAI yet: " + fqdn)
+                                               // Add the network policy with this FQDN to AAI
+                                               def networkPolicyId = UUID.randomUUID().toString()
+                                               msoLogger.debug("Adding network-policy with network-policy-id " + networkPolicyId)
+
+                                               NetworkPolicy policy = new NetworkPolicy()
+                                               policy.setNetworkPolicyId(networkPolicyId)
+                                               policy.setNetworkPolicyFqdn(fqdn)
+                                               policy.setHeatStackId(execution.getVariable("DCVFM_heatStackId"))
+                                               
+                                               AAIResourceUri netUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
+                                               resourceClient.create(netUri, policy)
+
+                                               rollbackData.put("VFMODULE", "rollbackCreateNetworkPoliciesAAI", "true")
+                                               rollbackData.put("VFMODULE", "contrailNetworkPolicyFqdn" + i, fqdn)
+                                               execution.setVariable("rollbackData", rollbackData)
+                                       }
+
+                               } // end loop
 
 
                   } else {
@@ -1933,7 +1934,6 @@ public class DoCreateVfModule extends VfModuleBase {
 
           } catch (BpmnError e) {
                   throw e;
-
           } catch (Exception ex) {
                   String exceptionMessage = "Bpmn error encountered in DoCreateVfModule flow. createNetworkPoliciesInAAI() - " + ex.getMessage()
                   msoLogger.debug(exceptionMessage)
@@ -1951,7 +1951,7 @@ public class DoCreateVfModule extends VfModuleBase {
           def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
                   'execution=' + execution.getId() +
                   ')'
-          
+
           msoLogger.trace('Entered ' + method)
 
           try {
@@ -2004,7 +2004,7 @@ public class DoCreateVfModule extends VfModuleBase {
           def method = getClass().getSimpleName() + '.postProcessUpdateAAIGenericVnf(' +
                   'execution=' + execution.getId() +
                   ')'
-          
+
           msoLogger.trace('Entered ' + method)
 
           try {
@@ -2036,37 +2036,37 @@ public class DoCreateVfModule extends VfModuleBase {
                   exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in postProcessUpdateAAIGenericVnf(): ' + e.getMessage())
           }
    }
-   
+
    public void queryCatalogDB (DelegateExecution execution) {
-         
+
           String msg = ""
           msoLogger.trace("queryCatalogDB ")
 
           try {
                   boolean twoPhaseDesign = false
                   // check for input
-                  
+
                   String vfModuleModelName = execution.getVariable("DCVFM_vfModuleModelName")
                   msoLogger.debug("vfModuleModelName: " + vfModuleModelName)
                   def vnfModelInfo = execution.getVariable("vnfModelInfo")
                   def vnfModelCustomizationUuid = jsonUtil.getJsonValue(vnfModelInfo, "modelCustomizationUuid")
-                 
-                  msoLogger.debug("vnfModelCustomizationUuid: " + vnfModelCustomizationUuid)              
-               
-                  JSONArray vnfs = catalog.getAllVnfsByVnfModelCustomizationUuid(execution, vnfModelCustomizationUuid, "v2")
-                  
-                  msoLogger.debug("Incoming Query Catalog DB for Vnf Response is: " + vnfModelCustomizationUuid) 
+
+                  msoLogger.debug("vnfModelCustomizationUuid: " + vnfModelCustomizationUuid)
+
+                  JSONArray vnfs = catalogDbUtils.getAllVnfsByVnfModelCustomizationUuid(execution, vnfModelCustomizationUuid, "v2")
+
+                  msoLogger.debug("Incoming Query Catalog DB for Vnf Response is: " + vnfModelCustomizationUuid)
                   // Only one match here
                   if (vnfs != null) {
                           JSONObject vnfObject = vnfs.get(0)
                           if (vnfObject != null) {
                                   String vnfJson = vnfObject.toString()
                                   //
-                                  ObjectMapper om = new ObjectMapper();                          
+                                  ObjectMapper om = new ObjectMapper();
                                   VnfResource vnf = om.readValue(vnfJson, VnfResource.class);
-                  
+
                                   // Get multiStageDesign flag
-                  
+
                                   String multiStageDesignValue = vnf.getMultiStageDesign()
                                   msoLogger.debug("multiStageDesign value from Catalog DB is: " + multiStageDesignValue)
                                   if (multiStageDesignValue != null) {
@@ -2076,10 +2076,10 @@ public class DoCreateVfModule extends VfModuleBase {
                                   }
                           }
                   }
-                  
+
                   msoLogger.debug("setting twoPhaseDesign flag to: " + twoPhaseDesign)
-                  
-                  execution.setVariable("DCVFM_twoPhaseDesign", twoPhaseDesign)                
+
+                  execution.setVariable("DCVFM_twoPhaseDesign", twoPhaseDesign)
           } catch (BpmnError e) {
                   throw e;
           } catch (Exception e) {
@@ -2087,13 +2087,13 @@ public class DoCreateVfModule extends VfModuleBase {
                   exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryCatalogDB(): ' + e.getMessage())
           }
    }
-       
-   
+
+
    public void preProcessRollback (DelegateExecution execution) {
 
           msoLogger.trace("preProcessRollback")
           try {
-                  
+
                   Object workflowException = execution.getVariable("WorkflowException");
 
                   if (workflowException instanceof WorkflowException) {