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