af1161b6565889a70ce624be77462026e4703773
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateVfModuleRollback.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
21 package org.openecomp.mso.bpmn.infrastructure.scripts
22 import org.camunda.bpm.engine.delegate.BpmnError
23 import org.camunda.bpm.engine.runtime.Execution
24 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
25 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
26 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
27 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
28 import org.openecomp.mso.bpmn.core.WorkflowException
29 import org.openecomp.mso.rest.APIResponse
30 import org.springframework.web.util.UriUtils
31
32
33
34 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
35
36         def Prefix="DCVFMR_"
37         ExceptionUtil exceptionUtil = new ExceptionUtil()
38
39         public void initProcessVariables(Execution execution) {
40                 execution.setVariable("prefix",Prefix)
41         }
42
43         // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
44         // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
45         public void preProcessRequest(Execution execution) {
46                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
47
48                 initProcessVariables(execution)
49
50                 def rollbackData = execution.getVariable("RollbackData")
51                 String vnfId = rollbackData.get("VFMODULE", "vnfid")
52                 execution.setVariable("DCVFMR_vnfId", vnfId)
53                 String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
54                 execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
55                 String source = rollbackData.get("VFMODULE", "source")
56                 execution.setVariable("DCVFMR_source", source)
57                 String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
58                 execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
59                 String serviceId = rollbackData.get("VFMODULE", "service-id")
60                 execution.setVariable("DCVFMR_serviceId", serviceId)
61                 String vnfType = rollbackData.get("VFMODULE", "vnftype")
62                 execution.setVariable("DCVFMR_vnfType", vnfType)
63                 String vnfName = rollbackData.get("VFMODULE", "vnfname")
64                 execution.setVariable("DCVFMR_vnfName", vnfName)
65                 String tenantId = rollbackData.get("VFMODULE", "tenantid")
66                 execution.setVariable("DCVFMR_tenantId", tenantId)
67                 String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
68                 execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
69                 String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
70                 execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
71                 String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
72                 execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
73                 String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
74                 execution.setVariable("DCVFMR_heatStackId", heatStackId)
75                 String requestId = rollbackData.get("VFMODULE", "attmsorequestid")
76                 execution.setVariable("DCVFMR_requestId", requestId)
77                 List createdNetworkPolicyFqdnList = []
78                 int i = 0
79                 while (i < 100) {
80                         String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
81                         if (fqdn == null) {
82                                 break
83                         }
84                         createdNetworkPolicyFqdnList.add(fqdn)
85                         logDebug("got fqdn # " + i + ": " + fqdn, isDebugEnabled)
86                         i = i + 1
87
88                 }
89
90                 execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
91                 String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
92                 execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
93                 String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
94                 execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
95                 //String serviceInstanceId = rollbackData.get("VFMODULE", "attmsoserviceinstanceid")
96                 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
97                 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
98                 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
99                 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
100                 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
101                 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
102                 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
103                 execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
104                 execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
105
106                 // formulate the request for PrepareUpdateAAIVfModule
107                 String request = """<PrepareUpdateAAIVfModuleRequest>
108                                                                 <vnf-id>${vnfId}</vnf-id>
109                                                                 <vf-module-id>${vfModuleId}</vf-module-id>
110                                                                 <orchestration-status>pending-delete</orchestration-status>
111                                                         </PrepareUpdateAAIVfModuleRequest>""" as String
112                 utils.log("DEBUG", "PrepareUpdateAAIVfModuleRequest :" + request, isDebugEnabled)
113                 utils.logAudit("DoCreateVfModuleRollback PrepareUpdateAAIVfModule Request: " + request)
114                 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
115         }
116
117         // build a SDNC vnf-topology-operation request for the specified action
118         // (note: the action passed is expected to be 'changedelete' or 'delete')
119         public void prepSDNCAdapterRequest(Execution execution) {
120                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
121                 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
122
123                 def callbackUrl = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
124
125                 String source = execution.getVariable("DCVFMR_source")
126                 String serviceId = execution.getVariable("DCVFMR_serviceId")
127                 String vnfId = execution.getVariable("DCVFMR_vnfId")
128                 String vnfType = execution.getVariable("DCVFMR_vnfType")
129                 String vnfName = execution.getVariable("DCVFMR_vnfName")
130                 String tenantId = execution.getVariable("DCVFMR_tenantId")
131                 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
132                 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
133                 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
134                 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
135                 String requestId = execution.getVariable("DCVFMR_requestId")
136
137                 String serviceInstanceIdToSdnc = ""
138                 if (srvInstId != null && !srvInstId.isEmpty()) {
139                         serviceInstanceIdToSdnc = srvInstId
140                 } else {
141                     serviceInstanceIdToSdnc = vfModuleId
142                 }
143
144                 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
145                 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
146
147                 def action = ""
148                 def requestAction = ""
149
150                 if (doSDNCActivateRollback.equals("true")) {
151                         action = "delete"
152                         requestAction = "DisconnectVNFRequest"
153                 }
154                 else if (doSDNCAssignRollback.equals("true")) {
155                         action = "rollback"
156                         requestAction = "VNFActivateRequest"
157                 }
158                 else
159                         return
160
161
162                 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
163                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
164                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
165                                                       <sdncadapter:RequestHeader>
166                                                          <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
167                                                          <sdncadapter:SvcInstanceId>${vfModuleId}</sdncadapter:SvcInstanceId>
168                                                          <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
169                                                          <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
170                                                          <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
171                                                       </sdncadapter:RequestHeader>
172                                                       <sdncadapterworkflow:SDNCRequestData>
173                                                          <request-information>
174                                                             <request-id>${requestId}</request-id>
175                                                             <request-action>${requestAction}</request-action>
176                                                             <source>${source}</source>
177                                                             <notification-url/>
178                                                             <order-number/>
179                                                             <order-version/>
180                                                          </request-information>
181                                                          <service-information>
182                                                             <service-id>${serviceId}</service-id>
183                                                                         <service-type>${serviceId}</service-type>
184                                                             <service-instance-id>${serviceInstanceIdToSdnc}</service-instance-id>
185                                                             <subscriber-name>notsurewecare</subscriber-name>
186                                                          </service-information>
187                                                          <vnf-request-information>
188                                                                 <vnf-id>${vfModuleId}</vnf-id>
189                                                                         <vnf-type>${vfModuleModelName}</vnf-type>
190                                     <vnf-name>${vfModuleName}</vnf-name>
191                                                                         <generic-vnf-id>${vnfId}</generic-vnf-id>
192                                     <generic-vnf-name>${vnfName}</generic-vnf-name>
193                                                                         <generic-vnf-type>${vnfType}</generic-vnf-type>
194                                                                         <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
195                                                                         <tenant>${tenantId}</tenant>
196                                                          </vnf-request-information>
197                                                       </sdncadapterworkflow:SDNCRequestData>
198                                                    </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
199
200                 utils.log("DEBUG", "sdncAdapterWorkflowRequest: " + request, isDebugEnabled)
201                 utils.logAudit("DoCreateVfModuleRollback sdncAdapterWorkflow Request: " + request)
202                 execution.setVariable("sdncAdapterWorkflowRequest", request)
203         }
204
205         // parse the incoming DELETE_VF_MODULE request
206         // and formulate the outgoing VnfAdapterDeleteV1 request
207         public void prepVNFAdapterRequest(Execution execution) {
208                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
209                 String requestId = UUID.randomUUID().toString()
210                 String origRequestId = execution.getVariable("DCVFMR_requestId")
211                 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
212                 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
213                 String vnfId = execution.getVariable("DCVFMR_vnfId")
214                 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
215                 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
216                 String tenantId = execution.getVariable("DCVFMR_tenantId")
217                 def messageId = execution.getVariable('mso-request-id') + '-' +
218                         System.currentTimeMillis()
219                 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
220                 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
221                 if ('true'.equals(useQualifiedHostName)) {
222                         notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
223                 }
224
225                 String request = """
226                         <deleteVfModuleRequest>
227                             <cloudSiteId>${aicCloudRegion}</cloudSiteId>
228                             <tenantId>${tenantId}</tenantId>
229                             <vnfId>${vnfId}</vnfId>
230                             <vfModuleId>${vfModuleId}</vfModuleId>
231                             <vfModuleStackId>${vfModuleStackId}</vfModuleStackId>
232                             <skipAAI>true</skipAAI>
233                             <msoRequest>
234                                 <requestId>${origRequestId}</requestId>
235                                 <serviceInstanceId>${srvInstId}</serviceInstanceId>
236                             </msoRequest>
237                             <messageId>${messageId}</messageId>
238                             <notificationUrl>${notificationUrl}</notificationUrl>
239                         </deleteVfModuleRequest>
240                         """ as String
241
242                 utils.log("DEBUG", "vnfAdapterRestV1Request: " + request, isDebugEnabled)
243                 utils.logAudit("PrepareUpdateAAIVfModule vnfAdapterRestV1 Request: " + request)
244                 execution.setVariable("vnfAdapterRestV1Request", request)
245         }
246
247         // parse the incoming DELETE_VF_MODULE request
248         // and formulate the outgoing UpdateAAIVfModuleRequest request
249         public void prepUpdateAAIVfModule(Execution execution) {
250                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
251                 String vnfId = execution.getVariable("DCVFMR_vnfId")
252                 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
253                 // formulate the request for UpdateAAIVfModule
254                 String request = """<UpdateAAIVfModuleRequest>
255                                                                 <vnf-id>${vnfId}</vnf-id>
256                                                                 <vf-module-id>${vfModuleId}</vf-module-id>
257                                                                 <heat-stack-id>DELETE</heat-stack-id>
258                                                                 <orchestration-status>deleted</orchestration-status>
259                                                         </UpdateAAIVfModuleRequest>""" as String
260                 utils.log("DEBUG", "UpdateAAIVfModuleRequest :" + request, isDebugEnabled)
261                 utils.logAudit("UpdateAAIVfModule Request: " + request)
262                 execution.setVariable("UpdateAAIVfModuleRequest", request)
263         }
264
265         // parse the incoming DELETE_VF_MODULE request
266         // and formulate the outgoing DeleteAAIVfModuleRequest request
267         public void prepDeleteAAIVfModule(Execution execution) {
268                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
269                 String vnfId = execution.getVariable("DCVFMR_vnfId")
270                 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
271                 // formulate the request for UpdateAAIVfModule
272                 String request = """<DeleteAAIVfModuleRequest>
273                                                                 <vnf-id>${vnfId}</vnf-id>
274                                                                 <vf-module-id>${vfModuleId}</vf-module-id>
275                                                         </DeleteAAIVfModuleRequest>""" as String
276                 utils.log("DEBUG", "DeleteAAIVfModuleRequest :" + request, isDebugEnabled)
277                 utils.logAudit("DeleteAAIVfModule Request: " + request)
278                 execution.setVariable("DeleteAAIVfModuleRequest", request)
279         }
280
281         // generates a WorkflowException if
282         //              -
283         public void handleDoDeleteVfModuleFailure(Execution execution) {
284                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
285                 utils.log("ERROR", "AAI error occurred deleting the Generic Vnf: "
286                         + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"), isDebugEnabled)
287                 String processKey = getProcessKey(execution);
288                 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
289
290         }
291
292         public void sdncValidateResponse(Execution execution, String response){
293                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
294                 execution.setVariable("prefix",Prefix)
295
296                 WorkflowException workflowException = execution.getVariable("WorkflowException")
297                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
298
299                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
300                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
301
302                 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
303                         utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
304                 }else{
305                         throw new BpmnError("MSOWorkflowException")
306                 }
307         }
308
309         public void deleteNetworkPoliciesFromAAI(Execution execution) {
310                 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
311                 'execution=' + execution.getId() +
312                 ')'
313                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
314                 logDebug('Entered ' + method, isDebugLogEnabled)
315                 execution.setVariable("prefix", Prefix)
316                 logDebug(" ======== STARTED deleteNetworkPoliciesFromAAI ======== ", isDebugLogEnabled)
317
318                 try {
319                         // get variables
320                         List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
321                         if (fqdnList == null) {
322                                 logDebug("No network policies to delete", isDebugLogEnabled)
323                                 return
324                         }
325                         int fqdnCount = fqdnList.size()
326
327                         execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
328                         logDebug("networkPolicyFqdnCount - " + fqdnCount, isDebugLogEnabled)
329
330                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
331                         AaiUtil aaiUriUtil = new AaiUtil(this)
332                         String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
333
334                         if (fqdnCount > 0) {
335                                 // AII loop call over contrail network policy fqdn list
336                                 for (i in 0..fqdnCount-1) {
337
338                                         int counting = i+1
339                                         String fqdn = fqdnList[i]
340
341                                         // Query AAI for this network policy FQDN
342
343                                         String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
344                                         utils.logAudit("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
345                                         logDebug("AAI request endpoint: "  + queryNetworkPolicyByFqdnAAIRequest, isDebugLogEnabled)
346
347                                         def aaiRequestId = UUID.randomUUID().toString()
348                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyByFqdnAAIRequest)
349                                         int returnCode = response.getStatusCode()
350                                         execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", returnCode)
351                                         logDebug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugLogEnabled)
352
353                                         String aaiResponseAsString = response.getResponseBodyAsString()
354
355                                         if (isOneOf(returnCode, 200, 201)) {
356                                                 logDebug("The return code is: "  + returnCode, isDebugLogEnabled)
357                                                 // This network policy FQDN exists in AAI - need to delete it now
358                                                 utils.logAudit(aaiResponseAsString)
359                                                 execution.setVariable(Prefix + "queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
360                                                 logDebug("QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugLogEnabled)
361                                                 // Retrieve the network policy id for this FQDN
362                                                 def networkPolicyId = utils.getNodeText1(aaiResponseAsString, "network-policy-id")
363                                                 logDebug("Deleting network-policy with network-policy-id " + networkPolicyId, isDebugLogEnabled)
364
365                                                 // Retrieve the resource version for this network policy
366                                                 def resourceVersion = utils.getNodeText1(aaiResponseAsString, "resource-version")
367                                                 logDebug("Deleting network-policy with resource-version " + resourceVersion, isDebugLogEnabled)
368
369                                                 String delNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8") +
370                                                         "?resource-version=" + UriUtils.encode(resourceVersion, "UTF-8")
371
372                                                 utils.logAudit("AAI request endpoint: " + delNetworkPolicyAAIRequest)
373                                                 logDebug("AAI request endpoint: " + delNetworkPolicyAAIRequest, isDebugLogEnabled)
374
375                                                 def aaiRequestIdDel = UUID.randomUUID().toString()
376                                                 logDebug("invoking DELETE call to AAI", isDebugLogEnabled)
377                                                 utils.logAudit("Sending DELETE call to AAI with Endpoint /n" + delNetworkPolicyAAIRequest)
378
379                                                 APIResponse responseDel = aaiUriUtil.executeAAIDeleteCall(execution, delNetworkPolicyAAIRequest)
380
381                                                 int returnCodeDel = responseDel.getStatusCode()
382                                                 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", returnCodeDel)
383                                                 logDebug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodeDel, isDebugLogEnabled)
384
385                                                 if (isOneOf(returnCodeDel, 200, 201, 204)) {
386                                                         logDebug("The return code from deleting network policy is: "  + returnCodeDel, isDebugLogEnabled)
387                                                         // This network policy was deleted from AAI successfully
388                                                         logDebug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ", isDebugLogEnabled)
389
390                                                 } else {
391                                                                 // aai all errors
392                                                                 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + returnCodeDel
393                                                          logDebug(delErrorMessage, isDebugLogEnabled)
394                                                          exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
395                                                 }
396                                         } else if (returnCode == 404) {
397                                                 // This network policy FQDN is not in AAI. No need to delete.
398                                                 logDebug("The return code is: "  + returnCode, isDebugLogEnabled)
399                                                 logDebug("This network policy FQDN is not in AAI: " + fqdn, isDebugLogEnabled)
400                                                 utils.logAudit("Network policy FQDN is not in AAI")
401                                         } else {
402                                            if (aaiResponseAsString.contains("RESTFault")) {
403                                                    WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
404                                                    execution.setVariable("WorkflowException", exceptionObject)
405                                                    throw new BpmnError("MSOWorkflowException")
406
407                                                    } else {
408                                                                 // aai all errors
409                                                                 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + returnCode
410                                                                 logDebug(dataErrorMessage, isDebugLogEnabled)
411                                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
412
413                                                   }
414                                         }
415
416
417
418                                 } // end loop
419
420
421                         } else {
422                                    logDebug("No contrail network policies to query/create", isDebugLogEnabled)
423
424                         }
425
426                 } catch (BpmnError e) {
427                         throw e;
428
429                 } catch (Exception ex) {
430                         String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
431                         logDebug(exceptionMessage, isDebugLogEnabled)
432                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
433                 }
434
435         }
436
437
438         /**
439          * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
440          *
441          * @param execution The flow's execution instance.
442          */
443         public void preProcessUpdateAAIGenericVnf(Execution execution) {
444                 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
445                         'execution=' + execution.getId() +
446                         ')'
447                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
448                 logDebug('Entered ' + method, isDebugLogEnabled)
449
450                 try {
451                         def vnfId = execution.getVariable('DCVFMR_vnfId')
452                         def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
453                         def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
454                         def ipv4OamAddressElement = ''
455                         def managementV6AddressElement = ''
456
457                         if (oamManagementV4Address != null) {
458                                 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
459                         }
460
461                         if (oamManagementV6Address != null) {
462                                 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
463                         }
464
465
466                         String updateAAIGenericVnfRequest = """
467                                         <UpdateAAIGenericVnfRequest>
468                                                 <vnf-id>${vnfId}</vnf-id>
469                                                 ${ipv4OamAddressElement}
470                                                 ${managementV6AddressElement}
471                                         </UpdateAAIGenericVnfRequest>
472                                 """
473                                 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
474                                 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
475                                 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
476                                 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
477
478
479                         logDebug('Exited ' + method, isDebugLogEnabled)
480                 } catch (BpmnError e) {
481                         throw e;
482                 } catch (Exception e) {
483                         logError('Caught exception in ' + method, e)
484                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
485                 }
486         }
487 }