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