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.MessageEnum
40 import org.onap.so.logger.MsoLogger
41 import org.slf4j.Logger
42 import org.slf4j.LoggerFactory
44 import org.springframework.web.util.UriUtils
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 heatStackId = rollbackData.get("VFMODULE", "heatstackid")
98 execution.setVariable("DCVFMR_heatStackId", heatStackId)
99 String requestId = rollbackData.get("VFMODULE", "msorequestid")
100 execution.setVariable("DCVFMR_requestId", requestId)
101 // Set mso-request-id to request-id for VNF Adapter interface
102 execution.setVariable("mso-request-id", requestId)
103 List createdNetworkPolicyFqdnList = []
106 String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
110 createdNetworkPolicyFqdnList.add(fqdn)
111 logger.debug("got fqdn # " + i + ": " + fqdn)
116 execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
117 String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
118 execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
119 String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
120 execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
121 //String serviceInstanceId = rollbackData.get("VFMODULE", "msoserviceinstanceid")
122 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
123 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
124 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
125 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
126 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
127 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
128 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
129 execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
130 execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
132 // formulate the request for PrepareUpdateAAIVfModule
133 String request = """<PrepareUpdateAAIVfModuleRequest>
134 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
135 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
136 <orchestration-status>pending-delete</orchestration-status>
137 </PrepareUpdateAAIVfModuleRequest>""" as String
138 logger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
139 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
141 execution.setVariable("skipRollback", true)
144 if (execution.getVariable("disableRollback").equals("true" )) {
145 execution.setVariable("skipRollback", true)
148 } catch (BpmnError e) {
150 } catch (Exception ex){
151 def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
153 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
157 // build a SDNC vnf-topology-operation request for the specified action
158 // (note: the action passed is expected to be 'changedelete' or 'delete')
159 public void prepSDNCAdapterRequest(DelegateExecution execution) {
161 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
163 String uuid = execution.getVariable('testReqId') // for junits
165 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
168 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
170 String source = execution.getVariable("DCVFMR_source")
171 String serviceId = execution.getVariable("DCVFMR_serviceId")
172 String vnfId = execution.getVariable("DCVFMR_vnfId")
173 String vnfType = execution.getVariable("DCVFMR_vnfType")
174 String vnfName = execution.getVariable("DCVFMR_vnfName")
175 String tenantId = execution.getVariable("DCVFMR_tenantId")
176 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
177 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
178 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
179 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
180 String requestId = execution.getVariable("DCVFMR_requestId")
182 String serviceInstanceIdToSdnc = ""
183 if (srvInstId != null && !srvInstId.isEmpty()) {
184 serviceInstanceIdToSdnc = srvInstId
186 serviceInstanceIdToSdnc = vfModuleId
189 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
190 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
193 def requestAction = ""
195 if (doSDNCActivateRollback.equals("true")) {
197 requestAction = "DisconnectVNFRequest"
199 else if (doSDNCAssignRollback.equals("true")) {
201 requestAction = "VNFActivateRequest"
207 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
208 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
209 xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
210 <sdncadapter:RequestHeader>
211 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
212 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
213 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
214 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
215 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
216 </sdncadapter:RequestHeader>
217 <sdncadapterworkflow:SDNCRequestData>
218 <request-information>
219 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
220 <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
221 <source>${MsoUtils.xmlEscape(source)}</source>
225 </request-information>
226 <service-information>
227 <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
228 <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
229 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
230 <subscriber-name>notsurewecare</subscriber-name>
231 </service-information>
232 <vnf-request-information>
233 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
234 <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
235 <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
236 <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
237 <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
238 <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
239 <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
240 <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
241 </vnf-request-information>
242 </sdncadapterworkflow:SDNCRequestData>
243 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
245 logger.debug("sdncAdapterWorkflowRequest: " + request)
246 execution.setVariable("sdncAdapterWorkflowRequest", request)
249 public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
251 execution.setVariable("prefix", Prefix)
252 logger.trace("STARTED preProcessSDNCDeactivateRequest")
254 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
259 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
261 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
262 execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
263 logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
266 logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
267 "Exception Occured Processing preProcessSDNCDeactivateRequest.", "BPMN",
268 MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
269 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
271 logger.trace("COMPLETED preProcessSDNCDeactivateRequest")
274 public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
275 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
276 'execution=' + execution.getId() +
278 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
279 logger.trace('Entered ' + method)
280 execution.setVariable("prefix", Prefix)
281 logger.trace("STARTED preProcessSDNCUnassignRequest Process")
283 String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
285 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
287 execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
288 logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
291 logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
292 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
294 logger.trace("COMPLETED preProcessSDNCUnassignRequest Process")
297 public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
299 String uuid = execution.getVariable('testReqId') // for junits
301 uuid = execution.getVariable("DCVFMR_requestId") + "-" + System.currentTimeMillis()
303 def callbackURL = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
304 def requestId = execution.getVariable("DCVFMR_requestId")
305 def serviceId = execution.getVariable("DCVFMR_serviceId")
306 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
307 def vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
308 def source = execution.getVariable("DCVFMR_source")
309 def vnfId = execution.getVariable("DCVFMR_vnfId")
311 def sdncVersion = execution.getVariable("sdncVersion")
314 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
315 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
316 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
317 <sdncadapter:RequestHeader>
318 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
319 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
320 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
321 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
322 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
323 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
324 </sdncadapter:RequestHeader>
325 <sdncadapterworkflow:SDNCRequestData>
326 <request-information>
327 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
328 <request-action>DeleteVfModuleInstance</request-action>
329 <source>${MsoUtils.xmlEscape(source)}</source>
333 </request-information>
334 <service-information>
336 <subscription-service-type/>
337 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
338 <global-customer-id/>
339 </service-information>
341 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
344 <vf-module-information>
345 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
346 </vf-module-information>
347 <vf-module-request-input/>
348 </sdncadapterworkflow:SDNCRequestData>
349 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
351 logger.debug("sdncRequest: " + sdncRequest)
355 // parse the incoming DELETE_VF_MODULE request
356 // and formulate the outgoing VnfAdapterDeleteV1 request
357 public void prepVNFAdapterRequest(DelegateExecution execution) {
359 String requestId = UUID.randomUUID().toString()
360 String origRequestId = execution.getVariable("DCVFMR_requestId")
361 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
362 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
363 String vnfId = execution.getVariable("DCVFMR_vnfId")
364 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
365 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
366 String tenantId = execution.getVariable("DCVFMR_tenantId")
367 def messageId = execution.getVariable('mso-request-id') + '-' +
368 System.currentTimeMillis()
369 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
370 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
371 if ('true'.equals(useQualifiedHostName)) {
372 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
376 <deleteVfModuleRequest>
377 <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
378 <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
379 <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
380 <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
381 <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
382 <skipAAI>true</skipAAI>
384 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
385 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
387 <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
388 <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
389 </deleteVfModuleRequest>
392 logger.debug("vnfAdapterRestV1Request: " + request)
393 execution.setVariable("vnfAdapterRestV1Request", request)
396 // parse the incoming DELETE_VF_MODULE request
397 // and formulate the outgoing UpdateAAIVfModuleRequest request
398 public void prepUpdateAAIVfModule(DelegateExecution execution) {
400 String vnfId = execution.getVariable("DCVFMR_vnfId")
401 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
402 // formulate the request for UpdateAAIVfModule
403 String request = """<UpdateAAIVfModuleRequest>
404 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
405 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
406 <heat-stack-id>DELETE</heat-stack-id>
407 <orchestration-status>deleted</orchestration-status>
408 </UpdateAAIVfModuleRequest>""" as String
409 logger.debug("UpdateAAIVfModuleRequest :" + request)
410 execution.setVariable("UpdateAAIVfModuleRequest", request)
413 // parse the incoming DELETE_VF_MODULE request
414 // and formulate the outgoing UpdateAAIVfModuleRequest request
415 public void prepUpdateAAIVfModuleToAssigned(DelegateExecution execution) {
417 String vnfId = execution.getVariable("DCVFMR_vnfId")
418 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
419 // formulate the request for UpdateAAIVfModule
420 String request = """<UpdateAAIVfModuleRequest>
421 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
422 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
423 <heat-stack-id></heat-stack-id>
424 <orchestration-status>Assigned</orchestration-status>
425 </UpdateAAIVfModuleRequest>""" as String
426 logger.debug("UpdateAAIVfModuleRequest :" + request)
427 execution.setVariable("UpdateAAIVfModuleRequest", request)
430 // parse the incoming DELETE_VF_MODULE request
431 // and formulate the outgoing DeleteAAIVfModuleRequest request
432 public void prepDeleteAAIVfModule(DelegateExecution execution) {
434 String vnfId = execution.getVariable("DCVFMR_vnfId")
435 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
436 // formulate the request for UpdateAAIVfModule
437 String request = """<DeleteAAIVfModuleRequest>
438 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
439 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
440 </DeleteAAIVfModuleRequest>""" as String
441 logger.debug("DeleteAAIVfModuleRequest :" + request)
442 execution.setVariable("DeleteAAIVfModuleRequest", request)
445 // generates a WorkflowException if
447 public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
449 logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
450 "AAI error occurred deleting the Generic Vnf" + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"),
451 "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue());
452 String processKey = getProcessKey(execution);
453 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
457 public void sdncValidateResponse(DelegateExecution execution, String response){
459 execution.setVariable("prefix",Prefix)
461 WorkflowException workflowException = execution.getVariable("WorkflowException")
462 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
464 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
465 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
467 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
468 logger.debug("Successfully Validated SDNC Response")
470 throw new BpmnError("MSOWorkflowException")
474 public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
475 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
476 'execution=' + execution.getId() +
478 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
479 logger.trace('Entered ' + method)
480 execution.setVariable("prefix", Prefix)
481 logger.trace("STARTED deleteNetworkPoliciesFromAAI")
485 List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
486 if (fqdnList == null) {
487 logger.debug("No network policies to delete")
490 int fqdnCount = fqdnList.size()
492 execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
493 logger.debug("networkPolicyFqdnCount - " + fqdnCount)
495 AaiUtil aaiUriUtil = new AaiUtil(this)
498 // AII loop call over contrail network policy fqdn list
499 for (i in 0..fqdnCount-1) {
502 String fqdn = fqdnList[i]
505 // Query AAI for this network policy FQDN
506 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
507 uri.queryParam("network-policy-fqdn", fqdn)
508 Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
510 if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
511 execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", 200)
512 NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
515 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicy.getNetworkPolicyId())
516 getAAIClient().delete(delUri)
517 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 200)
518 logger.debug("AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
519 logger.debug("The return code from deleting network policy is: " + 200)
520 // This network policy was deleted from AAI successfully
521 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
522 }catch(NotFoundException ne){
523 // This network policy FQDN is not in AAI. No need to delete.
524 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 404)
525 logger.debug("The return code is: " + 404)
526 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
529 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
530 logger.debug(delErrorMessage)
531 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
534 // This network policy FQDN is not in AAI. No need to delete.
535 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
537 }catch (BpmnError e){
540 catch (Exception e) {
542 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
543 logger.debug(dataErrorMessage)
544 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
550 logger.debug("No contrail network policies to query/create")
554 } catch (BpmnError e) {
557 } catch (Exception ex) {
558 String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
559 logger.debug(exceptionMessage)
560 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
567 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
569 * @param execution The flow's execution instance.
571 public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
572 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
573 'execution=' + execution.getId() +
575 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
576 logger.trace('Entered ' + method)
579 def vnfId = execution.getVariable('DCVFMR_vnfId')
580 def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
581 def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
582 def ipv4OamAddressElement = ''
583 def managementV6AddressElement = ''
585 if (oamManagementV4Address != null) {
586 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
589 if (oamManagementV6Address != null) {
590 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
594 String updateAAIGenericVnfRequest = """
595 <UpdateAAIGenericVnfRequest>
596 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
597 ${ipv4OamAddressElement}
598 ${managementV6AddressElement}
599 </UpdateAAIGenericVnfRequest>
601 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
602 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
603 logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
606 logger.trace('Exited ' + method)
607 } catch (BpmnError e) {
609 } catch (Exception e) {
610 logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
611 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),
612 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
613 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
617 public void setSuccessfulRollbackStatus (DelegateExecution execution){
619 execution.setVariable("prefix", Prefix)
620 logger.trace("STARTED setSuccessfulRollbackStatus")
623 // Set rolledBack to true, rollbackError to null
624 execution.setVariable("rolledBack", true)
625 execution.setVariable("rollbackError", null)
628 logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
629 "Exception Occured Processing setSuccessfulRollbackStatus.", "BPMN",
630 MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
631 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
633 logger.trace("COMPLETED setSuccessfulRollbackStatus")
636 public void setFailedRollbackStatus (DelegateExecution execution){
638 execution.setVariable("prefix", Prefix)
639 logger.trace("STARTED setFailedRollbackStatus")
642 // Set rolledBack to false, rollbackError to actual value, rollbackData to null
643 execution.setVariable("rolledBack", false)
644 execution.setVariable("rollbackError", 'Caught exception in DoCreateVfModuleRollback')
645 execution.setVariable("rollbackData", null)
648 logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
649 "Exception Occured Processing setFailedRollbackStatus.", "BPMN",
650 MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
651 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
653 logger.trace("COMPLETED setFailedRollbackStatus")