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