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 com.google.common.base.Strings
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.so.client.aai.AAIObjectPlurals
38 import org.onap.so.client.aai.AAIObjectType
39 import org.onap.so.client.aai.entities.uri.AAIResourceUri
40 import org.onap.so.client.aai.entities.uri.AAIUriFactory
41 import org.onap.so.logger.ErrorCode
42 import org.onap.so.logger.MessageEnum
43 import org.slf4j.Logger
44 import org.slf4j.LoggerFactory
46 import javax.ws.rs.NotFoundException
49 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
50 private static final Logger logger = LoggerFactory.getLogger( DoCreateVfModuleRollback.class);
53 ExceptionUtil exceptionUtil = new ExceptionUtil()
55 public void initProcessVariables(DelegateExecution execution) {
56 execution.setVariable("prefix",Prefix)
59 // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
60 // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
61 public void preProcessRequest(DelegateExecution execution) {
64 initProcessVariables(execution)
68 execution.setVariable("rolledBack", null)
69 execution.setVariable("rollbackError", null)
71 def rollbackData = execution.getVariable("rollbackData")
72 logger.debug("RollbackData:" + rollbackData)
74 if (rollbackData != null) {
75 String vnfId = rollbackData.get("VFMODULE", "vnfid")
76 execution.setVariable("DCVFMR_vnfId", vnfId)
77 String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
78 execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
79 String source = rollbackData.get("VFMODULE", "source")
80 execution.setVariable("DCVFMR_source", source)
81 String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
82 execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
83 String serviceId = rollbackData.get("VFMODULE", "service-id")
84 execution.setVariable("DCVFMR_serviceId", serviceId)
85 String vnfType = rollbackData.get("VFMODULE", "vnftype")
86 execution.setVariable("DCVFMR_vnfType", vnfType)
87 String vnfName = rollbackData.get("VFMODULE", "vnfname")
88 execution.setVariable("DCVFMR_vnfName", vnfName)
89 String tenantId = rollbackData.get("VFMODULE", "tenantid")
90 execution.setVariable("DCVFMR_tenantId", tenantId)
91 String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
92 execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
93 String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
94 execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
95 String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
96 execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
97 String cloudOwner = rollbackData.get("VFMODULE", "cloudowner")
98 execution.setVariable("DCVFMR_cloudOwner", cloudOwner)
99 String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
100 execution.setVariable("DCVFMR_heatStackId", heatStackId)
101 String requestId = rollbackData.get("VFMODULE", "msorequestid")
102 execution.setVariable("DCVFMR_requestId", requestId)
103 // Set mso-request-id to request-id for VNF Adapter interface
104 execution.setVariable("mso-request-id", requestId)
105 List createdNetworkPolicyFqdnList = []
108 String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
112 createdNetworkPolicyFqdnList.add(fqdn)
113 logger.debug("got fqdn # " + i + ": " + fqdn)
118 execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
119 String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
120 execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
121 String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
122 execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
123 //String serviceInstanceId = rollbackData.get("VFMODULE", "msoserviceinstanceid")
124 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
125 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
126 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
127 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
128 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
129 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
130 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
131 execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
132 execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
134 // formulate the request for PrepareUpdateAAIVfModule
135 String request = """<PrepareUpdateAAIVfModuleRequest>
136 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
137 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
138 <orchestration-status>pending-delete</orchestration-status>
139 </PrepareUpdateAAIVfModuleRequest>""" as String
140 logger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
141 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
143 execution.setVariable("skipRollback", true)
146 if (execution.getVariable("disableRollback").equals("true" )) {
147 execution.setVariable("skipRollback", true)
150 } catch (BpmnError e) {
152 } catch (Exception ex){
153 def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
155 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
159 // build a SDNC vnf-topology-operation request for the specified action
160 // (note: the action passed is expected to be 'changedelete' or 'delete')
161 public void prepSDNCAdapterRequest(DelegateExecution execution) {
163 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
165 String uuid = execution.getVariable('testReqId') // for junits
167 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
170 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
172 String source = execution.getVariable("DCVFMR_source")
173 String serviceId = execution.getVariable("DCVFMR_serviceId")
174 String vnfId = execution.getVariable("DCVFMR_vnfId")
175 String vnfType = execution.getVariable("DCVFMR_vnfType")
176 String vnfName = execution.getVariable("DCVFMR_vnfName")
177 String tenantId = execution.getVariable("DCVFMR_tenantId")
178 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
179 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
180 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
181 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
182 String requestId = execution.getVariable("DCVFMR_requestId")
184 String serviceInstanceIdToSdnc = ""
185 if (srvInstId != null && !srvInstId.isEmpty()) {
186 serviceInstanceIdToSdnc = srvInstId
188 serviceInstanceIdToSdnc = vfModuleId
191 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
192 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
195 def requestAction = ""
197 if (doSDNCActivateRollback.equals("true")) {
199 requestAction = "DisconnectVNFRequest"
201 else if (doSDNCAssignRollback.equals("true")) {
203 requestAction = "VNFActivateRequest"
209 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
210 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
211 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
212 <sdncadapter:RequestHeader>
213 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
214 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
215 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
216 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
217 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
218 </sdncadapter:RequestHeader>
219 <sdncadapterworkflow:SDNCRequestData>
220 <request-information>
221 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
222 <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
223 <source>${MsoUtils.xmlEscape(source)}</source>
227 </request-information>
228 <service-information>
229 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
230 <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
231 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
232 <subscriber-name>notsurewecare</subscriber-name>
233 </service-information>
234 <vnf-request-information>
235 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
236 <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
237 <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
238 <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
239 <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
240 <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
241 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
242 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
243 </vnf-request-information>
244 </sdncadapterworkflow:SDNCRequestData>
245 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
247 logger.debug("sdncAdapterWorkflowRequest: " + request)
248 execution.setVariable("sdncAdapterWorkflowRequest", request)
251 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
253 execution.setVariable("prefix", Prefix)
254 logger.trace("STARTED preProcessSDNCDeactivateRequest")
256 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
261 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
263 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
264 execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
265 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
268 logger.error(Strings.repeat("{} ", 5), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
269 "Exception Occured Processing preProcessSDNCDeactivateRequest.", "BPMN",
270 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
271 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
273 logger.trace("COMPLETED preProcessSDNCDeactivateRequest")
276 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
277 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
278 'execution=' + execution.getId() +
280 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
281 logger.trace('Entered ' + method)
282 execution.setVariable("prefix", Prefix)
283 logger.trace("STARTED preProcessSDNCUnassignRequest Process")
285 String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
287 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
289 execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
290 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
293 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
294 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
296 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process")
299 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
301 String uuid = execution.getVariable('testReqId') // for junits
303 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
305 def callbackURL = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
306 def requestId = execution.getVariable("DCVFMR_requestId")
307 def serviceId = execution.getVariable("DCVFMR_serviceId")
308 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
309 def vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
310 def source = execution.getVariable("DCVFMR_source")
311 def vnfId = execution.getVariable("DCVFMR_vnfId")
313 def sdncVersion = execution.getVariable("sdncVersion")
316 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
317 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
318 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
319 <sdncadapter:RequestHeader>
320 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
321 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
322 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
323 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
324 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
325 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
326 </sdncadapter:RequestHeader>
327 <sdncadapterworkflow:SDNCRequestData>
328 <request-information>
329 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
330 <request-action>DeleteVfModuleInstance</request-action>
331 <source>${MsoUtils.xmlEscape(source)}</source>
335 </request-information>
336 <service-information>
338 <subscription-service-type/>
339 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
340 <global-customer-id/>
341 </service-information>
343 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
346 <vf-module-information>
347 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
348 </vf-module-information>
349 <vf-module-request-input/>
350 </sdncadapterworkflow:SDNCRequestData>
351 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
353 logger.debug("sdncRequest: " + sdncRequest)
357 // parse the incoming DELETE_VF_MODULE request
358 // and formulate the outgoing VnfAdapterDeleteV1 request
359 public void prepVNFAdapterRequest(DelegateExecution execution) {
361 String requestId = UUID.randomUUID().toString()
362 String origRequestId = execution.getVariable("DCVFMR_requestId")
363 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
364 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
365 String cloudOwner = execution.getVariable("DCVFMR_cloudOwner")
366 String vnfId = execution.getVariable("DCVFMR_vnfId")
367 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
368 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
369 String tenantId = execution.getVariable("DCVFMR_tenantId")
370 def messageId = execution.getVariable('mso-request-id') + '-' +
371 System.currentTimeMillis()
372 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
373 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
374 if ('true'.equals(useQualifiedHostName)) {
375 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
379 <deleteVfModuleRequest>
380 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
381 <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
382 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
383 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
384 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
385 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
386 <skipAAI>true</skipAAI>
388 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
389 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
391 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
392 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
393 </deleteVfModuleRequest>
396 logger.debug("vnfAdapterRestV1Request: " + request)
397 execution.setVariable("vnfAdapterRestV1Request", request)
400 // parse the incoming DELETE_VF_MODULE request
401 // and formulate the outgoing UpdateAAIVfModuleRequest request
402 public void prepUpdateAAIVfModule(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>DELETE</heat-stack-id>
411 <orchestration-status>deleted</orchestration-status>
412 </UpdateAAIVfModuleRequest>""" as String
413 logger.debug("UpdateAAIVfModuleRequest :" + request)
414 execution.setVariable("UpdateAAIVfModuleRequest", request)
417 // parse the incoming DELETE_VF_MODULE request
418 // and formulate the outgoing UpdateAAIVfModuleRequest request
419 public void prepUpdateAAIVfModuleToAssigned(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 = """<UpdateAAIVfModuleRequest>
425 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
426 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
427 <heat-stack-id></heat-stack-id>
428 <orchestration-status>Assigned</orchestration-status>
429 </UpdateAAIVfModuleRequest>""" as String
430 logger.debug("UpdateAAIVfModuleRequest :" + request)
431 execution.setVariable("UpdateAAIVfModuleRequest", request)
434 // parse the incoming DELETE_VF_MODULE request
435 // and formulate the outgoing DeleteAAIVfModuleRequest request
436 public void prepDeleteAAIVfModule(DelegateExecution execution) {
438 String vnfId = execution.getVariable("DCVFMR_vnfId")
439 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
440 // formulate the request for UpdateAAIVfModule
441 String request = """<DeleteAAIVfModuleRequest>
442 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
443 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
444 </DeleteAAIVfModuleRequest>""" as String
445 logger.debug("DeleteAAIVfModuleRequest :" + request)
446 execution.setVariable("DeleteAAIVfModuleRequest", request)
449 // generates a WorkflowException if
451 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
453 logger.error(Strings.repeat("{} ", 5), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
454 "AAI error occurred deleting the Generic Vnf" + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"),
455 "BPMN", ErrorCode.UnknownError.getValue());
456 String processKey = getProcessKey(execution);
457 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
461 public void sdncValidateResponse(DelegateExecution execution, String response){
463 execution.setVariable("prefix",Prefix)
465 WorkflowException workflowException = execution.getVariable("WorkflowException")
466 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
468 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
469 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
471 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
472 logger.debug("Successfully Validated SDNC Response")
474 throw new BpmnError("MSOWorkflowException")
478 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
479 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
480 'execution=' + execution.getId() +
482 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
483 logger.trace('Entered ' + method)
484 execution.setVariable("prefix", Prefix)
485 logger.trace("STARTED deleteNetworkPoliciesFromAAI")
489 List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
490 if (fqdnList == null) {
491 logger.debug("No network policies to delete")
494 int fqdnCount = fqdnList.size()
496 execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
497 logger.debug("networkPolicyFqdnCount - " + fqdnCount)
499 AaiUtil aaiUriUtil = new AaiUtil(this)
502 // AII loop call over contrail network policy fqdn list
503 for (i in 0..fqdnCount-1) {
506 String fqdn = fqdnList[i]
509 // Query AAI for this network policy FQDN
510 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
511 uri.queryParam("network-policy-fqdn", fqdn)
512 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
514 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
515 execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", 200)
516 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
519 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicy.getNetworkPolicyId())
520 getAAIClient().delete(delUri)
521 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 200)
522 logger.debug("AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
523 logger.debug("The return code from deleting network policy is: " + 200)
524 // This network policy was deleted from AAI successfully
525 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
526 }catch(NotFoundException ne){
527 // This network policy FQDN is not in AAI. No need to delete.
528 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 404)
529 logger.debug("The return code is: " + 404)
530 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
533 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
534 logger.debug(delErrorMessage)
535 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
538 // This network policy FQDN is not in AAI. No need to delete.
539 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
541 }catch (BpmnError e){
544 catch (Exception e) {
546 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
547 logger.debug(dataErrorMessage)
548 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
554 logger.debug("No contrail network policies to query/create")
558 } catch (BpmnError e) {
561 } catch (Exception ex) {
562 String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
563 logger.debug(exceptionMessage)
564 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
571 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
573 * @param execution The flow's execution instance.
575 public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
576 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
577 'execution=' + execution.getId() +
579 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
580 logger.trace('Entered ' + method)
583 def vnfId = execution.getVariable('DCVFMR_vnfId')
584 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
585 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
586 def ipv4OamAddressElement = ''
587 def managementV6AddressElement = ''
589 if (oamManagementV4Address != null) {
590 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
593 if (oamManagementV6Address != null) {
594 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
598 String updateAAIGenericVnfRequest = """
599 <UpdateAAIGenericVnfRequest>
600 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
601 ${ipv4OamAddressElement}
602 ${managementV6AddressElement}
603 </UpdateAAIGenericVnfRequest>
605 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
606 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
607 logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
610 logger.trace('Exited ' + method)
611 } catch (BpmnError e) {
613 } catch (Exception e) {
614 logger.error(Strings.repeat("{} ", 5), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
615 'Caught exception in ' + method, "BPMN",
616 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
617 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
621 public void setSuccessfulRollbackStatus (DelegateExecution execution){
623 execution.setVariable("prefix", Prefix)
624 logger.trace("STARTED setSuccessfulRollbackStatus")
627 // Set rolledBack to true, rollbackError to null
628 execution.setVariable("rolledBack", true)
629 execution.setVariable("rollbackError", null)
632 logger.error(Strings.repeat("{} ", 5), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
633 "Exception Occured Processing setSuccessfulRollbackStatus.", "BPMN",
634 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
635 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
637 logger.trace("COMPLETED setSuccessfulRollbackStatus")
640 public void setFailedRollbackStatus (DelegateExecution execution){
642 execution.setVariable("prefix", Prefix)
643 logger.trace("STARTED setFailedRollbackStatus")
646 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
647 execution.setVariable("rolledBack", false)
648 execution.setVariable("rollbackError", 'Caught exception in DoCreateVfModuleRollback')
649 execution.setVariable("rollbackData", null)
652 logger.error(Strings.repeat("{} ", 5), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
653 "Exception Occured Processing setFailedRollbackStatus.", "BPMN",
654 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
655 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
657 logger.trace("COMPLETED setFailedRollbackStatus")