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.onap.so.bpmn.infrastructure.scripts
22 import org.camunda.bpm.engine.delegate.BpmnError
23 import org.camunda.bpm.engine.delegate.DelegateExecution
24 import org.onap.so.bpmn.common.scripts.AaiUtil
25 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
27 import org.onap.so.bpmn.common.scripts.MsoUtils
28 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
29 import org.onap.so.bpmn.core.UrnPropertiesReader
30 import org.onap.so.bpmn.core.WorkflowException
31 import org.onap.so.client.aai.AAIObjectPlurals
32 import org.onap.so.client.aai.AAIObjectType
33 import org.onap.so.client.aai.entities.uri.AAIResourceUri
34 import org.onap.so.client.aai.entities.uri.AAIUriFactory
35 import org.onap.so.logger.MessageEnum
36 import org.onap.so.logger.MsoLogger
37 import org.onap.so.rest.APIResponse
38 import org.springframework.web.util.UriUtils
42 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
43 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVfModuleRollback.class);
46 ExceptionUtil exceptionUtil = new ExceptionUtil()
48 public void initProcessVariables(DelegateExecution execution) {
49 execution.setVariable("prefix",Prefix)
52 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
53 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
54 public void preProcessRequest(DelegateExecution execution) {
57 initProcessVariables(execution)
61 execution.setVariable("rolledBack", null)
62 execution.setVariable("rollbackError", null)
64 def rollbackData = execution.getVariable("rollbackData")
65 msoLogger.debug("RollbackData:" + rollbackData)
67 if (rollbackData != null) {
68 String vnfId = rollbackData.get("VFMODULE", "vnfid")
69 execution.setVariable("DCVFMR_vnfId", vnfId)
70 String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
71 execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
72 String source = rollbackData.get("VFMODULE", "source")
73 execution.setVariable("DCVFMR_source", source)
74 String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
75 execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
76 String serviceId = rollbackData.get("VFMODULE", "service-id")
77 execution.setVariable("DCVFMR_serviceId", serviceId)
78 String vnfType = rollbackData.get("VFMODULE", "vnftype")
79 execution.setVariable("DCVFMR_vnfType", vnfType)
80 String vnfName = rollbackData.get("VFMODULE", "vnfname")
81 execution.setVariable("DCVFMR_vnfName", vnfName)
82 String tenantId = rollbackData.get("VFMODULE", "tenantid")
83 execution.setVariable("DCVFMR_tenantId", tenantId)
84 String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
85 execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
86 String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
87 execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
88 String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
89 execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
90 String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
91 execution.setVariable("DCVFMR_heatStackId", heatStackId)
92 String requestId = rollbackData.get("VFMODULE", "msorequestid")
93 execution.setVariable("DCVFMR_requestId", requestId)
94 // Set mso-request-id to request-id for VNF Adapter interface
95 execution.setVariable("mso-request-id", requestId)
96 List createdNetworkPolicyFqdnList = []
99 String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
103 createdNetworkPolicyFqdnList.add(fqdn)
104 msoLogger.debug("got fqdn # " + i + ": " + fqdn)
109 execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
110 String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
111 execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
112 String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
113 execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
114 //String serviceInstanceId = rollbackData.get("VFMODULE", "msoserviceinstanceid")
115 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
116 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
117 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
118 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
119 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
120 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
121 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
122 execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
123 execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
125 // formulate the request for PrepareUpdateAAIVfModule
126 String request = """<PrepareUpdateAAIVfModuleRequest>
127 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
128 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
129 <orchestration-status>pending-delete</orchestration-status>
130 </PrepareUpdateAAIVfModuleRequest>""" as String
131 msoLogger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
132 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
134 execution.setVariable("skipRollback", true)
137 if (execution.getVariable("disableRollback").equals("true" )) {
138 execution.setVariable("skipRollback", true)
141 } catch (BpmnError e) {
143 } catch (Exception ex){
144 def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
146 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
150 // build a SDNC vnf-topology-operation request for the specified action
151 // (note: the action passed is expected to be 'changedelete' or 'delete')
152 public void prepSDNCAdapterRequest(DelegateExecution execution) {
154 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
156 String uuid = execution.getVariable('testReqId') // for junits
158 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
161 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
163 String source = execution.getVariable("DCVFMR_source")
164 String serviceId = execution.getVariable("DCVFMR_serviceId")
165 String vnfId = execution.getVariable("DCVFMR_vnfId")
166 String vnfType = execution.getVariable("DCVFMR_vnfType")
167 String vnfName = execution.getVariable("DCVFMR_vnfName")
168 String tenantId = execution.getVariable("DCVFMR_tenantId")
169 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
170 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
171 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
172 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
173 String requestId = execution.getVariable("DCVFMR_requestId")
175 String serviceInstanceIdToSdnc = ""
176 if (srvInstId != null && !srvInstId.isEmpty()) {
177 serviceInstanceIdToSdnc = srvInstId
179 serviceInstanceIdToSdnc = vfModuleId
182 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
183 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
186 def requestAction = ""
188 if (doSDNCActivateRollback.equals("true")) {
190 requestAction = "DisconnectVNFRequest"
192 else if (doSDNCAssignRollback.equals("true")) {
194 requestAction = "VNFActivateRequest"
200 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
201 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
202 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
203 <sdncadapter:RequestHeader>
204 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
205 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
206 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
207 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
208 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
209 </sdncadapter:RequestHeader>
210 <sdncadapterworkflow:SDNCRequestData>
211 <request-information>
212 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
213 <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
214 <source>${MsoUtils.xmlEscape(source)}</source>
218 </request-information>
219 <service-information>
220 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
221 <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
222 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
223 <subscriber-name>notsurewecare</subscriber-name>
224 </service-information>
225 <vnf-request-information>
226 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
227 <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
228 <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
229 <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
230 <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
231 <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
232 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
233 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
234 </vnf-request-information>
235 </sdncadapterworkflow:SDNCRequestData>
236 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
238 msoLogger.debug("sdncAdapterWorkflowRequest: " + request)
239 execution.setVariable("sdncAdapterWorkflowRequest", request)
242 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
244 execution.setVariable("prefix", Prefix)
245 msoLogger.trace("STARTED preProcessSDNCDeactivateRequest")
247 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
252 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
254 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
255 execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
256 msoLogger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
259 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessSDNCDeactivateRequest.", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
260 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
262 msoLogger.trace("COMPLETED preProcessSDNCDeactivateRequest")
265 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
266 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
267 'execution=' + execution.getId() +
269 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
270 msoLogger.trace('Entered ' + method)
271 execution.setVariable("prefix", Prefix)
272 msoLogger.trace("STARTED preProcessSDNCUnassignRequest Process")
274 String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
276 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
278 execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
279 msoLogger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
282 msoLogger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
283 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
285 msoLogger.trace("COMPLETED preProcessSDNCUnassignRequest Process")
288 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
290 String uuid = execution.getVariable('testReqId') // for junits
292 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
294 def callbackURL = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
295 def requestId = execution.getVariable("DCVFMR_requestId")
296 def serviceId = execution.getVariable("DCVFMR_serviceId")
297 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
298 def vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
299 def source = execution.getVariable("DCVFMR_source")
300 def vnfId = execution.getVariable("DCVFMR_vnfId")
302 def sdncVersion = execution.getVariable("sdncVersion")
305 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
306 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
307 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
308 <sdncadapter:RequestHeader>
309 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
310 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
311 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
312 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
313 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
314 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
315 </sdncadapter:RequestHeader>
316 <sdncadapterworkflow:SDNCRequestData>
317 <request-information>
318 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
319 <request-action>DeleteVfModuleInstance</request-action>
320 <source>${MsoUtils.xmlEscape(source)}</source>
324 </request-information>
325 <service-information>
327 <subscription-service-type/>
328 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
329 <global-customer-id/>
330 </service-information>
332 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
335 <vf-module-information>
336 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
337 </vf-module-information>
338 <vf-module-request-input/>
339 </sdncadapterworkflow:SDNCRequestData>
340 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
342 msoLogger.debug("sdncRequest: " + sdncRequest)
346 // parse the incoming DELETE_VF_MODULE request
347 // and formulate the outgoing VnfAdapterDeleteV1 request
348 public void prepVNFAdapterRequest(DelegateExecution execution) {
350 String requestId = UUID.randomUUID().toString()
351 String origRequestId = execution.getVariable("DCVFMR_requestId")
352 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
353 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
354 String vnfId = execution.getVariable("DCVFMR_vnfId")
355 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
356 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
357 String tenantId = execution.getVariable("DCVFMR_tenantId")
358 def messageId = execution.getVariable('mso-request-id') + '-' +
359 System.currentTimeMillis()
360 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
361 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
362 if ('true'.equals(useQualifiedHostName)) {
363 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
367 <deleteVfModuleRequest>
368 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
369 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
370 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
371 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
372 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
373 <skipAAI>true</skipAAI>
375 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
376 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
378 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
379 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
380 </deleteVfModuleRequest>
383 msoLogger.debug("vnfAdapterRestV1Request: " + request)
384 execution.setVariable("vnfAdapterRestV1Request", request)
387 // parse the incoming DELETE_VF_MODULE request
388 // and formulate the outgoing UpdateAAIVfModuleRequest request
389 public void prepUpdateAAIVfModule(DelegateExecution execution) {
391 String vnfId = execution.getVariable("DCVFMR_vnfId")
392 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
393 // formulate the request for UpdateAAIVfModule
394 String request = """<UpdateAAIVfModuleRequest>
395 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
396 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
397 <heat-stack-id>DELETE</heat-stack-id>
398 <orchestration-status>deleted</orchestration-status>
399 </UpdateAAIVfModuleRequest>""" as String
400 msoLogger.debug("UpdateAAIVfModuleRequest :" + request)
401 execution.setVariable("UpdateAAIVfModuleRequest", request)
404 // parse the incoming DELETE_VF_MODULE request
405 // and formulate the outgoing UpdateAAIVfModuleRequest request
406 public void prepUpdateAAIVfModuleToAssigned(DelegateExecution execution) {
408 String vnfId = execution.getVariable("DCVFMR_vnfId")
409 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
410 // formulate the request for UpdateAAIVfModule
411 String request = """<UpdateAAIVfModuleRequest>
412 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
413 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
414 <heat-stack-id></heat-stack-id>
415 <orchestration-status>Assigned</orchestration-status>
416 </UpdateAAIVfModuleRequest>""" as String
417 msoLogger.debug("UpdateAAIVfModuleRequest :" + request)
418 execution.setVariable("UpdateAAIVfModuleRequest", request)
421 // parse the incoming DELETE_VF_MODULE request
422 // and formulate the outgoing DeleteAAIVfModuleRequest request
423 public void prepDeleteAAIVfModule(DelegateExecution execution) {
425 String vnfId = execution.getVariable("DCVFMR_vnfId")
426 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
427 // formulate the request for UpdateAAIVfModule
428 String request = """<DeleteAAIVfModuleRequest>
429 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
430 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
431 </DeleteAAIVfModuleRequest>""" as String
432 msoLogger.debug("DeleteAAIVfModuleRequest :" + request)
433 execution.setVariable("DeleteAAIVfModuleRequest", request)
436 // generates a WorkflowException if
438 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
440 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "AAI error occurred deleting the Generic Vnf"+ execution.getVariable("DoDVfMod_deleteGenericVnfResponse"), "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError);
441 String processKey = getProcessKey(execution);
442 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
446 public void sdncValidateResponse(DelegateExecution execution, String response){
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 msoLogger.debug("Successfully Validated SDNC Response")
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 msoLogger.trace('Entered ' + method)
469 execution.setVariable("prefix", Prefix)
470 msoLogger.trace("STARTED deleteNetworkPoliciesFromAAI")
474 List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
475 if (fqdnList == null) {
476 msoLogger.debug("No network policies to delete")
479 int fqdnCount = fqdnList.size()
481 execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
482 msoLogger.debug("networkPolicyFqdnCount - " + fqdnCount)
484 AaiUtil aaiUriUtil = new AaiUtil(this)
487 // AII loop call over contrail network policy fqdn list
488 for (i in 0..fqdnCount-1) {
491 String fqdn = fqdnList[i]
493 // Query AAI for this network policy FQDN
494 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
495 uri.queryParam("network-policy-fqdn", fqdn)
496 String queryNetworkPolicyByFqdnAAIRequest = aaiUriUtil.createAaiUri(uri)
498 msoLogger.debug("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
500 def aaiRequestId = UUID.randomUUID().toString()
501 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyByFqdnAAIRequest)
502 int returnCode = response.getStatusCode()
503 execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", returnCode)
504 msoLogger.debug("AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
506 String aaiResponseAsString = response.getResponseBodyAsString()
508 if (isOneOf(returnCode, 200, 201)) {
509 msoLogger.debug("The return code is: " + returnCode)
510 // This network policy FQDN exists in AAI - need to delete it now
511 execution.setVariable(Prefix + "queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
512 msoLogger.debug("QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
513 // Retrieve the network policy id for this FQDN
514 def networkPolicyId = utils.getNodeText(aaiResponseAsString, "network-policy-id")
515 msoLogger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
517 // Retrieve the resource version for this network policy
518 def resourceVersion = utils.getNodeText(aaiResponseAsString, "resource-version")
519 msoLogger.debug("Deleting network-policy with resource-version " + resourceVersion)
521 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
522 delUri.resourceVersion(resourceVersion)
523 String delNetworkPolicyAAIRequest = aaiUriUtil.createAaiUri(delUri)
525 msoLogger.debug("AAI request endpoint: " + delNetworkPolicyAAIRequest)
527 def aaiRequestIdDel = UUID.randomUUID().toString()
528 msoLogger.debug("Sending DELETE call to AAI with Endpoint /n" + delNetworkPolicyAAIRequest)
530 APIResponse responseDel = aaiUriUtil.executeAAIDeleteCall(execution, delNetworkPolicyAAIRequest)
532 int returnCodeDel = responseDel.getStatusCode()
533 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", returnCodeDel)
534 msoLogger.debug("AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodeDel)
536 if (isOneOf(returnCodeDel, 200, 201, 204)) {
537 msoLogger.debug("The return code from deleting network policy is: " + returnCodeDel)
538 // This network policy was deleted from AAI successfully
539 msoLogger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
543 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + returnCodeDel
544 msoLogger.debug(delErrorMessage)
545 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
547 } else if (returnCode == 404) {
548 // This network policy FQDN is not in AAI. No need to delete.
549 msoLogger.debug("The return code is: " + returnCode)
550 msoLogger.debug("This network policy FQDN is not in AAI: " + fqdn)
552 if (aaiResponseAsString.contains("RESTFault")) {
553 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
554 execution.setVariable("WorkflowException", exceptionObject)
555 throw new BpmnError("MSOWorkflowException")
559 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + returnCode
560 msoLogger.debug(dataErrorMessage)
561 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
572 msoLogger.debug("No contrail network policies to query/create")
576 } catch (BpmnError e) {
579 } catch (Exception ex) {
580 String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
581 msoLogger.debug(exceptionMessage)
582 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
589 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
591 * @param execution The flow's execution instance.
593 public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
594 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
595 'execution=' + execution.getId() +
597 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
598 msoLogger.trace('Entered ' + method)
601 def vnfId = execution.getVariable('DCVFMR_vnfId')
602 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
603 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
604 def ipv4OamAddressElement = ''
605 def managementV6AddressElement = ''
607 if (oamManagementV4Address != null) {
608 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
611 if (oamManagementV6Address != null) {
612 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
616 String updateAAIGenericVnfRequest = """
617 <UpdateAAIGenericVnfRequest>
618 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
619 ${ipv4OamAddressElement}
620 ${managementV6AddressElement}
621 </UpdateAAIGenericVnfRequest>
623 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
624 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
625 msoLogger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
628 msoLogger.trace('Exited ' + method)
629 } catch (BpmnError e) {
631 } catch (Exception e) {
632 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
633 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
637 public void setSuccessfulRollbackStatus (DelegateExecution execution){
639 execution.setVariable("prefix", Prefix)
640 msoLogger.trace("STARTED setSuccessfulRollbackStatus")
643 // Set rolledBack to true, rollbackError to null
644 execution.setVariable("rolledBack", true)
645 execution.setVariable("rollbackError", null)
648 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing setSuccessfulRollbackStatus.", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
649 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
651 msoLogger.trace("COMPLETED setSuccessfulRollbackStatus")
654 public void setFailedRollbackStatus (DelegateExecution execution){
656 execution.setVariable("prefix", Prefix)
657 msoLogger.trace("STARTED setFailedRollbackStatus")
660 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
661 execution.setVariable("rolledBack", false)
662 execution.setVariable("rollbackError", 'Caught exception in DoCreateVfModuleRollback')
663 execution.setVariable("rollbackData", null)
666 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing setFailedRollbackStatus.", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
667 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
669 msoLogger.trace("COMPLETED setFailedRollbackStatus")