AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoUpdateVfModule.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.bpmn.infrastructure.scripts
22
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
26 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
28 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
30 import org.openecomp.mso.bpmn.common.scripts.VfModule
31 import org.openecomp.mso.bpmn.common.scripts.VfModuleBase
32 import org.openecomp.mso.bpmn.core.WorkflowException
33 import org.openecomp.mso.bpmn.core.json.JsonUtils;
34 import org.openecomp.mso.client.aai.AAIResourcesClient
35 import org.openecomp.mso.client.aai.entities.AAIResultWrapper
36 import org.openecomp.mso.client.aai.entities.uri.AAIUri
37 import org.openecomp.mso.rest.APIResponse
38 import org.springframework.web.util.UriUtils
39 import org.openecomp.mso.client.aai.AAIObjectType;
40 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
41
42
43 public class DoUpdateVfModule extends VfModuleBase {
44
45         ExceptionUtil exceptionUtil = new ExceptionUtil()
46         JsonUtils jsonUtil = new JsonUtils()
47         CatalogDbUtils catalog = new CatalogDbUtils()
48
49         /**
50          * Initialize the flow's variables.
51          *
52          * @param execution The flow's execution instance.
53          */
54         public void initProcessVariables(DelegateExecution execution) {
55                 execution.setVariable('prefix', 'DOUPVfMod_')
56                 execution.setVariable('DOUPVfMod_requestInfo', null)
57                 execution.setVariable('DOUPVfMod_serviceInstanceId', null)
58                 execution.setVariable('DOUPVfMod_requestId', null)
59                 execution.setVariable('DOUPVfMod_vnfInputs', null)
60                 execution.setVariable('DOUPVfMod_vnfId', null)
61                 execution.setVariable('DOUPVfMod_vnfName', null)
62                 execution.setVariable('DOUPVfMod_vnfNameFromAAI', null)
63                 execution.setVariable('DOUPVfMod_vfModuleName', null)
64                 execution.setVariable('DOUPVfMod_vfModuleId', null)
65                 execution.setVariable('DOUPVfMod_vnfType', null)
66                 execution.setVariable('DOUPVfMod_asdcServiceModelVersion', null)
67                 execution.setVariable('DOUPVfMod_vfModuleModelName', null)
68                 execution.setVariable('DOUPVfMod_modelCustomizationUuid', null)
69                 execution.setVariable("DOUPVfMod_isBaseVfModule", "false")
70                 execution.setVariable('DOUPVfMod_serviceId', null)
71                 execution.setVariable('DOUPVfMod_aicCloudRegion', null)
72                 execution.setVariable('DOUPVfMod_tenantId', null)
73                 execution.setVariable('DOUPVfMod_volumeGroupId', null)
74                 execution.setVariable("DOUPVfMod_volumeGroupStackId", "")
75                 execution.setVariable('DOUPVfMod_vfModule', null)
76                 execution.setVariable('DOUPVfMod_vnfParams', null)
77                 execution.setVariable("DOUPVfMod_baseVfModuleId", "")
78                 execution.setVariable("DOUPVfMod_baseVfModuleHeatStackId", "")
79                 execution.setVariable('DOUPVfMod_prepareUpdateAAIVfModuleRequest', null)
80                 execution.setVariable('DOUPVfMod_sdncChangeAssignRequest', null)
81                 execution.setVariable('DOUPVfMod_sdncChangeAssignResponse', null)
82                 execution.setVariable('DOUPVfMod_sdncActivateRequest', null)
83                 execution.setVariable('DOUPVfMod_sdncActivateResponse', null)
84                 execution.setVariable('DOUPVfMod_sdncTopologyRequest', null)
85                 execution.setVariable('DOUPVfMod_sdncTopologyResponse', null)
86                 execution.setVariable('DOUPVfMod_vnfAdapterRestRequest', null)
87                 execution.setVariable('DOUPVfMod_updateAAIGenericVnfRequest', null)
88                 execution.setVariable('DOUPVfMod_updateAAIVfModuleRequest', null)
89                 execution.setVariable('DOUPVfMod_skipUpdateGenericVnf', false)
90                 execution.setVariable('DoUpdateVfModuleSuccessIndicator', false)
91         }
92
93         /**
94          * Check for missing elements in the received request.
95          *
96          * @param execution The flow's execution instance.
97          */
98         public void preProcessRequest(DelegateExecution execution) {
99                 def method = getClass().getSimpleName() + '.preProcessRequest(' +
100                         'execution=' + execution.getId() +
101                         ')'
102                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
103                 logDebug('Entered ' + method, isDebugLogEnabled)
104
105                 try {
106                         initProcessVariables(execution)
107                         def xml = getVariable(execution, 'DoUpdateVfModuleRequest')
108                         utils.logAudit("DoUpdateVfModule request: " + xml)
109                         logDebug('Received request xml:\n' + xml, isDebugLogEnabled)
110                         
111                         if (xml == null || xml.isEmpty()) {
112                                 // Building Block-type request
113
114                                 String cloudConfiguration = execution.getVariable("cloudConfiguration")
115                                 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
116                                 
117                                 def serviceModelInfo = execution.getVariable("serviceModelInfo")
118                                 logDebug("serviceModelInfo: " + serviceModelInfo, isDebugLogEnabled)
119                                 String modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
120                                 logDebug("modelInvariantUuid: " + modelInvariantUuid, isDebugLogEnabled)
121                                 def vnfModelInfo = execution.getVariable("vnfModelInfo")
122                                 
123                                 //tenantId
124                                 def tenantId = execution.getVariable("tenantId")
125                                 execution.setVariable("DOUPVfMod_tenantId", tenantId)
126                                 
127                                 //volumeGroupId
128                                 def volumeGroupId = execution.getVariable("volumeGroupId")
129                                 execution.setVariable("DOUPVfMod_volumeGroupId", volumeGroupId)
130                                 
131                                 //cloudSiteId
132                                 def cloudSiteId = execution.getVariable("lcpCloudRegionId")
133                                 execution.setVariable("DOUPVfMod_aicCloudRegion", cloudSiteId)
134                                 
135                                 logDebug("cloudSiteId: " + cloudSiteId, isDebugLogEnabled)
136                                 //vnfType
137                                 def vnfType = execution.getVariable("vnfType")
138                                 execution.setVariable("DOUPVfMod_vnfType", vnfType)
139                                 
140                                 logDebug("vnfType: " + vnfType, isDebugLogEnabled)
141                                 //vnfName
142                                 def vnfName = execution.getVariable("vnfName")
143                                 execution.setVariable("DOUPVfMod_vnfName", vnfName)
144                                 
145                                 logDebug("vnfName: " + vnfName, isDebugLogEnabled)
146                                 //vnfId
147                                 def vnfId = execution.getVariable("vnfId")
148                                 execution.setVariable("DOUPVfMod_vnfId", vnfId)
149                                 
150                                 logDebug("vnfId: " + vnfId, isDebugLogEnabled)
151                                 //vfModuleName
152                                 def vfModuleName = execution.getVariable("vfModuleName")
153                                 execution.setVariable("DOUPVfMod_vfModuleName", vfModuleName)
154                                 
155                                 logDebug("vfModuleName: " + vfModuleName, isDebugLogEnabled)
156                                 //vfModuleModelName
157                                 def vfModuleModelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
158                                 execution.setVariable("DOUPVfMod_vfModuleModelName", vfModuleModelName)
159                                 
160                                 logDebug("vfModuleModelName: " + vfModuleModelName, isDebugLogEnabled)
161                                 //modelCustomizationUuid
162                                 def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid")
163                                 if (modelCustomizationUuid == null) {
164                                         modelCustomizationUuid = ""
165                                 }
166                                 execution.setVariable("DOUPVfMod_modelCustomizationUuid", modelCustomizationUuid)
167                                 
168                                 logDebug("modelCustomizationUuid: " + modelCustomizationUuid, isDebugLogEnabled)
169                                 //vfModuleId
170                                 def vfModuleId = execution.getVariable("vfModuleId")
171                                 execution.setVariable("DOUPVfMod_vfModuleId", vfModuleId)
172                                 logDebug("vfModuleId: " + vfModuleId, isDebugLogEnabled)
173                                 def requestId = execution.getVariable("msoRequestId")
174                                 execution.setVariable("DOUPVfMod_requestId", requestId)
175                                 logDebug("requestId: " + requestId, isDebugLogEnabled)
176                                 // Set mso-request-id to request-id for VNF Adapter interface
177                                 execution.setVariable("mso-request-id", requestId)
178                                 //serviceId
179                                 def serviceId = execution.getVariable("serviceId")
180                                 execution.setVariable("DOUPVfMod_serviceId", serviceId)
181                                 logDebug("serviceId: " + serviceId, isDebugLogEnabled)
182                                 //serviceInstanceId
183                                 def serviceInstanceId = execution.getVariable("serviceInstanceId")
184                                 execution.setVariable("DOUPVfMod_serviceInstanceId", serviceInstanceId)
185                                 
186                                 logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled)
187                                 //source - HARDCODED
188                                 def source = "VID"
189                                 execution.setVariable("DOUPVfMod_source", source)
190                                 
191                                 logDebug("source: " + source, isDebugLogEnabled)
192                                 //backoutOnFailure
193                                 def disableRollback = execution.getVariable("disableRollback")
194                                 def backoutOnFailure = true
195                                 if (disableRollback != null && disableRollback.equals("true")) {
196                                         backoutOnFailure = false
197                                 }
198                                 execution.setVariable("DOUPVfMod_backoutOnFailure", backoutOnFailure)
199                                 logDebug("backoutOnFailure: " + backoutOnFailure, isDebugLogEnabled)
200                                 //isBaseVfModule
201                                 def isBaseVfModule = execution.getVariable("isBaseVfModule")
202                                 execution.setVariable("DOUPVfMod_isBaseVfModule", isBaseVfModule)
203                                 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
204                                 //asdcServiceModelVersion
205                                 def asdcServiceModelVersion = execution.getVariable("asdcServiceModelVersion")
206                                 execution.setVariable("DOUPVfMod_asdcServiceModelVersion", asdcServiceModelVersion)
207                                 logDebug("asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugLogEnabled)
208                                 //personaModelId
209                                 execution.setVariable("DOUPVfMod_personaModelId", jsonUtil.getJsonValue(vfModuleModelInfo, "modelInvariantUuid"))
210                                 //personaModelVersion
211                                 execution.setVariable("DOUPVfMod_personaModelVersion", jsonUtil.getJsonValue(vfModuleModelInfo, "modelVersion"))
212                                 //Get or Generate UUID
213                                 String uuid = execution.getVariable("DOUPVfMod_uuid")
214                                 if(uuid == null){
215                                         uuid = UUID.randomUUID()
216                                         logDebug("Generated messageId (UUID) is: " + uuid, isDebugLogEnabled)
217                                 }else{
218                                         logDebug("Found messageId (UUID) is: " + uuid, isDebugLogEnabled)
219                                 }
220                                 //isVidRequest
221                                 String isVidRequest = execution.getVariable("isVidRequest")
222                                 // default to true
223                                 if (isVidRequest == null || isVidRequest.isEmpty()) {
224                                         execution.setVariable("isVidRequest", "true")
225                                 }
226                                 //usePreload
227                                 def usePreload = execution.getVariable("usePreload")
228                                 execution.setVariable("DOUPVfMod_usePreload", usePreload)
229                                 logDebug("usePreload: " + usePreload, isDebugLogEnabled)
230                                 //globalSubscriberId
231                                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
232                                 execution.setVariable("DOUPVfMod_globalSubscriberId", globalSubscriberId)
233                                 logDebug("globalSubsrciberId: " + globalSubscriberId, isDebugLogEnabled)
234                                 //vnfQueryPath
235                                 String vnfQueryPath = execution.getVariable("vnfQueryPath")
236                                 execution.setVariable("DOUPVfMod_vnfQueryPath", vnfQueryPath)
237                                 logDebug("vnfQueryPath: " + vnfQueryPath, isDebugLogEnabled)
238                                 
239                                 Map<String,String> vfModuleInputParams = execution.getVariable("vfModuleInputParams")
240                                 if (vfModuleInputParams != null) {
241                                         execution.setVariable("DOUPVfMod_vnfParamsMap", vfModuleInputParams)                                    
242                                 }       
243                                 //get workload and environment context from parent SI
244                                 String environmentContext = ""
245                                 String workloadContext =""
246                                 String serviceType =""
247                                 
248                                 try{
249                                         String json = catalog.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid )
250                                         serviceType = jsonUtil.getJsonValue(json, "serviceResources.serviceType")
251                                 }catch(BpmnError e){
252                                         throw e
253                                 } catch (Exception ex){
254                                         String msg = "Exception in preProcessRequest " + ex.getMessage()
255                                         utils.log("DEBUG", msg, isDebugLogEnabled)
256                                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
257                                 }
258                                 
259                                 try{
260                                         AAIUri serviceInstanceURI = AAIUriFactory.create(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId,serviceType,serviceInstanceId)
261                                         AAIResourcesClient aaiRC = new AAIResourcesClient()
262                                         AAIResultWrapper aaiRW = aaiRC.get(serviceInstanceURI)
263                                         Map<String, Object> aaiJson = aaiRW.asMap()
264                                         environmentContext = aaiJson.getOrDefault("environment-context","")
265                                         workloadContext = aaiJson.getOrDefault("workload-context","")
266                                         
267                                 }catch (Exception ex) {
268                                         utils.log("DEBUG","Error retreiving parent service instance information", isDebugLogEnabled)
269                                 }
270                                 
271                                 execution.setVariable("DCVFM_environmentContext",environmentContext)
272                                 execution.setVariable("DCVFM_workloadContext",workloadContext)
273                         }
274                         else {
275
276                                 def requestInfo = getRequiredNodeXml(execution, xml, 'request-info')
277                                 execution.setVariable('DOUPVfMod_requestInfo', requestInfo)
278                                 execution.setVariable('DOUPVfMod_requestId', getRequiredNodeText(execution, requestInfo, 'request-id'))
279                                 def serviceInstanceId = execution.getVariable('mso-service-instance-id')
280                                 if (serviceInstanceId == null) {
281                                         serviceInstanceId = ''
282                                 }
283                                 execution.setVariable('DOUPVfMod_serviceInstanceId', serviceInstanceId)
284         
285                                 def vnfInputs = getRequiredNodeXml(execution, xml, 'vnf-inputs')
286                                 execution.setVariable('DOUPVfMod_vnfInputs', vnfInputs)
287                                 execution.setVariable('DOUPVfMod_vnfId', getRequiredNodeText(execution, vnfInputs, 'vnf-id'))
288                                 execution.setVariable('DOUPVfMod_vfModuleId', getRequiredNodeText(execution, vnfInputs, 'vf-module-id'))
289                                 execution.setVariable('DOUPVfMod_vfModuleName', getNodeTextForce(vnfInputs, 'vf-module-name'))
290                                 execution.setVariable('DOUPVfMod_vnfType', getNodeTextForce(vnfInputs, 'vnf-type'))
291                                 execution.setVariable('DOUPVfMod_vnfName', getNodeTextForce(vnfInputs, 'vnf-name'))
292                                 execution.setVariable('DOUPVfMod_asdcServiceModelVersion', getNodeTextForce(vnfInputs, 'asdc-service-model-version'))
293                                 execution.setVariable('DOUPVfMod_vfModuleModelName', getRequiredNodeText(execution, vnfInputs, 'vf-module-model-name'))
294                                 execution.setVariable('DOUPVfMod_modelCustomizationUuid', getNodeTextForce(vnfInputs, 'model-customization-id'))
295                                 execution.setVariable('DOUPVfMod_serviceId', getRequiredNodeText(execution, vnfInputs, 'service-id'))
296                                 execution.setVariable('DOUPVfMod_aicCloudRegion', getRequiredNodeText(execution, vnfInputs, 'aic-cloud-region'))
297                                 execution.setVariable('DOUPVfMod_tenantId', getRequiredNodeText(execution, vnfInputs, 'tenant-id'))
298                                 //isBaseVfModule
299                                 def isBaseVfModule = "false"
300                                 if (utils.nodeExists(xml, "is-base-vf-module")) {
301                                         isBaseVfModule = utils.getNodeText(xml, "is-base-vf-module")
302                                         execution.setVariable("DOUPVfMod_isBaseVfModule", isBaseVfModule)
303                                 }
304                                 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
305         
306                                 NetworkUtils networkUtils = new NetworkUtils()
307                                 def backoutOnFailure = networkUtils.isRollbackEnabled(execution, xml)
308                                 execution.setVariable("DOUPVfMod_backoutOnFailure", backoutOnFailure)
309         
310                                 def String vgi = getNodeTextForce(vnfInputs, 'volume-group-id')
311                                 execution.setVariable('DOUPVfMod_volumeGroupId', vgi)
312         
313                                 execution.setVariable('DOUPVfMod_vnfParams', utils.getNodeXml(xml, 'vnf-params', false))
314                         }
315
316                         def sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
317                         if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
318                                 def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
319                                 logError(msg)
320                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
321                         }
322
323                         logDebug('Exited ' + method, isDebugLogEnabled)
324                 } catch (BpmnError e) {
325                         throw e;
326                 } catch (Exception e) {
327                         logError('Caught exception in ' + method, e)
328                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessRequest(): ' + e.getMessage())
329                 }
330         }
331
332         /**
333          * Prepare a Request for invoking the PrepareUpdateAAIVfModule subflow.  This will
334          * set the orchestration-status to 'pending-update'.
335          *
336          * @param execution The flow's execution instance.
337          */
338         public void prepPrepareUpdateAAIVfModule(DelegateExecution execution) {
339                 def method = getClass().getSimpleName() + '.preparePrepareUpdateAAIVfModule(' +
340                         'execution=' + execution.getId() +
341                         ')'
342                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
343                 logDebug('Entered ' + method, isDebugLogEnabled)
344
345                 try {
346                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
347                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
348                         def orchestrationStatus = 'pending-update'
349
350                         String prepareUpdateAAIVfModuleRequest = """
351                                 <PrepareUpdateAAIVfModuleRequest>
352                                         <vnf-id>${vnfId}</vnf-id>
353                                         <vf-module-id>${vfModuleId}</vf-module-id>
354                                         <orchestration-status>${orchestrationStatus}</orchestration-status>
355                                 </PrepareUpdateAAIVfModuleRequest>
356                         """
357                         prepareUpdateAAIVfModuleRequest = utils.formatXml(prepareUpdateAAIVfModuleRequest)
358                         execution.setVariable('DOUPVfMod_prepareUpdateAAIVfModuleRequest', prepareUpdateAAIVfModuleRequest)
359                         utils.logAudit("DoUpdateAAIVfModule request: " + prepareUpdateAAIVfModuleRequest)
360                         logDebug('Request for PrepareUpdateAAIVfModule:\n' + prepareUpdateAAIVfModuleRequest, isDebugLogEnabled)
361
362                         logDebug('Exited ' + method, isDebugLogEnabled)
363                 } catch (BpmnError e) {
364                         throw e;
365                 } catch (Exception e) {
366                         logError('Caught exception in ' + method, e)
367                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preparePrepareUpdateAAIVfModule(): ' + e.getMessage())
368                 }
369         }
370
371         /**
372          * Prepare a Request for invoking the ConfirmVolumeGroupTenant subflow.
373          * Determine cloud region id for the volume group.
374          *
375          * @param execution The flow's execution instance.
376          */
377         public void prepConfirmVolumeGroupTenant(DelegateExecution execution) {
378                 def method = getClass().getSimpleName() + '.prepConfirmVolumeGroupTenant(' +
379                         'execution=' + execution.getId() +
380                         ')'
381                 
382                 def prefix = execution.getVariable("prefix")
383                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
384                 logDebug('Entered ' + method, isDebugLogEnabled)
385
386                 try {
387                         String cloudRegion = execution.getVariable(prefix + "aicCloudRegion")
388
389                         // Prepare AA&I url
390                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
391                         AaiUtil aaiUtil = new AaiUtil(this)
392                         String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
393                         String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
394                         utils.logAudit("CloudRegion Request: " + queryCloudRegionRequest)
395
396                         execution.setVariable(prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
397                         utils.log("DEBUG", prefix + "queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugLogEnabled)
398
399                         cloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "AAI", cloudRegion)
400
401                         if ((cloudRegion != "ERROR")) {
402                                 if(execution.getVariable(prefix + "queryCloudRegionReturnCode") == "404"){
403                                         execution.setVariable(prefix + "cloudRegionForVolume", "AAIAIC25")
404                                 }else{
405                                 execution.setVariable(prefix + "cloudRegionForVolume", cloudRegion)
406                                 }
407                                 execution.setVariable(prefix + "isCloudRegionGood", true)
408                         } else {
409                                 String errorMessage = "AAI Query Cloud Region Unsuccessful. AAI Response Code: " + execution.getVariable(prefix + "queryCloudRegionReturnCode")
410                                 utils.log("DEBUG", errorMessage, isDebugLogEnabled)
411                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
412                                 execution.setVariable(prefix + "isCloudRegionGood", false)
413                         }
414                         utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable(prefix + "isCloudRegionGood"), isDebugLogEnabled)
415
416                 } catch(BpmnError b){
417                         utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugLogEnabled)
418                         throw b
419                 }catch (Exception e) {
420                         // try error
421                         String errorMessage = "Bpmn error encountered in CreateVfModule flow. Unexpected Response from AAI - " + e.getMessage()
422                         utils.log("ERROR", " AAI Query Cloud Region Failed.  Exception - " + "\n" + errorMessage, isDebugLogEnabled)
423                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception occured during prepConfirmVolumeGroupTenant(): " + e.getMessage())
424                 }
425                 logDebug('Exited ' + method, isDebugLogEnabled)
426                 
427         }
428         
429         /**
430          * Prepare a Request for invoking the SDNC Adapter subflow to perform
431          * a VNF topology 'changeassign' operation.
432          *
433          * @param execution The flow's execution instance.
434          */
435         public void prepSDNCTopologyChg(DelegateExecution execution) {
436                 def method = getClass().getSimpleName() + '.prepSDNCTopologyChg(' +
437                         'execution=' + execution.getId() +
438                         ')'
439                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
440                 logDebug('Entered ' + method, isDebugLogEnabled)
441
442                 try {
443                         def requestId = execution.getVariable('DOUPVfMod_requestId')
444                         String uuid = execution.getVariable('testReqId') // for junits
445                         if(uuid==null){
446                                 uuid = execution.getVariable("DOUPVfMod_requestId") + "-" +     System.currentTimeMillis()
447                         }
448                         def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
449                         def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
450                         def serviceId = execution.getVariable('DOUPVfMod_serviceId')
451                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
452                         def vnfType = execution.getVariable('DOUPVfMod_vnfType')
453                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
454                         def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
455                         def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
456                         def vfModuleName = vfModule.getElementText('vf-module-name')
457                         def tenantId = execution.getVariable('DOUPVfMod_tenantId')
458                         def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
459                         boolean usePreload = execution.getVariable("DOUPVfMod_usePreload")
460                         String usePreloadToSDNC = usePreload ? "Y" : "N"
461                         def modelCustomizationUuid = execution.getVariable("DoUPVfMod_modelCustomizationUuid")
462                         def modelCustomizationUuidString = ""
463                         if (!usePreload) {
464                                 modelCustomizationUuidString = "<modelCustomizationUuid>" + modelCustomizationUuid + "</modelCustomizationUuid>"
465                         }
466
467                         // Retrieve vnf name from AAI response
468                         def vnfName = execution.getVariable('DOUPVfMod_vnfNameFromAAI')
469                         execution.setVariable('DOUPVfMod_vnfName', vnfName)
470
471                         def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
472                         def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
473
474                         String sdncTopologyRequest = """
475                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
476                                                 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
477                                                 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
478                                         <sdncadapter:RequestHeader>
479                                                 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
480                                                 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
481                                                 <sdncadapter:SvcAction>changeassign</sdncadapter:SvcAction>
482                                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
483                                                 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
484                                         </sdncadapter:RequestHeader>
485                                         <sdncadapterworkflow:SDNCRequestData>
486                                               <request-information>
487                                                  <request-id>${requestId}</request-id>
488                                                  <request-action>ChangeVNFActivateRequest</request-action>
489                                                  <source>PORTAL</source>
490                                                  <notification-url/>
491                                                  <order-number/>
492                                                  <order-version/>
493                                               </request-information>
494                                               <service-information>
495                                                  <service-type>${serviceId}</service-type>
496                                                  <service-instance-id>${vnfId}</service-instance-id>
497                                                  <subscriber-name>dontcare</subscriber-name>
498                                               </service-information>
499                                               <vnf-request-information>
500                                                  <vnf-id>${vfModuleId}</vnf-id>
501                                                  <vnf-type>${vfModuleModelName}</vnf-type>
502                                                  <vnf-name>${vfModuleName}</vnf-name>
503                                                  <generic-vnf-id>${vnfId}</generic-vnf-id>
504                                                  <generic-vnf-name>${vnfName}</generic-vnf-name>
505                                                          <generic-vnf-type>${vnfType}</generic-vnf-type>
506                                                  <tenant>${tenantId}</tenant>
507                                                  <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
508                                                          ${modelCustomizationUuidString}
509                                                          <use-preload>${usePreloadToSDNC}</use-preload>
510                                                  ${vnfNetworks}
511                                               </vnf-request-information>
512                                         </sdncadapterworkflow:SDNCRequestData>
513                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
514                         """
515                         sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
516                         execution.setVariable('DOUPVfMod_sdncChangeAssignRequest', sdncTopologyRequest)
517                         utils.logAudit("sdncChangeAssignRequest : " + sdncTopologyRequest)
518                         logDebug('Request for SDNCAdapter topology/changeassign:\n' + sdncTopologyRequest, isDebugLogEnabled)
519
520                         logDebug('Exited ' + method, isDebugLogEnabled)
521                 } catch (BpmnError e) {
522                         throw e;
523                 } catch (Exception e) {
524                         logError('Caught exception in ' + method, e)
525                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepSDNCTopologyChg(): ' + e.getMessage())
526                 }
527         }
528
529         /**
530          * Prepare a Request for invoking the SDNC Adapter subflow to perform
531          * a VNF topology 'query' operation.
532          *
533          * @param execution The flow's execution instance.
534          */
535         public void prepSDNCTopologyQuery(DelegateExecution execution) {
536                 def method = getClass().getSimpleName() + '.prepSDNCTopologyQuery(' +
537                         'execution=' + execution.getId() +
538                         ')'
539                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
540                 logDebug('Entered ' + method, isDebugLogEnabled)
541
542                 try {
543                         String uuid = execution.getVariable('testReqId') // for junits
544                         if(uuid==null){
545                                 uuid = execution.getVariable("DOUPVfMod_requestId") + "-" +     System.currentTimeMillis()
546                         }
547                         def requestId = execution.getVariable('DOUPVfMod_requestId')
548                         def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
549                         def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
550                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
551
552                         def svcInstId = ""
553                         if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
554                                 svcInstId = vfModuleId
555                         }
556                         else {
557                                 svcInstId = serviceInstanceId
558                         }
559
560                         //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
561                         sleep(5000)
562
563                         String sdncTopologyRequest = """
564                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
565                                                 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
566                                                 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
567                                         <sdncadapter:RequestHeader>
568                                                 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
569                                                 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
570                                                 <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
571                                                 <sdncadapter:SvcOperation>/VNF-API:vnfs/vnf-list/${vfModuleId}</sdncadapter:SvcOperation>
572                                                 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
573                                                 <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
574                                         </sdncadapter:RequestHeader>
575                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
576                         """
577                         sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
578                         execution.setVariable('DOUPVfMod_sdncTopologyRequest', sdncTopologyRequest)
579                         utils.logAudit("sdncTopologyRequest : " + sdncTopologyRequest)
580                         logDebug('Request for SDNCAdapter query:\n' + sdncTopologyRequest, isDebugLogEnabled)
581
582                         logDebug('Exited ' + method, isDebugLogEnabled)
583                 } catch (BpmnError e) {
584                         throw e;
585                 } catch (Exception e) {
586                         logError('Caught exception in ' + method, e)
587                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepSDNCTopologyQuery(): ' + e.getMessage())
588                 }
589         }
590
591         /**
592          * Prepare a Request for invoking the VnfAdapterRest subflow.
593          *
594          * @param execution The flow's execution instance.
595          */
596         public void prepVnfAdapterRest(DelegateExecution execution) {
597                 def method = getClass().getSimpleName() + '.prepVnfAdapterRest(' +
598                         'execution=' + execution.getId() +
599                         ')'
600                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
601                 logDebug('Entered ' + method, isDebugLogEnabled)
602
603                 try {
604                         def requestId = execution.getVariable('DOUPVfMod_requestId')
605                         def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
606                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
607                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
608                         def vfModuleName = execution.getVariable('DOUPVfMod_vfModuleName')
609                         def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
610                         def tenantId = execution.getVariable('DOUPVfMod_tenantId')
611                         def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
612                         def volumeGroupStackId = execution.getVariable('DOUPVfMod_volumeGroupStackId')
613                         def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
614                         def heatStackId = vfModule.getElementText('heat-stack-id')
615                         def cloudId = execution.getVariable('DOUPVfMod_aicCloudRegion')
616                         def vnfType = execution.getVariable('DOUPVfMod_vnfType')
617                         def vnfName = execution.getVariable('DOUPVfMod_vnfName')
618                         def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
619                         def baseVfModuleId = execution.getVariable("DOUPVfMod_baseVfModuleId")
620                         def baseVfModuleStackId = execution.getVariable("DOUPVfMod_baseVfModuleHeatStackId")
621                         def asdcServiceModelVersion = execution.getVariable('DOUPVfMod_asdcServiceModelVersion')
622                         def modelCustomizationUuid = execution.getVariable('DOUPVfMod_modelCustomizationUuid')
623                         def backoutOnFailure = execution.getVariable("DOUPVfMod_backoutOnFailure")
624                         
625                         def messageId = execution.getVariable('mso-request-id') + '-' + System.currentTimeMillis()
626                         def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
627                         def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
628                         if ('true'.equals(useQualifiedHostName)) {
629                                         notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
630                         }
631                         
632                         String environmentContext = execution.getVariable("DOUPVEnvironment_context")
633                         String workloadContext = execution.getVariable("DOUPVWorkload_context")
634                         logDebug("workloadContext: " + workloadContext, isDebugLogEnabled)
635                         logDebug("environmentContext: " + environmentContext, isDebugLogEnabled)
636                         
637                         Map<String, String> vnfParamsMap = execution.getVariable("DOUPVfMod_vnfParamsMap")
638
639                         String sdncGetResponse = execution.getVariable('DOUPVfMod_sdncTopologyResponse')
640
641                         String vfModuleParams = buildVfModuleParams(vnfParamsMap, sdncGetResponse, vnfId, vnfName,
642                                         vfModuleId, vfModuleName, null, environmentContext, workloadContext)
643
644
645                         String vnfAdapterRestRequest = """
646                                 <updateVfModuleRequest>
647                                         <cloudSiteId>${cloudId}</cloudSiteId>
648                                         <tenantId>${tenantId}</tenantId>
649                                         <vnfId>${vnfId}</vnfId>
650                                         <vfModuleId>${vfModuleId}</vfModuleId>
651                                         <vfModuleStackId>${heatStackId}</vfModuleStackId>
652                                         <vnfType>${vnfType}</vnfType>
653                                         <vnfVersion>${asdcServiceModelVersion}</vnfVersion>
654                                         <modelCustomizationUuid>${modelCustomizationUuid}</modelCustomizationUuid>
655                                         <vfModuleType>${vfModuleModelName}</vfModuleType>
656                                         <volumeGroupId>${volumeGroupId}</volumeGroupId>
657                                         <volumeGroupStackId>${volumeGroupStackId}</volumeGroupStackId>
658                                         <baseVfModuleId>${baseVfModuleId}</baseVfModuleId>
659                                 <baseVfModuleStackId>${baseVfModuleStackId}</baseVfModuleStackId>
660                                         <skipAAI>true</skipAAI>
661                                         <backout>${backoutOnFailure}</backout>
662                                     <failIfExists>false</failIfExists>
663                                         <vfModuleParams>
664                                                 ${vfModuleParams}
665                                     </vfModuleParams>
666                                     <msoRequest>
667                                         <requestId>${requestId}</requestId>
668                                         <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
669                                     </msoRequest>
670                                     <messageId>${messageId}</messageId>
671                                     <notificationUrl>${notificationUrl}</notificationUrl>
672                                 </updateVfModuleRequest>
673                         """
674                         vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)
675                         execution.setVariable('DOUPVfMod_vnfAdapterRestRequest', vnfAdapterRestRequest)
676                         utils.logAudit("vnfAdapterRestRequest : " + vnfAdapterRestRequest)
677                         logDebug('Request for VNFAdapter Rest:\n' + vnfAdapterRestRequest, isDebugLogEnabled)
678
679                         logDebug('Exited ' + method, isDebugLogEnabled)
680                 } catch (BpmnError e) {
681                         throw e;
682                 } catch (Exception e) {
683                         logError('Caught exception in ' + method, e)
684                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepVnfAdapterRest(): ' + e.getMessage())
685                 }
686         }
687
688         /**
689          * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
690          *
691          * @param execution The flow's execution instance.
692          */
693         public void prepUpdateAAIGenericVnf(DelegateExecution execution) {
694                 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
695                         'execution=' + execution.getId() +
696                         ')'
697                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
698                 logDebug('Entered ' + method, isDebugLogEnabled)
699
700                 try {
701                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
702                         def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
703
704                         def personaModelId = utils.getNodeText1(vnfInputs, 'vnf-persona-model-id')
705                         def personaModelVersion = utils.getNodeText1(vnfInputs, 'vnf-persona-model-version')
706                         if ((personaModelId == null) || (personaModelVersion == null)) {
707                                 logDebug('Skipping update for Generic VNF ' + vnfId +
708                                         ' because either \'vnf-persona-model-id\' or \'vnf-persona-model-version\' is absent', isDebugLogEnabled)
709                                 execution.setVariable('DOUPVfMod_skipUpdateGenericVnf', true)
710                         } else {
711                                 def personaModelIdElement = '<model-invariant-id>' + personaModelId + '</model-invariant-id>'
712                                 def personaModelVersionElement = '<model-version-id>' + personaModelVersion + '</model-version-id>'
713
714                                 String updateAAIGenericVnfRequest = """
715                                         <UpdateAAIGenericVnfRequest>
716                                                 <vnf-id>${vnfId}</vnf-id>
717                                                 ${personaModelIdElement}
718                                                 ${personaModelVersionElement}
719                                         </UpdateAAIGenericVnfRequest>
720                                 """
721                                 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
722                                 execution.setVariable('DOUPVfMod_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
723                                 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
724                                 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
725                         }
726
727                         logDebug('Exited ' + method, isDebugLogEnabled)
728                 } catch (BpmnError e) {
729                         throw e;
730                 } catch (Exception e) {
731                         logError('Caught exception in ' + method, e)
732                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
733                 }
734         }
735
736         /**
737          * Prepare a Request for invoking the UpdateAAIVfModule subflow.
738          *
739          * @param execution The flow's execution instance.
740          */
741         public void prepUpdateAAIVfModule(DelegateExecution execution) {
742                 def method = getClass().getSimpleName() + '.prepUpdateAAIVfModule(' +
743                         'execution=' + execution.getId() +
744                         ')'
745                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
746                 logDebug('Entered ' + method, isDebugLogEnabled)
747
748                 try {
749                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
750                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
751                         def orchestrationStatus = 'updated'
752                         def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
753
754                         def volumeGroupIdElement = ''
755                         def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
756                         if (volumeGroupId != null) {
757                                 volumeGroupIdElement = '<volume-group-id>' + volumeGroupId + '</volume-group-id>'
758                         }
759                         def personaModelIdElement = ''
760                         def personaModelId = utils.getNodeText1(vnfInputs, 'persona-model-id')
761                         if (personaModelId != null) {
762                                 personaModelIdElement = '<model-invariant-id>' + personaModelId + '</model-invariant-id>'
763                         }
764                         def personaModelVersionElement = ''
765                         def personaModelVersion = utils.getNodeText1(vnfInputs, 'persona-model-version')
766                         if (personaModelVersion != null) {
767                                 personaModelVersionElement = '<model-version-id>' + personaModelVersion + '</model-version-id>'
768                         }
769                         def contrailServiceInstanceFqdnElement = ''
770                         def contrailServiceInstanceFqdn = utils.getNodeText1(vnfInputs, 'contrail-service-instance-fqdn')
771                         if (contrailServiceInstanceFqdn != null) {
772                                 contrailServiceInstanceFqdnElement = '<contrail-service-instance-fqdn>' + contrailServiceInstanceFqdn + '</contrail-service-instance-fqdn>'
773                         }
774                         def personaModelCustomizationIdElement = ''
775                         def modelCustomizationId = execution.getVariable('DOUPVfMod_modelCustomizationUuid')
776                         if (modelCustomizationId != null) {
777                                 personaModelCustomizationIdElement = '<model-customization-id>' + modelCustomizationId + '</model-customization-id>'
778                         }
779
780                         String updateAAIVfModuleRequest = """
781                                 <UpdateAAIVfModuleRequest>
782                                         <vnf-id>${vnfId}</vnf-id>
783                                         <vf-module-id>${vfModuleId}</vf-module-id>
784                                         <orchestration-status>${orchestrationStatus}</orchestration-status>
785                                         ${volumeGroupIdElement}
786                                         ${personaModelIdElement}
787                                         ${personaModelVersionElement}
788                                         ${contrailServiceInstanceFqdnElement}
789                                         ${personaModelCustomizationIdElement}
790                                 </UpdateAAIVfModuleRequest>
791                         """
792                         
793                         logDebug('Unformatted updateAAIVfModuleRequest: ' + updateAAIVfModuleRequest, isDebugLogEnabled)
794                         updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
795                         execution.setVariable('DOUPVfMod_updateAAIVfModuleRequest', updateAAIVfModuleRequest)
796                         utils.logAudit("updateAAIVfModuleRequest : " + updateAAIVfModuleRequest)
797                         logDebug('Request for UpdateAAIVfModule:\n' + updateAAIVfModuleRequest, isDebugLogEnabled)
798
799                         logDebug('Exited ' + method, isDebugLogEnabled)
800                 } catch (BpmnError e) {
801                         throw e;
802                 } catch (Exception e) {
803                         logError('Caught exception in ' + method, e)
804                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIVfModule(): ' + e.getMessage())
805                 }
806         }
807
808         /**
809          * Prepare a Request for invoking the SDNC Adapter subflow to perform
810          * a VNF topology 'activate' operation.
811          *
812          * @param execution The flow's execution instance.
813          */
814         public void prepSDNCTopologyAct(DelegateExecution execution) {
815                 def method = getClass().getSimpleName() + '.prepSDNCTopologyAct(' +
816                         'execution=' + execution.getId() +
817                         ')'
818                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
819                 logDebug('Entered ' + method, isDebugLogEnabled)
820
821                 try {
822                         String uuid = execution.getVariable('testReqId') // for junits
823                         if(uuid==null){
824                                 uuid = execution.getVariable("DOUPVfMod_requestId") + "-" +     System.currentTimeMillis()
825                         }
826                         def requestId = execution.getVariable('DOUPVfMod_requestId')
827                         def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
828                         def callbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
829                         def serviceId = execution.getVariable('DOUPVfMod_serviceId')
830                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
831                         def vnfName = execution.getVariable('DOUPVfMod_vnfName')
832                         def vnfType = execution.getVariable('DOUPVfMod_vnfType')
833                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
834                         def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
835                         def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
836                         def vfModuleName = vfModule.getElementText('vf-module-name')
837                         def tenantId = execution.getVariable('DOUPVfMod_tenantId')
838                         def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
839
840                         boolean usePreload = execution.getVariable("DOUPVfMod_usePreload")
841                         String usePreloadToSDNC = usePreload ? "Y" : "N"
842                         def modelCustomizationUuid = execution.getVariable("DoUPVfMod_modelCustomizationUuid")
843                         def modelCustomizationUuidString = ""
844                         if (!usePreload) {
845                                 modelCustomizationUuidString = "<modelCustomizationUuid>" + modelCustomizationUuid + "</modelCustomizationUuid>"
846                         }
847                         
848                         def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
849                         def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
850
851                         String sdncTopologyRequest = """
852                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
853                                                 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
854                                                 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
855                                         <sdncadapter:RequestHeader>
856                                                 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
857                                                 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
858                                                 <sdncadapter:SvcAction>activate</sdncadapter:SvcAction>
859                                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
860                                                 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
861                                         </sdncadapter:RequestHeader>
862                                         <sdncadapterworkflow:SDNCRequestData>
863                                               <request-information>
864                                                  <request-id>${requestId}</request-id>
865                                                  <request-action>ChangeVNFActivateRequest</request-action>
866                                                  <source>PORTAL</source>
867                                                  <notification-url/>
868                                                  <order-number/>
869                                                  <order-version/>
870                                               </request-information>
871                                               <service-information>
872                                                  <service-type>${serviceId}</service-type>
873                                                  <service-instance-id>${vnfId}</service-instance-id>
874                                                  <subscriber-name>dontcare</subscriber-name>
875                                               </service-information>
876                                               <vnf-request-information>
877                                                  <vnf-id>${vfModuleId}</vnf-id>
878                                                  <vnf-type>${vfModuleModelName}</vnf-type>
879                                                  <vnf-name>${vfModuleName}</vnf-name>
880                                                  <generic-vnf-id>${vnfId}</generic-vnf-id>
881                                                  <generic-vnf-name>${vnfName}</generic-vnf-name>
882                                                          <generic-vnf-type>${vnfType}</generic-vnf-type>
883                                                  <tenant>${tenantId}</tenant>
884                                                  <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
885                                                          ${modelCustomizationUuidString}
886                                                         <use-preload>${usePreloadToSDNC}</use-preload>
887                                               </vnf-request-information>
888                                         </sdncadapterworkflow:SDNCRequestData>
889                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
890                         """
891                         sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
892                         execution.setVariable('DOUPVfMod_sdncActivateRequest', sdncTopologyRequest)
893                         utils.logAudit("sdncActivateRequest : " + sdncTopologyRequest)
894                         logDebug('Request for SDNCAdapter topology/activate:\n' + sdncTopologyRequest, isDebugLogEnabled)
895
896
897                         logDebug('Exited ' + method, isDebugLogEnabled)
898                 } catch (BpmnError e) {
899                         throw e;
900                 } catch (Exception e) {
901                         logError('Caught exception in ' + method, e)
902                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepSDNCTopologyAct(): ' + e.getMessage())
903                 }
904         }
905
906         /**
907          * Log a WorkflowException that has been created.
908          *
909          * @param execution The flow's execution instance.
910          */
911         public void handleWorkflowException(DelegateExecution execution) {
912                 def method = getClass().getSimpleName() + '.handleWorkflowException(' +
913                         'execution=' + execution.getId() +
914                         ')'
915                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
916                 logDebug('Entered ' + method, isDebugLogEnabled)
917
918                 try {
919                         def WorkflowException workflowException = (WorkflowException) execution.getVariable('WorkflowException')
920                         logError(method + ' caught WorkflowException: ' + workflowException.getErrorMessage())
921
922                         logDebug('Exited ' + method, isDebugLogEnabled)
923                 } catch (BpmnError e) {
924                         throw e;
925                 } catch (Exception e) {
926                         logError('Caught exception in ' + method, e)
927                         exceptionUtil.buildWorkflowException(execution, 1002, 'Error in handleWorkflowException(): ' + e.getMessage())
928                 }
929         }
930
931         public void validateSDNCResponse(DelegateExecution execution, String response, String method){
932                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
933                 def prefix = execution.getVariable("prefix")
934
935                 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
936
937                 WorkflowException workflowException = execution.getVariable("WorkflowException")
938                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
939
940                 utils.logAudit("workflowException: " + workflowException)
941
942                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
943                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
944
945                 utils.logAudit("SDNCResponse: " + response)
946
947                 String sdncResponse = response
948                 if(execution.getVariable(prefix + 'sdncResponseSuccess') == true){
949                         logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse, isDebugLogEnabled)
950                 }else{
951                         logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
952                         throw new BpmnError("MSOWorkflowException")
953                 }
954                 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
955         }
956
957         /**
958          * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
959          * A 200 response is expected with the VNF info in the response body. Will find out the base module info.
960          *
961          * @param execution The flow's execution instance.
962          */
963         public void queryAAIVfModule(DelegateExecution execution) {
964                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
965                 def method = getClass().getSimpleName() + '.getVfModule(' +
966                         'execution=' + execution.getId() +
967                         ')'
968                 logDebug('Entered ' + method, isDebugLogEnabled)
969
970                 try {
971                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
972                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
973
974                         AaiUtil aaiUriUtil = new AaiUtil(this)
975                         String  aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
976                         logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
977
978                         String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
979                         utils.logAudit("AAI endPoint: " + endPoint)
980
981                         try {
982                                 def aaiRequestId = UUID.randomUUID().toString()
983                                 logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
984                                 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, endPoint)
985                                 utils.logAudit("createVfModule - invoking httpGet() to AAI")
986
987                                 def responseData = response.getResponseBodyAsString()
988                                 if (responseData != null) {
989                                         logDebug("Received generic VNF data: " + responseData, isDebugLogEnabled)
990
991                                 }
992
993                                 utils.logAudit("createVfModule - queryAAIVfModule Response: " + responseData)
994                                 utils.logAudit("createVfModule - queryAAIVfModule ResponseCode: " + response.getStatusCode())
995
996                                 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponseCode', response.getStatusCode())
997                                 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponse', responseData)
998                                 logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
999                                 logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
1000                                 if (response.getStatusCode() == 200) {
1001                                         // Parse the VNF record from A&AI to find base module info
1002                                         logDebug('Parsing the VNF data to find base module info', isDebugLogEnabled)
1003                                         if (responseData != null) {
1004                                                 def vfModulesText = utils.getNodeXml(responseData, "vf-modules")
1005                                                 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
1006                                                 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
1007                                                 int vfModulesSize = 0
1008                                                 for (i in 0..vfModules.size()-1) {
1009                                                         def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
1010                                                         def isBaseVfModule = utils.getNodeText(vfModuleXml, "is-base-vf-module")
1011
1012                                                         if (isBaseVfModule == "true") {
1013                                                             String baseModuleId = utils.getNodeText1(vfModuleXml, "vf-module-id")
1014                                                             execution.setVariable("DOUPVfMod_baseVfModuleId", baseModuleId)
1015                                                             logDebug('Received baseVfModuleId: ' + baseModuleId, isDebugLogEnabled)
1016                                                             String baseModuleHeatStackId = utils.getNodeText1(vfModuleXml, "heat-stack-id")
1017                                                             execution.setVariable("DOUPVfMod_baseVfModuleHeatStackId", baseModuleHeatStackId)
1018                                                             logDebug('Received baseVfModuleHeatStackId: ' + baseModuleHeatStackId, isDebugLogEnabled)
1019                                                         }
1020                                                 }
1021                                         }
1022                                 }
1023                         } catch (Exception ex) {
1024                                 ex.printStackTrace()
1025                                 logDebug('Exception occurred while executing AAI GET:' + ex.getMessage(),isDebugLogEnabled)
1026                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
1027                         }
1028                         logDebug('Exited ' + method, isDebugLogEnabled)
1029                 } catch (BpmnError e) {
1030                         throw e;
1031                 } catch (Exception e) {
1032                         logError('Caught exception in ' + method, e)
1033                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())
1034                 }
1035         }
1036
1037
1038 }