2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts;
23 import javax.ws.rs.core.UriBuilder
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
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.NetworkUtils
33 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
34 import org.onap.so.bpmn.common.scripts.VidUtils
35 import org.onap.so.bpmn.core.UrnPropertiesReader
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.client.aai.AAIObjectType
39 import org.onap.so.client.aai.AAIResourcesClient
40 import org.onap.so.client.aai.entities.uri.AAIResourceUri
41 import org.onap.so.client.aai.entities.uri.AAIUriFactory
42 import org.onap.so.client.aai.entities.AAIResultWrapper
43 import org.onap.so.client.graphinventory.entities.uri.Depth
44 import org.onap.so.constants.Defaults
45 import org.onap.so.logger.MsoLogger
46 import org.onap.so.rest.APIResponse
47 import org.springframework.web.util.UriUtils
48 import org.onap.aai.domain.yang.VpnBinding
49 import org.onap.aai.domain.yang.RouteTarget
50 import javax.ws.rs.NotFoundException
53 import groovy.xml.XmlUtil
56 * This groovy class supports the <class>DoUpdateNetworkInstance.bpmn</class> process.
59 public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor {
60 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoUpdateNetworkInstance.class);
62 String Prefix="UPDNETI_"
63 ExceptionUtil exceptionUtil = new ExceptionUtil()
64 JsonUtils jsonUtil = new JsonUtils()
65 VidUtils vidUtils = new VidUtils(this)
66 NetworkUtils networkUtils = new NetworkUtils()
67 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
70 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
73 public InitializeProcessVariables(DelegateExecution execution){
74 /* Initialize all the process variables in this block */
76 execution.setVariable(Prefix + "messageId", "")
77 execution.setVariable("BasicAuthHeaderValuePO", "")
78 execution.setVariable("BasicAuthHeaderValueSDNC", "")
79 execution.setVariable(Prefix + "networkRequest", "")
80 execution.setVariable(Prefix + "networkInputs", "")
81 execution.setVariable(Prefix + "networkOutputs", "")
82 execution.setVariable(Prefix + "requestId", "")
83 execution.setVariable(Prefix + "source", "")
84 execution.setVariable(Prefix + "networkId", "")
86 execution.setVariable(Prefix + "isPONR", false) // Point-of-no-return, means, rollback is not needed
88 // AAI query Cloud Region
89 execution.setVariable(Prefix + "queryCloudRegionRequest","")
90 execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
91 execution.setVariable(Prefix + "queryCloudRegionResponse","")
92 execution.setVariable(Prefix + "cloudRegionPo","")
93 execution.setVariable(Prefix + "cloudRegionSdnc","")
94 execution.setVariable(Prefix + "isCloudRegionGood", false)
97 execution.setVariable(Prefix + "queryIdAAIRequest","")
98 execution.setVariable(Prefix + "queryIdAAIResponse", "")
99 execution.setVariable(Prefix + "aaiIdReturnCode", "")
101 // AAI query vpn binding
102 execution.setVariable(Prefix + "queryVpnBindingAAIRequest","")
103 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", "")
104 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "")
105 execution.setVariable(Prefix + "vpnBindings", null)
106 execution.setVariable(Prefix + "vpnCount", 0)
107 execution.setVariable(Prefix + "routeCollection", "")
109 // AAI query network policy
110 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest","")
111 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", "")
112 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "")
113 execution.setVariable(Prefix + "networkPolicyUriList", null)
114 execution.setVariable(Prefix + "networkPolicyCount", 0)
115 execution.setVariable(Prefix + "networkCollection", "")
117 // AAI query route table reference
118 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest","")
119 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", "")
120 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "")
121 execution.setVariable(Prefix + "networkTableRefUriList", null)
122 execution.setVariable(Prefix + "networkTableRefCount", 0)
123 execution.setVariable(Prefix + "tableRefCollection", "")
126 execution.setVariable(Prefix + "requeryIdAAIRequest","")
127 execution.setVariable(Prefix + "requeryIdAAIResponse", "")
128 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
130 // AAI update contrail
131 execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
132 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
133 execution.setVariable(Prefix + "updateContrailAAIResponse", "")
134 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
136 execution.setVariable(Prefix + "updateNetworkRequest", "")
137 execution.setVariable(Prefix + "updateNetworkResponse", "")
138 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
139 execution.setVariable(Prefix + "networkReturnCode", "")
140 execution.setVariable(Prefix + "isNetworkRollbackNeeded", false)
142 execution.setVariable(Prefix + "changeAssignSDNCRequest", "")
143 execution.setVariable(Prefix + "changeAssignSDNCResponse", "")
144 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
145 execution.setVariable(Prefix + "sdncReturnCode", "")
146 execution.setVariable(Prefix + "isSdncRollbackNeeded", false)
147 execution.setVariable(Prefix + "sdncResponseSuccess", false)
149 execution.setVariable(Prefix + "isVnfBindingPresent", false)
150 execution.setVariable(Prefix + "Success", false)
151 execution.setVariable(Prefix + "serviceInstanceId", "")
153 execution.setVariable(Prefix + "isException", false)
157 // **************************************************
158 // Pre or Prepare Request Section
159 // **************************************************
161 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
164 public void preProcessRequest (DelegateExecution execution) {
166 execution.setVariable("prefix",Prefix)
168 msoLogger.trace("Inside preProcessRequest DoUpdateNetworkInstance Request ")
171 // initialize flow variables
172 InitializeProcessVariables(execution)
174 // GET Incoming request & validate 3 kinds of format.
175 execution.setVariable("action", "UPDATE")
176 String networkRequest = execution.getVariable("bpmnRequest")
177 if (networkRequest != null) {
178 if (networkRequest.contains("requestDetails")) {
179 // JSON format request is sent, create xml
181 def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
182 msoLogger.debug(" Incoming message formatted . . . : " + '\n' + prettyJson)
183 networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
185 } catch (Exception ex) {
186 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
187 msoLogger.debug(dataErrorMessage)
188 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
191 // XML format request is sent
195 // vIPR format request is sent, create xml from individual variables
196 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
199 networkRequest = utils.formatXml(networkRequest)
200 msoLogger.debug(networkRequest)
201 execution.setVariable(Prefix + "networkRequest", networkRequest)
202 msoLogger.debug(" network-request - " + '\n' + networkRequest)
204 // validate 'disableRollback' (aka, 'suppressRollback')
205 boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
206 execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
207 msoLogger.debug(Prefix + "rollbackEnabled - " + rollbackEnabled)
209 String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
210 execution.setVariable(Prefix + "networkInputs", networkInputs)
211 msoLogger.debug(Prefix + "networkInputs - " + '\n' + networkInputs)
214 String messageId = execution.getVariable(Prefix + "messageId") // for testing
215 if (messageId == null || messageId == "") {
216 messageId = UUID.randomUUID()
217 msoLogger.debug(" UPDNETI_messageId, random generated: " + messageId)
219 msoLogger.debug(" UPDNETI_messageId, pre-assigned: " + messageId)
221 execution.setVariable(Prefix + "messageId", messageId)
223 String source = utils.getNodeText(networkRequest, "source")
224 execution.setVariable(Prefix + "source", source)
225 msoLogger.debug(Prefix + "source - " + source)
227 String networkId = ""
228 if (utils.nodeExists(networkRequest, "network-id")) {
229 networkId = utils.getNodeText(networkRequest, "network-id")
230 if (networkId == 'null' || networkId == "") {
231 sendSyncError(execution)
232 // missing value of networkId
233 String dataErrorMessage = "Variable 'network-id' value/element is missing."
234 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
235 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
240 String lcpCloudRegion = ""
241 if (utils.nodeExists(networkRequest, "aic-cloud-region")) {
242 lcpCloudRegion = utils.getNodeText(networkRequest, "aic-cloud-region")
243 if ((lcpCloudRegion == 'null') || (lcpCloudRegion == "")) {
244 sendSyncError(execution)
245 String dataErrorMessage = "requestDetails has missing 'aic-cloud-region' value/element."
246 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
247 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
251 String serviceInstanceId = ""
252 if (utils.nodeExists(networkRequest, "service-instance-id")) {
253 serviceInstanceId = utils.getNodeText(networkRequest, "service-instance-id")
254 if ((serviceInstanceId == 'null') || (lcpCloudRegion == "")) {
255 sendSyncError(execution)
256 String dataErrorMessage = "Variable 'serviceInstanceId' value/element is missing."
257 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
258 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
262 // PO Authorization Info / headers Authorization=
263 String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution)
267 def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey", execution))
268 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
269 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
271 } catch (IOException ex) {
272 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - "
273 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
274 msoLogger.debug(dataErrorMessage)
275 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
278 // Set variables for Generic Get Sub Flow use
279 execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
280 msoLogger.debug(Prefix + "serviceInstanceId - " + serviceInstanceId)
282 msoLogger.debug(" Url for SDNC adapter: " + UrnPropertiesReader.getVariable("mso.adapters.sdnc.endpoint",execution))
284 String sdncVersion = execution.getVariable("sdncVersion")
285 msoLogger.debug("sdncVersion? : " + sdncVersion)
287 // build 'networkOutputs'
288 networkId = utils.getNodeText(networkRequest, "network-id")
289 if ((networkId == null) || (networkId == "null")) {
292 String networkName = utils.getNodeText(networkRequest, "network-name")
293 if ((networkName == null) || (networkName == "null")) {
296 String networkOutputs =
298 <network-id>${MsoUtils.xmlEscape(networkId)}</network-id>
299 <network-name>${MsoUtils.xmlEscape(networkName)}</network-name>
300 </network-outputs>"""
301 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
302 msoLogger.debug(Prefix + "networkOutputs - " + '\n' + networkOutputs)
303 execution.setVariable(Prefix + "networkId", networkId)
304 execution.setVariable(Prefix + "networkName", networkName)
307 } catch (BpmnError e) {
310 } catch (Exception ex){
311 sendSyncError(execution)
313 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - " + ex.getMessage()
314 msoLogger.debug(exceptionMessage)
315 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
321 * Gets the service instance uri from aai
324 public void getServiceInstance(DelegateExecution execution) {
325 msoLogger.trace("getServiceInstance ")
327 String serviceInstanceId = execution.getVariable('serviceInstanceId')
329 AAIResourcesClient resourceClient = new AAIResourcesClient()
330 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
332 if(!resourceClient.exists(uri)){
333 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Service Instance not found in aai")
335 Map<String, String> keys = uri.getURIKeys()
336 execution.setVariable("serviceType", keys.get("service-type"))
337 execution.setVariable("subscriberName", keys.get("global-customer-id"))
340 }catch(BpmnError e) {
342 }catch (Exception ex){
343 String msg = "Exception in getServiceInstance. " + ex.getMessage()
345 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
349 public void callRESTQueryAAICloudRegion (DelegateExecution execution) {
351 execution.setVariable("prefix", Prefix)
353 msoLogger.debug(" ***** Inside callRESTQueryAAICloudRegion of DoUpdateNetworkInstance ***** " )
356 String networkInputs = execution.getVariable(Prefix + "networkInputs")
357 String cloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
360 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
361 AaiUtil aaiUtil = new AaiUtil(this)
363 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, Defaults.CLOUD_OWNER.toString(), cloudRegion)
364 def queryCloudRegionRequest = aaiUtil.createAaiUri(uri)
366 execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
368 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
369 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
371 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
372 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
373 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
374 execution.setVariable(Prefix + "isCloudRegionGood", true)
377 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
378 msoLogger.debug(dataErrorMessage)
379 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
383 msoLogger.debug(" is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"))
385 } catch (BpmnError e) {
388 } catch (Exception ex) {
390 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
391 msoLogger.debug(exceptionMessage)
392 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
398 public void callRESTQueryAAINetworkId(DelegateExecution execution) {
400 execution.setVariable("prefix", Prefix)
402 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
406 String networkRequest = execution.getVariable(Prefix + "networkRequest")
407 String networkId = utils.getNodeText(networkRequest, "network-id")
408 networkId = UriUtils.encode(networkId,"UTF-8")
409 execution.setVariable(Prefix + "networkId", networkId)
412 AaiUtil aaiUriUtil = new AaiUtil(this)
413 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId)
415 String queryIdAAIRequest = aaiUriUtil.createAaiUri(uri)
417 msoLogger.debug(queryIdAAIRequest)
418 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
419 msoLogger.debug(Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest)
421 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
422 String returnCode = response.getStatusCode()
423 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
424 msoLogger.debug(" ***** AAI Response Code : " + returnCode)
426 String aaiResponseAsString = response.getResponseBodyAsString()
428 if (returnCode=='200') {
429 msoLogger.debug(aaiResponseAsString)
430 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
431 msoLogger.debug(" QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
434 if (returnCode=='404') {
435 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
436 msoLogger.debug(" AAI Query Failed. " + dataErrorMessage)
437 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
440 if (aaiResponseAsString.contains("RESTFault")) {
441 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
442 execution.setVariable("WorkflowException", exceptionObject)
443 throw new BpmnError("MSOWorkflowException")
447 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
448 msoLogger.debug("Unexpected Response from QueryAAINetworkId - " + dataErrorMessage)
449 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
455 } catch (BpmnError e) {
458 } catch (Exception ex) {
459 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
460 msoLogger.debug(exceptionMessage)
461 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
467 public void callRESTReQueryAAINetworkId(DelegateExecution execution) {
469 execution.setVariable("prefix", Prefix)
471 msoLogger.debug(" ***** Inside callRESTReQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
475 String networkRequest = execution.getVariable(Prefix + "networkRequest")
476 String networkId = utils.getNodeText(networkRequest, "network-id")
477 networkId = UriUtils.encode(networkId,"UTF-8")
480 AaiUtil aaiUriUtil = new AaiUtil(this)
481 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId)
483 String requeryIdAAIRequest = aaiUriUtil.createAaiUri(uri)
485 msoLogger.debug(requeryIdAAIRequest)
486 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
487 msoLogger.debug(" UPDNETI_requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest)
489 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
490 String returnCode = response.getStatusCode()
491 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
492 msoLogger.debug(" ***** AAI ReQuery Response Code : " + returnCode)
494 String aaiResponseAsString = response.getResponseBodyAsString()
496 if (returnCode=='200') {
497 msoLogger.debug(aaiResponseAsString)
498 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
499 msoLogger.debug(" ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
501 String netId = utils.getNodeText(aaiResponseAsString, "network-id")
502 String netName = utils.getNodeText(aaiResponseAsString, "network-name")
503 String networkOutputs =
505 <network-id>${MsoUtils.xmlEscape(netId)}</network-id>
506 <network-name>${MsoUtils.xmlEscape(netName)}</network-name>
507 </network-outputs>"""
508 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
509 msoLogger.debug(" networkOutputs - " + '\n' + networkOutputs)
512 if (returnCode=='404') {
513 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
514 msoLogger.debug(" AAI ReQuery Failed. - " + dataErrorMessage)
515 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
518 if (aaiResponseAsString.contains("RESTFault")) {
519 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
520 execution.setVariable("WorkflowException", exceptionObject)
521 throw new BpmnError("MSOWorkflowException")
525 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
526 msoLogger.debug(dataErrorMessage)
527 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
533 } catch (BpmnError e) {
536 } catch (Exception ex) {
537 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
538 msoLogger.debug(exceptionMessage)
539 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
545 public void callRESTQueryAAINetworkVpnBinding(DelegateExecution execution) {
547 execution.setVariable("prefix", Prefix)
549 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkVpnBinding of DoUpdateNetworkInstance ***** " )
554 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
555 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
556 msoLogger.debug(" relationship - " + relationship)
558 // Check if Vnf Binding is present, then build a List of vnfBinding
559 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
560 int vpnCount = vpnBindingUri.size()
561 execution.setVariable(Prefix + "vpnCount", vpnCount)
562 msoLogger.debug(" UPDNETI_vpnCount - " + vpnCount)
565 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
566 msoLogger.debug(" vpnBindingUri List - " + vpnBindingUri)
568 String routeTargets = ""
569 // AII loop call using list vpnBindings
570 for(i in 0..vpnBindingUri.size()-1) {
573 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
574 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
575 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
578 AAIResourcesClient resourceClient = new AAIResourcesClient()
579 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDING, vpnBindingId)
580 AAIResultWrapper wrapper = resourceClient.get(uri.depth(Depth.TWO), NotFoundException.class)
582 Optional<VpnBinding> binding = wrapper.asBean(VpnBinding.class)
584 String routeTarget = ""
585 String routeRole = ""
586 if(binding.get().getRouteTargets() != null) {
587 List<RouteTarget> targets = binding.get().getRouteTargets().getRouteTarget()
588 for(RouteTarget target : targets) {
589 routeTarget = target.getGlobalRouteTarget()
590 routeRole = target.getRouteTargetRole()
591 routeTargets += "<routeTargets>" + '\n' +
592 " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
593 " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
594 "</routeTargets>" + '\n'
600 execution.setVariable(Prefix + "routeCollection", routeTargets)
601 msoLogger.debug(" UPDNETI_routeCollection - " + '\n' + routeTargets)
604 // reset return code to success
605 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
606 AaiUtil aaiUriUtil = new AaiUtil(this)
607 String schemaVersion = aaiUriUtil.getNamespace()
608 String aaiStubResponse =
609 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
610 <vpn-binding xmlns="${schemaVersion}">
611 <global-route-target/>
614 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
615 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
616 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
617 msoLogger.debug(" No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml)
621 } catch (NotFoundException e) {
622 msoLogger.debug("Response Error from AAINetworkVpnBinding is 404 (Not Found).")
623 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Response Error from AAINetworkVpnBinding is 404 (Not Found).")
624 } catch (Exception ex) {
625 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
626 msoLogger.debug(exceptionMessage)
627 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
633 public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
635 execution.setVariable("prefix", Prefix)
637 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " )
641 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
642 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
643 msoLogger.debug(" relationship - " + relationship)
645 // Check if Network Policy is present, then build a List of network policy
646 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
647 int networkPolicyCount = networkPolicyUriList.size()
648 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
649 msoLogger.debug(" UPDNETI_networkPolicyCount - " + networkPolicyCount)
651 AaiUtil aaiUriUtil = new AaiUtil(this)
653 if (networkPolicyCount > 0) {
654 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
655 msoLogger.debug(" networkPolicyUri List - " + networkPolicyUriList)
657 String networkPolicies = ""
658 // AII loop call using list vpnBindings
659 for (i in 0..networkPolicyUriList.size()-1) {
663 URI uri = UriBuilder.fromUri(networkPolicyUriList[i]).build()
665 AAIResourceUri aaiUri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.NETWORK_POLICY, uri)
666 aaiUri.depth(Depth.ALL)
667 String queryNetworkPolicyAAIRequest = aaiUriUtil.createAaiUri(aaiUri)
669 msoLogger.debug(queryNetworkPolicyAAIRequest)
670 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
671 msoLogger.debug(" UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest)
673 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
674 String returnCode = response.getStatusCode()
675 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
676 msoLogger.debug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
678 String aaiResponseAsString = response.getResponseBodyAsString()
680 if (returnCode=='200') {
681 msoLogger.debug(aaiResponseAsString)
682 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
683 msoLogger.debug(" QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
685 String networkPolicy = ""
686 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
687 networkPolicy = utils.getNodeText(aaiResponseAsString, "network-policy-fqdn")
688 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
692 if (returnCode=='404') {
693 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
694 msoLogger.debug(dataErrorMessage)
695 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
698 if (aaiResponseAsString.contains("RESTFault")) {
699 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
700 execution.setVariable("WorkflowException", exceptionObject)
701 throw new BpmnError("MSOWorkflowException")
705 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
706 msoLogger.debug(dataErrorMessage)
707 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
715 execution.setVariable(Prefix + "networkCollection", networkPolicies)
716 msoLogger.debug(" UPDNETI_networkCollection - " + '\n' + networkPolicies)
719 // reset return code to success
720 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
721 String schemaVersion = aaiUriUtil.getNamespace()
722 String aaiStubResponse =
723 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
724 <network-policy xmlns="${schemaVersion}">
725 <network-policy-fqdn/>
728 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
729 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
730 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
731 msoLogger.debug(" No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml)
735 } catch (BpmnError e) {
738 } catch (Exception ex) {
739 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
740 msoLogger.debug(exceptionMessage)
741 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
747 public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
749 execution.setVariable("prefix", Prefix)
751 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " )
755 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
756 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
757 msoLogger.debug(" relationship - " + relationship)
759 // Check if Network TableREf is present, then build a List of network policy
760 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
761 int networkTableRefCount = networkTableRefUriList.size()
762 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
763 msoLogger.debug(" UPDNETI_networkTableRefCount - " + networkTableRefCount)
765 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
766 AaiUtil aaiUriUtil = new AaiUtil(this)
768 if (networkTableRefCount > 0) {
769 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
770 msoLogger.debug(" networkTableRefUri List - " + networkTableRefUriList)
772 // AII loop call using list vpnBindings
773 String networkTableRefs = ""
774 for (i in 0..networkTableRefUriList.size()-1) {
778 // prepare url using tableRef
779 URI uri = UriBuilder.fromUri(networkTableRefUriList[i]).build()
781 AAIResourceUri aaiUri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.ROUTE_TABLE_REFERENCE, uri)
782 aaiUri.depth(Depth.ALL)
783 String queryNetworkTableRefAAIRequest = aaiUriUtil.createAaiUri(aaiUri)
785 msoLogger.debug(queryNetworkTableRefAAIRequest)
786 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
787 msoLogger.debug(" UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest)
789 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
790 String returnCode = response.getStatusCode()
791 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
792 msoLogger.debug(" ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode)
794 String aaiResponseAsString = response.getResponseBodyAsString()
796 if (returnCode=='200') {
797 msoLogger.debug(aaiResponseAsString)
798 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
799 msoLogger.debug(" QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString)
801 String networkTableRef = ""
802 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
803 networkTableRef = utils.getNodeText(aaiResponseAsString, "route-table-reference-fqdn")
804 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
808 if (returnCode=='404') {
809 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
810 msoLogger.debug(dataErrorMessage)
811 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
814 if (aaiResponseAsString.contains("RESTFault")) {
815 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
816 execution.setVariable("WorkflowException", exceptionObject)
817 throw new BpmnError("MSOWorkflowException")
821 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
822 msoLogger.debug(dataErrorMessage)
823 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
831 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
832 msoLogger.debug(" UPDNETI_tableRefCollection - " + '\n' + networkTableRefs)
835 // reset return code to success
836 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
837 String schemaVersion = aaiUriUtil.getNamespace()
838 String aaiStubResponse =
839 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
840 <route-table-references xmlns="${schemaVersion}">
841 <route-table-reference-fqdn/>
842 </route-table-references>
844 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
845 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
846 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
847 msoLogger.debug(" No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml)
851 } catch (BpmnError e) {
854 } catch (Exception ex) {
855 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
856 msoLogger.debug(exceptionMessage)
857 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
863 public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
865 execution.setVariable("prefix", Prefix)
867 msoLogger.debug(" ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " )
871 String networkRequest = execution.getVariable(Prefix + "networkRequest")
872 String networkId = utils.getNodeText(networkRequest, "network-id")
873 networkId = UriUtils.encode(networkId,"UTF-8")
874 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
875 String updateNetworkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
878 AaiUtil aaiUriUtil = new AaiUtil(this)
879 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId)
881 String updateContrailAAIUrlRequest = aaiUriUtil.createAaiUri(uri)
883 msoLogger.debug(updateContrailAAIUrlRequest)
884 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
885 msoLogger.debug(" UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest)
887 //Prepare payload (PUT)
888 String schemaVersion = aaiUriUtil.getNamespaceFromUri(updateContrailAAIUrlRequest)
889 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
890 String payloadXml = utils.formatXml(payload)
891 msoLogger.debug(payloadXml)
892 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
893 msoLogger.debug(" 'payload' to Update Contrail - " + "\n" + payloadXml)
895 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
896 String returnCode = response.getStatusCode()
897 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
899 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
900 msoLogger.debug(" ***** AAI Update Contrail Response Code : " + returnCode)
903 if (returnCode=='200') {
904 msoLogger.debug(aaiUpdateContrailResponseAsString)
905 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
906 msoLogger.debug(" AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString)
907 // Point-of-no-return is set to false, rollback not needed.
908 execution.setVariable(Prefix + "isPONR", true)
911 if (returnCode=='404') {
912 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
913 msoLogger.debug(dataErrorMessage)
914 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
917 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
918 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
919 execution.setVariable("WorkflowException", exceptionObject)
920 throw new BpmnError("MSOWorkflowException")
924 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
925 msoLogger.debug(errorMessage)
926 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
931 } catch (BpmnError e) {
934 } catch (Exception ex) {
935 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
936 msoLogger.debug(exceptionMessage)
937 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
943 public void prepareUpdateNetworkRequest (DelegateExecution execution) {
945 execution.setVariable("prefix", Prefix)
947 msoLogger.trace("Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ")
952 String requestId = execution.getVariable(Prefix + "requestId")
953 String messageId = execution.getVariable(Prefix + "messageId")
954 String source = execution.getVariable(Prefix + "source")
956 String requestInput = execution.getVariable(Prefix + "networkRequest")
957 String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
958 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
959 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
961 // Prepare Network request
962 String routeCollection = execution.getVariable(Prefix + "routeCollection")
963 String policyCollection = execution.getVariable(Prefix + "networkCollection")
964 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
965 String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
967 String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
968 buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
969 msoLogger.debug(buildUpdateNetworkRequestAsString)
971 execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
972 msoLogger.debug(" UPDNETI_updateNetworkRequest - " + "\n" + buildUpdateNetworkRequestAsString)
974 } catch (Exception ex) {
975 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
976 msoLogger.debug(exceptionMessage)
977 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
983 public void prepareSDNCRequest (DelegateExecution execution) {
985 execution.setVariable("prefix", Prefix)
987 msoLogger.trace("Inside prepareSDNCRequest of DoUpdateNetworkInstance ")
991 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
992 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
993 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
995 String networkId = ""
996 if (utils.nodeExists(updateNetworkInput, "network-id")) {
997 networkId = utils.getNodeText(updateNetworkInput, "network-id")
999 if (networkId == null) {networkId = ""}
1001 String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1003 String queryAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1005 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1006 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, queryAAIResponse, null)
1008 String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1009 msoLogger.debug(sndcTopologyUpdateRequesAsString)
1010 execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1011 msoLogger.debug(" UPDNETI_changeAssignSDNCRequest - " + "\n" + sndcTopologyUpdateRequesAsString)
1014 } catch (Exception ex) {
1015 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1016 msoLogger.debug(exceptionMessage)
1017 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1026 // **************************************************
1027 // Post or Validate Response Section
1028 // **************************************************
1030 public void validateUpdateNetworkResponse (DelegateExecution execution) {
1032 execution.setVariable("prefix", Prefix)
1034 msoLogger.trace("Inside validateUpdateNetworkResponse of DoUpdateNetworkInstance ")
1037 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1038 String networkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
1039 if (networkResponse==null) {
1040 networkResponse="" // reset
1043 msoLogger.debug(" Network Adapter update responseCode: " + returnCode)
1045 String errorMessage = ""
1046 if (returnCode == "200") {
1047 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1048 msoLogger.debug(networkResponse)
1049 execution.setVariable(Prefix + "updateNetworkResponse", networkResponse)
1050 msoLogger.debug(" Network Adapter update Success Response - " + "\n" + networkResponse)
1052 // prepare rollback data
1053 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1054 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1055 String rollbackNetwork =
1056 """<rollbackNetworkRequest>
1058 </rollbackNetworkRequest>"""
1059 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1060 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1061 msoLogger.debug(" Network Adapter rollback data - " + "\n" + rollbackNetworkXml)
1063 } else { // network error
1064 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1065 if (networkResponse.contains("updateNetworkError")) {
1066 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1067 errorMessage = utils.getNodeText(networkResponse, "message")
1068 errorMessage = "Received error from Network Adapter: " + errorMessage
1069 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1071 } else { // CatchAll exception
1072 if (returnCode == "500") {
1073 errorMessage = "JBWEB000065: HTTP Status 500."
1075 errorMessage = "Return code is " + returnCode
1077 errorMessage = "Received error from Network Adapter: " + errorMessage
1078 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1082 } else { // CatchAll exception
1083 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1084 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1090 } catch (BpmnError e) {
1093 } catch (Exception ex) {
1094 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1095 msoLogger.debug(exceptionMessage)
1096 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1103 public void validateSDNCResponse (DelegateExecution execution) {
1105 execution.setVariable("prefix", Prefix)
1107 msoLogger.trace("Inside validateSDNCResponse of DoUpdateNetworkInstance ")
1109 String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1110 WorkflowException workflowException = null
1112 workflowException = execution.getVariable(Prefix + "WorkflowException")
1113 //execution.setVariable("WorkflowException", workflowException)
1114 } catch (Exception ex) {
1115 msoLogger.debug(" Sdnc 'WorkflowException' object is empty or null. ")
1118 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1120 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1121 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1123 String changeAssignSDNCResponseDecodeXml = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1124 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1125 execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1127 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, prefix+'sdncResponseSuccess'
1128 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1129 msoLogger.debug("Successfully Validated SDNC Response")
1132 msoLogger.debug("Did NOT Successfully Validated SDNC Response")
1133 throw new BpmnError("MSOWorkflowException")
1139 public void postProcessResponse (DelegateExecution execution) {
1141 execution.setVariable("prefix", Prefix)
1143 msoLogger.trace("Inside postProcessResponse of DoUpdateNetworkInstance ")
1146 msoLogger.debug(" ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"))
1147 if (execution.getVariable(Prefix + "isException") == false) {
1148 // set rollback data
1149 execution.setVariable("orchestrationStatus", "")
1150 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1151 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1152 prepareSuccessRollbackData(execution) // populate rollbackData
1153 execution.setVariable("WorkflowException", null)
1154 execution.setVariable(Prefix + "Success", true)
1155 msoLogger.debug(" ***** postProcessResponse(), GOOD !!!")
1157 execution.setVariable(Prefix + "Success", false)
1158 execution.setVariable("rollbackData", null)
1159 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1160 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1161 msoLogger.debug(" ***** workflowException: " + execution.getVariable("workflowException"))
1162 WorkflowException wfex = execution.getVariable("workflowException")
1163 exceptionMessage = wfex.getErrorMessage()
1165 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1166 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1167 exceptionMessage = pwfex.getErrorMessage()
1170 // going to the Main flow: a-la-carte or macro
1171 msoLogger.debug(" ***** postProcessResponse(), BAD !!!")
1172 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1173 throw new BpmnError("MSOWorkflowException")
1176 } catch(BpmnError b){
1177 msoLogger.debug("Rethrowing MSOWorkflowException")
1181 } catch (Exception ex) {
1182 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1183 msoLogger.debug(exceptionMessage)
1184 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1191 public void prepareSDNCRollbackRequest (DelegateExecution execution) {
1193 execution.setVariable("prefix", Prefix)
1195 msoLogger.trace("Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ")
1198 // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException.
1199 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1201 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1202 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1203 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1204 String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1205 String networkId = utils.getNodeText(changeAssignSDNCResponse, "network-id")
1207 String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1209 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1210 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1211 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1212 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1213 msoLogger.debug(" Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" + sndcTopologyRollbackRequestAsString)
1215 } catch (Exception ex) {
1216 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1217 msoLogger.debug(exceptionMessage)
1218 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1224 public void prepareRollbackData(DelegateExecution execution) {
1226 execution.setVariable("prefix",Prefix)
1228 msoLogger.trace("Inside prepareRollbackData() of DoUpdateNetworkInstance ")
1232 Map<String, String> rollbackData = new HashMap<String, String>();
1233 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1234 if (rollbackSDNCRequest != null) {
1235 if (rollbackSDNCRequest != "") {
1236 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1239 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1240 if (rollbackNetworkRequest != null) {
1241 if (rollbackNetworkRequest != "") {
1242 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1245 execution.setVariable("rollbackData", rollbackData)
1246 msoLogger.debug("** rollbackData : " + rollbackData)
1248 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1249 msoLogger.debug("** WorkflowException : " + execution.getVariable("WorkflowException"))
1251 } catch (Exception ex) {
1252 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1253 msoLogger.debug(exceptionMessage)
1254 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1260 public void prepareSuccessRollbackData(DelegateExecution execution) {
1262 execution.setVariable("prefix",Prefix)
1264 msoLogger.trace("Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ")
1268 if (execution.getVariable("sdncVersion") != '1610') {
1269 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1271 prepareSDNCRollbackRequest(execution)
1274 Map<String, String> rollbackData = new HashMap<String, String>();
1275 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1276 if (rollbackSDNCRequest != null) {
1277 if (rollbackSDNCRequest != "") {
1278 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1281 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1282 if (rollbackNetworkRequest != null) {
1283 if (rollbackNetworkRequest != "") {
1284 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1287 execution.setVariable("rollbackData", rollbackData)
1289 msoLogger.debug("** 'rollbackData' for Full Rollback : " + rollbackData)
1290 execution.setVariable("WorkflowException", null)
1293 } catch (Exception ex) {
1294 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1295 msoLogger.debug(exceptionMessage)
1296 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1302 public void setExceptionFlag(DelegateExecution execution){
1304 execution.setVariable("prefix",Prefix)
1306 msoLogger.trace("Inside setExceptionFlag() of DoUpdateNetworkInstance ")
1310 execution.setVariable(Prefix + "isException", true)
1312 if (execution.getVariable("SavedWorkflowException1") != null) {
1313 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1315 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1317 msoLogger.debug(Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"))
1319 } catch(Exception ex){
1320 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1321 msoLogger.debug(exceptionMessage)
1322 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1328 // *******************************
1329 // Build Error Section
1330 // *******************************
1332 public void processJavaException(DelegateExecution execution){
1334 execution.setVariable("prefix",Prefix)
1336 msoLogger.debug("Caught a Java Exception")
1337 msoLogger.debug("Started processJavaException Method")
1338 msoLogger.debug("Variables List: " + execution.getVariables())
1339 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1340 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1342 }catch(Exception e){
1343 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
1344 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
1345 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1347 msoLogger.debug("Completed processJavaException Method")