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.logger.MessageEnum
32 import org.onap.so.logger.MsoLogger
33 import org.onap.so.rest.APIResponse
34 import org.springframework.web.util.UriUtils
38 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
39 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateVfModuleRollback.class);
42 ExceptionUtil exceptionUtil = new ExceptionUtil()
44 public void initProcessVariables(DelegateExecution execution) {
45 execution.setVariable("prefix",Prefix)
48 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
49 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
50 public void preProcessRequest(DelegateExecution execution) {
53 initProcessVariables(execution)
57 execution.setVariable("rolledBack", null)
58 execution.setVariable("rollbackError", null)
60 def rollbackData = execution.getVariable("rollbackData")
61 msoLogger.debug("RollbackData:" + rollbackData)
63 if (rollbackData != null) {
64 String vnfId = rollbackData.get("VFMODULE", "vnfid")
65 execution.setVariable("DCVFMR_vnfId", vnfId)
66 String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
67 execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
68 String source = rollbackData.get("VFMODULE", "source")
69 execution.setVariable("DCVFMR_source", source)
70 String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
71 execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
72 String serviceId = rollbackData.get("VFMODULE", "service-id")
73 execution.setVariable("DCVFMR_serviceId", serviceId)
74 String vnfType = rollbackData.get("VFMODULE", "vnftype")
75 execution.setVariable("DCVFMR_vnfType", vnfType)
76 String vnfName = rollbackData.get("VFMODULE", "vnfname")
77 execution.setVariable("DCVFMR_vnfName", vnfName)
78 String tenantId = rollbackData.get("VFMODULE", "tenantid")
79 execution.setVariable("DCVFMR_tenantId", tenantId)
80 String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
81 execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
82 String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
83 execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
84 String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
85 execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
86 String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
87 execution.setVariable("DCVFMR_heatStackId", heatStackId)
88 String requestId = rollbackData.get("VFMODULE", "msorequestid")
89 execution.setVariable("DCVFMR_requestId", requestId)
90 // Set mso-request-id to request-id for VNF Adapter interface
91 execution.setVariable("mso-request-id", requestId)
92 List createdNetworkPolicyFqdnList = []
95 String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
99 createdNetworkPolicyFqdnList.add(fqdn)
100 msoLogger.debug("got fqdn # " + i + ": " + fqdn)
105 execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
106 String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
107 execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
108 String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
109 execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
110 //String serviceInstanceId = rollbackData.get("VFMODULE", "msoserviceinstanceid")
111 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
112 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
113 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
114 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
115 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
116 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
117 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
118 execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
119 execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
121 // formulate the request for PrepareUpdateAAIVfModule
122 String request = """<PrepareUpdateAAIVfModuleRequest>
123 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
124 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
125 <orchestration-status>pending-delete</orchestration-status>
126 </PrepareUpdateAAIVfModuleRequest>""" as String
127 msoLogger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
128 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
130 execution.setVariable("skipRollback", true)
133 if (execution.getVariable("disableRollback").equals("true" )) {
134 execution.setVariable("skipRollback", true)
137 } catch (BpmnError e) {
139 } catch (Exception ex){
140 def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
142 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
146 // build a SDNC vnf-topology-operation request for the specified action
147 // (note: the action passed is expected to be 'changedelete' or 'delete')
148 public void prepSDNCAdapterRequest(DelegateExecution execution) {
150 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
152 String uuid = execution.getVariable('testReqId') // for junits
154 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
157 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
159 String source = execution.getVariable("DCVFMR_source")
160 String serviceId = execution.getVariable("DCVFMR_serviceId")
161 String vnfId = execution.getVariable("DCVFMR_vnfId")
162 String vnfType = execution.getVariable("DCVFMR_vnfType")
163 String vnfName = execution.getVariable("DCVFMR_vnfName")
164 String tenantId = execution.getVariable("DCVFMR_tenantId")
165 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
166 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
167 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
168 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
169 String requestId = execution.getVariable("DCVFMR_requestId")
171 String serviceInstanceIdToSdnc = ""
172 if (srvInstId != null && !srvInstId.isEmpty()) {
173 serviceInstanceIdToSdnc = srvInstId
175 serviceInstanceIdToSdnc = vfModuleId
178 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
179 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
182 def requestAction = ""
184 if (doSDNCActivateRollback.equals("true")) {
186 requestAction = "DisconnectVNFRequest"
188 else if (doSDNCAssignRollback.equals("true")) {
190 requestAction = "VNFActivateRequest"
196 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
197 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
198 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
199 <sdncadapter:RequestHeader>
200 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
201 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
202 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
203 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
204 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
205 </sdncadapter:RequestHeader>
206 <sdncadapterworkflow:SDNCRequestData>
207 <request-information>
208 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
209 <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
210 <source>${MsoUtils.xmlEscape(source)}</source>
214 </request-information>
215 <service-information>
216 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
217 <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
218 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
219 <subscriber-name>notsurewecare</subscriber-name>
220 </service-information>
221 <vnf-request-information>
222 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
223 <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
224 <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
225 <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
226 <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
227 <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
228 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
229 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
230 </vnf-request-information>
231 </sdncadapterworkflow:SDNCRequestData>
232 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
234 msoLogger.debug("sdncAdapterWorkflowRequest: " + request)
235 execution.setVariable("sdncAdapterWorkflowRequest", request)
238 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
240 execution.setVariable("prefix", Prefix)
241 msoLogger.trace("STARTED preProcessSDNCDeactivateRequest")
243 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
248 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
250 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
251 execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
252 msoLogger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
255 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessSDNCDeactivateRequest.", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
256 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
258 msoLogger.trace("COMPLETED preProcessSDNCDeactivateRequest")
261 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
262 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
263 'execution=' + execution.getId() +
265 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
266 msoLogger.trace('Entered ' + method)
267 execution.setVariable("prefix", Prefix)
268 msoLogger.trace("STARTED preProcessSDNCUnassignRequest Process")
270 String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
272 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
274 execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
275 msoLogger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
278 msoLogger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
279 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
281 msoLogger.trace("COMPLETED preProcessSDNCUnassignRequest Process")
284 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
286 String uuid = execution.getVariable('testReqId') // for junits
288 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
290 def callbackURL = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
291 def requestId = execution.getVariable("DCVFMR_requestId")
292 def serviceId = execution.getVariable("DCVFMR_serviceId")
293 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
294 def vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
295 def source = execution.getVariable("DCVFMR_source")
296 def vnfId = execution.getVariable("DCVFMR_vnfId")
298 def sdncVersion = execution.getVariable("sdncVersion")
301 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
302 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
303 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
304 <sdncadapter:RequestHeader>
305 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
306 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
307 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
308 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
309 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
310 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
311 </sdncadapter:RequestHeader>
312 <sdncadapterworkflow:SDNCRequestData>
313 <request-information>
314 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
315 <request-action>DeleteVfModuleInstance</request-action>
316 <source>${MsoUtils.xmlEscape(source)}</source>
320 </request-information>
321 <service-information>
323 <subscription-service-type/>
324 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
325 <global-customer-id/>
326 </service-information>
328 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
331 <vf-module-information>
332 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
333 </vf-module-information>
334 <vf-module-request-input/>
335 </sdncadapterworkflow:SDNCRequestData>
336 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
338 msoLogger.debug("sdncRequest: " + sdncRequest)
342 // parse the incoming DELETE_VF_MODULE request
343 // and formulate the outgoing VnfAdapterDeleteV1 request
344 public void prepVNFAdapterRequest(DelegateExecution execution) {
346 String requestId = UUID.randomUUID().toString()
347 String origRequestId = execution.getVariable("DCVFMR_requestId")
348 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
349 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
350 String vnfId = execution.getVariable("DCVFMR_vnfId")
351 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
352 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
353 String tenantId = execution.getVariable("DCVFMR_tenantId")
354 def messageId = execution.getVariable('mso-request-id') + '-' +
355 System.currentTimeMillis()
356 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
357 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
358 if ('true'.equals(useQualifiedHostName)) {
359 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
363 <deleteVfModuleRequest>
364 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
365 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
366 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
367 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
368 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
369 <skipAAI>true</skipAAI>
371 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
372 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
374 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
375 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
376 </deleteVfModuleRequest>
379 msoLogger.debug("vnfAdapterRestV1Request: " + 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) {
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>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
392 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
393 <heat-stack-id>DELETE</heat-stack-id>
394 <orchestration-status>deleted</orchestration-status>
395 </UpdateAAIVfModuleRequest>""" as String
396 msoLogger.debug("UpdateAAIVfModuleRequest :" + request)
397 execution.setVariable("UpdateAAIVfModuleRequest", request)
400 // parse the incoming DELETE_VF_MODULE request
401 // and formulate the outgoing UpdateAAIVfModuleRequest request
402 public void prepUpdateAAIVfModuleToAssigned(DelegateExecution execution) {
404 String vnfId = execution.getVariable("DCVFMR_vnfId")
405 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
406 // formulate the request for UpdateAAIVfModule
407 String request = """<UpdateAAIVfModuleRequest>
408 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
409 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
410 <heat-stack-id></heat-stack-id>
411 <orchestration-status>Assigned</orchestration-status>
412 </UpdateAAIVfModuleRequest>""" as String
413 msoLogger.debug("UpdateAAIVfModuleRequest :" + request)
414 execution.setVariable("UpdateAAIVfModuleRequest", request)
417 // parse the incoming DELETE_VF_MODULE request
418 // and formulate the outgoing DeleteAAIVfModuleRequest request
419 public void prepDeleteAAIVfModule(DelegateExecution execution) {
421 String vnfId = execution.getVariable("DCVFMR_vnfId")
422 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
423 // formulate the request for UpdateAAIVfModule
424 String request = """<DeleteAAIVfModuleRequest>
425 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
426 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
427 </DeleteAAIVfModuleRequest>""" as String
428 msoLogger.debug("DeleteAAIVfModuleRequest :" + request)
429 execution.setVariable("DeleteAAIVfModuleRequest", request)
432 // generates a WorkflowException if
434 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
436 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "AAI error occurred deleting the Generic Vnf"+ execution.getVariable("DoDVfMod_deleteGenericVnfResponse"), "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError);
437 String processKey = getProcessKey(execution);
438 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
442 public void sdncValidateResponse(DelegateExecution execution, String response){
444 execution.setVariable("prefix",Prefix)
446 WorkflowException workflowException = execution.getVariable("WorkflowException")
447 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
449 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
450 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
452 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
453 msoLogger.debug("Successfully Validated SDNC Response")
455 throw new BpmnError("MSOWorkflowException")
459 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
460 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
461 'execution=' + execution.getId() +
463 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
464 msoLogger.trace('Entered ' + method)
465 execution.setVariable("prefix", Prefix)
466 msoLogger.trace("STARTED deleteNetworkPoliciesFromAAI")
470 List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
471 if (fqdnList == null) {
472 msoLogger.debug("No network policies to delete")
475 int fqdnCount = fqdnList.size()
477 execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
478 msoLogger.debug("networkPolicyFqdnCount - " + fqdnCount)
480 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
481 AaiUtil aaiUriUtil = new AaiUtil(this)
482 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
485 // AII loop call over contrail network policy fqdn list
486 for (i in 0..fqdnCount-1) {
489 String fqdn = fqdnList[i]
491 // Query AAI for this network policy FQDN
493 String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
494 msoLogger.debug("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
496 def aaiRequestId = UUID.randomUUID().toString()
497 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyByFqdnAAIRequest)
498 int returnCode = response.getStatusCode()
499 execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", returnCode)
500 msoLogger.debug("AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
502 String aaiResponseAsString = response.getResponseBodyAsString()
504 if (isOneOf(returnCode, 200, 201)) {
505 msoLogger.debug("The return code is: " + returnCode)
506 // This network policy FQDN exists in AAI - need to delete it now
507 execution.setVariable(Prefix + "queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
508 msoLogger.debug("QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
509 // Retrieve the network policy id for this FQDN
510 def networkPolicyId = utils.getNodeText(aaiResponseAsString, "network-policy-id")
511 msoLogger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
513 // Retrieve the resource version for this network policy
514 def resourceVersion = utils.getNodeText(aaiResponseAsString, "resource-version")
515 msoLogger.debug("Deleting network-policy with resource-version " + resourceVersion)
517 String delNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8") +
518 "?resource-version=" + UriUtils.encode(resourceVersion, "UTF-8")
520 msoLogger.debug("AAI request endpoint: " + delNetworkPolicyAAIRequest)
522 def aaiRequestIdDel = UUID.randomUUID().toString()
523 msoLogger.debug("Sending DELETE call to AAI with Endpoint /n" + delNetworkPolicyAAIRequest)
525 APIResponse responseDel = aaiUriUtil.executeAAIDeleteCall(execution, delNetworkPolicyAAIRequest)
527 int returnCodeDel = responseDel.getStatusCode()
528 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", returnCodeDel)
529 msoLogger.debug("AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodeDel)
531 if (isOneOf(returnCodeDel, 200, 201, 204)) {
532 msoLogger.debug("The return code from deleting network policy is: " + returnCodeDel)
533 // This network policy was deleted from AAI successfully
534 msoLogger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
538 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + returnCodeDel
539 msoLogger.debug(delErrorMessage)
540 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
542 } else if (returnCode == 404) {
543 // This network policy FQDN is not in AAI. No need to delete.
544 msoLogger.debug("The return code is: " + returnCode)
545 msoLogger.debug("This network policy FQDN is not in AAI: " + fqdn)
547 if (aaiResponseAsString.contains("RESTFault")) {
548 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
549 execution.setVariable("WorkflowException", exceptionObject)
550 throw new BpmnError("MSOWorkflowException")
554 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + returnCode
555 msoLogger.debug(dataErrorMessage)
556 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
567 msoLogger.debug("No contrail network policies to query/create")
571 } catch (BpmnError e) {
574 } catch (Exception ex) {
575 String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
576 msoLogger.debug(exceptionMessage)
577 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
584 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
586 * @param execution The flow's execution instance.
588 public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
589 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
590 'execution=' + execution.getId() +
592 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
593 msoLogger.trace('Entered ' + method)
596 def vnfId = execution.getVariable('DCVFMR_vnfId')
597 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
598 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
599 def ipv4OamAddressElement = ''
600 def managementV6AddressElement = ''
602 if (oamManagementV4Address != null) {
603 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
606 if (oamManagementV6Address != null) {
607 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
611 String updateAAIGenericVnfRequest = """
612 <UpdateAAIGenericVnfRequest>
613 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
614 ${ipv4OamAddressElement}
615 ${managementV6AddressElement}
616 </UpdateAAIGenericVnfRequest>
618 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
619 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
620 msoLogger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
623 msoLogger.trace('Exited ' + method)
624 } catch (BpmnError e) {
626 } catch (Exception e) {
627 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
628 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
632 public void setSuccessfulRollbackStatus (DelegateExecution execution){
634 execution.setVariable("prefix", Prefix)
635 msoLogger.trace("STARTED setSuccessfulRollbackStatus")
638 // Set rolledBack to true, rollbackError to null
639 execution.setVariable("rolledBack", true)
640 execution.setVariable("rollbackError", null)
643 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing setSuccessfulRollbackStatus.", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
644 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
646 msoLogger.trace("COMPLETED setSuccessfulRollbackStatus")
649 public void setFailedRollbackStatus (DelegateExecution execution){
651 execution.setVariable("prefix", Prefix)
652 msoLogger.trace("STARTED setFailedRollbackStatus")
655 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
656 execution.setVariable("rolledBack", false)
657 execution.setVariable("rollbackError", 'Caught exception in DoCreateVfModuleRollback')
658 execution.setVariable("rollbackData", null)
661 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing setFailedRollbackStatus.", "BPMN", MsoLogger.getServiceName(),MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
662 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
664 msoLogger.trace("COMPLETED setFailedRollbackStatus")