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
25 import org.onap.so.logger.LoggingAnchor
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.aai.domain.yang.NetworkPolicies
29 import org.onap.aai.domain.yang.NetworkPolicy
30 import org.onap.so.bpmn.common.scripts.AaiUtil
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.common.scripts.MsoUtils
34 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
35 import org.onap.so.bpmn.core.UrnPropertiesReader
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.aaiclient.client.aai.AAIObjectType
38 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
39 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
40 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
41 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
42 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
43 import org.onap.logging.filter.base.ErrorCode
44 import org.onap.so.logger.MessageEnum
45 import org.slf4j.Logger
46 import org.slf4j.LoggerFactory
48 import javax.ws.rs.NotFoundException
51 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
52 private static final Logger logger = LoggerFactory.getLogger( DoCreateVfModuleRollback.class);
55 ExceptionUtil exceptionUtil = new ExceptionUtil()
57 public void initProcessVariables(DelegateExecution execution) {
58 execution.setVariable("prefix",Prefix)
61 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
62 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
63 public void preProcessRequest(DelegateExecution execution) {
66 initProcessVariables(execution)
70 execution.setVariable("rolledBack", null)
71 execution.setVariable("rollbackError", null)
73 def rollbackData = execution.getVariable("rollbackData")
74 logger.debug("RollbackData:" + rollbackData)
76 if (rollbackData != null) {
77 String vnfId = rollbackData.get("VFMODULE", "vnfid")
78 execution.setVariable("DCVFMR_vnfId", vnfId)
79 String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
80 execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
81 String source = rollbackData.get("VFMODULE", "source")
82 execution.setVariable("DCVFMR_source", source)
83 String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
84 execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
85 String serviceId = rollbackData.get("VFMODULE", "service-id")
86 execution.setVariable("DCVFMR_serviceId", serviceId)
87 String vnfType = rollbackData.get("VFMODULE", "vnftype")
88 execution.setVariable("DCVFMR_vnfType", vnfType)
89 String vnfName = rollbackData.get("VFMODULE", "vnfname")
90 execution.setVariable("DCVFMR_vnfName", vnfName)
91 String tenantId = rollbackData.get("VFMODULE", "tenantid")
92 execution.setVariable("DCVFMR_tenantId", tenantId)
93 String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
94 execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
95 String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
96 execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
97 String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
98 execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
99 String cloudOwner = rollbackData.get("VFMODULE", "cloudowner")
100 execution.setVariable("DCVFMR_cloudOwner", cloudOwner)
101 String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
102 execution.setVariable("DCVFMR_heatStackId", heatStackId)
103 String requestId = rollbackData.get("VFMODULE", "msorequestid")
104 execution.setVariable("DCVFMR_requestId", requestId)
105 // Set mso-request-id to request-id for VNF Adapter interface
106 execution.setVariable("mso-request-id", requestId)
107 List createdNetworkPolicyFqdnList = []
110 String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
114 createdNetworkPolicyFqdnList.add(fqdn)
115 logger.debug("got fqdn # " + i + ": " + fqdn)
120 execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
121 String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
122 execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
123 String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
124 execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
125 //String serviceInstanceId = rollbackData.get("VFMODULE", "msoserviceinstanceid")
126 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
127 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
128 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
129 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
130 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
131 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
132 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
133 execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
134 execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
136 // formulate the request for PrepareUpdateAAIVfModule
137 String request = """<PrepareUpdateAAIVfModuleRequest>
138 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
139 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
140 <orchestration-status>pending-delete</orchestration-status>
141 </PrepareUpdateAAIVfModuleRequest>""" as String
142 logger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
143 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
145 execution.setVariable("skipRollback", true)
148 if (execution.getVariable("disableRollback").equals("true" )) {
149 execution.setVariable("skipRollback", true)
152 } catch (BpmnError e) {
154 } catch (Exception ex){
155 def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
157 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
161 // build a SDNC vnf-topology-operation request for the specified action
162 // (note: the action passed is expected to be 'changedelete' or 'delete')
163 public void prepSDNCAdapterRequest(DelegateExecution execution) {
165 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
167 String uuid = execution.getVariable('testReqId') // for junits
169 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
172 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
174 String source = execution.getVariable("DCVFMR_source")
175 String serviceId = execution.getVariable("DCVFMR_serviceId")
176 String vnfId = execution.getVariable("DCVFMR_vnfId")
177 String vnfType = execution.getVariable("DCVFMR_vnfType")
178 String vnfName = execution.getVariable("DCVFMR_vnfName")
179 String tenantId = execution.getVariable("DCVFMR_tenantId")
180 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
181 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
182 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
183 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
184 String requestId = execution.getVariable("DCVFMR_requestId")
186 String serviceInstanceIdToSdnc = ""
187 if (srvInstId != null && !srvInstId.isEmpty()) {
188 serviceInstanceIdToSdnc = srvInstId
190 serviceInstanceIdToSdnc = vfModuleId
193 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
194 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
197 def requestAction = ""
199 if (doSDNCActivateRollback.equals("true")) {
201 requestAction = "DisconnectVNFRequest"
203 else if (doSDNCAssignRollback.equals("true")) {
205 requestAction = "VNFActivateRequest"
211 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
212 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
213 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
214 <sdncadapter:RequestHeader>
215 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
216 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
217 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
218 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
219 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
220 </sdncadapter:RequestHeader>
221 <sdncadapterworkflow:SDNCRequestData>
222 <request-information>
223 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
224 <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
225 <source>${MsoUtils.xmlEscape(source)}</source>
229 </request-information>
230 <service-information>
231 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
232 <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
233 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
234 <subscriber-name>notsurewecare</subscriber-name>
235 </service-information>
236 <vnf-request-information>
237 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
238 <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
239 <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
240 <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
241 <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
242 <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
243 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
244 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
245 </vnf-request-information>
246 </sdncadapterworkflow:SDNCRequestData>
247 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
249 logger.debug("sdncAdapterWorkflowRequest: " + request)
250 execution.setVariable("sdncAdapterWorkflowRequest", request)
253 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
255 execution.setVariable("prefix", Prefix)
256 logger.trace("STARTED preProcessSDNCDeactivateRequest")
258 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
263 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
265 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
266 execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
267 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
270 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
271 "Exception Occured Processing preProcessSDNCDeactivateRequest.", "BPMN",
272 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
273 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
275 logger.trace("COMPLETED preProcessSDNCDeactivateRequest")
278 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
279 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
280 'execution=' + execution.getId() +
282 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
283 logger.trace('Entered ' + method)
284 execution.setVariable("prefix", Prefix)
285 logger.trace("STARTED preProcessSDNCUnassignRequest Process")
287 String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
289 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
291 execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
292 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
295 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
296 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
298 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process")
301 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
303 String uuid = execution.getVariable('testReqId') // for junits
305 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
307 def callbackURL = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
308 def requestId = execution.getVariable("DCVFMR_requestId")
309 def serviceId = execution.getVariable("DCVFMR_serviceId")
310 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
311 def vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
312 def source = execution.getVariable("DCVFMR_source")
313 def vnfId = execution.getVariable("DCVFMR_vnfId")
315 def sdncVersion = execution.getVariable("sdncVersion")
318 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
319 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
320 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
321 <sdncadapter:RequestHeader>
322 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
323 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
324 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
325 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
326 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
327 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
328 </sdncadapter:RequestHeader>
329 <sdncadapterworkflow:SDNCRequestData>
330 <request-information>
331 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
332 <request-action>DeleteVfModuleInstance</request-action>
333 <source>${MsoUtils.xmlEscape(source)}</source>
337 </request-information>
338 <service-information>
340 <subscription-service-type/>
341 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
342 <global-customer-id/>
343 </service-information>
345 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
348 <vf-module-information>
349 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
350 </vf-module-information>
351 <vf-module-request-input/>
352 </sdncadapterworkflow:SDNCRequestData>
353 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
355 logger.debug("sdncRequest: " + sdncRequest)
359 // parse the incoming DELETE_VF_MODULE request
360 // and formulate the outgoing VnfAdapterDeleteV1 request
361 public void prepVNFAdapterRequest(DelegateExecution execution) {
363 String requestId = UUID.randomUUID().toString()
364 String origRequestId = execution.getVariable("DCVFMR_requestId")
365 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
366 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
367 String cloudOwner = execution.getVariable("DCVFMR_cloudOwner")
368 String vnfId = execution.getVariable("DCVFMR_vnfId")
369 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
370 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
371 String tenantId = execution.getVariable("DCVFMR_tenantId")
372 def messageId = execution.getVariable('mso-request-id') + '-' +
373 System.currentTimeMillis()
374 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
375 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
376 if ('true'.equals(useQualifiedHostName)) {
377 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
381 <deleteVfModuleRequest>
382 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
383 <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
384 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
385 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
386 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
387 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
388 <skipAAI>true</skipAAI>
390 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
391 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
393 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
394 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
395 </deleteVfModuleRequest>
398 execution.setVariable("vnfAdapterTaskRequest", request)
401 // parse the incoming DELETE_VF_MODULE request
402 // and formulate the outgoing UpdateAAIVfModuleRequest request
403 public void prepUpdateAAIVfModule(DelegateExecution execution) {
405 String vnfId = execution.getVariable("DCVFMR_vnfId")
406 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
407 // formulate the request for UpdateAAIVfModule
408 String request = """<UpdateAAIVfModuleRequest>
409 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
410 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
411 <heat-stack-id>DELETE</heat-stack-id>
412 <orchestration-status>deleted</orchestration-status>
413 </UpdateAAIVfModuleRequest>""" as String
414 logger.debug("UpdateAAIVfModuleRequest :" + request)
415 execution.setVariable("UpdateAAIVfModuleRequest", request)
418 // parse the incoming DELETE_VF_MODULE request
419 // and formulate the outgoing UpdateAAIVfModuleRequest request
420 public void prepUpdateAAIVfModuleToAssigned(DelegateExecution execution) {
422 String vnfId = execution.getVariable("DCVFMR_vnfId")
423 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
424 // formulate the request for UpdateAAIVfModule
425 String request = """<UpdateAAIVfModuleRequest>
426 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
427 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
428 <heat-stack-id></heat-stack-id>
429 <orchestration-status>Assigned</orchestration-status>
430 </UpdateAAIVfModuleRequest>""" as String
431 logger.debug("UpdateAAIVfModuleRequest :" + request)
432 execution.setVariable("UpdateAAIVfModuleRequest", request)
435 // parse the incoming DELETE_VF_MODULE request
436 // and formulate the outgoing DeleteAAIVfModuleRequest request
437 public void prepDeleteAAIVfModule(DelegateExecution execution) {
439 String vnfId = execution.getVariable("DCVFMR_vnfId")
440 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
441 // formulate the request for UpdateAAIVfModule
442 String request = """<DeleteAAIVfModuleRequest>
443 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
444 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
445 </DeleteAAIVfModuleRequest>""" as String
446 logger.debug("DeleteAAIVfModuleRequest :" + request)
447 execution.setVariable("DeleteAAIVfModuleRequest", request)
450 // generates a WorkflowException if
452 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
454 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
455 "AAI error occurred deleting the Generic Vnf" + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"),
456 "BPMN", ErrorCode.UnknownError.getValue());
457 String processKey = getProcessKey(execution);
458 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
462 public void sdncValidateResponse(DelegateExecution execution, String response){
464 execution.setVariable("prefix",Prefix)
466 WorkflowException workflowException = execution.getVariable("WorkflowException")
467 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
469 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
470 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
472 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
473 logger.debug("Successfully Validated SDNC Response")
475 throw new BpmnError("MSOWorkflowException")
479 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
480 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
481 'execution=' + execution.getId() +
483 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
484 logger.trace('Entered ' + method)
485 execution.setVariable("prefix", Prefix)
486 logger.trace("STARTED deleteNetworkPoliciesFromAAI")
490 List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
491 if (fqdnList == null) {
492 logger.debug("No network policies to delete")
495 int fqdnCount = fqdnList.size()
497 execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
498 logger.debug("networkPolicyFqdnCount - " + fqdnCount)
500 AaiUtil aaiUriUtil = new AaiUtil(this)
503 // AII loop call over contrail network policy fqdn list
504 for (i in 0..fqdnCount-1) {
507 String fqdn = fqdnList[i]
510 // Query AAI for this network policy FQDN
511 AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicies())
512 uri.queryParam("network-policy-fqdn", fqdn)
513 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
515 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
516 execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", 200)
517 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
520 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicy.getNetworkPolicyId()))
521 getAAIClient().delete(delUri)
522 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 200)
523 logger.debug("AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
524 logger.debug("The return code from deleting network policy is: " + 200)
525 // This network policy was deleted from AAI successfully
526 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
527 }catch(NotFoundException ne){
528 // This network policy FQDN is not in AAI. No need to delete.
529 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 404)
530 logger.debug("The return code is: " + 404)
531 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
534 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
535 logger.debug(delErrorMessage)
536 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
539 // This network policy FQDN is not in AAI. No need to delete.
540 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
542 }catch (BpmnError e){
545 catch (Exception e) {
547 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
548 logger.debug(dataErrorMessage)
549 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
555 logger.debug("No contrail network policies to query/create")
559 } catch (BpmnError e) {
562 } catch (Exception ex) {
563 String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
564 logger.debug(exceptionMessage)
565 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
572 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
574 * @param execution The flow's execution instance.
576 public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
577 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
578 'execution=' + execution.getId() +
580 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
581 logger.trace('Entered ' + method)
584 def vnfId = execution.getVariable('DCVFMR_vnfId')
585 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
586 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
587 def ipv4OamAddressElement = ''
588 def managementV6AddressElement = ''
590 if (oamManagementV4Address != null) {
591 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
594 if (oamManagementV6Address != null) {
595 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
599 String updateAAIGenericVnfRequest = """
600 <UpdateAAIGenericVnfRequest>
601 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
602 ${ipv4OamAddressElement}
603 ${managementV6AddressElement}
604 </UpdateAAIGenericVnfRequest>
606 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
607 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
608 logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
611 logger.trace('Exited ' + method)
612 } catch (BpmnError e) {
614 } catch (Exception e) {
615 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
616 'Caught exception in ' + method, "BPMN",
617 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
618 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
622 public void setSuccessfulRollbackStatus (DelegateExecution execution){
624 execution.setVariable("prefix", Prefix)
625 logger.trace("STARTED setSuccessfulRollbackStatus")
628 // Set rolledBack to true, rollbackError to null
629 execution.setVariable("rolledBack", true)
630 execution.setVariable("rollbackError", null)
633 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
634 "Exception Occured Processing setSuccessfulRollbackStatus.", "BPMN",
635 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
636 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
638 logger.trace("COMPLETED setSuccessfulRollbackStatus")
641 public void setFailedRollbackStatus (DelegateExecution execution){
643 execution.setVariable("prefix", Prefix)
644 logger.trace("STARTED setFailedRollbackStatus")
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 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
654 "Exception Occured Processing setFailedRollbackStatus.", "BPMN",
655 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
656 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
658 logger.trace("COMPLETED setFailedRollbackStatus")