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