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