[MSO-8] Second step of the rebase for MSO
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateVfModule.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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 \r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
22 \r
23 import javax.xml.parsers.DocumentBuilder\r
24 import javax.xml.parsers.DocumentBuilderFactory\r
25 \r
26 import org.apache.commons.lang3.*
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.runtime.Execution
29 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
30 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
31 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
32 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
33 import org.openecomp.mso.bpmn.common.scripts.VfModuleBase
34 import org.openecomp.mso.bpmn.core.RollbackData
35 import org.openecomp.mso.bpmn.core.WorkflowException
36 import org.openecomp.mso.bpmn.core.json.JsonUtils
37 import org.openecomp.mso.rest.APIResponse
38 import org.openecomp.mso.rest.RESTClient
39 import org.openecomp.mso.rest.RESTConfig
40 import org.springframework.web.util.UriUtils\r
41 import org.w3c.dom.Document\r
42 import org.w3c.dom.Element\r
43 import org.w3c.dom.NamedNodeMap\r
44 import org.w3c.dom.Node\r
45 import org.w3c.dom.NodeList
46 import org.xml.sax.InputSource\r
47 \r
48 \r
49
50 public class DoCreateVfModule extends VfModuleBase {
51
52         String Prefix="DCVFM_"
53         ExceptionUtil exceptionUtil = new ExceptionUtil()
54         JsonUtils jsonUtil = new JsonUtils()
55         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
56
57         /**
58          * Validates the request message and sets up the workflow.
59          * @param execution the execution
60          */
61         public void preProcessRequest(Execution execution) {
62                 def method = getClass().getSimpleName() + '.preProcessRequest(' +
63                         'execution=' + execution.getId() +
64                         ')'
65                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
66                 logDebug('Entered ' + method, isDebugLogEnabled)
67
68                 execution.setVariable('prefix', Prefix)
69                 try{
70                         def rollbackData = execution.getVariable("RollbackData")
71                         if (rollbackData == null) {
72                                 rollbackData = new RollbackData()
73                         }
74
75                         execution.setVariable("DCVFM_vnfParamsExistFlag", false)
76                         execution.setVariable("DCVFM_oamManagementV4Address", "")
77                         execution.setVariable("DCVFM_oamManagementV6Address", "")
78
79                         String request = execution.getVariable("DoCreateVfModuleRequest")
80
81                         if (request == null || request.isEmpty()) {
82                                 // Building Block-type request
83
84                                 String vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")           
85                                 
86                                 def serviceModelInfo = execution.getVariable("serviceModelInfo")
87                                 logDebug("serviceModelInfo: " + serviceModelInfo, isDebugLogEnabled)
88                                 def vnfModelInfo = execution.getVariable("vnfModelInfo")
89                                 
90
91                                 //tenantId
92                                 def tenantId = execution.getVariable("tenantId")
93                                 execution.setVariable("DCVFM_tenantId", tenantId)
94                                 rollbackData.put("VFMODULE", "tenantid", tenantId)
95                                 //volumeGroupId
96                                 def volumeGroupId = execution.getVariable("volumeGroupId")
97                                 execution.setVariable("DCVFM_volumeGroupId", volumeGroupId)
98                                 //volumeGroupName
99                                 def volumeGroupName = execution.getVariable("volumeGroupName")
100                                 execution.setVariable("DCVFM_volumeGroupName", volumeGroupName)
101                                 //cloudSiteId
102                                 def cloudSiteId = execution.getVariable("lcpCloudRegionId")
103                                 execution.setVariable("DCVFM_cloudSiteId", cloudSiteId)
104                                 rollbackData.put("VFMODULE", "aiccloudregion", cloudSiteId)
105                                 logDebug("cloudSiteId: " + cloudSiteId, isDebugLogEnabled)
106                                 //vnfType
107                                 def vnfType = execution.getVariable("vnfType")
108                                 execution.setVariable("DCVFM_vnfType", vnfType)
109                                 rollbackData.put("VFMODULE", "vnftype", vnfType)
110                                 logDebug("vnfType: " + vnfType, isDebugLogEnabled)
111                                 //vnfName
112                                 def vnfName = execution.getVariable("vnfName")
113                                 execution.setVariable("DCVFM_vnfName", vnfName)
114                                 rollbackData.put("VFMODULE", "vnfname", vnfName)
115                                 logDebug("vnfName: " + vnfName, isDebugLogEnabled)
116                                 //vnfId
117                                 def vnfId = execution.getVariable("vnfId")
118                                 execution.setVariable("DCVFM_vnfId", vnfId)
119                                 rollbackData.put("VFMODULE", "vnfid", vnfId)
120                                 logDebug("vnfId: " + vnfId, isDebugLogEnabled)
121                                 //vfModuleName
122                                 def vfModuleName = execution.getVariable("vfModuleName")
123                                 execution.setVariable("DCVFM_vfModuleName", vfModuleName)
124                                 rollbackData.put("VFMODULE", "vfmodulename", vfModuleName)
125                                 logDebug("vfModuleName: " + vfModuleName, isDebugLogEnabled)
126                                 //vfModuleModelName
127                                 def vfModuleModelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName")
128                                 execution.setVariable("DCVFM_vfModuleModelName", vfModuleModelName)
129                                 rollbackData.put("VFMODULE", "vfmodulemodelname", vfModuleModelName)
130                                 logDebug("vfModuleModelName: " + vfModuleModelName, isDebugLogEnabled)
131                                 //modelCustomizationUuid
132                                 def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid")
133                                 execution.setVariable("DCVFM_modelCustomizationUuid", modelCustomizationUuid)
134                                 rollbackData.put("VFMODULE", "modelcustomizationuuid", modelCustomizationUuid)
135                                 logDebug("modelCustomizationUuid: " + modelCustomizationUuid, isDebugLogEnabled)
136                                 //vfModuleId
137                                 def vfModuleId = execution.getVariable("vfModuleId")
138                                 execution.setVariable("DCVFM_vfModuleId", vfModuleId)
139                                 logDebug("vfModuleId: " + vfModuleId, isDebugLogEnabled)
140                                 def requestId = execution.getVariable("msoRequestId")
141                                 execution.setVariable("DCVFM_requestId", requestId)
142                                 logDebug("requestId: " + requestId, isDebugLogEnabled)
143                                 // Set mso-request-id to request-id for VNF Adapter interface                           
144                                 execution.setVariable("mso-request-id", requestId)
145                                 //serviceId
146                                 def serviceId = execution.getVariable("serviceId")
147                                 execution.setVariable("DCVFM_serviceId", serviceId)
148                                 logDebug("serviceId: " + serviceId, isDebugLogEnabled)
149                                 //serviceInstanceId
150                                 def serviceInstanceId = execution.getVariable("serviceInstanceId")
151                                 execution.setVariable("DCVFM_serviceInstanceId", serviceInstanceId)
152                                 rollbackData.put("VFMODULE", "serviceInstanceId", serviceInstanceId)
153                                 logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled)
154                                 //source - HARDCODED
155                                 def source = "VID"
156                                 execution.setVariable("DCVFM_source", source)
157                                 rollbackData.put("VFMODULE", "source", source)
158                                 logDebug("source: " + source, isDebugLogEnabled)
159                                 //backoutOnFailure
160                                 def disableRollback = execution.getVariable("disableRollback")
161                                 def backoutOnFailure = true
162                                 if (disableRollback != null && disableRollback.equals("true")) {
163                                         backoutOnFailure = false
164                                 }
165                                 execution.setVariable("DCVFM_backoutOnFailure", backoutOnFailure)
166                                 logDebug("backoutOnFailure: " + backoutOnFailure, isDebugLogEnabled)
167                                 //isBaseVfModule
168                                 def isBaseVfModule = execution.getVariable("isBaseVfModule")
169                                 execution.setVariable("DCVFM_isBaseVfModule", isBaseVfModule)
170                                 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
171                                 //asdcServiceModelVersion
172                                 def asdcServiceModelVersion = execution.getVariable("asdcServiceModelVersion")
173                                 execution.setVariable("DCVFM_asdcServiceModelVersion", asdcServiceModelVersion)
174                                 logDebug("asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugLogEnabled)
175                                 //personaModelId
176                                 execution.setVariable("DCVFM_personaModelId", jsonUtil.getJsonValue(vfModuleModelInfo, "modelInvariantId"))
177                                 //personaModelVersion
178                                 execution.setVariable("DCVFM_personaModelVersion", jsonUtil.getJsonValue(vfModuleModelInfo, "modelVersion"))
179                                 //vfModuleLabel
180                                 def vfModuleLabel = execution.getVariable("vfModuleLabel")
181                                 if (vfModuleLabel != null) {
182                                         execution.setVariable("DCVFM_vfModuleLabel", vfModuleLabel)
183                                         logDebug("vfModuleLabel: " + vfModuleLabel, isDebugLogEnabled)
184                                 }
185                                 //Get or Generate UUID
186                                 String uuid = execution.getVariable("DCVFM_uuid")
187                                 if(uuid == null){
188                                         uuid = UUID.randomUUID()
189                                         logDebug("Generated messageId (UUID) is: " + uuid, isDebugLogEnabled)
190                                 }else{
191                                         logDebug("Found messageId (UUID) is: " + uuid, isDebugLogEnabled)
192                                 }
193                                 //isVidRequest
194                                 String isVidRequest = execution.getVariable("isVidRequest")
195                                 // default to true
196                                 if (isVidRequest == null || isVidRequest.isEmpty()) {
197                                         execution.setVariable("isVidRequest", "true")
198                                 }
199                                 //globalSubscriberId
200                                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
201                                 execution.setVariable("DCVFM_globalSubscriberId", globalSubscriberId)
202                                 logDebug("globalSubsrciberId: " + globalSubscriberId, isDebugLogEnabled)                                
203                                 Map<String,String> vfModuleInputParams = execution.getVariable("vfModuleInputParams")
204                                 if (vfModuleInputParams != null) {
205                                         execution.setVariable("DCVFM_vnfParamsMap", vfModuleInputParams)
206                                         execution.setVariable("DCVFM_vnfParamsExistFlag", true)
207                                 }
208                                 //usePreload
209                                 def usePreload = execution.getVariable("usePreload")
210                                 execution.setVariable("DCVFM_usePreload", usePreload)
211                                 logDebug("usePreload: " + usePreload, isDebugLogEnabled)
212
213                         }
214                         else {
215                                 // The info is inside the request - DEAD CODE
216                                 utils.logAudit("DoCreateVfModule request: " + request)
217
218                                 //tenantId
219                                 def tenantId = ""
220                                 if (utils.nodeExists(request, "tenant-id")) {
221                                         tenantId = utils.getNodeText(request, "tenant-id")
222                                 }
223                                 execution.setVariable("DCVFM_tenantId", tenantId)
224                                 rollbackData.put("VFMODULE", "tenantid", tenantId)
225                                 //volumeGroupId
226                                 def volumeGroupId = ""
227                                 if (utils.nodeExists(request, "volume-group-id")) {
228                                         volumeGroupId = utils.getNodeText(request, "volume-group-id")
229                                 }
230                                 execution.setVariable("DCVFM_volumeGroupId", volumeGroupId)
231                                 //volumeGroupId
232                                 def volumeGroupName = ""
233                                 if (utils.nodeExists(request, "volume-group-name")) {
234                                         volumeGroupName = utils.getNodeText(request, "volume-group-name")
235                                 }
236                                 execution.setVariable("DCVFM_volumeGroupName", volumeGroupName)
237                                 //cloudSiteId
238                                 def cloudSiteId = ""
239                                 if (utils.nodeExists(request, "aic-cloud-region")) {
240                                         cloudSiteId = utils.getNodeText(request, "aic-cloud-region")
241                                 }
242                                 execution.setVariable("DCVFM_cloudSiteId", cloudSiteId)
243                                 rollbackData.put("VFMODULE", "aiccloudregion", cloudSiteId)
244                                 logDebug("cloudSiteId: " + cloudSiteId, isDebugLogEnabled)
245                                 //vnfType
246                                 def vnfType = ""
247                                 if (utils.nodeExists(request, "vnf-type")) {
248                                         vnfType = utils.getNodeText(request, "vnf-type")
249                                 }
250                                 execution.setVariable("DCVFM_vnfType", vnfType)
251                                 rollbackData.put("VFMODULE", "vnftype", vnfType)
252                                 logDebug("vnfType: " + vnfType, isDebugLogEnabled)
253                                 //vnfName
254                                 def vnfName = ""
255                                 if (utils.nodeExists(request, "vnf-name")) {
256                                         vnfName = utils.getNodeText(request, "vnf-name")
257                                 }
258                                 execution.setVariable("DCVFM_vnfName", vnfName)
259                                 rollbackData.put("VFMODULE", "vnfname", vnfName)
260                                 logDebug("vnfName: " + vnfName, isDebugLogEnabled)
261                                 //vnfId
262                                 def vnfId = ""
263                                 if (utils.nodeExists(request, "vnf-id")) {
264                                         vnfId = utils.getNodeText(request, "vnf-id")
265                                 }
266                                 execution.setVariable("DCVFM_vnfId", vnfId)
267                                 rollbackData.put("VFMODULE", "vnfid", vnfId)
268                                 logDebug("vnfId: " + vnfId, isDebugLogEnabled)
269                                 //vfModuleName
270                                 def vfModuleName = ""
271                                 if (utils.nodeExists(request, "vf-module-name")) {
272                                         vfModuleName = utils.getNodeText(request, "vf-module-name")
273                                 }
274                                 execution.setVariable("DCVFM_vfModuleName", vfModuleName)
275                                 rollbackData.put("VFMODULE", "vfmodulename", vfModuleName)
276                                 logDebug("vfModuleName: " + vfModuleName, isDebugLogEnabled)
277                                 //vfModuleModelName
278                                 def vfModuleModelName = ""
279                                 if (utils.nodeExists(request, "vf-module-model-name")) {
280                                         vfModuleModelName = utils.getNodeText(request, "vf-module-model-name")
281                                 }
282                                 execution.setVariable("DCVFM_vfModuleModelName", vfModuleModelName)
283                                 rollbackData.put("VFMODULE", "vfmodulemodelname", vfModuleModelName)
284                                 logDebug("vfModuleModelName: " + vfModuleModelName, isDebugLogEnabled)
285                                 //modelCustomizationUuid
286                                 def modelCustomizationUuid = ""
287                                 if (utils.nodeExists(request, "model-customization-id")) {
288                                         modelCustomizationUuid = utils.getNodeText(request, "model-customization-id")
289                                 }
290                                 execution.setVariable("DCVFM_modelCustomizationUuid", modelCustomizationUuid)
291                                 rollbackData.put("VFMODULE", "modelcustomizationuuid", modelCustomizationUuid)
292                                 logDebug("modelCustomizationUuid: " + modelCustomizationUuid, isDebugLogEnabled)
293                                 //vfModuleId
294                                 def vfModuleId = ""
295                                 if (utils.nodeExists(request, "vf-module-id")) {
296                                         vfModuleId = utils.getNodeText(request, "vf-module-id")
297                                 }
298                                 execution.setVariable("DCVFM_vfModuleId", vfModuleId)
299                                 logDebug("vfModuleId: " + vfModuleId, isDebugLogEnabled)
300                                 def requestId = ""
301                                 if (utils.nodeExists(request, "request-id")) {
302                                         requestId = utils.getNodeText(request, "request-id")
303                                 }
304                                 execution.setVariable("DCVFM_requestId", requestId)
305                                 logDebug("requestId: " + requestId, isDebugLogEnabled)
306                                 //serviceId
307                                 def serviceId = ""
308                                 if (utils.nodeExists(request, "service-id")) {
309                                         serviceId = utils.getNodeText(request, "service-id")
310                                 }
311                                 execution.setVariable("DCVFM_serviceId", serviceId)
312                                 logDebug("serviceId: " + serviceId, isDebugLogEnabled)
313                                 //serviceInstanceId
314                                 def serviceInstanceId = ""
315                                 if (utils.nodeExists(request, "service-instance-id")) {
316                                         serviceInstanceId = utils.getNodeText(request, "service-instance-id")
317                                 }
318                                 execution.setVariable("DCVFM_serviceInstanceId", serviceInstanceId)
319                                 rollbackData.put("VFMODULE", "serviceInstanceId", serviceInstanceId)
320                                 logDebug("serviceInstanceId: " + serviceInstanceId, isDebugLogEnabled)
321                                 //source
322                                 def source = ""
323                                 if (utils.nodeExists(request, "source")) {
324                                         source = utils.getNodeText(request, "source")
325                                 }
326                                 execution.setVariable("DCVFM_source", source)
327                                 rollbackData.put("VFMODULE", "source", source)
328                                 logDebug("source: " + source, isDebugLogEnabled)
329                                 //backoutOnFailure
330                                 NetworkUtils networkUtils = new NetworkUtils()
331                                 def backoutOnFailure = networkUtils.isRollbackEnabled(execution,request)
332                                 execution.setVariable("DCVFM_backoutOnFailure", backoutOnFailure)
333                                 logDebug("backoutOnFailure: " + backoutOnFailure, isDebugLogEnabled)
334                                 //isBaseVfModule
335                                 def isBaseVfModule = "false"
336                                 if (utils.nodeExists(request, "is-base-vf-module")) {
337                                         isBaseVfModule = utils.getNodeText(request, "is-base-vf-module")
338                                 }
339                                 execution.setVariable("DCVFM_isBaseVfModule", isBaseVfModule)
340                                 logDebug("isBaseVfModule: " + isBaseVfModule, isDebugLogEnabled)
341
342                                 //asdcServiceModelVersion
343                                 def asdcServiceModelVersion = ""
344                                 if (utils.nodeExists(request, "asdc-service-model-version")) {
345                                         asdcServiceModelVersion = utils.getNodeText(request, "asdc-service-model-version")
346                                 }
347                                 execution.setVariable("DCVFM_asdcServiceModelVersion", asdcServiceModelVersion)
348                                 logDebug("asdcServiceModelVersion: " + asdcServiceModelVersion, isDebugLogEnabled)
349
350                                 //personaModelId
351                                 def personaModelId = ""
352                                 if (utils.nodeExists(request, "persona-model-id")) {
353                                         personaModelId = utils.getNodeText(request, "persona-model-id")
354                                 }
355                                 execution.setVariable("DCVFM_personaModelId", personaModelId)
356                                 logDebug("personaModelId: " + personaModelId, isDebugLogEnabled)
357
358                                 //personaModelVersion
359                                 def personaModelVersion = ""
360                                 if (utils.nodeExists(request, "persona-model-version")) {
361                                         personaModelVersion = utils.getNodeText(request, "persona-model-version")
362                                 }
363                                 execution.setVariable("DCVFM_personaModelVersion", personaModelVersion)
364                                 logDebug("personaModelVersion: " + personaModelVersion, isDebugLogEnabled)
365
366                                 // Process the parameters
367
368                                                 String vnfParamsChildNodes = utils.getChildNodes(request, "vnf-params")
369                                                 if(vnfParamsChildNodes == null || vnfParamsChildNodes.length() < 1){
370                                                                 utils.log("DEBUG", "Request contains NO VNF Params", isDebugLogEnabled)
371                                                 }else{
372                                                                 utils.log("DEBUG", "Request does contain VNF Params", isDebugLogEnabled)
373                                                                 execution.setVariable("DCVFM_vnfParamsExistFlag", true)
374
375                                                                 InputSource xmlSource = new InputSource(new StringReader(request));
376                                                                 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
377                                                                 docFactory.setNamespaceAware(true)
378                                                                 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
379                                                                 Document xml = docBuilder.parse(xmlSource)
380                                                                 //Get params, build map
381                                                                 Map<String, String> paramsMap = new HashMap<String, String>()
382                                                                 NodeList paramsList = xml.getElementsByTagNameNS("*", "param")
383
384                                                                 for (int z = 0; z < paramsList.getLength(); z++) {
385                                                                         Node node = paramsList.item(z)
386                                                                         String paramValue = node.getTextContent()
387                                                                         NamedNodeMap e = node.getAttributes()
388                                                                         String paramName = e.getNamedItem("name").getTextContent()
389                                                                         paramsMap.put(paramName, paramValue)
390                                                                 }
391                                                                 execution.setVariable("DCVFM_vnfParamsMap", paramsMap)
392                                                         }
393                         }
394
395                         //Get or Generate UUID
396                         String uuid = execution.getVariable("DCVFM_uuid")
397                         if(uuid == null){
398                                 uuid = UUID.randomUUID()
399                                 logDebug("Generated messageId (UUID) is: " + uuid, isDebugLogEnabled)
400                         }else{
401                                 logDebug("Found messageId (UUID) is: " + uuid, isDebugLogEnabled)
402                         }
403                         // Get sdncVersion, default to empty
404                         String sdncVersion = execution.getVariable("sdncVersion")
405                         if (sdncVersion == null) {
406                                 sdncVersion = ""
407                         }
408                         logDebug("sdncVersion: " + sdncVersion, isDebugLogEnabled)
409                         execution.setVariable("DCVFM_sdncVersion", sdncVersion)
410                         
411                         execution.setVariable("DCVFM_uuid", uuid)
412                         execution.setVariable("DCVFM_baseVfModuleId", "")
413                         execution.setVariable("DCVFM_baseVfModuleHeatStackId", "")
414                         execution.setVariable("DCVFM_heatStackId", "")
415                         execution.setVariable("DCVFM_contrailServiceInstanceFqdn", "")
416                         execution.setVariable("DCVFM_volumeGroupStackId", "")
417                         execution.setVariable("DCVFM_cloudRegionForVolume", "")
418                         execution.setVariable("DCVFM_contrailNetworkPolicyFqdnList", "")
419                         execution.setVariable("DCVFM_vnfTypeToQuery", "generic-vnf")
420                         rollbackData.put("VFMODULE", "rollbackPrepareUpdateVfModule", "false")
421                         rollbackData.put("VFMODULE", "rollbackUpdateAAIVfModule", "false")
422                         rollbackData.put("VFMODULE", "rollbackVnfAdapterCreate", "false")
423                         rollbackData.put("VFMODULE", "rollbackSDNCRequestActivate", "false")
424                         rollbackData.put("VFMODULE", "rollbackSDNCRequestAssign", "false")
425                         rollbackData.put("VFMODULE", "rollbackCreateAAIVfModule", "false")
426                         rollbackData.put("VFMODULE", "rollbackCreateNetworkPoliciesAAI", "false")
427                         rollbackData.put("VFMODULE", "rollbackUpdateVnfAAI", "false")
428
429                         String sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
430                                 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
431                                         def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
432                                         logError(msg)
433                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
434                                 }
435                                 execution.setVariable("DCVFM_sdncCallbackUrl", sdncCallbackUrl)
436                                 utils.logAudit("SDNC Callback URL: " + sdncCallbackUrl)
437                             logDebug("SDNC Callback URL is: " + sdncCallbackUrl, isDebugLogEnabled)
438
439
440                         execution.setVariable("RollbackData", rollbackData)
441                 }catch(BpmnError b){
442                         throw b
443                 }catch(Exception e){
444                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
445                 }
446
447                 logDebug('Exited ' + method, isDebugLogEnabled)
448         }
449
450         /**
451          * Validates a workflow response.
452          * @param execution the execution
453          * @param responseVar the execution variable in which the response is stored
454          * @param responseCodeVar the execution variable in which the response code is stored
455          * @param errorResponseVar the execution variable in which the error response is stored
456          */
457         public void validateWorkflowResponse(Execution execution, String responseVar,
458                         String responseCodeVar, String errorResponseVar) {
459                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
460                 sdncAdapterUtils.validateSDNCResponse(execution, responseVar, responseCodeVar, errorResponseVar)
461         }
462
463
464         /**
465          * Sends the empty, synchronous response back to the API Handler.
466          * @param execution the execution
467          */
468         public void sendResponse(Execution execution) {
469                 def method = getClass().getSimpleName() + '.sendResponse(' +
470                         'execution=' + execution.getId() +
471                         ')'
472                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
473                 logDebug('Entered ' + method, isDebugLogEnabled)
474
475                 try {
476                         sendWorkflowResponse(execution, 200, "")
477                         logDebug('Exited ' + method, isDebugLogEnabled)
478                 } catch (BpmnError e) {
479                         throw e;
480                 } catch (Exception e) {
481                         logError('Caught exception in ' + method, e)
482                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Internal Error')
483                 }
484         }
485
486         /**
487          * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
488          * A 200 response is expected with the VNF info in the response body. Will find out the base module info
489          * and existing VNF's name for add-on modules
490          *
491          * @param execution The flow's execution instance.
492          */
493         public void postProcessCreateAAIVfModule(Execution execution) {
494                 def method = getClass().getSimpleName() + '.getVfModule(' +
495                         'execution=' + execution.getId() +
496                         ')'
497                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
498                 logDebug('Entered ' + method, isDebugLogEnabled)
499
500                 try {
501                         def createResponse = execution.getVariable('DCVFM_createVfModuleResponse')
502                         utils.logAudit("createVfModule Response: " + createResponse)
503
504                         def rollbackData = execution.getVariable("RollbackData")
505                         String vnfName = utils.getNodeText1(createResponse, 'vnf-name')
506                         if (vnfName != null) {
507                                 execution.setVariable('DCVFM_vnfName', vnfName)
508                                 logDebug("vnfName retrieved from AAI is: " + vnfName, isDebugLogEnabled)
509                                 rollbackData.put("VFMODULE", "vnfname", vnfName)
510                         }
511                         String vnfId = utils.getNodeText1(createResponse, 'vnf-id')
512                         execution.setVariable('DCVFM_vnfId', vnfId)
513                         logDebug("vnfId is: " + vnfId, isDebugLogEnabled)
514                         String vfModuleId = utils.getNodeText1(createResponse, 'vf-module-id')
515                         execution.setVariable('DCVFM_vfModuleId', vfModuleId)
516                         logDebug("vfModuleId is: " + vfModuleId, isDebugLogEnabled)
517                         String vfModuleIndex= utils.getNodeText1(createResponse, 'vf-module-index')
518                         execution.setVariable('DCVFM_vfModuleIndex', vfModuleIndex)
519                         logDebug("vfModuleIndex is: " + vfModuleIndex, isDebugLogEnabled)
520                         rollbackData.put("VFMODULE", "vnfid", vnfId)
521                         rollbackData.put("VFMODULE", "vfmoduleid", vfModuleId)
522                         rollbackData.put("VFMODULE", "rollbackCreateAAIVfModule", "true")
523                         rollbackData.put("VFMODULE", "rollbackPrepareUpdateVfModule", "true")
524                         execution.setVariable("RollbackData", rollbackData)
525                 } catch (Exception ex) {
526                                 ex.printStackTrace()
527                                 logDebug('Exception occurred while postProcessing CreateAAIVfModule request:' + ex.getMessage(),isDebugLogEnabled)
528                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Bad response from CreateAAIVfModule' + ex.getMessage())
529                 }
530                 logDebug('Exited ' + method, isDebugLogEnabled)
531         }
532
533
534         /**
535          * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
536          * A 200 response is expected with the VNF info in the response body. Will find out the base module info.
537          *
538          * @param execution The flow's execution instance.
539          */
540         public void queryAAIVfModule(Execution execution) {
541                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
542                 def method = getClass().getSimpleName() + '.getVfModule(' +
543                         'execution=' + execution.getId() +
544                         ')'
545                 logDebug('Entered ' + method, isDebugLogEnabled)
546
547                 try {
548                         def vnfId = execution.getVariable('DCVFM_vnfId')
549                         def vfModuleId = execution.getVariable('DCVFM_vfModuleId')
550
551                         AaiUtil aaiUriUtil = new AaiUtil(this)
552                         String  aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
553                         logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
554
555                         String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
556                         utils.logAudit("AAI endPoint: " + endPoint)
557
558                         try {
559                                 RESTConfig config = new RESTConfig(endPoint);
560                                 def responseData = ''
561                                 def aaiRequestId = UUID.randomUUID().toString()
562                                 RESTClient client = new RESTClient(config).
563                                         addHeader('X-TransactionId', aaiRequestId).
564                                         addHeader('X-FromAppId', 'MSO').
565                                         addHeader('Content-Type', 'application/xml').
566                                         addHeader('Accept','application/xml');
567                                 logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
568                                 APIResponse response = client.httpGet()
569                                 utils.logAudit("createVfModule - invoking httpGet() to AAI")
570
571                                 responseData = response.getResponseBodyAsString()
572                                 if (responseData != null) {
573                                         logDebug("Received generic VNF data: " + responseData, isDebugLogEnabled)
574
575                                 }
576
577                                 utils.logAudit("createVfModule - queryAAIVfModule Response: " + responseData)
578                                 utils.logAudit("createVfModule - queryAAIVfModule ResponseCode: " + response.getStatusCode())
579
580                                 execution.setVariable('DCVFM_queryAAIVfModuleResponseCode', response.getStatusCode())
581                                 execution.setVariable('DCVFM_queryAAIVfModuleResponse', responseData)
582                                 logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
583                                 logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
584                                 if (response.getStatusCode() == 200) {
585                                         // Parse the VNF record from A&AI to find base module info
586                                         logDebug('Parsing the VNF data to find base module info', isDebugLogEnabled)
587                                         if (responseData != null) {
588                                                 def vfModulesText = utils.getNodeXml(responseData, "vf-modules")
589                                                 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
590                                                 def vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
591                                                 int vfModulesSize = 0
592                                                 for (i in 0..vfModules.size()-1) {
593                                                         def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
594                                                         def isBaseVfModule = utils.getNodeText(vfModuleXml, "is-base-vf-module")
595
596                                                         if (isBaseVfModule == "true") {
597                                                             String baseModuleId = utils.getNodeText1(vfModuleXml, "vf-module-id")
598                                                             execution.setVariable("DCVFM_baseVfModuleId", baseModuleId)
599                                                             logDebug('Received baseVfModuleId: ' + baseModuleId, isDebugLogEnabled)
600                                                             String baseModuleHeatStackId = utils.getNodeText1(vfModuleXml, "heat-stack-id")
601                                                             execution.setVariable("DCVFM_baseVfModuleHeatStackId", baseModuleHeatStackId)
602                                                             logDebug('Received baseVfModuleHeatStackId: ' + baseModuleHeatStackId, isDebugLogEnabled)
603                                                         }
604                                                 }
605                                         }
606                                 }
607                         } catch (Exception ex) {
608                                 ex.printStackTrace()
609                                 logDebug('Exception occurred while executing AAI GET:' + ex.getMessage(),isDebugLogEnabled)
610                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
611                         }
612                         logDebug('Exited ' + method, isDebugLogEnabled)
613                 } catch (BpmnError e) {
614                         throw e;
615                 } catch (Exception e) {
616                         logError('Caught exception in ' + method, e)
617                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())
618                 }
619         }
620
621
622         public void preProcessSDNCAssignRequest(Execution execution){
623                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
624                 execution.setVariable("prefix", Prefix)
625                 logDebug(" ======== STARTED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
626                 def vnfId = execution.getVariable("DCVFM_vnfId")
627                 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
628                 def serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId")
629                 logDebug("NEW VNF ID: " + vnfId, isDebugLogEnabled)
630                 utils.logAudit("NEW VNF ID: " + vnfId)
631
632                 try{
633
634                         //Build SDNC Request
635
636                         def svcInstId = ""
637                         if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
638                                 svcInstId = vfModuleId
639                         }
640                         else {
641                                 svcInstId = serviceInstanceId
642                         }
643
644                         String assignSDNCRequest = buildSDNCRequest(execution, svcInstId, "assign")
645
646                         assignSDNCRequest = utils.formatXml(assignSDNCRequest)
647                         execution.setVariable("DCVFM_assignSDNCRequest", assignSDNCRequest)
648                         logDebug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest, isDebugLogEnabled)
649                         utils.logAudit("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
650
651                 }catch(Exception e){
652                         utils.log("ERROR", "Exception Occured Processing preProcessSDNCAssignRequest. Exception is:\n" + e, isDebugLogEnabled)
653                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareProvision Method:\n" + e.getMessage())
654                 }
655                 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
656         }
657
658         public void preProcessSDNCGetRequest(Execution execution, String element){
659                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
660                 String sdncVersion = execution.getVariable("DCVFM_sdncVersion")
661                 execution.setVariable("prefix", Prefix)
662                 utils.log("DEBUG", " ======== STARTED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
663                 try{
664                         def serviceInstanceId = execution.getVariable('DCVFM_serviceInstanceId')
665                         
666                         String uuid = execution.getVariable('testReqId') // for junits
667                         if(uuid==null){
668                                 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
669                         }
670                                         
671                         def callbackUrl = execution.getVariable("DCVFM_sdncCallbackUrl")
672                         utils.logAudit("callbackUrl:" + callbackUrl)
673                         
674                         def vfModuleId = execution.getVariable('DCVFM_vfModuleId')
675                         
676                         def svcInstId = ""
677                         if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
678                                 svcInstId = vfModuleId
679                         }
680                         else {
681                                 svcInstId = serviceInstanceId
682                         }
683                         // For VNF, serviceOperation (URI for topology GET) will be retrieved from "selflink" element 
684                         // in the response from GenericGetVnf
685                         // For VF Module, in 1707 serviceOperation will be retrieved from "object-path" element
686                         // in SDNC Assign Response
687                         // For VF Module for older versions, serviceOperation is constructed using vfModuleId
688                         
689                         String serviceOperation = ""
690                         if (element.equals("vnf")) {
691                                 def vnfQueryResponse = execution.getVariable("DCVFM_vnfQueryResponse")
692                                 serviceOperation = utils.getNodeText1(vnfQueryResponse, "selflink")
693                                 utils.log("DEBUG", "VNF - service operation: " + serviceOperation, isDebugLogEnabled)
694                         }
695                         else if (element.equals("vfmodule")) {
696                                 String response = execution.getVariable("DCVFM_assignSDNCAdapterResponse")
697                                 utils.logAudit("DCVFM_assignSDNCAdapterResponse is: \n" + response)                                                     
698                         
699                                 if (!sdncVersion.equals("1707")) {
700                                         serviceOperation = "/VNF-API:vnfs/vnf-list/" + vfModuleId
701                                         utils.log("DEBUG", "VF Module with sdncVersion before 1707 - service operation: " + serviceOperation, isDebugLogEnabled)
702                                 }
703                                 else {                          
704                                         String data = utils.getNodeXml(response, "response-data")                                       
705                                         data = data.replaceAll("&lt;", "<")
706                                         data = data.replaceAll("&gt;", ">")
707                                         utils.log("DEBUG", "responseData: " + data, isDebugLogEnabled)
708                                         serviceOperation = utils.getNodeText1(data, "object-path")
709                                         utils.log("DEBUG", "VF Module with sdncVersion of 1707 - service operation: " + serviceOperation, isDebugLogEnabled)
710                                 }                               
711                         }               
712
713                         //!!!! TEMPORARY WORKAROUND FOR SDNC REPLICATION ISSUE
714                         sleep(5000)
715
716                         String SDNCGetRequest =
717                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
718                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
719                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
720                                         <sdncadapter:RequestHeader>
721                                         <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
722                                         <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
723                                         <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
724                                         <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
725                                         <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
726                                         <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
727                                 </sdncadapter:RequestHeader>
728                                         <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
729                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
730
731                         utils.logAudit("SDNCGetRequest: \n" + SDNCGetRequest)
732                         execution.setVariable("DCVFM_getSDNCRequest", SDNCGetRequest)
733                         utils.log("DEBUG", "Outgoing GetSDNCRequest is: \n" + SDNCGetRequest, isDebugLogEnabled)
734
735                 }catch(Exception e){
736                         utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled)
737                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
738                 }
739                 utils.log("DEBUG", "======== COMPLETED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
740         }
741
742
743         public void preProcessVNFAdapterRequest(Execution execution) {
744                 def method = getClass().getSimpleName() + '.VNFAdapterCreateVfModule(' +
745                         'execution=' + execution.getId() +
746                         ')'
747                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
748                 logDebug('Entered ' + method, isDebugLogEnabled)
749
750                 //def xml = execution.getVariable("DoCreateVfModuleRequest")
751                 //logDebug('VNF REQUEST is: ' + xml, isDebugLogEnabled)
752
753                 //Get variables
754                 //cloudSiteId
755                 def cloudSiteId = execution.getVariable("DCVFM_cloudSiteId")
756                 //tenantId
757                 def tenantId = execution.getVariable("DCVFM_tenantId")
758                 //vnfType
759                 def vnfType = execution.getVariable("DCVFM_vnfType")
760                 //vnfName
761                 def vnfName = execution.getVariable("DCVFM_vnfName")
762                 //vnfId
763                 def vnfId = execution.getVariable("DCVFM_vnfId")
764                 //vfModuleName
765                 def vfModuleName = execution.getVariable("DCVFM_vfModuleName")
766                 //vfModuleModelName
767                 def vfModuleModelName = execution.getVariable("DCVFM_vfModuleModelName")
768                 //vfModuleId
769                 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
770                 //vfModuleIndex
771                 def vfModuleIndex = execution.getVariable("DCVFM_vfModuleIndex")
772                 //requestId
773                 def requestId = execution.getVariable("DCVFM_requestId")
774                 //serviceId
775                 def serviceId = execution.getVariable("DCVFM_serviceId")
776                 //serviceInstanceId
777                 def serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId")
778                 //backoutOnFailure
779                 def backoutOnFailure = execution.getVariable("DCVFM_backoutOnFailure")
780                 //volumeGroupId
781                 def volumeGroupId = execution.getVariable("DCVFM_volumeGroupId")
782                 // baseVfModuleId
783                 def baseVfModuleId = execution.getVariable("DCVFM_baseVfModuleId")
784                 // baseVfModuleStackId
785                 def baseVfModuleStackId = execution.getVariable("DCVFM_baseVfModuleHeatStackId")
786                 // asdcServiceModelVersion
787                 def asdcServiceModelVersion = execution.getVariable("DCVFM_asdcServiceModelVersion")
788                 //volumeGroupStackId
789                 def volumeGroupStackId = execution.getVariable("DCVFM_volumeGroupStackId")
790                 //modelCustomizationUuid
791                 def modelCustomizationUuid = execution.getVariable("DCVFM_modelCustomizationUuid")
792
793                 def messageId = execution.getVariable('mso-request-id') + '-' +
794                                 System.currentTimeMillis()
795
796                 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
797                 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
798
799                 utils.logAudit("notificationUrl: " + notificationUrl)
800                 utils.logAudit("QualifiedHostName: " + useQualifiedHostName)
801
802                 if ('true'.equals(useQualifiedHostName)) {
803                         notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
804                 }
805
806                 Map<String, String> vnfParamsMap = execution.getVariable("DCVFM_vnfParamsMap")
807                 
808                 //Get SDNC Response Data for VnfSubCreate Request
809                 String sdncGetResponse = execution.getVariable('DCVFM_getSDNCAdapterResponse')
810                 utils.logAudit("sdncGetResponse: " + sdncGetResponse)
811
812                 String vfModuleParams = buildVfModuleParams(vnfParamsMap, sdncGetResponse, vnfId, vnfName,
813                                 vfModuleId, vfModuleName, vfModuleIndex)
814
815                 def svcInstId = ""
816                 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
817                                 svcInstId = serviceId
818                 }
819                 else {
820                         svcInstId = serviceInstanceId
821                 }
822
823                 def createVnfARequest = """
824                 <createVfModuleRequest>
825                 <cloudSiteId>${cloudSiteId}</cloudSiteId>
826                 <tenantId>${tenantId}</tenantId>
827                 <vnfId>${vnfId}</vnfId>
828                 <vnfName>${vnfName}</vnfName>
829                 <vfModuleName>${vfModuleName}</vfModuleName>
830                 <vfModuleId>${vfModuleId}</vfModuleId>
831                 <vnfType>${vnfType}</vnfType>
832                 <vfModuleType>${vfModuleModelName}</vfModuleType>
833                 <vnfVersion>${asdcServiceModelVersion}</vnfVersion>
834                 <modelCustomizationUuid>${modelCustomizationUuid}</modelCustomizationUuid>
835                 <requestType></requestType>
836                 <volumeGroupId>${volumeGroupId}</volumeGroupId>
837         <volumeGroupStackId>${volumeGroupStackId}</volumeGroupStackId>
838         <baseVfModuleId>${baseVfModuleId}</baseVfModuleId>
839         <baseVfModuleStackId>${baseVfModuleStackId}</baseVfModuleStackId>
840         <skipAAI>true</skipAAI>
841         <backout>${backoutOnFailure}</backout>
842         <failIfExists>true</failIfExists>
843                 <vfModuleParams>
844                 ${vfModuleParams}
845                 </vfModuleParams>
846                 <msoRequest>
847                         <requestId>${requestId}</requestId>
848                         <serviceInstanceId>${svcInstId}</serviceInstanceId>
849                 </msoRequest>
850                 <messageId>${messageId}</messageId>
851                 <notificationUrl>${notificationUrl}</notificationUrl>
852                 </createVfModuleRequest>"""
853
854                 utils.logAudit("Create VfModule Request to VNF Adapter : " + createVnfARequest)
855                 logDebug("Create VfModule Request to VNF Adapter: " + createVnfARequest, isDebugLogEnabled)
856                 execution.setVariable("DCVFM_createVnfARequest", createVnfARequest)
857         }
858
859         /**
860          * Validates the request, request id and service instance id.  If a problem is found,
861          * a WorkflowException is generated and an MSOWorkflowException event is thrown. This
862          * method also sets up the log context for the workflow.
863          * @param execution the execution
864          * @return the validated request
865          */
866         public String validateInfraRequest(Execution execution) {
867                 def method = getClass().getSimpleName() + '.validateInfraRequest(' +
868                         'execution=' + execution.getId() +
869                         ')'
870                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
871                 logDebug('Entered ' + method, isDebugLogEnabled)
872
873                 String processKey = getProcessKey(execution);
874                 def prefix = execution.getVariable("prefix")
875
876                 if (prefix == null) {
877                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " prefix is null")
878                 }
879
880                 try {
881                         def request = execution.getVariable(prefix + 'Request')
882
883                         if (request == null) {
884                                 request = execution.getVariable(processKey + 'Request')
885
886                                 if (request == null) {
887                                         request = execution.getVariable('bpmnRequest')
888                                 }
889
890                                 setVariable(execution, processKey + 'Request', null);
891                                 setVariable(execution, 'bpmnRequest', null);
892                                 setVariable(execution, prefix + 'Request', request);
893                         }
894
895                         if (request == null) {
896                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request is null")
897                         }
898                         utils.logAudit("DoCreateVfModule Request: " + request)
899
900                         /*
901
902                         def requestId = execution.getVariable("mso-request-id")
903
904                         if (requestId == null) {
905                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request has no mso-request-id")\r
906                         }
907
908                         def serviceInstanceId = execution.getVariable("mso-service-instance-id")
909
910                         if (serviceInstanceId == null) {
911                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, processKey + " request message has no mso-service-instance-id")\r
912                         }
913
914                         utils.logContext(requestId, serviceInstanceId)
915                         */
916                         logDebug('Incoming message: ' + System.lineSeparator() + request, isDebugLogEnabled)
917                         logDebug('Exited ' + method, isDebugLogEnabled)
918                         return request
919                 } catch (BpmnError e) {
920                         throw e;
921                 } catch (Exception e) {
922                         logError('Caught exception in ' + method, e)
923                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")
924                 }
925         }
926
927         public boolean isVolumeGroupIdPresent(Execution execution) {
928
929                 def method = getClass().getSimpleName() + '.isVolumeGroupIdPresent(' +
930                         'execution=' + execution.getId() +
931                         ')'
932                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
933                 logDebug('Entered ' + method, isDebugLogEnabled)
934
935                 def request = execution.getVariable('DoCreateVfModuleRequest')
936                 String volumeGroupId = utils.getNodeText1(request, "volume-group-id")
937                 if (volumeGroupId == null || volumeGroupId.isEmpty()) {
938                         logDebug('No volume group id is present', isDebugLogEnabled)
939                         return false
940                 }
941                 else {
942                         logDebug('Volume group id is present', isDebugLogEnabled)
943                         return true
944                 }
945
946         }
947
948         public boolean isVolumeGroupNamePresent(Execution execution) {
949
950                 def method = getClass().getSimpleName() + '.isVolumeGroupNamePresent(' +
951                         'execution=' + execution.getId() +
952                         ')'
953                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
954                 logDebug('Entered ' + method, isDebugLogEnabled)
955
956                 def request = execution.getVariable('DoCreateVfModuleRequest')
957                 String volumeGroupName = utils.getNodeText1(request, "volume-group-name")
958                 if (volumeGroupName == null || volumeGroupName.isEmpty()) {
959                         logDebug('No volume group name is present', isDebugLogEnabled)
960                         return false
961                 }
962                 else {
963                         logDebug('Volume group name is present', isDebugLogEnabled)
964                         return true
965                 }
966
967         }
968
969         public String buildSDNCRequest(Execution execution, String svcInstId, String action){
970
971                 String uuid = execution.getVariable('testReqId') // for junits
972                 if(uuid==null){
973                         uuid = execution.getVariable("mso-request-id") + "-" +          System.currentTimeMillis()
974                 }
975                 def callbackURL = execution.getVariable("DCVFM_sdncCallbackUrl")
976                 def requestId = execution.getVariable("DCVFM_requestId")
977                 def serviceId = execution.getVariable("DCVFM_serviceId")
978                 def vnfType = execution.getVariable("DCVFM_vnfType")
979                 def vnfName = execution.getVariable("DCVFM_vnfName")
980                 def tenantId = execution.getVariable("DCVFM_tenantId")
981                 def source = execution.getVariable("DCVFM_source")
982                 def backoutOnFailure = execution.getVariable("DCVFM_backoutOnFailure")
983                 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
984                 def vfModuleName = execution.getVariable("DCVFM_vfModuleName")
985                 def vfModuleModelName = execution.getVariable("DCVFM_vfModuleModelName")
986                 def vnfId = execution.getVariable("DCVFM_vnfId")
987                 def cloudSiteId = execution.getVariable("DCVFM_cloudSiteId")
988                 def sdncVersion = execution.getVariable("DCVFM_sdncVersion")
989                 def serviceModelInfo = execution.getVariable("serviceModelInfo")
990                 def vnfModelInfo = execution.getVariable("vnfModelInfo")
991                 def vfModuleModelInfo = execution.getVariable("vfModuleModelInfo")
992                 String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
993                 String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)
994                 String vfModuleEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vfModuleModelInfo)
995                 def globalSubscriberId = execution.getVariable("DCVFM_globalSubscriberId")
996                 boolean usePreload = execution.getVariable("DCVFM_usePreload")
997                 String usePreloadToSDNC = usePreload ? "Y" : "N"
998                 def modelCustomizationUuid = execution.getVariable("DCVFM_modelCustomizationUuid")
999                 def modelCustomizationUuidString = ""
1000                 if (!usePreload) {
1001                         modelCustomizationUuidString = "<modelCustomizationUuid>" + modelCustomizationUuid + "</modelCustomizationUuid>"
1002                 }
1003
1004                 String sdncVNFParamsXml = ""
1005
1006                 if(execution.getVariable("DCVFM_vnfParamsExistFlag") == true){
1007                         sdncVNFParamsXml = buildSDNCParamsXml(execution)
1008                 }else{
1009                         sdncVNFParamsXml = ""
1010                 }
1011                 
1012                 String sdncRequest = ""
1013                 
1014                 if (!sdncVersion.equals("1707")) {
1015
1016                         sdncRequest =
1017         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1018                                                     xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1019                                                     xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">\r
1020            <sdncadapter:RequestHeader>
1021                                 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
1022                                 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
1023                                 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
1024                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
1025                                 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
1026                 </sdncadapter:RequestHeader>
1027         <sdncadapterworkflow:SDNCRequestData>
1028                 <request-information>
1029                         <request-id>${requestId}</request-id>
1030                         <request-action>VNFActivateRequest</request-action>
1031                         <source>${source}</source>
1032                         <notification-url/>
1033                 </request-information>
1034                 <service-information>
1035                         <service-id>${serviceId}</service-id>
1036                         <service-type>${serviceId}</service-type>
1037                         <service-instance-id>${svcInstId}</service-instance-id>
1038                         <subscriber-name>notsurewecare</subscriber-name>
1039                 </service-information>
1040                 <vnf-request-information>
1041                         <vnf-id>${vfModuleId}</vnf-id>
1042                         <vnf-type>${vfModuleModelName}</vnf-type>
1043                         <vnf-name>${vfModuleName}</vnf-name>
1044                         <generic-vnf-id>${vnfId}</generic-vnf-id>
1045                         <generic-vnf-name>${vnfName}</generic-vnf-name>
1046                         <generic-vnf-type>${vnfType}</generic-vnf-type>
1047                         <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
1048                         <tenant>${tenantId}</tenant>
1049                         ${modelCustomizationUuidString}
1050                         <use-preload>${usePreloadToSDNC}</use-preload>
1051                 ${sdncVNFParamsXml}
1052                 </vnf-request-information>
1053         </sdncadapterworkflow:SDNCRequestData>
1054         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1055                 
1056                 }
1057                 else {  
1058                         
1059                         sdncRequest =
1060         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1061                                                     xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1062                                                     xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">\r
1063            <sdncadapter:RequestHeader>
1064                                 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
1065                                 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
1066                                 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
1067                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
1068                                 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
1069                                 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
1070                 </sdncadapter:RequestHeader>
1071         <sdncadapterworkflow:SDNCRequestData>
1072                 <request-information>
1073                         <request-id>${requestId}</request-id>
1074                         <request-action>CreateVfModuleInstance</request-action>
1075                         <source>${source}</source>
1076                         <notification-url/>
1077                 </request-information>
1078                 <service-information>
1079                         <service-id>${serviceId}</service-id>
1080                         <subscription-service-type>${serviceId}</subscription-service-type>
1081                         ${serviceEcompModelInformation}
1082                         <service-instance-id>${svcInstId}</service-instance-id>
1083                         <global-customer-id>${globalSubscriberId}</global-customer-id>                  
1084                 </service-information>
1085                 <vnf-request-information>
1086                         <vnf-type>${vfModuleModelName}</vnf-type>
1087                 </vnf-request-information>
1088                 <vnf-information>
1089                         <vnf-id>${vnfId}</vnf-id>
1090                         <vnf-type>${vnfType}</vnf-type>
1091                         ${vnfEcompModelInformation}                     
1092                 </vnf-information>
1093                 <vf-module-information>
1094                         <vf-module-id>${vfModuleId}</vf-module-id>
1095                         <vf-module-type>${vfModuleModelName}</vf-module-type>
1096                         ${vfModuleEcompModelInformation}                        
1097                 </vf-module-information>
1098                 <vf-module-request-input>
1099                         <request-version>${sdncVersion}</request-version>
1100                         <vf-module-name>${vfModuleName}</vf-module-name>
1101                         <tenant>${tenantId}</tenant>
1102                         <aic-cloud-region>${cloudSiteId}</aic-cloud-region>                             
1103                 ${sdncVNFParamsXml}
1104                 </vf-module-request-input>
1105           </sdncadapterworkflow:SDNCRequestData>
1106         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1107                         
1108                         
1109                         /*
1110                         sdncRequest =
1111                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"\r
1112                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"\r
1113                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">\r
1114            <sdncadapter:RequestHeader>
1115                                 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
1116                                 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
1117                                 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
1118                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
1119                                 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
1120                 </sdncadapter:RequestHeader>
1121         <sdncadapterworkflow:SDNCRequestData>
1122                 <request-information>
1123                         <request-id>${requestId}</request-id>
1124                         <request-action>CreateVfModuleInstance</request-action>
1125                         <source>${source}</source>
1126                         <notification-url/>
1127                 </request-information>
1128                 <service-information>
1129                         <service-id>${serviceId}</service-id>
1130                         <service-type>${serviceId}</service-type>
1131                         ${serviceEcompModelInformation}                 
1132                         <service-instance-id>${svcInstId}</service-instance-id>
1133                         <global-customer-id>${globalSubscriberId}</global-customer-id>
1134                 </service-information>
1135                 <vnf-information>
1136                         <vnf-id>${vnfId}</vnf-id>
1137                         <vnf-type>${vnfType}</vnf-type>
1138                         ${vnfEcompModelInformation}                     
1139                 </vnf-information>
1140                 <vf-module-information>
1141                         <vf-module-id>${vfModuleId}</vf-module-id>
1142                         <vf-module-type>${vfModuleModelName}</vf-module-type>
1143                         ${vfModuleEcompModelInformation}                        
1144                 </vf-module-information>
1145                 <vf-module-request-input>
1146                         <request-version>${sdncVersion}</request-version>
1147                         <vf-module-name>${vfModuleName}</vf-module-name>
1148                         <tenant>${tenantId}</tenant>
1149                         <aic-cloud-region>${cloudSiteId}</aic-cloud-region>                             
1150                 ${sdncVNFParamsXml}
1151                 </vf-module-request-input>              
1152         </sdncadapterworkflow:SDNCRequestData>
1153         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1154                         */
1155                         
1156                 }
1157
1158         utils.logAudit("sdncRequest:  " + sdncRequest)
1159         return sdncRequest
1160
1161         }
1162
1163         public void preProcessSDNCActivateRequest(Execution execution) {
1164                 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
1165                         'execution=' + execution.getId() +
1166                         ')'
1167                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1168                 logDebug('Entered ' + method, isDebugLogEnabled)
1169                 execution.setVariable("prefix", Prefix)
1170                 logDebug(" ======== STARTED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
1171                 try{
1172                         String vnfId = execution.getVariable("DCVFM_vnfId")
1173                         String vfModuleId = execution.getVariable("DCVFM_vfModuleId")
1174                         String serviceInstanceId = execution.getVariable("DCVFM_serviceInstanceId")
1175
1176                         def svcInstId = ""
1177                         if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
1178                                 svcInstId = vfModuleId
1179                         }
1180                         else {
1181                                 svcInstId = serviceInstanceId
1182                         }
1183                         String activateSDNCRequest = buildSDNCRequest(execution, svcInstId, "activate")
1184
1185                         execution.setVariable("DCVFM_activateSDNCRequest", activateSDNCRequest)
1186                         logDebug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest, isDebugLogEnabled)
1187                         utils.logAudit("Outgoing CommitSDNCRequest is: \n"  + activateSDNCRequest)
1188
1189                 }catch(Exception e){
1190                         log.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e, isDebugLogEnabled)
1191                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCActivateRequest Method:\n" + e.getMessage())
1192                 }
1193                 logDebug("======== COMPLETED  preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
1194         }
1195
1196         public void postProcessVNFAdapterRequest(Execution execution) {
1197                 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
1198                         'execution=' + execution.getId() +
1199                         ')'
1200                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1201                 logDebug('Entered ' + method, isDebugLogEnabled)
1202                 execution.setVariable("prefix",Prefix)
1203                 try{
1204                 logDebug(" *** STARTED postProcessVNFAdapterRequest Process*** ", isDebugLogEnabled)
1205
1206                 String vnfResponse = execution.getVariable("DCVFM_createVnfAResponse")
1207                 logDebug("VNF Adapter Response is: " + vnfResponse, isDebugLogEnabled)
1208                 utils.logAudit("createVnfAResponse is: \n"  + vnfResponse)
1209
1210                 RollbackData rollbackData = execution.getVariable("RollbackData")
1211                 if(vnfResponse != null){
1212
1213                         if(vnfResponse.contains("createVfModuleResponse")){
1214                                 logDebug("Received a Good Response from VNF Adapter for CREATE_VF_MODULE Call.", isDebugLogEnabled)
1215                                 execution.setVariable("DCVFM_vnfVfModuleCreateCompleted", true)
1216                                 String heatStackId = utils.getNodeText1(vnfResponse, "vfModuleStackId")
1217                                 execution.setVariable("DCVFM_heatStackId", heatStackId)
1218                                 logDebug("Received heat stack id from VNF Adapter: " + heatStackId, isDebugLogEnabled)
1219                                 rollbackData.put("VFMODULE", "heatstackid", heatStackId)
1220                                 // Parse vnfOutputs for network_fqdn
1221                                 if (vnfResponse.contains("vfModuleOutputs")) {
1222                                         def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
1223                                         InputSource source = new InputSource(new StringReader(vfModuleOutputsXml));
1224                         DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
1225                         docFactory.setNamespaceAware(true)
1226                         DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
1227                         Document outputsXml = docBuilder.parse(source)
1228
1229                                         NodeList entries = outputsXml.getElementsByTagNameNS("*", "entry")
1230                                         List contrailNetworkPolicyFqdnList = []
1231                                         for (int i = 0; i< entries.getLength(); i++) {
1232                                                 Node node = entries.item(i)
1233                                                 if (node.getNodeType() == Node.ELEMENT_NODE) {
1234                                                         Element element = (Element) node
1235                                                         String key = element.getElementsByTagNameNS("*", "key").item(0).getTextContent()
1236                                                         if (key.equals("contrail-service-instance-fqdn")) {
1237                                                                 String contrailServiceInstanceFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1238                                                                 logDebug("Obtained contrailServiceInstanceFqdn: " + contrailServiceInstanceFqdn, isDebugLogEnabled)
1239                                                                 execution.setVariable("DCVFM_contrailServiceInstanceFqdn", contrailServiceInstanceFqdn)
1240                                                         }
1241                                                         else if (key.endsWith("contrail_network_policy_fqdn")) {
1242                                                                 String contrailNetworkPolicyFqdn = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1243                                                                 logDebug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn, isDebugLogEnabled)
1244                                                                 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
1245                                                         }
1246                                                         else if (key.equals("oam_management_v4_address")) {
1247                                                                 String oamManagementV4Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1248                                                                 logDebug("Obtained oamManagementV4Address: " + oamManagementV4Address, isDebugLogEnabled)
1249                                                                 execution.setVariable("DCVFM_oamManagementV4Address", oamManagementV4Address)
1250                                                         }
1251                                                         else if (key.equals("oam_management_v6_address")) {
1252                                                                 String oamManagementV6Address = element.getElementsByTagNameNS("*", "value").item(0).getTextContent()
1253                                                                 logDebug("Obtained oamManagementV6Address: " + oamManagementV6Address, isDebugLogEnabled)
1254                                                                 execution.setVariable("DCVFM_oamManagementV6Address", oamManagementV6Address)
1255                                                         }
1256
1257                                                 }
1258                                         }
1259                                         if (!contrailNetworkPolicyFqdnList.isEmpty()) {
1260                                                 execution.setVariable("DCVFM_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
1261                                         }
1262                                 }
1263                         }else{
1264                                 logDebug("Received a BAD Response from VNF Adapter for CREATE_VF_MODULE Call.", isDebugLogEnabled)
1265                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
1266                         }
1267                 }else{
1268                         logDebug("Response from VNF Adapter is Null for CREATE_VF_MODULE Call.", isDebugLogEnabled)
1269                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
1270                 }
1271
1272                 rollbackData.put("VFMODULE", "rollbackVnfAdapterCreate", "true")
1273                 execution.setVariable("RollbackData", rollbackData)
1274
1275                 }catch(BpmnError b){
1276                         throw b
1277                 }catch(Exception e){
1278                         logDebug("Internal Error Occured in PostProcess Method", isDebugLogEnabled)
1279                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
1280                 }
1281                 logDebug(" *** COMPLETED postProcessVnfAdapterResponse Process*** ", isDebugLogEnabled)
1282         }
1283
1284
1285         public void preProcessUpdateAAIVfModuleRequestOrch(Execution execution) {
1286                 def method = getClass().getSimpleName() + '.preProcessUpdateAAIVfModuleRequestOrch(' +
1287                         'execution=' + execution.getId() +
1288                         ')'
1289                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1290                 logDebug('Entered ' + method, isDebugLogEnabled)
1291                 execution.setVariable("prefix", Prefix)
1292                 logDebug(" ======== STARTED preProcessUpdateAAIVfModuleRequestOrch ======== ", isDebugLogEnabled)
1293
1294                 try{
1295
1296                         //Build UpdateAAIVfModule Request
1297                         boolean setContrailServiceInstanceFqdn = false
1298                         def contrailServiceInstanceFqdn = execution.getVariable("DCVFM_contrailServiceInstanceFqdn")
1299                         if (!contrailServiceInstanceFqdn.equals("")) {
1300                                 setContrailServiceInstanceFqdn = true
1301                         }
1302
1303                         String updateAAIVfModuleRequest = buildUpdateAAIVfModuleRequest(execution, false, true, true, setContrailServiceInstanceFqdn)
1304
1305                         updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
1306                         execution.setVariable("DCVFM_updateAAIVfModuleRequest", updateAAIVfModuleRequest)
1307                         logDebug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest, isDebugLogEnabled)
1308                         utils.logAudit("Outgoing UpdateAAIVfModuleRequest is: \n"  + updateAAIVfModuleRequest)
1309
1310                 }catch(Exception e){
1311                         utils.log("ERROR", "Exception Occured Processing preProcessUpdateAAIVfModuleRequestOrch. Exception is:\n" + e, isDebugLogEnabled)
1312                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestOrch Method:\n" + e.getMessage())
1313                 }
1314                 logDebug("======== COMPLETED preProcessUpdateAAIVfModuleRequestOrch ======== ", isDebugLogEnabled)
1315
1316         }
1317
1318         public void preProcessUpdateAAIVfModuleRequestGroup(Execution execution) {
1319                 def method = getClass().getSimpleName() + '.preProcessUpdateAAIVfModuleRequestGroup(' +
1320                         'execution=' + execution.getId() +
1321                         ')'
1322                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1323                 logDebug('Entered ' + method, isDebugLogEnabled)
1324                 execution.setVariable("prefix", Prefix)
1325                 logDebug(" ======== STARTED preProcessUpdateAAIVfModuleRequestGroup ======== ", isDebugLogEnabled)
1326
1327                 try{
1328
1329                         //Build UpdateAAIVfModule Request
1330
1331                         String updateAAIVfModuleRequest = buildUpdateAAIVfModuleRequest(execution, true, false, false, false)
1332
1333                         updateAAIVfModuleRequest = utils.formatXml(updateAAIVfModuleRequest)
1334                         execution.setVariable("DCVFM_updateAAIVfModuleRequest", updateAAIVfModuleRequest)
1335                         logDebug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest, isDebugLogEnabled)
1336                         utils.logAudit("Outgoing UpdateAAIVfModuleRequest is: \n"  + updateAAIVfModuleRequest)
1337
1338                 }catch(Exception e){
1339                         utils.log("ERROR", "Exception Occured Processing preProcessUpdateAAIVfModuleRequestGroup. Exception is:\n" + e, isDebugLogEnabled)
1340                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestGroup Method:\n" + e.getMessage())
1341                 }
1342                 logDebug("======== COMPLETED  preProcessUpdateAAIVfModuleRequestGroup ======== ", isDebugLogEnabled)
1343
1344         }
1345
1346         public void validateSDNCResponse(Execution execution, String response, String method){
1347                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
1348                 execution.setVariable("prefix",Prefix)
1349                 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
1350
1351                 WorkflowException workflowException = execution.getVariable("WorkflowException")
1352                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1353
1354                 utils.logAudit("workflowException: " + workflowException)
1355
1356                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1357                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1358
1359                 utils.logAudit("SDNCResponse: " + response)
1360
1361                 String sdncResponse = response
1362                 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
1363                         logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse, isDebugLogEnabled)
1364                         RollbackData rollbackData = execution.getVariable("RollbackData")
1365
1366                         if(method.equals("assign")){
1367                                 rollbackData.put("VFMODULE", "rollbackSDNCRequestAssign", "true")
1368                                 execution.setVariable("CRTGVNF_sdncAssignCompleted", true)
1369                         }
1370                         else if (method.equals("activate")) {
1371                                 rollbackData.put("VFMODULE", "rollbackSDNCRequestActivate", "true")
1372                         }
1373                         execution.setVariable("RollbackData", rollbackData)
1374                 }else{
1375                         logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
1376                         throw new BpmnError("MSOWorkflowException")
1377                 }
1378                 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
1379         }
1380
1381         public void preProcessUpdateAfterCreateRequest(Execution execution){
1382                 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
1383                 execution.setVariable("prefix", Prefix)
1384                 utils.log("DEBUG", " ======== STARTED preProcessRequest Process ======== ", isDebugLogEnabled)
1385                 try{
1386                         String response = execution.getVariable("DCVFM_assignSDNCAdapterResponse")
1387                         utils.logAudit("DCVFM_assignSDNCAdapterResponse: " + response)
1388
1389                         String data = utils.getNodeXml(response, "response-data")
1390                         data = data.replaceAll("&lt;", "<")
1391                         data = data.replaceAll("&gt;", ">")
1392                         String vnfId = utils.getNodeText1(data, "vnf-id")
1393
1394                         String uuid = execution.getVariable('testReqId') // for junits
1395                         if(uuid==null){
1396                                 uuid = execution.getVariable("mso-request-id") + "-" +          System.currentTimeMillis()
1397                         }
1398
1399                         String serviceOperation = "/VNF-API:vnfs/vnf-list/" + vnfId
1400                         def callbackUrl = execution.getVariable("DCVFM_sdncCallbackUrl")
1401                         utils.logAudit("callbackUrl: " + callbackUrl)
1402
1403                         String SDNCGetRequest =
1404                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
1405                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
1406                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
1407                                         <sdncadapter:RequestHeader>
1408                                         <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
1409                                         <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
1410                                         <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
1411                                         <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
1412                                         <sdncadapter:MsoAction>mobility</sdncadapter:MsoAction>
1413                                 </sdncadapter:RequestHeader>
1414                                         <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
1415                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
1416
1417                         execution.setVariable("DCVFM_getSDNCRequest", SDNCGetRequest)
1418                         utils.log("DEBUG", "Outgoing GetSDNCRequest is: \n" + SDNCGetRequest, isDebugLogEnabled)
1419                         utils.logAudit("Outgoing GetSDNCRequest: " + SDNCGetRequest)
1420
1421                 }catch(Exception e){
1422                         utils.log("ERROR", "Exception Occured Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled)
1423                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
1424                 }
1425                 utils.log("DEBUG", "======== COMPLETED preProcessSDNCGetRequest Process ======== ", isDebugLogEnabled)
1426         }
1427
1428         public String buildUpdateAAIVfModuleRequest(Execution execution, boolean updateVolumeGroupId,
1429                 boolean updateOrchestrationStatus, boolean updateHeatStackId, boolean updateContrailFqdn){
1430
1431                 def vnfId = execution.getVariable("DCVFM_vnfId")
1432                 def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
1433                 def volumeGroupIdString = ""
1434                 if (updateVolumeGroupId) {
1435                         volumeGroupIdString = "<volume-group-id>" + execution.getVariable("DCVFM_volumeGroupId") +
1436                                         "</volume-group-id>"
1437                 }
1438                 def orchestrationStatusString = ""
1439                 if (updateOrchestrationStatus) {
1440                         orchestrationStatusString = "<orchestration-status>Created</orchestration-status>"
1441                 }
1442                 def heatStackIdString = ""
1443                 if (updateHeatStackId) {
1444                         heatStackIdString = "<heat-stack-id>" + execution.getVariable("DCVFM_heatStackId") + "</heat-stack-id>"
1445                 }
1446                 def contrailFqdnString = ""
1447                 if (updateContrailFqdn) {
1448                         contrailFqdnString = "<contrail-service-instance-fqdn>" + execution.getVariable("DCVFM_contrailServiceInstanceFqdn") +
1449                                 "</contrail-service-instance-fqdn>"
1450                 }
1451
1452                 String updateAAIVfModuleRequest =
1453                         """<UpdateAAIVfModuleRequest>
1454                                 <vnf-id>${vnfId}</vnf-id>
1455                                 <vf-module-id>${vfModuleId}</vf-module-id>
1456                                 ${heatStackIdString}
1457                                 ${orchestrationStatusString}
1458                                 ${volumeGroupIdString}
1459                                 ${contrailFqdnString}
1460                         </UpdateAAIVfModuleRequest>"""
1461
1462         utils.logAudit("updateAAIVfModule Request: " + updateAAIVfModuleRequest)
1463         return updateAAIVfModuleRequest
1464
1465         }
1466
1467         public String buildSDNCParamsXml(Execution execution){
1468
1469                 String params = ""
1470                 StringBuilder sb = new StringBuilder()
1471                 Map<String, String> paramsMap = execution.getVariable("DCVFM_vnfParamsMap")
1472
1473                 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
1474                         String paramsXml
1475                         String key = entry.getKey();
1476                         if(key.endsWith("_network")){
1477                                 String requestKey = key.substring(0, key.indexOf("_network"))
1478                                 String requestValue = entry.getValue()
1479                                 paramsXml =
1480 """<vnf-networks>
1481         <network-role>{ functx:substring-before-match(data($param/@name), '_network') }</network-role>
1482         <network-name>{ $param/text() }</network-name>
1483 </vnf-networks>"""
1484                         }else{
1485                         paramsXml = ""
1486                         }
1487                         params = sb.append(paramsXml)
1488                 }
1489                 return params
1490         }
1491
1492    public void queryCloudRegion (Execution execution) {
1493                 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
1494                 execution.setVariable("prefix", Prefix)
1495                 utils.log("DEBUG", " ======== STARTED queryCloudRegion ======== ", isDebugLogEnabled)
1496
1497                 try {
1498                         String cloudRegion = execution.getVariable("DCVFM_cloudSiteId")
1499
1500                         // Prepare AA&I url
1501                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1502                         AaiUtil aaiUtil = new AaiUtil(this)
1503                         String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
1504                         String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
1505                         utils.logAudit("CloudRegion Request: " + queryCloudRegionRequest)
1506
1507                         execution.setVariable("DCVFM_queryCloudRegionRequest", queryCloudRegionRequest)
1508                         utils.log("DEBUG", "DCVFM_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugLogEnabled)
1509
1510                         cloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
1511
1512                         if ((cloudRegion != "ERROR")) {
1513                                 if(execution.getVariable("DCVFM_queryCloudRegionReturnCode") == "404"){
1514                                         execution.setVariable("DCVFM_cloudRegionForVolume", "AAIAIC25")
1515                                 }else{
1516                                 execution.setVariable("DCVFM_cloudRegionForVolume", cloudRegion)
1517                                 }
1518                                 execution.setVariable("DCVFM_isCloudRegionGood", true)
1519                         } else {
1520                                 String errorMessage = "AAI Query Cloud Region Unsuccessful. AAI Response Code: " + execution.getVariable("DCVFM_queryCloudRegionReturnCode")
1521                                 utils.log("DEBUG", errorMessage, isDebugLogEnabled)
1522                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1523                                 execution.setVariable("DCVFM_isCloudRegionGood", false)
1524                         }
1525                         utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable("DCVFM_isCloudRegionGood"), isDebugLogEnabled)
1526
1527                 } catch(BpmnError b){
1528                         utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugLogEnabled)
1529                         throw b
1530                 }catch (Exception ex) {
1531                         // try error
1532                         String errorMessage = "Bpmn error encountered in CreateVfModule flow. Unexpected Response from AAI - " + ex.getMessage()
1533                         utils.log("ERROR", " AAI Query Cloud Region Failed.  Exception - " + "\n" + errorMessage, isDebugLogEnabled)
1534                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception occured during queryCloudRegion method")
1535                 }
1536         }
1537
1538    /**
1539     *
1540     *This method occurs when an MSOWorkflowException is caught.  It logs the
1541     *variables and ensures that the "WorkflowException" Variable is set.
1542     *
1543     */
1544    public void processBPMNException(Execution execution){
1545            def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1546            execution.setVariable("prefix",Prefix)
1547            try{
1548                    utils.log("DEBUG", "Caught a BPMN Exception", isDebugEnabled)
1549                    utils.log("DEBUG", "Started processBPMNException Method", isDebugEnabled)
1550                    utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1551                    if(execution.getVariable("WorkflowException") == null){
1552                            exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception occured during DoCreateVfModule Sub Process")
1553                    }
1554
1555            }catch(Exception e){
1556                    utils.log("DEBUG", "Caught Exception during processBPMNException Method: " + e, isDebugEnabled)
1557            }
1558            utils.log("DEBUG", "Completed processBPMNException Method", isDebugEnabled)
1559    }
1560
1561    public void prepareCreateAAIVfModuleVolumeGroupRequest(Execution execution) {
1562                 def method = getClass().getSimpleName() + '.prepareCreateAAIVfModuleVolumeGroupRequest(' +
1563                         'execution=' + execution.getId() +
1564                         ')'
1565                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1566                 logDebug('Entered ' + method, isDebugLogEnabled)
1567                 execution.setVariable("prefix", Prefix)
1568                 logDebug(" ======== STARTED prepareCreateAAIVfModuleVolumeGroupRequest ======== ", isDebugLogEnabled)
1569
1570                 try{
1571
1572                         //Build CreateAAIVfModuleVolumeGroup Request
1573
1574                         def vnfId = execution.getVariable("DCVFM_vnfId")
1575                         def vfModuleId = execution.getVariable("DCVFM_vfModuleId")
1576                         def volumeGroupId = execution.getVariable("DCVFM_volumeGroupId")
1577                         //def aicCloudRegion = execution.getVariable("DCVFM_cloudSiteId")
1578                         def aicCloudRegion = execution.getVariable("DCVFM_cloudRegionForVolume")
1579                         String createAAIVfModuleVolumeGroupRequest =
1580                         """<CreateAAIVfModuleVolumeGroupRequest>
1581                                 <vnf-id>${vnfId}</vnf-id>
1582                                 <vf-module-id>${vfModuleId}</vf-module-id>
1583                                 <volume-group-id>${volumeGroupId}</volume-group-id>
1584                                 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
1585                         </CreateAAIVfModuleVolumeGroupRequest>"""
1586
1587                         createAAIVfModuleVolumeGroupRequest = utils.formatXml(createAAIVfModuleVolumeGroupRequest)
1588                         execution.setVariable("DCVFM_createAAIVfModuleVolumeGroupRequest", createAAIVfModuleVolumeGroupRequest)
1589                         logDebug("Outgoing CreateAAIVfModuleVolumeGroupRequest is: \n" + createAAIVfModuleVolumeGroupRequest, isDebugLogEnabled)
1590                         utils.logAudit("Outgoing CreateAAIVfModuleVolumeGroupRequest is: \n"  + createAAIVfModuleVolumeGroupRequest)
1591
1592                 }catch(Exception e){
1593                         utils.log("ERROR", "Exception Occured Processing prepareCreateAAIVfModuleVolumeGroupRequest. Exception is:\n" + e, isDebugLogEnabled)
1594                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareCreateAAIVfModuleVolumeGroupRequest Method:\n" + e.getMessage())
1595                 }
1596                 logDebug("======== COMPLETED  prepareCreateAAIVfModuleVolumeGroupRequest ======== ", isDebugLogEnabled)
1597
1598         }
1599
1600    public void createNetworkPoliciesInAAI(Execution execution) {
1601            def method = getClass().getSimpleName() + '.createNetworkPoliciesInAAI(' +
1602            'execution=' + execution.getId() +
1603            ')'
1604            def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1605            logDebug('Entered ' + method, isDebugLogEnabled)
1606            execution.setVariable("prefix", Prefix)
1607            logDebug(" ======== STARTED createNetworkPoliciesInAAI ======== ", isDebugLogEnabled)
1608
1609            try {
1610                    // get variables
1611                    List fqdnList = execution.getVariable("DCVFM_contrailNetworkPolicyFqdnList")
1612                    int fqdnCount = fqdnList.size()
1613                    def rollbackData = execution.getVariable("RollbackData")
1614
1615                    execution.setVariable("DCVFM_networkPolicyFqdnCount", fqdnCount)
1616                    logDebug("DCVFM_networkPolicyFqdnCount - " + fqdnCount, isDebugLogEnabled)
1617
1618                    String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1619                    AaiUtil aaiUriUtil = new AaiUtil(this)
1620                    String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
1621
1622                    if (fqdnCount > 0) {
1623
1624                            // AII loop call over contrail network policy fqdn list
1625                            for (i in 0..fqdnCount-1) {
1626
1627                                    int counting = i+1
1628                                    String fqdn = fqdnList[i]
1629
1630                                    // Query AAI for this network policy FQDN
1631
1632                                    String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
1633                                    utils.logAudit("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
1634
1635                                    def aaiRequestId = UUID.randomUUID().toString()
1636                                    RESTConfig config = new RESTConfig(queryNetworkPolicyByFqdnAAIRequest);
1637                                    RESTClient client = new RESTClient(config).addHeader("X-TransactionId", aaiRequestId)
1638                                                                                                                          .addHeader("X-FromAppId", "MSO")
1639                                                                                                                          .addHeader("Content-Type", "application/xml")
1640                                                                                                                          .addHeader("Accept","application/xml");
1641                                    APIResponse response = client.get()
1642                                    int returnCode = response.getStatusCode()
1643                                    execution.setVariable("DCVFM_aaiQqueryNetworkPolicyByFqdnReturnCode", returnCode)
1644                                    logDebug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugLogEnabled)
1645
1646                                    String aaiResponseAsString = response.getResponseBodyAsString()
1647
1648                                    if (isOneOf(returnCode, 200, 201)) {
1649                                            logDebug("The return code is: "  + returnCode, isDebugLogEnabled)
1650                                            // This network policy FQDN already exists in AAI
1651                                            utils.logAudit(aaiResponseAsString)
1652                                            execution.setVariable("DCVFM_queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
1653                                            logDebug(" QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugLogEnabled)
1654
1655                                    } else {
1656                                            if (returnCode == 404) {
1657                                                    // This network policy FQDN is not in AAI yet. Add it now
1658                                                    logDebug("The return code is: "  + returnCode, isDebugLogEnabled)
1659                                                    logDebug("This network policy FQDN is not in AAI yet: " + fqdn, isDebugLogEnabled)
1660                                                    utils.logAudit("Network policy FQDN is not in AAI yet")
1661                                                    // Add the network policy with this FQDN to AAI
1662                                                    def networkPolicyId = UUID.randomUUID().toString()
1663                                                    logDebug("Adding network-policy with network-policy-id " + networkPolicyId, isDebugLogEnabled)
1664
1665                                                    String aaiNamespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
1666                                                    logDebug('AAI namespace is: ' + aaiNamespace, isDebugLogEnabled)
1667                                                    String payload = """<network-policy xmlns="${aaiNamespace}">
1668                                                                 <network-policy-id>${networkPolicyId}</network-policy-id>
1669                                                                 <network-policy-fqdn>${fqdn}</network-policy-fqdn>
1670                                                                 <heat-stack-id>${execution.getVariable("DCVFM_heatStackId")}</heat-stack-id>
1671                                                                 </network-policy>""" as String
1672
1673                                                    execution.setVariable("DCVFM_addNetworkPolicyAAIRequestBody", payload)
1674
1675                                                    String addNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8")
1676                                                    utils.logAudit("AAI request endpoint: " + addNetworkPolicyAAIRequest)
1677                                                    logDebug("AAI request endpoint: " + addNetworkPolicyAAIRequest, isDebugLogEnabled)
1678
1679                                                    def aaiRequestIdPut = UUID.randomUUID().toString()
1680                                                    RESTConfig configPut = new RESTConfig(addNetworkPolicyAAIRequest);
1681                                                    RESTClient clientPut = new RESTClient(configPut).addHeader("X-TransactionId", aaiRequestIdPut)
1682                                                                                                                                          .addHeader("X-FromAppId", "MSO")
1683                                                                                                                                          .addHeader("Content-Type", "application/xml")
1684                                                                                                                                          .addHeader("Accept","application/xml");
1685                                                    logDebug("invoking PUT call to AAI with payload:"+System.lineSeparator()+payload, isDebugLogEnabled)
1686                                                    utils.logAudit("Sending PUT call to AAI with Endpoint /n" + addNetworkPolicyAAIRequest + " with payload /n" + payload)
1687                                                    APIResponse responsePut = clientPut.httpPut(payload)
1688                                                    int returnCodePut = responsePut.getStatusCode()
1689                                                    execution.setVariable("DCVFM_aaiAddNetworkPolicyReturnCode", returnCodePut)
1690                                                    logDebug(" ***** AAI add network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodePut, isDebugLogEnabled)
1691
1692                                                    String aaiResponseAsStringPut = responsePut.getResponseBodyAsString()
1693                                                    if (isOneOf(returnCodePut, 200, 201)) {
1694                                                            logDebug("The return code from adding network policy is: "  + returnCodePut, isDebugLogEnabled)
1695                                                            // This network policy was created in AAI successfully
1696                                                            utils.logAudit(aaiResponseAsStringPut)
1697                                                            execution.setVariable("DCVFM_addNetworkPolicyAAIResponse", aaiResponseAsStringPut)
1698                                                            logDebug(" AddAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsStringPut, isDebugLogEnabled)
1699                                                            rollbackData.put("VFMODULE", "rollbackCreateNetworkPoliciesAAI", "true")
1700                                                            rollbackData.put("VFMODULE", "contrailNetworkPolicyFqdn" + i, fqdn)
1701                                                            execution.setVariable("RollbackData", rollbackData)
1702
1703                                                    } else {
1704                                                                 // aai all errors
1705                                                                 String putErrorMessage = "Unable to add network-policy to AAI createNetworkPoliciesInAAI - " + returnCodePut
1706                                                                 logDebug(putErrorMessage, isDebugLogEnabled)
1707                                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, putErrorMessage)
1708                                                    }
1709
1710                                            } else {
1711                                                   if (aaiResponseAsString.contains("RESTFault")) {
1712                                                           WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
1713                                                           execution.setVariable("WorkflowException", exceptionObject)
1714                                                           throw new BpmnError("MSOWorkflowException")
1715
1716                                                           } else {
1717                                                                    // aai all errors
1718                                                                    String dataErrorMessage = "Unexpected Response from createNetworkPoliciesInAAI - " + returnCode
1719                                                                    logDebug(dataErrorMessage, isDebugLogEnabled)
1720                                                                    exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1721
1722                                                          }
1723                                            }
1724                                    }
1725
1726                            } // end loop
1727
1728
1729                    } else {
1730                            logDebug("No contrail network policies to query/create", isDebugLogEnabled)
1731
1732                    }
1733
1734            } catch (BpmnError e) {
1735                    throw e;
1736
1737            } catch (Exception ex) {
1738                    String exceptionMessage = "Bpmn error encountered in DoCreateVfModule flow. createNetworkPoliciesInAAI() - " + ex.getMessage()
1739                    logDebug(exceptionMessage, isDebugLogEnabled)
1740                    exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1741            }
1742
1743    }
1744
1745    /**
1746         * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
1747         *
1748         * @param execution The flow's execution instance.
1749         */
1750    public void prepUpdateAAIGenericVnf(Execution execution) {
1751            def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
1752                    'execution=' + execution.getId() +
1753                    ')'
1754            def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1755            logDebug('Entered ' + method, isDebugLogEnabled)
1756
1757            try {
1758                    def rollbackData = execution.getVariable("RollbackData")
1759                    def vnfId = execution.getVariable('DCVFM_vnfId')
1760                    def oamManagementV4Address = execution.getVariable("DCVFM_oamManagementV4Address")
1761                    def oamManagementV6Address = execution.getVariable("DCVFM_oamManagementV6Address")
1762                    def ipv4OamAddressElement = ''
1763                    def managementV6AddressElement = ''
1764
1765                    if (oamManagementV4Address != null && !oamManagementV4Address.isEmpty()) {
1766                            ipv4OamAddressElement = '<ipv4-oam-address>' + oamManagementV4Address + '</ipv4-oam-address>'
1767                    }
1768
1769                    if (oamManagementV6Address != null && !oamManagementV6Address.isEmpty()) {
1770                            managementV6AddressElement = '<management-v6-address>' + oamManagementV6Address + '</management-v6-address>'
1771                    }
1772
1773                    rollbackData.put("VFMODULE", "oamManagementV4Address", oamManagementV4Address)
1774
1775
1776                    String updateAAIGenericVnfRequest = """
1777                                         <UpdateAAIGenericVnfRequest>
1778                                                 <vnf-id>${vnfId}</vnf-id>
1779                                                 ${ipv4OamAddressElement}
1780                                                 ${managementV6AddressElement}
1781                                         </UpdateAAIGenericVnfRequest>
1782                                 """
1783                            updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
1784                            execution.setVariable('DCVM_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
1785                            utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
1786                            logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
1787
1788
1789                    logDebug('Exited ' + method, isDebugLogEnabled)
1790            } catch (BpmnError e) {
1791                    throw e;
1792            } catch (Exception e) {
1793                    logError('Caught exception in ' + method, e)
1794                    exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
1795            }
1796    }
1797
1798    /**
1799         * Post process a result from invoking the UpdateAAIGenericVnf subflow.
1800         *
1801         * @param execution The flow's execution instance.
1802         */
1803    public void postProcessUpdateAAIGenericVnf(Execution execution) {
1804            def method = getClass().getSimpleName() + '.postProcessUpdateAAIGenericVnf(' +
1805                    'execution=' + execution.getId() +
1806                    ')'
1807            def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
1808            logDebug('Entered ' + method, isDebugLogEnabled)
1809
1810            try {
1811                    def rollbackData = execution.getVariable("RollbackData")
1812
1813                    rollbackData.put("VFMODULE", "rollbackUpdateVnfAAI", "true")
1814
1815                    def vnfId = execution.getVariable('DCVFM_vnfId')
1816                    def oamManagementV4Address = execution.getVariable("DCVFM_oamManagementV4Address")
1817                    def oamManagementV6Address = execution.getVariable("DCVFM_oamManagementV6Address")
1818                    def ipv4OamAddressElement = ''
1819                    def managementV6AddressElement = ''
1820
1821                    if (oamManagementV4Address != null && !oamManagementV4Address.isEmpty()) {
1822                            rollbackData.put("VFMODULE", "oamManagementV4Address", oamManagementV4Address)
1823                    }
1824
1825                    if (oamManagementV6Address != null && !oamManagementV6Address.isEmpty()) {
1826                            rollbackData.put("VFMODULE", "oamManagementV6Address", oamManagementV6Address)
1827                    }
1828
1829                    execution.setVariable("RollbackData", rollbackData)
1830
1831                    logDebug('Exited ' + method, isDebugLogEnabled)
1832            } catch (BpmnError e) {
1833                    throw e;
1834            } catch (Exception e) {
1835                    logError('Caught exception in ' + method, e)
1836                    exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in postProcessUpdateAAIGenericVnf(): ' + e.getMessage())
1837            }
1838    }
1839
1840
1841 }