2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.scripts
22 import org.camunda.bpm.engine.delegate.BpmnError
23 import org.camunda.bpm.engine.delegate.DelegateExecution
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
34 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
37 ExceptionUtil exceptionUtil = new ExceptionUtil()
39 public void initProcessVariables(DelegateExecution execution) {
40 execution.setVariable("prefix",Prefix)
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(DelegateExecution execution) {
46 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
48 initProcessVariables(execution)
52 execution.setVariable("rolledBack", null)
53 execution.setVariable("rollbackError", null)
55 def rollbackData = execution.getVariable("rollbackData")
56 utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
58 if (rollbackData != null) {
59 String vnfId = rollbackData.get("VFMODULE", "vnfid")
60 execution.setVariable("DCVFMR_vnfId", vnfId)
61 String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
62 execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
63 String source = rollbackData.get("VFMODULE", "source")
64 execution.setVariable("DCVFMR_source", source)
65 String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
66 execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
67 String serviceId = rollbackData.get("VFMODULE", "service-id")
68 execution.setVariable("DCVFMR_serviceId", serviceId)
69 String vnfType = rollbackData.get("VFMODULE", "vnftype")
70 execution.setVariable("DCVFMR_vnfType", vnfType)
71 String vnfName = rollbackData.get("VFMODULE", "vnfname")
72 execution.setVariable("DCVFMR_vnfName", vnfName)
73 String tenantId = rollbackData.get("VFMODULE", "tenantid")
74 execution.setVariable("DCVFMR_tenantId", tenantId)
75 String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
76 execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
77 String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
78 execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
79 String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
80 execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
81 String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
82 execution.setVariable("DCVFMR_heatStackId", heatStackId)
83 String requestId = rollbackData.get("VFMODULE", "msorequestid")
84 execution.setVariable("DCVFMR_requestId", requestId)
85 // Set mso-request-id to request-id for VNF Adapter interface
86 execution.setVariable("mso-request-id", requestId)
87 List createdNetworkPolicyFqdnList = []
90 String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
94 createdNetworkPolicyFqdnList.add(fqdn)
95 logDebug("got fqdn # " + i + ": " + fqdn, isDebugEnabled)
100 execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
101 String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
102 execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
103 String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
104 execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
105 //String serviceInstanceId = rollbackData.get("VFMODULE", "msoserviceinstanceid")
106 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
107 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
108 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
109 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
110 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
111 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
112 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
113 execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
114 execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
116 // formulate the request for PrepareUpdateAAIVfModule
117 String request = """<PrepareUpdateAAIVfModuleRequest>
118 <vnf-id>${vnfId}</vnf-id>
119 <vf-module-id>${vfModuleId}</vf-module-id>
120 <orchestration-status>pending-delete</orchestration-status>
121 </PrepareUpdateAAIVfModuleRequest>""" as String
122 utils.log("DEBUG", "PrepareUpdateAAIVfModuleRequest :" + request, isDebugEnabled)
123 utils.logAudit("DoCreateVfModuleRollback PrepareUpdateAAIVfModule Request: " + request)
124 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
126 execution.setVariable("skipRollback", true)
129 if (execution.getVariable("disableRollback").equals("true" )) {
130 execution.setVariable("skipRollback", true)
133 } catch (BpmnError e) {
135 } catch (Exception ex){
136 def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
137 utils.log("DEBUG", msg, isDebugEnabled)
138 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
142 // build a SDNC vnf-topology-operation request for the specified action
143 // (note: the action passed is expected to be 'changedelete' or 'delete')
144 public void prepSDNCAdapterRequest(DelegateExecution execution) {
145 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
146 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
148 String uuid = execution.getVariable('testReqId') // for junits
150 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
153 def callbackUrl = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
155 String source = execution.getVariable("DCVFMR_source")
156 String serviceId = execution.getVariable("DCVFMR_serviceId")
157 String vnfId = execution.getVariable("DCVFMR_vnfId")
158 String vnfType = execution.getVariable("DCVFMR_vnfType")
159 String vnfName = execution.getVariable("DCVFMR_vnfName")
160 String tenantId = execution.getVariable("DCVFMR_tenantId")
161 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
162 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
163 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
164 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
165 String requestId = execution.getVariable("DCVFMR_requestId")
167 String serviceInstanceIdToSdnc = ""
168 if (srvInstId != null && !srvInstId.isEmpty()) {
169 serviceInstanceIdToSdnc = srvInstId
171 serviceInstanceIdToSdnc = vfModuleId
174 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
175 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
178 def requestAction = ""
180 if (doSDNCActivateRollback.equals("true")) {
182 requestAction = "DisconnectVNFRequest"
184 else if (doSDNCAssignRollback.equals("true")) {
186 requestAction = "VNFActivateRequest"
192 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
193 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
194 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
195 <sdncadapter:RequestHeader>
196 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
197 <sdncadapter:SvcInstanceId>${vfModuleId}</sdncadapter:SvcInstanceId>
198 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
199 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
200 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
201 </sdncadapter:RequestHeader>
202 <sdncadapterworkflow:SDNCRequestData>
203 <request-information>
204 <request-id>${requestId}</request-id>
205 <request-action>${requestAction}</request-action>
206 <source>${source}</source>
210 </request-information>
211 <service-information>
212 <service-id>${serviceId}</service-id>
213 <service-type>${serviceId}</service-type>
214 <service-instance-id>${serviceInstanceIdToSdnc}</service-instance-id>
215 <subscriber-name>notsurewecare</subscriber-name>
216 </service-information>
217 <vnf-request-information>
218 <vnf-id>${vfModuleId}</vnf-id>
219 <vnf-type>${vfModuleModelName}</vnf-type>
220 <vnf-name>${vfModuleName}</vnf-name>
221 <generic-vnf-id>${vnfId}</generic-vnf-id>
222 <generic-vnf-name>${vnfName}</generic-vnf-name>
223 <generic-vnf-type>${vnfType}</generic-vnf-type>
224 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
225 <tenant>${tenantId}</tenant>
226 </vnf-request-information>
227 </sdncadapterworkflow:SDNCRequestData>
228 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
230 utils.log("DEBUG", "sdncAdapterWorkflowRequest: " + request, isDebugEnabled)
231 utils.logAudit("DoCreateVfModuleRollback sdncAdapterWorkflow Request: " + request)
232 execution.setVariable("sdncAdapterWorkflowRequest", request)
235 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
236 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
237 execution.setVariable("prefix", Prefix)
238 logDebug(" ======== STARTED preProcessSDNCDeactivateRequest ======== ", isDebugLogEnabled)
240 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
245 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
247 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
248 execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
249 logDebug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest, isDebugLogEnabled)
250 utils.logAudit("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
253 utils.log("ERROR", "Exception Occured Processing preProcessSDNCDeactivateRequest. Exception is:\n" + e, isDebugLogEnabled)
254 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
256 logDebug("======== COMPLETED preProcessSDNCDeactivateRequest ======== ", isDebugLogEnabled)
259 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
260 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
261 'execution=' + execution.getId() +
263 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
264 logDebug('Entered ' + method, isDebugLogEnabled)
265 execution.setVariable("prefix", Prefix)
266 logDebug(" ======== STARTED preProcessSDNCUnassignRequest Process ======== ", isDebugLogEnabled)
268 String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
270 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
272 execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
273 logDebug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest, isDebugLogEnabled)
274 utils.logAudit("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
277 log.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e, isDebugLogEnabled)
278 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
280 logDebug("======== COMPLETED preProcessSDNCUnassignRequest Process ======== ", isDebugLogEnabled)
283 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
285 String uuid = execution.getVariable('testReqId') // for junits
287 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
289 def callbackURL = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
290 def requestId = execution.getVariable("DCVFMR_requestId")
291 def serviceId = execution.getVariable("DCVFMR_serviceId")
292 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
293 def vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
294 def source = execution.getVariable("DCVFMR_source")
295 def vnfId = execution.getVariable("DCVFMR_vnfId")
297 def sdncVersion = execution.getVariable("sdncVersion")
300 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
301 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
302 xmlns:sdncadapter="http://org.openecomp.mso/workflow/sdnc/adapter/schema/v1">
303 <sdncadapter:RequestHeader>
304 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
305 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
306 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
307 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
308 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
309 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
310 </sdncadapter:RequestHeader>
311 <sdncadapterworkflow:SDNCRequestData>
312 <request-information>
313 <request-id>${requestId}</request-id>
314 <request-action>DeleteVfModuleInstance</request-action>
315 <source>${source}</source>
319 </request-information>
320 <service-information>
322 <subscription-service-type/>
323 <service-instance-id>${serviceInstanceId}</service-instance-id>
324 <global-customer-id/>
325 </service-information>
327 <vnf-id>${vnfId}</vnf-id>
330 <vf-module-information>
331 <vf-module-id>${vfModuleId}</vf-module-id>
332 </vf-module-information>
333 <vf-module-request-input/>
334 </sdncadapterworkflow:SDNCRequestData>
335 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
337 utils.logAudit("sdncRequest: " + sdncRequest)
341 // parse the incoming DELETE_VF_MODULE request
342 // and formulate the outgoing VnfAdapterDeleteV1 request
343 public void prepVNFAdapterRequest(DelegateExecution execution) {
344 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
345 String requestId = UUID.randomUUID().toString()
346 String origRequestId = execution.getVariable("DCVFMR_requestId")
347 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
348 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
349 String vnfId = execution.getVariable("DCVFMR_vnfId")
350 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
351 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
352 String tenantId = execution.getVariable("DCVFMR_tenantId")
353 def messageId = execution.getVariable('mso-request-id') + '-' +
354 System.currentTimeMillis()
355 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
356 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
357 if ('true'.equals(useQualifiedHostName)) {
358 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
362 <deleteVfModuleRequest>
363 <cloudSiteId>${aicCloudRegion}</cloudSiteId>
364 <tenantId>${tenantId}</tenantId>
365 <vnfId>${vnfId}</vnfId>
366 <vfModuleId>${vfModuleId}</vfModuleId>
367 <vfModuleStackId>${vfModuleStackId}</vfModuleStackId>
368 <skipAAI>true</skipAAI>
370 <requestId>${origRequestId}</requestId>
371 <serviceInstanceId>${srvInstId}</serviceInstanceId>
373 <messageId>${messageId}</messageId>
374 <notificationUrl>${notificationUrl}</notificationUrl>
375 </deleteVfModuleRequest>
378 utils.log("DEBUG", "vnfAdapterRestV1Request: " + request, isDebugEnabled)
379 utils.logAudit("PrepareUpdateAAIVfModule vnfAdapterRestV1 Request: " + request)
380 execution.setVariable("vnfAdapterRestV1Request", request)
383 // parse the incoming DELETE_VF_MODULE request
384 // and formulate the outgoing UpdateAAIVfModuleRequest request
385 public void prepUpdateAAIVfModule(DelegateExecution execution) {
386 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
387 String vnfId = execution.getVariable("DCVFMR_vnfId")
388 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
389 // formulate the request for UpdateAAIVfModule
390 String request = """<UpdateAAIVfModuleRequest>
391 <vnf-id>${vnfId}</vnf-id>
392 <vf-module-id>${vfModuleId}</vf-module-id>
393 <heat-stack-id>DELETE</heat-stack-id>
394 <orchestration-status>deleted</orchestration-status>
395 </UpdateAAIVfModuleRequest>""" as String
396 utils.log("DEBUG", "UpdateAAIVfModuleRequest :" + request, isDebugEnabled)
397 utils.logAudit("UpdateAAIVfModule Request: " + request)
398 execution.setVariable("UpdateAAIVfModuleRequest", request)
401 // parse the incoming DELETE_VF_MODULE request
402 // and formulate the outgoing UpdateAAIVfModuleRequest request
403 public void prepUpdateAAIVfModuleToAssigned(DelegateExecution execution) {
404 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
405 String vnfId = execution.getVariable("DCVFMR_vnfId")
406 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
407 // formulate the request for UpdateAAIVfModule
408 String request = """<UpdateAAIVfModuleRequest>
409 <vnf-id>${vnfId}</vnf-id>
410 <vf-module-id>${vfModuleId}</vf-module-id>
411 <heat-stack-id></heat-stack-id>
412 <orchestration-status>Assigned</orchestration-status>
413 </UpdateAAIVfModuleRequest>""" as String
414 utils.log("DEBUG", "UpdateAAIVfModuleRequest :" + request, isDebugEnabled)
415 utils.logAudit("UpdateAAIVfModule Request: " + request)
416 execution.setVariable("UpdateAAIVfModuleRequest", request)
419 // parse the incoming DELETE_VF_MODULE request
420 // and formulate the outgoing DeleteAAIVfModuleRequest request
421 public void prepDeleteAAIVfModule(DelegateExecution execution) {
422 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
423 String vnfId = execution.getVariable("DCVFMR_vnfId")
424 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
425 // formulate the request for UpdateAAIVfModule
426 String request = """<DeleteAAIVfModuleRequest>
427 <vnf-id>${vnfId}</vnf-id>
428 <vf-module-id>${vfModuleId}</vf-module-id>
429 </DeleteAAIVfModuleRequest>""" as String
430 utils.log("DEBUG", "DeleteAAIVfModuleRequest :" + request, isDebugEnabled)
431 utils.logAudit("DeleteAAIVfModule Request: " + request)
432 execution.setVariable("DeleteAAIVfModuleRequest", request)
435 // generates a WorkflowException if
437 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
438 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
439 utils.log("ERROR", "AAI error occurred deleting the Generic Vnf: "
440 + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"), isDebugEnabled)
441 String processKey = getProcessKey(execution);
442 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
446 public void sdncValidateResponse(DelegateExecution execution, String response){
447 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
448 execution.setVariable("prefix",Prefix)
450 WorkflowException workflowException = execution.getVariable("WorkflowException")
451 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
453 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
454 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
456 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
457 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
459 throw new BpmnError("MSOWorkflowException")
463 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
464 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
465 'execution=' + execution.getId() +
467 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
468 logDebug('Entered ' + method, isDebugLogEnabled)
469 execution.setVariable("prefix", Prefix)
470 logDebug(" ======== STARTED deleteNetworkPoliciesFromAAI ======== ", isDebugLogEnabled)
474 List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
475 if (fqdnList == null) {
476 logDebug("No network policies to delete", isDebugLogEnabled)
479 int fqdnCount = fqdnList.size()
481 execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
482 logDebug("networkPolicyFqdnCount - " + fqdnCount, isDebugLogEnabled)
484 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
485 AaiUtil aaiUriUtil = new AaiUtil(this)
486 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
489 // AII loop call over contrail network policy fqdn list
490 for (i in 0..fqdnCount-1) {
493 String fqdn = fqdnList[i]
495 // Query AAI for this network policy FQDN
497 String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
498 utils.logAudit("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
499 logDebug("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest, isDebugLogEnabled)
501 def aaiRequestId = UUID.randomUUID().toString()
502 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyByFqdnAAIRequest)
503 int returnCode = response.getStatusCode()
504 execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", returnCode)
505 logDebug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugLogEnabled)
507 String aaiResponseAsString = response.getResponseBodyAsString()
509 if (isOneOf(returnCode, 200, 201)) {
510 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
511 // This network policy FQDN exists in AAI - need to delete it now
512 utils.logAudit(aaiResponseAsString)
513 execution.setVariable(Prefix + "queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
514 logDebug("QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugLogEnabled)
515 // Retrieve the network policy id for this FQDN
516 def networkPolicyId = utils.getNodeText1(aaiResponseAsString, "network-policy-id")
517 logDebug("Deleting network-policy with network-policy-id " + networkPolicyId, isDebugLogEnabled)
519 // Retrieve the resource version for this network policy
520 def resourceVersion = utils.getNodeText1(aaiResponseAsString, "resource-version")
521 logDebug("Deleting network-policy with resource-version " + resourceVersion, isDebugLogEnabled)
523 String delNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8") +
524 "?resource-version=" + UriUtils.encode(resourceVersion, "UTF-8")
526 utils.logAudit("AAI request endpoint: " + delNetworkPolicyAAIRequest)
527 logDebug("AAI request endpoint: " + delNetworkPolicyAAIRequest, isDebugLogEnabled)
529 def aaiRequestIdDel = UUID.randomUUID().toString()
530 logDebug("invoking DELETE call to AAI", isDebugLogEnabled)
531 utils.logAudit("Sending DELETE call to AAI with Endpoint /n" + delNetworkPolicyAAIRequest)
533 APIResponse responseDel = aaiUriUtil.executeAAIDeleteCall(execution, delNetworkPolicyAAIRequest)
535 int returnCodeDel = responseDel.getStatusCode()
536 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", returnCodeDel)
537 logDebug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodeDel, isDebugLogEnabled)
539 if (isOneOf(returnCodeDel, 200, 201, 204)) {
540 logDebug("The return code from deleting network policy is: " + returnCodeDel, isDebugLogEnabled)
541 // This network policy was deleted from AAI successfully
542 logDebug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ", isDebugLogEnabled)
546 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + returnCodeDel
547 logDebug(delErrorMessage, isDebugLogEnabled)
548 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
550 } else if (returnCode == 404) {
551 // This network policy FQDN is not in AAI. No need to delete.
552 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
553 logDebug("This network policy FQDN is not in AAI: " + fqdn, isDebugLogEnabled)
554 utils.logAudit("Network policy FQDN is not in AAI")
556 if (aaiResponseAsString.contains("RESTFault")) {
557 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
558 execution.setVariable("WorkflowException", exceptionObject)
559 throw new BpmnError("MSOWorkflowException")
563 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + returnCode
564 logDebug(dataErrorMessage, isDebugLogEnabled)
565 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
576 logDebug("No contrail network policies to query/create", isDebugLogEnabled)
580 } catch (BpmnError e) {
583 } catch (Exception ex) {
584 String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
585 logDebug(exceptionMessage, isDebugLogEnabled)
586 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
593 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
595 * @param execution The flow's execution instance.
597 public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
598 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
599 'execution=' + execution.getId() +
601 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
602 logDebug('Entered ' + method, isDebugLogEnabled)
605 def vnfId = execution.getVariable('DCVFMR_vnfId')
606 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
607 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
608 def ipv4OamAddressElement = ''
609 def managementV6AddressElement = ''
611 if (oamManagementV4Address != null) {
612 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
615 if (oamManagementV6Address != null) {
616 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
620 String updateAAIGenericVnfRequest = """
621 <UpdateAAIGenericVnfRequest>
622 <vnf-id>${vnfId}</vnf-id>
623 ${ipv4OamAddressElement}
624 ${managementV6AddressElement}
625 </UpdateAAIGenericVnfRequest>
627 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
628 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
629 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
630 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
633 logDebug('Exited ' + method, isDebugLogEnabled)
634 } catch (BpmnError e) {
636 } catch (Exception e) {
637 logError('Caught exception in ' + method, e)
638 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
642 public void setSuccessfulRollbackStatus (DelegateExecution execution){
643 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
644 execution.setVariable("prefix", Prefix)
645 logDebug(" ======== STARTED setSuccessfulRollbackStatus ======== ", isDebugLogEnabled)
648 // Set rolledBack to true, rollbackError to null
649 execution.setVariable("rolledBack", true)
650 execution.setVariable("rollbackError", null)
653 utils.log("ERROR", "Exception Occured Processing setSuccessfulRollbackStatus. Exception is:\n" + e, isDebugLogEnabled)
654 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
656 logDebug("======== COMPLETED setSuccessfulRollbackStatus ======== ", isDebugLogEnabled)
659 public void setFailedRollbackStatus (DelegateExecution execution){
660 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
661 execution.setVariable("prefix", Prefix)
662 logDebug(" ======== STARTED setFailedRollbackStatus ======== ", isDebugLogEnabled)
665 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
666 execution.setVariable("rolledBack", false)
667 execution.setVariable("rollbackError", 'Caught exception in DoCreateVfModuleRollback')
668 execution.setVariable("rollbackData", null)
671 utils.log("ERROR", "Exception Occured Processing setFailedRollbackStatus. Exception is:\n" + e, isDebugLogEnabled)
672 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
674 logDebug("======== COMPLETED setFailedRollbackStatus ======== ", isDebugLogEnabled)