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