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