Dynamic Cloud Owner Support
[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 VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
462                         def vfModuleName = vfModule.getElementText('vf-module-name')
463                         def tenantId = execution.getVariable('DOUPVfMod_tenantId')
464                         def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
465                         boolean usePreload = execution.getVariable("DOUPVfMod_usePreload")
466                         String usePreloadToSDNC = usePreload ? "Y" : "N"
467                         def modelCustomizationUuid = execution.getVariable("DoUPVfMod_modelCustomizationUuid")
468                         def modelCustomizationUuidString = ""
469                         if (!usePreload) {
470                                 modelCustomizationUuidString = "<modelCustomizationUuid>" + modelCustomizationUuid + "</modelCustomizationUuid>"
471                         }
472
473                         // Retrieve vnf name from AAI response
474                         def vnfName = execution.getVariable('DOUPVfMod_vnfNameFromAAI')
475                         execution.setVariable('DOUPVfMod_vnfName', vnfName)
476
477                         def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
478                         def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
479
480                         String sdncTopologyRequest = """
481                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
482                                                 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
483                                                 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
484                                         <sdncadapter:RequestHeader>
485                                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
486                                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
487                                                 <sdncadapter:SvcAction>changeassign</sdncadapter:SvcAction>
488                                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
489                                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
490                                         </sdncadapter:RequestHeader>
491                                         <sdncadapterworkflow:SDNCRequestData>
492                                               <request-information>
493                                                  <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
494                                                  <request-action>ChangeVNFActivateRequest</request-action>
495                                                  <source>PORTAL</source>
496                                                  <notification-url/>
497                                                  <order-number/>
498                                                  <order-version/>
499                                               </request-information>
500                                               <service-information>
501                                                  <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
502                                                  <service-instance-id>${MsoUtils.xmlEscape(vnfId)}</service-instance-id>
503                                                  <subscriber-name>dontcare</subscriber-name>
504                                               </service-information>
505                                               <vnf-request-information>
506                                                  <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
507                                                  <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
508                                                  <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
509                                                  <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
510                                                  <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
511                                                          <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
512                                                  <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
513                                                  <aic-cloud-region>${MsoUtils.xmlEscape(aicCloudRegion)}</aic-cloud-region>
514                                                          ${modelCustomizationUuidString}
515                                                          <use-preload>${MsoUtils.xmlEscape(usePreloadToSDNC)}</use-preload>
516                                                  ${vnfNetworks}
517                                               </vnf-request-information>
518                                         </sdncadapterworkflow:SDNCRequestData>
519                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
520                         """
521                         sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
522                         execution.setVariable('DOUPVfMod_sdncChangeAssignRequest', sdncTopologyRequest)
523                         msoLogger.debug("sdncChangeAssignRequest : " + sdncTopologyRequest)
524                         msoLogger.debug('Request for SDNCAdapter topology/changeassign:\n' + sdncTopologyRequest)
525
526                         msoLogger.trace('Exited ' + method)
527                 } catch (BpmnError e) {
528                         throw e;
529                 } catch (Exception e) {
530                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
531                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepSDNCTopologyChg(): ' + e.getMessage())
532                 }
533         }
534
535         /**
536          * Prepare a Request for invoking the SDNC Adapter subflow to perform
537          * a VNF topology 'query' operation.
538          *
539          * @param execution The flow's execution instance.
540          */
541         public void prepSDNCTopologyQuery(DelegateExecution execution) {
542                 def method = getClass().getSimpleName() + '.prepSDNCTopologyQuery(' +
543                         'execution=' + execution.getId() +
544                         ')'
545
546                 msoLogger.trace('Entered ' + method)
547
548                 try {
549                         String uuid = execution.getVariable('testReqId') // for junits
550                         if(uuid==null){
551                                 uuid = execution.getVariable("DOUPVfMod_requestId") + "-" +     System.currentTimeMillis()
552                         }
553                         def requestId = execution.getVariable('DOUPVfMod_requestId')
554                         def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
555                         def callbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
556                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
557
558                         def svcInstId = ""
559                         if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
560                                 svcInstId = vfModuleId
561                         }
562                         else {
563                                 svcInstId = serviceInstanceId
564                         }
565
566                         //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
567                         sleep(5000)
568
569                         String sdncTopologyRequest = """
570                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
571                                                 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
572                                                 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
573                                         <sdncadapter:RequestHeader>
574                                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
575                                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
576                                                 <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
577                                                 <sdncadapter:SvcOperation>/VNF-API:vnfs/vnf-list/${vfModuleId}</sdncadapter:SvcOperation>
578                                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
579                                                 <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
580                                         </sdncadapter:RequestHeader>
581                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
582                         """
583                         sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
584                         execution.setVariable('DOUPVfMod_sdncTopologyRequest', sdncTopologyRequest)
585                         msoLogger.debug("sdncTopologyRequest : " + sdncTopologyRequest)
586                         msoLogger.debug('Request for SDNCAdapter query:\n' + sdncTopologyRequest)
587
588                         msoLogger.trace('Exited ' + method)
589                 } catch (BpmnError e) {
590                         throw e;
591                 } catch (Exception e) {
592                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
593                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepSDNCTopologyQuery(): ' + e.getMessage())
594                 }
595         }
596
597         /**
598          * Prepare a Request for invoking the VnfAdapterRest subflow.
599          *
600          * @param execution The flow's execution instance.
601          */
602         public void prepVnfAdapterRest(DelegateExecution execution) {
603                 def method = getClass().getSimpleName() + '.prepVnfAdapterRest(' +
604                         'execution=' + execution.getId() +
605                         ')'
606
607                 msoLogger.trace('Entered ' + method)
608
609                 try {
610                         def requestId = execution.getVariable('DOUPVfMod_requestId')
611                         def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
612                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
613                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
614                         def vfModuleName = execution.getVariable('DOUPVfMod_vfModuleName')
615                         def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
616                         def tenantId = execution.getVariable('DOUPVfMod_tenantId')
617                         def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
618                         def volumeGroupStackId = execution.getVariable('DOUPVfMod_volumeGroupStackId')
619                         def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
620                         def heatStackId = vfModule.getElementText('heat-stack-id')
621                         def cloudId = execution.getVariable('DOUPVfMod_aicCloudRegion')
622                         def vnfType = execution.getVariable('DOUPVfMod_vnfType')
623                         def vnfName = execution.getVariable('DOUPVfMod_vnfName')
624                         def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
625                         def baseVfModuleId = execution.getVariable("DOUPVfMod_baseVfModuleId")
626                         def baseVfModuleStackId = execution.getVariable("DOUPVfMod_baseVfModuleHeatStackId")
627                         def asdcServiceModelVersion = execution.getVariable('DOUPVfMod_asdcServiceModelVersion')
628                         def modelCustomizationUuid = execution.getVariable('DOUPVfMod_modelCustomizationUuid')
629                         def backoutOnFailure = execution.getVariable("DOUPVfMod_backoutOnFailure")
630
631                         def messageId = execution.getVariable('mso-request-id') + '-' + System.currentTimeMillis()
632                         def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
633                         def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
634                         if ('true'.equals(useQualifiedHostName)) {
635                                         notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
636                         }
637
638                         String environmentContext = execution.getVariable("DOUPVEnvironment_context")
639                         String workloadContext = execution.getVariable("DOUPVWorkload_context")
640                         msoLogger.debug("workloadContext: " + workloadContext)
641                         msoLogger.debug("environmentContext: " + environmentContext)
642
643                         Map<String, String> vnfParamsMap = execution.getVariable("DOUPVfMod_vnfParamsMap")
644
645                         String sdncGetResponse = execution.getVariable('DOUPVfMod_sdncTopologyResponse')
646
647                         String vfModuleParams = buildVfModuleParams(vnfParamsMap, sdncGetResponse, vnfId, vnfName,
648                                         vfModuleId, vfModuleName, null, environmentContext, workloadContext)
649
650
651                         String vnfAdapterRestRequest = """
652                                 <updateVfModuleRequest>
653                                         <cloudSiteId>${MsoUtils.xmlEscape(cloudId)}</cloudSiteId>
654                                         <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
655                                         <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
656                                         <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
657                                         <vfModuleStackId>${MsoUtils.xmlEscape(heatStackId)}</vfModuleStackId>
658                                         <vnfType>${MsoUtils.xmlEscape(vnfType)}</vnfType>
659                                         <vnfVersion>${MsoUtils.xmlEscape(asdcServiceModelVersion)}</vnfVersion>
660                                         <modelCustomizationUuid>${MsoUtils.xmlEscape(modelCustomizationUuid)}</modelCustomizationUuid>
661                                         <vfModuleType>${MsoUtils.xmlEscape(vfModuleModelName)}</vfModuleType>
662                                         <volumeGroupId>${MsoUtils.xmlEscape(volumeGroupId)}</volumeGroupId>
663                                         <volumeGroupStackId>${MsoUtils.xmlEscape(volumeGroupStackId)}</volumeGroupStackId>
664                                         <baseVfModuleId>${MsoUtils.xmlEscape(baseVfModuleId)}</baseVfModuleId>
665                                 <baseVfModuleStackId>${MsoUtils.xmlEscape(baseVfModuleStackId)}</baseVfModuleStackId>
666                                         <skipAAI>true</skipAAI>
667                                         <backout>${MsoUtils.xmlEscape(backoutOnFailure)}</backout>
668                                     <failIfExists>false</failIfExists>
669                                         <vfModuleParams>
670                                                 ${vfModuleParams}
671                                     </vfModuleParams>
672                                     <msoRequest>
673                                         <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
674                                         <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
675                                     </msoRequest>
676                                     <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
677                                     <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
678                                 </updateVfModuleRequest>
679                         """
680                         vnfAdapterRestRequest = utils.formatXml(vnfAdapterRestRequest)
681                         execution.setVariable('DOUPVfMod_vnfAdapterRestRequest', vnfAdapterRestRequest)
682                         msoLogger.debug("vnfAdapterRestRequest : " + vnfAdapterRestRequest)
683                         msoLogger.debug('Request for VNFAdapter Rest:\n' + vnfAdapterRestRequest)
684
685                         msoLogger.trace('Exited ' + method)
686                 } catch (BpmnError e) {
687                         throw e;
688                 } catch (Exception e) {
689                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
690                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepVnfAdapterRest(): ' + e.getMessage())
691                 }
692         }
693
694         /**
695          * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
696          *
697          * @param execution The flow's execution instance.
698          */
699         public void prepUpdateAAIGenericVnf(DelegateExecution execution) {
700                 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
701                         'execution=' + execution.getId() +
702                         ')'
703                 msoLogger.trace('Entered ' + method)
704
705                 try {
706                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
707                         def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
708
709                         def personaModelId = utils.getNodeText(vnfInputs, 'vnf-persona-model-id')
710                         def personaModelVersion = utils.getNodeText(vnfInputs, 'vnf-persona-model-version')
711                         if ((personaModelId == null) || (personaModelVersion == null)) {
712                                 msoLogger.debug("Skipping update for Generic VNF ' + vnfId + ' because either \'vnf-persona-model-id\' or \'vnf-persona-model-version\' is absent")
713                                 execution.setVariable('DOUPVfMod_skipUpdateGenericVnf', true)
714                         } else {
715                                 def personaModelIdElement = '<model-invariant-id>' + personaModelId + '</model-invariant-id>'
716                                 def personaModelVersionElement = '<model-version-id>' + personaModelVersion + '</model-version-id>'
717
718                                 String updateAAIGenericVnfRequest = """
719                                         <UpdateAAIGenericVnfRequest>
720                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
721                                                 ${personaModelIdElement}
722                                                 ${personaModelVersionElement}
723                                         </UpdateAAIGenericVnfRequest>
724                                 """
725                                 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
726                                 execution.setVariable('DOUPVfMod_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
727                                 msoLogger.debug("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
728                                 msoLogger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
729                         }
730
731                         msoLogger.trace('Exited ' + method)
732                 } catch (BpmnError e) {
733                         throw e;
734                 } catch (Exception e) {
735                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
736                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
737                 }
738         }
739
740         /**
741          * Prepare a Request for invoking the UpdateAAIVfModule subflow.
742          *
743          * @param execution The flow's execution instance.
744          */
745         public void prepUpdateAAIVfModule(DelegateExecution execution) {
746                 def method = getClass().getSimpleName() + '.prepUpdateAAIVfModule(' +
747                         'execution=' + execution.getId() +
748                         ')'
749
750                 msoLogger.trace('Entered ' + method)
751
752                 try {
753                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
754                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
755                         def orchestrationStatus = 'updated'
756                         def vnfInputs = execution.getVariable('DOUPVfMod_vnfInputs')
757
758                         def volumeGroupIdElement = ''
759                         def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId')
760                         if (volumeGroupId != null) {
761                                 volumeGroupIdElement = '<volume-group-id>' + volumeGroupId + '</volume-group-id>'
762                         }
763                         def personaModelIdElement = ''
764                         def personaModelId = utils.getNodeText(vnfInputs, 'persona-model-id')
765                         if (personaModelId != null) {
766                                 personaModelIdElement = '<model-invariant-id>' + personaModelId + '</model-invariant-id>'
767                         }
768                         def personaModelVersionElement = ''
769                         def personaModelVersion = utils.getNodeText(vnfInputs, 'persona-model-version')
770                         if (personaModelVersion != null) {
771                                 personaModelVersionElement = '<model-version-id>' + personaModelVersion + '</model-version-id>'
772                         }
773                         def contrailServiceInstanceFqdnElement = ''
774                         def contrailServiceInstanceFqdn = utils.getNodeText(vnfInputs, 'contrail-service-instance-fqdn')
775                         if (contrailServiceInstanceFqdn != null) {
776                                 contrailServiceInstanceFqdnElement = '<contrail-service-instance-fqdn>' + contrailServiceInstanceFqdn + '</contrail-service-instance-fqdn>'
777                         }
778                         def personaModelCustomizationIdElement = ''
779                         def modelCustomizationId = execution.getVariable('DOUPVfMod_modelCustomizationUuid')
780                         if (modelCustomizationId != null) {
781                                 personaModelCustomizationIdElement = '<model-customization-id>' + modelCustomizationId + '</model-customization-id>'
782                         }
783
784                         String updateAAIVfModuleRequest = """
785                                 <UpdateAAIVfModuleRequest>
786                                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
787                                         <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
788                                         <orchestration-status>${MsoUtils.xmlEscape(orchestrationStatus)}</orchestration-status>
789                                         ${volumeGroupIdElement}
790                                         ${personaModelIdElement}
791                                         ${personaModelVersionElement}
792                                         ${contrailServiceInstanceFqdnElement}
793                                         ${personaModelCustomizationIdElement}
794                                 </UpdateAAIVfModuleRequest>
795                         """
796
797                         msoLogger.debug('Unformatted updateAAIVfModuleRequest: ' + updateAAIVfModuleRequest)
798                         updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
799                         execution.setVariable('DOUPVfMod_updateAAIVfModuleRequest', updateAAIVfModuleRequest)
800                         msoLogger.debug("updateAAIVfModuleRequest : " + updateAAIVfModuleRequest)
801                         msoLogger.debug('Request for UpdateAAIVfModule:\n' + updateAAIVfModuleRequest)
802
803                         msoLogger.trace('Exited ' + method)
804                 } catch (BpmnError e) {
805                         throw e;
806                 } catch (Exception e) {
807                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
808                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIVfModule(): ' + e.getMessage())
809                 }
810         }
811
812         /**
813          * Prepare a Request for invoking the SDNC Adapter subflow to perform
814          * a VNF topology 'activate' operation.
815          *
816          * @param execution The flow's execution instance.
817          */
818         public void prepSDNCTopologyAct(DelegateExecution execution) {
819                 def method = getClass().getSimpleName() + '.prepSDNCTopologyAct(' +
820                         'execution=' + execution.getId() +
821                         ')'
822
823                 msoLogger.trace('Entered ' + method)
824
825                 try {
826                         String uuid = execution.getVariable('testReqId') // for junits
827                         if(uuid==null){
828                                 uuid = execution.getVariable("DOUPVfMod_requestId") + "-" +     System.currentTimeMillis()
829                         }
830                         def requestId = execution.getVariable('DOUPVfMod_requestId')
831                         def serviceInstanceId = execution.getVariable('DOUPVfMod_serviceInstanceId')
832                         def callbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
833                         def serviceId = execution.getVariable('DOUPVfMod_serviceId')
834                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
835                         def vnfName = execution.getVariable('DOUPVfMod_vnfName')
836                         def vnfType = execution.getVariable('DOUPVfMod_vnfType')
837                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
838                         def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName')
839                         def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule')
840                         def vfModuleName = vfModule.getElementText('vf-module-name')
841                         def tenantId = execution.getVariable('DOUPVfMod_tenantId')
842                         def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion')
843
844                         boolean usePreload = execution.getVariable("DOUPVfMod_usePreload")
845                         String usePreloadToSDNC = usePreload ? "Y" : "N"
846                         def modelCustomizationUuid = execution.getVariable("DoUPVfMod_modelCustomizationUuid")
847                         def modelCustomizationUuidString = ""
848                         if (!usePreload) {
849                                 modelCustomizationUuidString = "<modelCustomizationUuid>" + modelCustomizationUuid + "</modelCustomizationUuid>"
850                         }
851
852                         def vnfParamsXml = execution.getVariable('DOUPVfMod_vnfParams')
853                         def vnfNetworks = transformNetworkParamsToVnfNetworks(vnfParamsXml)
854
855                         String sdncTopologyRequest = """
856                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest
857                                                 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
858                                                 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
859                                         <sdncadapter:RequestHeader>
860                                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
861                                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
862                                                 <sdncadapter:SvcAction>activate</sdncadapter:SvcAction>
863                                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
864                                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
865                                         </sdncadapter:RequestHeader>
866                                         <sdncadapterworkflow:SDNCRequestData>
867                                               <request-information>
868                                                  <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
869                                                  <request-action>ChangeVNFActivateRequest</request-action>
870                                                  <source>PORTAL</source>
871                                                  <notification-url/>
872                                                  <order-number/>
873                                                  <order-version/>
874                                               </request-information>
875                                               <service-information>
876                                                  <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
877                                                  <service-instance-id>${MsoUtils.xmlEscape(vnfId)}</service-instance-id>
878                                                  <subscriber-name>dontcare</subscriber-name>
879                                               </service-information>
880                                               <vnf-request-information>
881                                                  <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
882                                                  <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
883                                                  <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
884                                                  <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
885                                                  <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
886                                                          <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
887                                                  <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
888                                                  <aic-cloud-region>${MsoUtils.xmlEscape(aicCloudRegion)}</aic-cloud-region>
889                                                          ${modelCustomizationUuidString}
890                                                         <use-preload>${MsoUtils.xmlEscape(usePreloadToSDNC)}</use-preload>
891                                               </vnf-request-information>
892                                         </sdncadapterworkflow:SDNCRequestData>
893                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
894                         """
895                         sdncTopologyRequest = utils.formatXml(sdncTopologyRequest)
896                         execution.setVariable('DOUPVfMod_sdncActivateRequest', sdncTopologyRequest)
897                         msoLogger.debug("sdncActivateRequest : " + sdncTopologyRequest)
898                         msoLogger.debug('Request for SDNCAdapter topology/activate:\n' + sdncTopologyRequest)
899
900
901                         msoLogger.trace('Exited ' + method)
902                 } catch (BpmnError e) {
903                         throw e;
904                 } catch (Exception e) {
905                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
906                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepSDNCTopologyAct(): ' + e.getMessage())
907                 }
908         }
909
910         /**
911          * Log a WorkflowException that has been created.
912          *
913          * @param execution The flow's execution instance.
914          */
915         public void handleWorkflowException(DelegateExecution execution) {
916                 def method = getClass().getSimpleName() + '.handleWorkflowException(' +
917                         'execution=' + execution.getId() +
918                         ')'
919
920                 msoLogger.trace('Entered ' + method)
921
922                 try {
923                         def WorkflowException workflowException = (WorkflowException) execution.getVariable('WorkflowException')
924                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, method + ' caught WorkflowException: ' + workflowException.getErrorMessage(), "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
925
926                         msoLogger.trace('Exited ' + method)
927                 } catch (BpmnError e) {
928                         throw e;
929                 } catch (Exception e) {
930                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
931                         exceptionUtil.buildWorkflowException(execution, 1002, 'Error in handleWorkflowException(): ' + e.getMessage())
932                 }
933         }
934
935         public void validateSDNCResponse(DelegateExecution execution, String response, String method){
936
937                 def prefix = execution.getVariable("prefix")
938
939                 msoLogger.trace("STARTED ValidateSDNCResponse Process")
940
941                 WorkflowException workflowException = execution.getVariable("WorkflowException")
942                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
943
944                 msoLogger.debug("workflowException: " + workflowException)
945
946                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
947                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
948
949                 msoLogger.debug("SDNCResponse: " + response)
950
951                 String sdncResponse = response
952                 if(execution.getVariable(prefix + 'sdncResponseSuccess') == true){
953                         msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse)
954                 }else{
955                         msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
956                         throw new BpmnError("MSOWorkflowException")
957                 }
958                 msoLogger.trace("COMPLETED ValidateSDNCResponse Process")
959         }
960
961         /**
962          * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
963          * A 200 response is expected with the VNF info in the response body. Will find out the base module info.
964          *
965          * @param execution The flow's execution instance.
966          */
967         public void queryAAIVfModule(DelegateExecution execution) {
968
969                 def method = getClass().getSimpleName() + '.getVfModule(' +
970                         'execution=' + execution.getId() +
971                         ')'
972                 msoLogger.trace('Entered ' + method)
973
974                 try {
975                         def vnfId = execution.getVariable('DOUPVfMod_vnfId')
976                         def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId')
977
978                         AaiUtil aaiUriUtil = new AaiUtil(this)
979                         
980                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
981                         String endPoint = aaiUriUtil.createAaiUri(uri)
982
983                         msoLogger.debug("AAI endPoint: " + endPoint)
984
985                         try {
986                                 def aaiRequestId = UUID.randomUUID().toString()
987                                 msoLogger.debug('sending GET to AAI endpoint \'' + endPoint + '\'')
988                                 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, endPoint)
989                                 msoLogger.debug("createVfModule - invoking httpGet() to AAI")
990
991                                 def responseData = response.getResponseBodyAsString()
992                                 if (responseData != null) {
993                                         msoLogger.debug("Received generic VNF data: " + responseData)
994
995                                 }
996
997                                 msoLogger.debug("createVfModule - queryAAIVfModule Response: " + responseData)
998                                 msoLogger.debug("createVfModule - queryAAIVfModule ResponseCode: " + response.getStatusCode())
999
1000                                 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponseCode', response.getStatusCode())
1001                                 execution.setVariable('DOUPVfMod_queryAAIVfModuleResponse', responseData)
1002                                 msoLogger.debug('Response code:' + response.getStatusCode())
1003                                 msoLogger.debug('Response:' + System.lineSeparator() + responseData)
1004                                 if (response.getStatusCode() == 200) {
1005                                         // Parse the VNF record from A&AI to find base module info
1006                                         msoLogger.debug('Parsing the VNF data to find base module info')
1007                                         if (responseData != null) {
1008                                                 def vfModulesText = utils.getNodeXml(responseData, "vf-modules")
1009                                                 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
1010                                                 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
1011                                                 int vfModulesSize = 0
1012                                                 for (i in 0..vfModules.size()-1) {
1013                                                         def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
1014                                                         def isBaseVfModule = utils.getNodeText(vfModuleXml, "is-base-vf-module")
1015
1016                                                         if (isBaseVfModule == "true") {
1017                                                             String baseModuleId = utils.getNodeText(vfModuleXml, "vf-module-id")
1018                                                             execution.setVariable("DOUPVfMod_baseVfModuleId", baseModuleId)
1019                                                             msoLogger.debug('Received baseVfModuleId: ' + baseModuleId)
1020                                                             String baseModuleHeatStackId = utils.getNodeText(vfModuleXml, "heat-stack-id")
1021                                                             execution.setVariable("DOUPVfMod_baseVfModuleHeatStackId", baseModuleHeatStackId)
1022                                                             msoLogger.debug('Received baseVfModuleHeatStackId: ' + baseModuleHeatStackId)
1023                                                         }
1024                                                 }
1025                                         }
1026                                 }
1027                         } catch (Exception ex) {
1028                                 ex.printStackTrace()
1029                                 msoLogger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
1030                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
1031                         }
1032                         msoLogger.trace('Exited ' + method)
1033                 } catch (BpmnError e) {
1034                         throw e;
1035                 } catch (Exception e) {
1036                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
1037                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())
1038                 }
1039         }
1040
1041
1042 }