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