2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.aai.domain.yang.NetworkPolicies
27 import org.onap.aai.domain.yang.NetworkPolicy
28 import org.onap.so.bpmn.common.scripts.AaiUtil
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.MsoUtils
32 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
33 import org.onap.so.bpmn.core.UrnPropertiesReader
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.client.aai.AAIObjectPlurals
36 import org.onap.so.client.aai.AAIObjectType
37 import org.onap.so.client.aai.entities.uri.AAIResourceUri
38 import org.onap.so.client.aai.entities.uri.AAIUriFactory
39 import org.onap.so.logger.ErrorCode
40 import org.onap.so.logger.MessageEnum
41 import org.slf4j.Logger
42 import org.slf4j.LoggerFactory
44 import javax.ws.rs.NotFoundException
47 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
48 private static final Logger logger = LoggerFactory.getLogger( DoCreateVfModuleRollback.class);
51 ExceptionUtil exceptionUtil = new ExceptionUtil()
53 public void initProcessVariables(DelegateExecution execution) {
54 execution.setVariable("prefix",Prefix)
57 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
58 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
59 public void preProcessRequest(DelegateExecution execution) {
62 initProcessVariables(execution)
66 execution.setVariable("rolledBack", null)
67 execution.setVariable("rollbackError", null)
69 def rollbackData = execution.getVariable("rollbackData")
70 logger.debug("RollbackData:" + rollbackData)
72 if (rollbackData != null) {
73 String vnfId = rollbackData.get("VFMODULE", "vnfid")
74 execution.setVariable("DCVFMR_vnfId", vnfId)
75 String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
76 execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
77 String source = rollbackData.get("VFMODULE", "source")
78 execution.setVariable("DCVFMR_source", source)
79 String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
80 execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
81 String serviceId = rollbackData.get("VFMODULE", "service-id")
82 execution.setVariable("DCVFMR_serviceId", serviceId)
83 String vnfType = rollbackData.get("VFMODULE", "vnftype")
84 execution.setVariable("DCVFMR_vnfType", vnfType)
85 String vnfName = rollbackData.get("VFMODULE", "vnfname")
86 execution.setVariable("DCVFMR_vnfName", vnfName)
87 String tenantId = rollbackData.get("VFMODULE", "tenantid")
88 execution.setVariable("DCVFMR_tenantId", tenantId)
89 String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
90 execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
91 String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
92 execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
93 String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
94 execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
95 String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
96 execution.setVariable("DCVFMR_heatStackId", heatStackId)
97 String requestId = rollbackData.get("VFMODULE", "msorequestid")
98 execution.setVariable("DCVFMR_requestId", requestId)
99 // Set mso-request-id to request-id for VNF Adapter interface
100 execution.setVariable("mso-request-id", requestId)
101 List createdNetworkPolicyFqdnList = []
104 String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
108 createdNetworkPolicyFqdnList.add(fqdn)
109 logger.debug("got fqdn # " + i + ": " + fqdn)
114 execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
115 String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
116 execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
117 String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
118 execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
119 //String serviceInstanceId = rollbackData.get("VFMODULE", "msoserviceinstanceid")
120 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
121 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
122 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
123 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
124 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
125 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
126 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
127 execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
128 execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
130 // formulate the request for PrepareUpdateAAIVfModule
131 String request = """<PrepareUpdateAAIVfModuleRequest>
132 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
133 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
134 <orchestration-status>pending-delete</orchestration-status>
135 </PrepareUpdateAAIVfModuleRequest>""" as String
136 logger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
137 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
139 execution.setVariable("skipRollback", true)
142 if (execution.getVariable("disableRollback").equals("true" )) {
143 execution.setVariable("skipRollback", true)
146 } catch (BpmnError e) {
148 } catch (Exception ex){
149 def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
151 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
155 // build a SDNC vnf-topology-operation request for the specified action
156 // (note: the action passed is expected to be 'changedelete' or 'delete')
157 public void prepSDNCAdapterRequest(DelegateExecution execution) {
159 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
161 String uuid = execution.getVariable('testReqId') // for junits
163 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
166 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
168 String source = execution.getVariable("DCVFMR_source")
169 String serviceId = execution.getVariable("DCVFMR_serviceId")
170 String vnfId = execution.getVariable("DCVFMR_vnfId")
171 String vnfType = execution.getVariable("DCVFMR_vnfType")
172 String vnfName = execution.getVariable("DCVFMR_vnfName")
173 String tenantId = execution.getVariable("DCVFMR_tenantId")
174 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
175 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
176 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
177 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
178 String requestId = execution.getVariable("DCVFMR_requestId")
180 String serviceInstanceIdToSdnc = ""
181 if (srvInstId != null && !srvInstId.isEmpty()) {
182 serviceInstanceIdToSdnc = srvInstId
184 serviceInstanceIdToSdnc = vfModuleId
187 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
188 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
191 def requestAction = ""
193 if (doSDNCActivateRollback.equals("true")) {
195 requestAction = "DisconnectVNFRequest"
197 else if (doSDNCAssignRollback.equals("true")) {
199 requestAction = "VNFActivateRequest"
205 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
206 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
207 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
208 <sdncadapter:RequestHeader>
209 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
210 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
211 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
212 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
213 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
214 </sdncadapter:RequestHeader>
215 <sdncadapterworkflow:SDNCRequestData>
216 <request-information>
217 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
218 <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
219 <source>${MsoUtils.xmlEscape(source)}</source>
223 </request-information>
224 <service-information>
225 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
226 <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
227 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
228 <subscriber-name>notsurewecare</subscriber-name>
229 </service-information>
230 <vnf-request-information>
231 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
232 <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
233 <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
234 <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
235 <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
236 <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
237 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
238 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
239 </vnf-request-information>
240 </sdncadapterworkflow:SDNCRequestData>
241 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
243 logger.debug("sdncAdapterWorkflowRequest: " + request)
244 execution.setVariable("sdncAdapterWorkflowRequest", request)
247 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
249 execution.setVariable("prefix", Prefix)
250 logger.trace("STARTED preProcessSDNCDeactivateRequest")
252 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
257 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
259 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
260 execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
261 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
264 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
265 "Exception Occured Processing preProcessSDNCDeactivateRequest.", "BPMN",
266 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
267 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
269 logger.trace("COMPLETED preProcessSDNCDeactivateRequest")
272 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
273 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
274 'execution=' + execution.getId() +
276 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
277 logger.trace('Entered ' + method)
278 execution.setVariable("prefix", Prefix)
279 logger.trace("STARTED preProcessSDNCUnassignRequest Process")
281 String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
283 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
285 execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
286 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
289 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
290 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
292 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process")
295 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
297 String uuid = execution.getVariable('testReqId') // for junits
299 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
301 def callbackURL = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
302 def requestId = execution.getVariable("DCVFMR_requestId")
303 def serviceId = execution.getVariable("DCVFMR_serviceId")
304 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
305 def vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
306 def source = execution.getVariable("DCVFMR_source")
307 def vnfId = execution.getVariable("DCVFMR_vnfId")
309 def sdncVersion = execution.getVariable("sdncVersion")
312 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
313 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
314 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
315 <sdncadapter:RequestHeader>
316 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
317 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
318 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
319 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
320 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
321 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
322 </sdncadapter:RequestHeader>
323 <sdncadapterworkflow:SDNCRequestData>
324 <request-information>
325 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
326 <request-action>DeleteVfModuleInstance</request-action>
327 <source>${MsoUtils.xmlEscape(source)}</source>
331 </request-information>
332 <service-information>
334 <subscription-service-type/>
335 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
336 <global-customer-id/>
337 </service-information>
339 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
342 <vf-module-information>
343 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
344 </vf-module-information>
345 <vf-module-request-input/>
346 </sdncadapterworkflow:SDNCRequestData>
347 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
349 logger.debug("sdncRequest: " + sdncRequest)
353 // parse the incoming DELETE_VF_MODULE request
354 // and formulate the outgoing VnfAdapterDeleteV1 request
355 public void prepVNFAdapterRequest(DelegateExecution execution) {
357 String requestId = UUID.randomUUID().toString()
358 String origRequestId = execution.getVariable("DCVFMR_requestId")
359 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
360 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
361 String vnfId = execution.getVariable("DCVFMR_vnfId")
362 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
363 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
364 String tenantId = execution.getVariable("DCVFMR_tenantId")
365 def messageId = execution.getVariable('mso-request-id') + '-' +
366 System.currentTimeMillis()
367 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
368 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
369 if ('true'.equals(useQualifiedHostName)) {
370 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
374 <deleteVfModuleRequest>
375 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
376 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
377 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
378 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
379 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
380 <skipAAI>true</skipAAI>
382 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
383 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
385 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
386 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
387 </deleteVfModuleRequest>
390 logger.debug("vnfAdapterRestV1Request: " + request)
391 execution.setVariable("vnfAdapterRestV1Request", request)
394 // parse the incoming DELETE_VF_MODULE request
395 // and formulate the outgoing UpdateAAIVfModuleRequest request
396 public void prepUpdateAAIVfModule(DelegateExecution execution) {
398 String vnfId = execution.getVariable("DCVFMR_vnfId")
399 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
400 // formulate the request for UpdateAAIVfModule
401 String request = """<UpdateAAIVfModuleRequest>
402 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
403 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
404 <heat-stack-id>DELETE</heat-stack-id>
405 <orchestration-status>deleted</orchestration-status>
406 </UpdateAAIVfModuleRequest>""" as String
407 logger.debug("UpdateAAIVfModuleRequest :" + request)
408 execution.setVariable("UpdateAAIVfModuleRequest", request)
411 // parse the incoming DELETE_VF_MODULE request
412 // and formulate the outgoing UpdateAAIVfModuleRequest request
413 public void prepUpdateAAIVfModuleToAssigned(DelegateExecution execution) {
415 String vnfId = execution.getVariable("DCVFMR_vnfId")
416 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
417 // formulate the request for UpdateAAIVfModule
418 String request = """<UpdateAAIVfModuleRequest>
419 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
420 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
421 <heat-stack-id></heat-stack-id>
422 <orchestration-status>Assigned</orchestration-status>
423 </UpdateAAIVfModuleRequest>""" as String
424 logger.debug("UpdateAAIVfModuleRequest :" + request)
425 execution.setVariable("UpdateAAIVfModuleRequest", request)
428 // parse the incoming DELETE_VF_MODULE request
429 // and formulate the outgoing DeleteAAIVfModuleRequest request
430 public void prepDeleteAAIVfModule(DelegateExecution execution) {
432 String vnfId = execution.getVariable("DCVFMR_vnfId")
433 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
434 // formulate the request for UpdateAAIVfModule
435 String request = """<DeleteAAIVfModuleRequest>
436 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
437 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
438 </DeleteAAIVfModuleRequest>""" as String
439 logger.debug("DeleteAAIVfModuleRequest :" + request)
440 execution.setVariable("DeleteAAIVfModuleRequest", request)
443 // generates a WorkflowException if
445 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
447 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
448 "AAI error occurred deleting the Generic Vnf" + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"),
449 "BPMN", ErrorCode.UnknownError.getValue());
450 String processKey = getProcessKey(execution);
451 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
455 public void sdncValidateResponse(DelegateExecution execution, String response){
457 execution.setVariable("prefix",Prefix)
459 WorkflowException workflowException = execution.getVariable("WorkflowException")
460 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
462 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
463 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
465 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
466 logger.debug("Successfully Validated SDNC Response")
468 throw new BpmnError("MSOWorkflowException")
472 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
473 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
474 'execution=' + execution.getId() +
476 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
477 logger.trace('Entered ' + method)
478 execution.setVariable("prefix", Prefix)
479 logger.trace("STARTED deleteNetworkPoliciesFromAAI")
483 List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
484 if (fqdnList == null) {
485 logger.debug("No network policies to delete")
488 int fqdnCount = fqdnList.size()
490 execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
491 logger.debug("networkPolicyFqdnCount - " + fqdnCount)
493 AaiUtil aaiUriUtil = new AaiUtil(this)
496 // AII loop call over contrail network policy fqdn list
497 for (i in 0..fqdnCount-1) {
500 String fqdn = fqdnList[i]
503 // Query AAI for this network policy FQDN
504 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
505 uri.queryParam("network-policy-fqdn", fqdn)
506 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
508 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
509 execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", 200)
510 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
513 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicy.getNetworkPolicyId())
514 getAAIClient().delete(delUri)
515 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 200)
516 logger.debug("AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
517 logger.debug("The return code from deleting network policy is: " + 200)
518 // This network policy was deleted from AAI successfully
519 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
520 }catch(NotFoundException ne){
521 // This network policy FQDN is not in AAI. No need to delete.
522 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 404)
523 logger.debug("The return code is: " + 404)
524 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
527 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
528 logger.debug(delErrorMessage)
529 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
532 // This network policy FQDN is not in AAI. No need to delete.
533 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
535 }catch (BpmnError e){
538 catch (Exception e) {
540 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
541 logger.debug(dataErrorMessage)
542 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
548 logger.debug("No contrail network policies to query/create")
552 } catch (BpmnError e) {
555 } catch (Exception ex) {
556 String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
557 logger.debug(exceptionMessage)
558 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
565 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
567 * @param execution The flow's execution instance.
569 public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
570 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
571 'execution=' + execution.getId() +
573 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
574 logger.trace('Entered ' + method)
577 def vnfId = execution.getVariable('DCVFMR_vnfId')
578 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
579 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
580 def ipv4OamAddressElement = ''
581 def managementV6AddressElement = ''
583 if (oamManagementV4Address != null) {
584 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
587 if (oamManagementV6Address != null) {
588 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
592 String updateAAIGenericVnfRequest = """
593 <UpdateAAIGenericVnfRequest>
594 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
595 ${ipv4OamAddressElement}
596 ${managementV6AddressElement}
597 </UpdateAAIGenericVnfRequest>
599 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
600 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
601 logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
604 logger.trace('Exited ' + method)
605 } catch (BpmnError e) {
607 } catch (Exception e) {
608 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
609 'Caught exception in ' + method, "BPMN",
610 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
611 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
615 public void setSuccessfulRollbackStatus (DelegateExecution execution){
617 execution.setVariable("prefix", Prefix)
618 logger.trace("STARTED setSuccessfulRollbackStatus")
621 // Set rolledBack to true, rollbackError to null
622 execution.setVariable("rolledBack", true)
623 execution.setVariable("rollbackError", null)
626 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
627 "Exception Occured Processing setSuccessfulRollbackStatus.", "BPMN",
628 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
629 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
631 logger.trace("COMPLETED setSuccessfulRollbackStatus")
634 public void setFailedRollbackStatus (DelegateExecution execution){
636 execution.setVariable("prefix", Prefix)
637 logger.trace("STARTED setFailedRollbackStatus")
640 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
641 execution.setVariable("rolledBack", false)
642 execution.setVariable("rollbackError", 'Caught exception in DoCreateVfModuleRollback')
643 execution.setVariable("rollbackData", null)
646 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
647 "Exception Occured Processing setFailedRollbackStatus.", "BPMN",
648 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
649 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
651 logger.trace("COMPLETED setFailedRollbackStatus")