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.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
34 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
37 ExceptionUtil exceptionUtil = new ExceptionUtil()
39 public void initProcessVariables(Execution 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(Execution 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(Execution 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(Execution 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(Execution 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(Execution 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(Execution 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(Execution 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 DeleteAAIVfModuleRequest request
403 public void prepDeleteAAIVfModule(Execution 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 = """<DeleteAAIVfModuleRequest>
409 <vnf-id>${vnfId}</vnf-id>
410 <vf-module-id>${vfModuleId}</vf-module-id>
411 </DeleteAAIVfModuleRequest>""" as String
412 utils.log("DEBUG", "DeleteAAIVfModuleRequest :" + request, isDebugEnabled)
413 utils.logAudit("DeleteAAIVfModule Request: " + request)
414 execution.setVariable("DeleteAAIVfModuleRequest", request)
417 // generates a WorkflowException if
419 public void handleDoDeleteVfModuleFailure(Execution execution) {
420 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
421 utils.log("ERROR", "AAI error occurred deleting the Generic Vnf: "
422 + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"), isDebugEnabled)
423 String processKey = getProcessKey(execution);
424 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
428 public void sdncValidateResponse(Execution execution, String response){
429 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
430 execution.setVariable("prefix",Prefix)
432 WorkflowException workflowException = execution.getVariable("WorkflowException")
433 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
435 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
436 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
438 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
439 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
441 throw new BpmnError("MSOWorkflowException")
445 public void deleteNetworkPoliciesFromAAI(Execution execution) {
446 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
447 'execution=' + execution.getId() +
449 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
450 logDebug('Entered ' + method, isDebugLogEnabled)
451 execution.setVariable("prefix", Prefix)
452 logDebug(" ======== STARTED deleteNetworkPoliciesFromAAI ======== ", isDebugLogEnabled)
456 List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
457 if (fqdnList == null) {
458 logDebug("No network policies to delete", isDebugLogEnabled)
461 int fqdnCount = fqdnList.size()
463 execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
464 logDebug("networkPolicyFqdnCount - " + fqdnCount, isDebugLogEnabled)
466 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
467 AaiUtil aaiUriUtil = new AaiUtil(this)
468 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
471 // AII loop call over contrail network policy fqdn list
472 for (i in 0..fqdnCount-1) {
475 String fqdn = fqdnList[i]
477 // Query AAI for this network policy FQDN
479 String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
480 utils.logAudit("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
481 logDebug("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest, isDebugLogEnabled)
483 def aaiRequestId = UUID.randomUUID().toString()
484 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyByFqdnAAIRequest)
485 int returnCode = response.getStatusCode()
486 execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", returnCode)
487 logDebug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugLogEnabled)
489 String aaiResponseAsString = response.getResponseBodyAsString()
491 if (isOneOf(returnCode, 200, 201)) {
492 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
493 // This network policy FQDN exists in AAI - need to delete it now
494 utils.logAudit(aaiResponseAsString)
495 execution.setVariable(Prefix + "queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
496 logDebug("QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugLogEnabled)
497 // Retrieve the network policy id for this FQDN
498 def networkPolicyId = utils.getNodeText1(aaiResponseAsString, "network-policy-id")
499 logDebug("Deleting network-policy with network-policy-id " + networkPolicyId, isDebugLogEnabled)
501 // Retrieve the resource version for this network policy
502 def resourceVersion = utils.getNodeText1(aaiResponseAsString, "resource-version")
503 logDebug("Deleting network-policy with resource-version " + resourceVersion, isDebugLogEnabled)
505 String delNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8") +
506 "?resource-version=" + UriUtils.encode(resourceVersion, "UTF-8")
508 utils.logAudit("AAI request endpoint: " + delNetworkPolicyAAIRequest)
509 logDebug("AAI request endpoint: " + delNetworkPolicyAAIRequest, isDebugLogEnabled)
511 def aaiRequestIdDel = UUID.randomUUID().toString()
512 logDebug("invoking DELETE call to AAI", isDebugLogEnabled)
513 utils.logAudit("Sending DELETE call to AAI with Endpoint /n" + delNetworkPolicyAAIRequest)
515 APIResponse responseDel = aaiUriUtil.executeAAIDeleteCall(execution, delNetworkPolicyAAIRequest)
517 int returnCodeDel = responseDel.getStatusCode()
518 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", returnCodeDel)
519 logDebug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodeDel, isDebugLogEnabled)
521 if (isOneOf(returnCodeDel, 200, 201, 204)) {
522 logDebug("The return code from deleting network policy is: " + returnCodeDel, isDebugLogEnabled)
523 // This network policy was deleted from AAI successfully
524 logDebug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ", isDebugLogEnabled)
528 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + returnCodeDel
529 logDebug(delErrorMessage, isDebugLogEnabled)
530 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
532 } else if (returnCode == 404) {
533 // This network policy FQDN is not in AAI. No need to delete.
534 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
535 logDebug("This network policy FQDN is not in AAI: " + fqdn, isDebugLogEnabled)
536 utils.logAudit("Network policy FQDN is not in AAI")
538 if (aaiResponseAsString.contains("RESTFault")) {
539 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
540 execution.setVariable("WorkflowException", exceptionObject)
541 throw new BpmnError("MSOWorkflowException")
545 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + returnCode
546 logDebug(dataErrorMessage, isDebugLogEnabled)
547 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
558 logDebug("No contrail network policies to query/create", isDebugLogEnabled)
562 } catch (BpmnError e) {
565 } catch (Exception ex) {
566 String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
567 logDebug(exceptionMessage, isDebugLogEnabled)
568 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
575 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
577 * @param execution The flow's execution instance.
579 public void preProcessUpdateAAIGenericVnf(Execution execution) {
580 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
581 'execution=' + execution.getId() +
583 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
584 logDebug('Entered ' + method, isDebugLogEnabled)
587 def vnfId = execution.getVariable('DCVFMR_vnfId')
588 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
589 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
590 def ipv4OamAddressElement = ''
591 def managementV6AddressElement = ''
593 if (oamManagementV4Address != null) {
594 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
597 if (oamManagementV6Address != null) {
598 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
602 String updateAAIGenericVnfRequest = """
603 <UpdateAAIGenericVnfRequest>
604 <vnf-id>${vnfId}</vnf-id>
605 ${ipv4OamAddressElement}
606 ${managementV6AddressElement}
607 </UpdateAAIGenericVnfRequest>
609 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
610 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
611 utils.logAudit("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
612 logDebug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest, isDebugLogEnabled)
615 logDebug('Exited ' + method, isDebugLogEnabled)
616 } catch (BpmnError e) {
618 } catch (Exception e) {
619 logError('Caught exception in ' + method, e)
620 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
624 public void setSuccessfulRollbackStatus (Execution execution){
625 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
626 execution.setVariable("prefix", Prefix)
627 logDebug(" ======== STARTED setSuccessfulRollbackStatus ======== ", isDebugLogEnabled)
630 // Set rolledBack to true, rollbackError to null
631 execution.setVariable("rolledBack", true)
632 execution.setVariable("rollbackError", null)
635 utils.log("ERROR", "Exception Occured Processing setSuccessfulRollbackStatus. Exception is:\n" + e, isDebugLogEnabled)
636 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
638 logDebug("======== COMPLETED setSuccessfulRollbackStatus ======== ", isDebugLogEnabled)
641 public void setFailedRollbackStatus (Execution execution){
642 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
643 execution.setVariable("prefix", Prefix)
644 logDebug(" ======== STARTED setFailedRollbackStatus ======== ", isDebugLogEnabled)
647 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
648 execution.setVariable("rolledBack", false)
649 execution.setVariable("rollbackError", 'Caught exception in DoCreateVfModuleRollback')
650 execution.setVariable("rollbackData", null)
653 utils.log("ERROR", "Exception Occured Processing setFailedRollbackStatus. Exception is:\n" + e, isDebugLogEnabled)
654 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
656 logDebug("======== COMPLETED setFailedRollbackStatus ======== ", isDebugLogEnabled)