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 org.apache.commons.lang3.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.so.bpmn.common.scripts.AaiUtil
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.NetworkUtils
31 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
32 import org.onap.so.bpmn.common.scripts.VidUtils
33 import org.onap.so.bpmn.core.UrnPropertiesReader
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.onap.so.logger.MsoLogger
37 import org.onap.so.rest.APIResponse
38 import org.springframework.web.util.UriUtils
41 import groovy.xml.XmlUtil
44 * This groovy class supports the <class>DoUpdateNetworkInstance.bpmn</class> process.
47 public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor {
48 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoUpdateNetworkInstance.class);
50 String Prefix="UPDNETI_"
51 ExceptionUtil exceptionUtil = new ExceptionUtil()
52 JsonUtils jsonUtil = new JsonUtils()
53 VidUtils vidUtils = new VidUtils(this)
54 NetworkUtils networkUtils = new NetworkUtils()
55 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
58 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
61 public InitializeProcessVariables(DelegateExecution execution){
62 /* Initialize all the process variables in this block */
64 execution.setVariable(Prefix + "messageId", "")
65 execution.setVariable("BasicAuthHeaderValuePO", "")
66 execution.setVariable("BasicAuthHeaderValueSDNC", "")
67 execution.setVariable(Prefix + "networkRequest", "")
68 execution.setVariable(Prefix + "networkInputs", "")
69 execution.setVariable(Prefix + "networkOutputs", "")
70 execution.setVariable(Prefix + "requestId", "")
71 execution.setVariable(Prefix + "source", "")
72 execution.setVariable(Prefix + "networkId", "")
74 execution.setVariable(Prefix + "isPONR", false) // Point-of-no-return, means, rollback is not needed
76 // AAI query Cloud Region
77 execution.setVariable(Prefix + "queryCloudRegionRequest","")
78 execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
79 execution.setVariable(Prefix + "queryCloudRegionResponse","")
80 execution.setVariable(Prefix + "cloudRegionPo","")
81 execution.setVariable(Prefix + "cloudRegionSdnc","")
82 execution.setVariable(Prefix + "isCloudRegionGood", false)
85 execution.setVariable(Prefix + "queryIdAAIRequest","")
86 execution.setVariable(Prefix + "queryIdAAIResponse", "")
87 execution.setVariable(Prefix + "aaiIdReturnCode", "")
89 // AAI query vpn binding
90 execution.setVariable(Prefix + "queryVpnBindingAAIRequest","")
91 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", "")
92 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "")
93 execution.setVariable(Prefix + "vpnBindings", null)
94 execution.setVariable(Prefix + "vpnCount", 0)
95 execution.setVariable(Prefix + "routeCollection", "")
97 // AAI query network policy
98 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest","")
99 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", "")
100 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "")
101 execution.setVariable(Prefix + "networkPolicyUriList", null)
102 execution.setVariable(Prefix + "networkPolicyCount", 0)
103 execution.setVariable(Prefix + "networkCollection", "")
105 // AAI query route table reference
106 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest","")
107 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", "")
108 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "")
109 execution.setVariable(Prefix + "networkTableRefUriList", null)
110 execution.setVariable(Prefix + "networkTableRefCount", 0)
111 execution.setVariable(Prefix + "tableRefCollection", "")
114 execution.setVariable(Prefix + "requeryIdAAIRequest","")
115 execution.setVariable(Prefix + "requeryIdAAIResponse", "")
116 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
118 // AAI update contrail
119 execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
120 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
121 execution.setVariable(Prefix + "updateContrailAAIResponse", "")
122 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
124 execution.setVariable(Prefix + "updateNetworkRequest", "")
125 execution.setVariable(Prefix + "updateNetworkResponse", "")
126 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
127 execution.setVariable(Prefix + "networkReturnCode", "")
128 execution.setVariable(Prefix + "isNetworkRollbackNeeded", false)
130 execution.setVariable(Prefix + "changeAssignSDNCRequest", "")
131 execution.setVariable(Prefix + "changeAssignSDNCResponse", "")
132 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
133 execution.setVariable(Prefix + "sdncReturnCode", "")
134 execution.setVariable(Prefix + "isSdncRollbackNeeded", false)
135 execution.setVariable(Prefix + "sdncResponseSuccess", false)
137 execution.setVariable(Prefix + "isVnfBindingPresent", false)
138 execution.setVariable(Prefix + "Success", false)
139 execution.setVariable(Prefix + "serviceInstanceId", "")
141 execution.setVariable(Prefix + "isException", false)
145 // **************************************************
146 // Pre or Prepare Request Section
147 // **************************************************
149 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
152 public void preProcessRequest (DelegateExecution execution) {
154 execution.setVariable("prefix",Prefix)
156 msoLogger.trace("Inside preProcessRequest DoUpdateNetworkInstance Request ")
159 // initialize flow variables
160 InitializeProcessVariables(execution)
162 // GET Incoming request & validate 3 kinds of format.
163 execution.setVariable("action", "UPDATE")
164 String networkRequest = execution.getVariable("bpmnRequest")
165 if (networkRequest != null) {
166 if (networkRequest.contains("requestDetails")) {
167 // JSON format request is sent, create xml
169 def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
170 msoLogger.debug(" Incoming message formatted . . . : " + '\n' + prettyJson)
171 networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
173 } catch (Exception ex) {
174 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
175 msoLogger.debug(dataErrorMessage)
176 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
179 // XML format request is sent
183 // vIPR format request is sent, create xml from individual variables
184 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
187 networkRequest = utils.formatXml(networkRequest)
188 msoLogger.debug(networkRequest)
189 execution.setVariable(Prefix + "networkRequest", networkRequest)
190 msoLogger.debug(" network-request - " + '\n' + networkRequest)
192 // validate 'disableRollback' (aka, 'suppressRollback')
193 boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
194 execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
195 msoLogger.debug(Prefix + "rollbackEnabled - " + rollbackEnabled)
197 String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
198 execution.setVariable(Prefix + "networkInputs", networkInputs)
199 msoLogger.debug(Prefix + "networkInputs - " + '\n' + networkInputs)
202 String messageId = execution.getVariable(Prefix + "messageId") // for testing
203 if (messageId == null || messageId == "") {
204 messageId = UUID.randomUUID()
205 msoLogger.debug(" UPDNETI_messageId, random generated: " + messageId)
207 msoLogger.debug(" UPDNETI_messageId, pre-assigned: " + messageId)
209 execution.setVariable(Prefix + "messageId", messageId)
211 String source = utils.getNodeText(networkRequest, "source")
212 execution.setVariable(Prefix + "source", source)
213 msoLogger.debug(Prefix + "source - " + source)
215 String networkId = ""
216 if (utils.nodeExists(networkRequest, "network-id")) {
217 networkId = utils.getNodeText(networkRequest, "network-id")
218 if (networkId == 'null' || networkId == "") {
219 sendSyncError(execution)
220 // missing value of networkId
221 String dataErrorMessage = "Variable 'network-id' value/element is missing."
222 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
223 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
228 String lcpCloudRegion = ""
229 if (utils.nodeExists(networkRequest, "aic-cloud-region")) {
230 lcpCloudRegion = utils.getNodeText(networkRequest, "aic-cloud-region")
231 if ((lcpCloudRegion == 'null') || (lcpCloudRegion == "")) {
232 sendSyncError(execution)
233 String dataErrorMessage = "requestDetails has missing 'aic-cloud-region' value/element."
234 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
235 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
239 String serviceInstanceId = ""
240 if (utils.nodeExists(networkRequest, "service-instance-id")) {
241 serviceInstanceId = utils.getNodeText(networkRequest, "service-instance-id")
242 if ((serviceInstanceId == 'null') || (lcpCloudRegion == "")) {
243 sendSyncError(execution)
244 String dataErrorMessage = "Variable 'serviceInstanceId' value/element is missing."
245 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
246 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
250 // PO Authorization Info / headers Authorization=
251 String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution)
255 def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey", execution))
256 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
257 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
259 } catch (IOException ex) {
260 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - "
261 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
262 msoLogger.debug(dataErrorMessage)
263 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
266 // Set variables for Generic Get Sub Flow use
267 execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
268 msoLogger.debug(Prefix + "serviceInstanceId - " + serviceInstanceId)
270 execution.setVariable("GENGS_type", "service-instance")
271 msoLogger.debug("GENGS_type - " + "service-instance")
272 msoLogger.debug(" Url for SDNC adapter: " + UrnPropertiesReader.getVariable("mso.adapters.sdnc.endpoint",execution))
274 String sdncVersion = execution.getVariable("sdncVersion")
275 msoLogger.debug("sdncVersion? : " + sdncVersion)
277 // build 'networkOutputs'
278 networkId = utils.getNodeText(networkRequest, "network-id")
279 if ((networkId == null) || (networkId == "null")) {
282 String networkName = utils.getNodeText(networkRequest, "network-name")
283 if ((networkName == null) || (networkName == "null")) {
286 String networkOutputs =
288 <network-id>${MsoUtils.xmlEscape(networkId)}</network-id>
289 <network-name>${MsoUtils.xmlEscape(networkName)}</network-name>
290 </network-outputs>"""
291 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
292 msoLogger.debug(Prefix + "networkOutputs - " + '\n' + networkOutputs)
293 execution.setVariable(Prefix + "networkId", networkId)
294 execution.setVariable(Prefix + "networkName", networkName)
297 } catch (BpmnError e) {
300 } catch (Exception ex){
301 sendSyncError(execution)
303 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - " + ex.getMessage()
304 msoLogger.debug(exceptionMessage)
305 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
310 public void callRESTQueryAAICloudRegion (DelegateExecution execution) {
312 execution.setVariable("prefix", Prefix)
314 msoLogger.debug(" ***** Inside callRESTQueryAAICloudRegion of DoUpdateNetworkInstance ***** " )
317 String networkInputs = execution.getVariable(Prefix + "networkInputs")
318 String cloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
319 cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
322 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
323 AaiUtil aaiUtil = new AaiUtil(this)
324 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
325 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
326 msoLogger.debug(queryCloudRegionRequest)
327 execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
328 msoLogger.debug(" UPDNETI_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest)
330 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
331 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
333 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
334 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
335 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
336 execution.setVariable(Prefix + "isCloudRegionGood", true)
339 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
340 msoLogger.debug(dataErrorMessage)
341 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
345 msoLogger.debug(" is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"))
347 } catch (BpmnError e) {
350 } catch (Exception ex) {
352 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
353 msoLogger.debug(exceptionMessage)
354 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
360 public void callRESTQueryAAINetworkId(DelegateExecution execution) {
362 execution.setVariable("prefix", Prefix)
364 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
368 String networkRequest = execution.getVariable(Prefix + "networkRequest")
369 String networkId = utils.getNodeText(networkRequest, "network-id")
370 networkId = UriUtils.encode(networkId,"UTF-8")
371 execution.setVariable(Prefix + "networkId", networkId)
374 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
375 AaiUtil aaiUriUtil = new AaiUtil(this)
376 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
377 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
378 msoLogger.debug(queryIdAAIRequest)
379 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
380 msoLogger.debug(Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest)
382 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
383 String returnCode = response.getStatusCode()
384 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
385 msoLogger.debug(" ***** AAI Response Code : " + returnCode)
387 String aaiResponseAsString = response.getResponseBodyAsString()
389 if (returnCode=='200') {
390 msoLogger.debug(aaiResponseAsString)
391 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
392 msoLogger.debug(" QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
395 if (returnCode=='404') {
396 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
397 msoLogger.debug(" AAI Query Failed. " + dataErrorMessage)
398 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
401 if (aaiResponseAsString.contains("RESTFault")) {
402 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
403 execution.setVariable("WorkflowException", exceptionObject)
404 throw new BpmnError("MSOWorkflowException")
408 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
409 msoLogger.debug("Unexpected Response from QueryAAINetworkId - " + dataErrorMessage)
410 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
416 } catch (BpmnError e) {
419 } catch (Exception ex) {
420 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
421 msoLogger.debug(exceptionMessage)
422 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
428 public void callRESTReQueryAAINetworkId(DelegateExecution execution) {
430 execution.setVariable("prefix", Prefix)
432 msoLogger.debug(" ***** Inside callRESTReQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
436 String networkRequest = execution.getVariable(Prefix + "networkRequest")
437 String networkId = utils.getNodeText(networkRequest, "network-id")
438 networkId = UriUtils.encode(networkId,"UTF-8")
441 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
442 AaiUtil aaiUriUtil = new AaiUtil(this)
443 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
444 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
445 msoLogger.debug(requeryIdAAIRequest)
446 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
447 msoLogger.debug(" UPDNETI_requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest)
449 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
450 String returnCode = response.getStatusCode()
451 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
452 msoLogger.debug(" ***** AAI ReQuery Response Code : " + returnCode)
454 String aaiResponseAsString = response.getResponseBodyAsString()
456 if (returnCode=='200') {
457 msoLogger.debug(aaiResponseAsString)
458 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
459 msoLogger.debug(" ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
461 String netId = utils.getNodeText(aaiResponseAsString, "network-id")
462 String netName = utils.getNodeText(aaiResponseAsString, "network-name")
463 String networkOutputs =
465 <network-id>${MsoUtils.xmlEscape(netId)}</network-id>
466 <network-name>${MsoUtils.xmlEscape(netName)}</network-name>
467 </network-outputs>"""
468 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
469 msoLogger.debug(" networkOutputs - " + '\n' + networkOutputs)
472 if (returnCode=='404') {
473 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
474 msoLogger.debug(" AAI ReQuery Failed. - " + dataErrorMessage)
475 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
478 if (aaiResponseAsString.contains("RESTFault")) {
479 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
480 execution.setVariable("WorkflowException", exceptionObject)
481 throw new BpmnError("MSOWorkflowException")
485 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
486 msoLogger.debug(dataErrorMessage)
487 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
493 } catch (BpmnError e) {
496 } catch (Exception ex) {
497 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
498 msoLogger.debug(exceptionMessage)
499 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
505 public void callRESTQueryAAINetworkVpnBinding(DelegateExecution execution) {
507 execution.setVariable("prefix", Prefix)
509 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkVpnBinding of DoUpdateNetworkInstance ***** " )
514 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
515 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
516 msoLogger.debug(" relationship - " + relationship)
518 // Check if Vnf Binding is present, then build a List of vnfBinding
519 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
520 int vpnCount = vpnBindingUri.size()
521 execution.setVariable(Prefix + "vpnCount", vpnCount)
522 msoLogger.debug(" UPDNETI_vpnCount - " + vpnCount)
524 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
525 AaiUtil aaiUriUtil = new AaiUtil(this)
528 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
529 msoLogger.debug(" vpnBindingUri List - " + vpnBindingUri)
531 String routeTargets = ""
532 // AII loop call using list vpnBindings
533 for (i in 0..vpnBindingUri.size()-1) {
537 // prepare url using vpnBinding
538 String queryVpnBindingAAIRequest = ""
539 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
541 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
542 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
543 if (aai_uri == null || aai_uri == "") {
544 // using value of 'related-link' from response
545 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
546 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1) + "?depth=all"
548 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i] + "?depth=all"
552 // using uri value in URN mapping
553 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
554 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
555 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
557 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId + "?depth=all"
560 msoLogger.debug(queryVpnBindingAAIRequest)
561 execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
562 msoLogger.debug(" UPDNETI_queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest)
564 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
565 String returnCode = response.getStatusCode()
566 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
567 msoLogger.debug(" ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode)
569 String aaiResponseAsString = response.getResponseBodyAsString()
571 if (returnCode=='200') {
572 msoLogger.debug(aaiResponseAsString)
573 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
574 msoLogger.debug(" AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString)
576 String routeTarget = ""
577 String routeRole = ""
578 if (utils.nodeExists(aaiResponseAsString, "route-targets")) {
579 String aaiRouteTargets = utils.getNodeXml(aaiResponseAsString, "route-targets", false)
580 def aaiRouteTargetsXml = new XmlSlurper().parseText(aaiRouteTargets)
581 def aaiRouteTarget = aaiRouteTargetsXml.'**'.findAll {it.name() == "route-target"}
582 for (j in 0..aaiRouteTarget.size()-1) {
583 routeTarget = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "global-route-target")
584 routeRole = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "route-target-role")
585 routeTargets += "<routeTargets>" + '\n' +
586 " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
587 " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
588 "</routeTargets>" + '\n'
593 if (returnCode=='404') {
594 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
595 msoLogger.debug(dataErrorMessage)
596 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
599 if (aaiResponseAsString.contains("RESTFault")) {
600 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
601 execution.setVariable("WorkflowException", exceptionObject)
602 throw new BpmnError("MSOWorkflowException")
606 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
607 msoLogger.debug(dataErrorMessage)
608 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
616 execution.setVariable(Prefix + "routeCollection", routeTargets)
617 msoLogger.debug(" UPDNETI_routeCollection - " + '\n' + routeTargets)
620 // reset return code to success
621 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
622 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
623 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
624 String aaiStubResponse =
625 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
626 <vpn-binding xmlns="${schemaVersion}">
627 <global-route-target/>
630 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
631 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
632 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
633 msoLogger.debug(" No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml)
637 } catch (BpmnError e) {
640 } catch (Exception ex) {
641 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
642 msoLogger.debug(exceptionMessage)
643 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
649 public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
651 execution.setVariable("prefix", Prefix)
653 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " )
657 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
658 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
659 msoLogger.debug(" relationship - " + relationship)
661 // Check if Network Policy is present, then build a List of network policy
662 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
663 int networkPolicyCount = networkPolicyUriList.size()
664 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
665 msoLogger.debug(" UPDNETI_networkPolicyCount - " + networkPolicyCount)
667 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
668 AaiUtil aaiUriUtil = new AaiUtil(this)
670 if (networkPolicyCount > 0) {
671 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
672 msoLogger.debug(" networkPolicyUri List - " + networkPolicyUriList)
674 String networkPolicies = ""
675 // AII loop call using list vpnBindings
676 for (i in 0..networkPolicyUriList.size()-1) {
680 // prepare url using vpnBinding
681 String queryNetworkPolicyAAIRequest = ""
683 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
685 // Note: By default, the network policy url is found in 'related-link' of the response,
686 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
687 if (aai_uri == null || aai_uri == "") {
688 // using value of 'related-link' from response
689 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
690 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1) + "?depth=all"
692 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i] + "?depth=all"
695 // using uri value in URN mapping
696 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
697 println " networkPolicyId - " + networkPolicyId
698 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
699 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
701 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId + "?depth=all"
706 msoLogger.debug(queryNetworkPolicyAAIRequest)
707 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
708 msoLogger.debug(" UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest)
710 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
711 String returnCode = response.getStatusCode()
712 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
713 msoLogger.debug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
715 String aaiResponseAsString = response.getResponseBodyAsString()
717 if (returnCode=='200') {
718 msoLogger.debug(aaiResponseAsString)
719 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
720 msoLogger.debug(" QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
722 String networkPolicy = ""
723 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
724 networkPolicy = utils.getNodeText(aaiResponseAsString, "network-policy-fqdn")
725 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
729 if (returnCode=='404') {
730 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
731 msoLogger.debug(dataErrorMessage)
732 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
735 if (aaiResponseAsString.contains("RESTFault")) {
736 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
737 execution.setVariable("WorkflowException", exceptionObject)
738 throw new BpmnError("MSOWorkflowException")
742 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
743 msoLogger.debug(dataErrorMessage)
744 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
752 execution.setVariable(Prefix + "networkCollection", networkPolicies)
753 msoLogger.debug(" UPDNETI_networkCollection - " + '\n' + networkPolicies)
756 // reset return code to success
757 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
758 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
759 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
760 String aaiStubResponse =
761 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
762 <network-policy xmlns="${schemaVersion}">
763 <network-policy-fqdn/>
766 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
767 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
768 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
769 msoLogger.debug(" No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml)
773 } catch (BpmnError e) {
776 } catch (Exception ex) {
777 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
778 msoLogger.debug(exceptionMessage)
779 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
785 public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
787 execution.setVariable("prefix", Prefix)
789 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " )
793 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
794 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
795 msoLogger.debug(" relationship - " + relationship)
797 // Check if Network TableREf is present, then build a List of network policy
798 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
799 int networkTableRefCount = networkTableRefUriList.size()
800 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
801 msoLogger.debug(" UPDNETI_networkTableRefCount - " + networkTableRefCount)
803 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
804 AaiUtil aaiUriUtil = new AaiUtil(this)
806 if (networkTableRefCount > 0) {
807 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
808 msoLogger.debug(" networkTableRefUri List - " + networkTableRefUriList)
810 // AII loop call using list vpnBindings
811 String networkTableRefs = ""
812 for (i in 0..networkTableRefUriList.size()-1) {
816 // prepare url using tableRef
817 String queryNetworkTableRefAAIRequest = ""
819 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
821 // Note: By default, the network policy url is found in 'related-link' of the response,
822 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
823 if (aai_uri == null || aai_uri == "") {
824 // using value of 'related-link' from response
825 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
826 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1) + "?depth=all"
828 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i] + "?depth=all"
831 // using uri value in URN mapping
832 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
834 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
835 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
837 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId + "?depth=all"
842 msoLogger.debug(queryNetworkTableRefAAIRequest)
843 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
844 msoLogger.debug(" UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest)
846 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
847 String returnCode = response.getStatusCode()
848 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
849 msoLogger.debug(" ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode)
851 String aaiResponseAsString = response.getResponseBodyAsString()
853 if (returnCode=='200') {
854 msoLogger.debug(aaiResponseAsString)
855 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
856 msoLogger.debug(" QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString)
858 String networkTableRef = ""
859 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
860 networkTableRef = utils.getNodeText(aaiResponseAsString, "route-table-reference-fqdn")
861 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
865 if (returnCode=='404') {
866 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
867 msoLogger.debug(dataErrorMessage)
868 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
871 if (aaiResponseAsString.contains("RESTFault")) {
872 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
873 execution.setVariable("WorkflowException", exceptionObject)
874 throw new BpmnError("MSOWorkflowException")
878 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
879 msoLogger.debug(dataErrorMessage)
880 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
888 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
889 msoLogger.debug(" UPDNETI_tableRefCollection - " + '\n' + networkTableRefs)
892 // reset return code to success
893 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
894 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
895 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
896 String aaiStubResponse =
897 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
898 <route-table-references xmlns="${schemaVersion}">
899 <route-table-reference-fqdn/>
900 </route-table-references>
902 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
903 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
904 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
905 msoLogger.debug(" No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml)
909 } catch (BpmnError e) {
912 } catch (Exception ex) {
913 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
914 msoLogger.debug(exceptionMessage)
915 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
921 public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
923 execution.setVariable("prefix", Prefix)
925 msoLogger.debug(" ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " )
929 String networkRequest = execution.getVariable(Prefix + "networkRequest")
930 String networkId = utils.getNodeText(networkRequest, "network-id")
931 networkId = UriUtils.encode(networkId,"UTF-8")
932 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
933 String updateNetworkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
936 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
937 AaiUtil aaiUriUtil = new AaiUtil(this)
938 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
939 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
941 msoLogger.debug(updateContrailAAIUrlRequest)
942 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
943 msoLogger.debug(" UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest)
945 //Prepare payload (PUT)
946 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
947 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
948 String payloadXml = utils.formatXml(payload)
949 msoLogger.debug(payloadXml)
950 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
951 msoLogger.debug(" 'payload' to Update Contrail - " + "\n" + payloadXml)
953 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
954 String returnCode = response.getStatusCode()
955 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
957 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
958 msoLogger.debug(" ***** AAI Update Contrail Response Code : " + returnCode)
961 if (returnCode=='200') {
962 msoLogger.debug(aaiUpdateContrailResponseAsString)
963 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
964 msoLogger.debug(" AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString)
965 // Point-of-no-return is set to false, rollback not needed.
966 execution.setVariable(Prefix + "isPONR", true)
969 if (returnCode=='404') {
970 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
971 msoLogger.debug(dataErrorMessage)
972 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
975 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
976 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
977 execution.setVariable("WorkflowException", exceptionObject)
978 throw new BpmnError("MSOWorkflowException")
982 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
983 msoLogger.debug(errorMessage)
984 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
989 } catch (BpmnError e) {
992 } catch (Exception ex) {
993 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
994 msoLogger.debug(exceptionMessage)
995 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1001 public void prepareUpdateNetworkRequest (DelegateExecution execution) {
1003 execution.setVariable("prefix", Prefix)
1005 msoLogger.trace("Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ")
1010 String requestId = execution.getVariable(Prefix + "requestId")
1011 String messageId = execution.getVariable(Prefix + "messageId")
1012 String source = execution.getVariable(Prefix + "source")
1014 String requestInput = execution.getVariable(Prefix + "networkRequest")
1015 String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1016 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1017 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1019 // Prepare Network request
1020 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1021 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1022 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1023 String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1025 String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
1026 buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1027 msoLogger.debug(buildUpdateNetworkRequestAsString)
1029 execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
1030 msoLogger.debug(" UPDNETI_updateNetworkRequest - " + "\n" + buildUpdateNetworkRequestAsString)
1032 } catch (Exception ex) {
1033 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
1034 msoLogger.debug(exceptionMessage)
1035 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1041 public void prepareSDNCRequest (DelegateExecution execution) {
1043 execution.setVariable("prefix", Prefix)
1045 msoLogger.trace("Inside prepareSDNCRequest of DoUpdateNetworkInstance ")
1049 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1050 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1051 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1053 String networkId = ""
1054 if (utils.nodeExists(updateNetworkInput, "network-id")) {
1055 networkId = utils.getNodeText(updateNetworkInput, "network-id")
1057 if (networkId == null) {networkId = ""}
1059 String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1061 String queryAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1063 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1064 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, queryAAIResponse, null)
1066 String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1067 msoLogger.debug(sndcTopologyUpdateRequesAsString)
1068 execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1069 msoLogger.debug(" UPDNETI_changeAssignSDNCRequest - " + "\n" + sndcTopologyUpdateRequesAsString)
1072 } catch (Exception ex) {
1073 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1074 msoLogger.debug(exceptionMessage)
1075 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1084 // **************************************************
1085 // Post or Validate Response Section
1086 // **************************************************
1088 public void validateUpdateNetworkResponse (DelegateExecution execution) {
1090 execution.setVariable("prefix", Prefix)
1092 msoLogger.trace("Inside validateUpdateNetworkResponse of DoUpdateNetworkInstance ")
1095 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1096 String networkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
1097 if (networkResponse==null) {
1098 networkResponse="" // reset
1101 msoLogger.debug(" Network Adapter update responseCode: " + returnCode)
1103 String errorMessage = ""
1104 if (returnCode == "200") {
1105 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1106 msoLogger.debug(networkResponse)
1107 execution.setVariable(Prefix + "updateNetworkResponse", networkResponse)
1108 msoLogger.debug(" Network Adapter update Success Response - " + "\n" + networkResponse)
1110 // prepare rollback data
1111 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1112 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1113 String rollbackNetwork =
1114 """<rollbackNetworkRequest>
1116 </rollbackNetworkRequest>"""
1117 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1118 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1119 msoLogger.debug(" Network Adapter rollback data - " + "\n" + rollbackNetworkXml)
1121 } else { // network error
1122 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1123 if (networkResponse.contains("updateNetworkError")) {
1124 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1125 errorMessage = utils.getNodeText(networkResponse, "message")
1126 errorMessage = "Received error from Network Adapter: " + errorMessage
1127 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1129 } else { // CatchAll exception
1130 if (returnCode == "500") {
1131 errorMessage = "JBWEB000065: HTTP Status 500."
1133 errorMessage = "Return code is " + returnCode
1135 errorMessage = "Received error from Network Adapter: " + errorMessage
1136 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1140 } else { // CatchAll exception
1141 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1142 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1148 } catch (BpmnError e) {
1151 } catch (Exception ex) {
1152 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1153 msoLogger.debug(exceptionMessage)
1154 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1161 public void validateSDNCResponse (DelegateExecution execution) {
1163 execution.setVariable("prefix", Prefix)
1165 msoLogger.trace("Inside validateSDNCResponse of DoUpdateNetworkInstance ")
1167 String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1168 WorkflowException workflowException = null
1170 workflowException = execution.getVariable(Prefix + "WorkflowException")
1171 //execution.setVariable("WorkflowException", workflowException)
1172 } catch (Exception ex) {
1173 msoLogger.debug(" Sdnc 'WorkflowException' object is empty or null. ")
1176 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1178 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1179 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1181 String changeAssignSDNCResponseDecodeXml = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1182 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1183 execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1185 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, prefix+'sdncResponseSuccess'
1186 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1187 msoLogger.debug("Successfully Validated SDNC Response")
1190 msoLogger.debug("Did NOT Successfully Validated SDNC Response")
1191 throw new BpmnError("MSOWorkflowException")
1197 public void postProcessResponse (DelegateExecution execution) {
1199 execution.setVariable("prefix", Prefix)
1201 msoLogger.trace("Inside postProcessResponse of DoUpdateNetworkInstance ")
1204 msoLogger.debug(" ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"))
1205 if (execution.getVariable(Prefix + "isException") == false) {
1206 // set rollback data
1207 execution.setVariable("orchestrationStatus", "")
1208 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1209 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1210 prepareSuccessRollbackData(execution) // populate rollbackData
1211 execution.setVariable("WorkflowException", null)
1212 execution.setVariable(Prefix + "Success", true)
1213 msoLogger.debug(" ***** postProcessResponse(), GOOD !!!")
1215 execution.setVariable(Prefix + "Success", false)
1216 execution.setVariable("rollbackData", null)
1217 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1218 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1219 msoLogger.debug(" ***** workflowException: " + execution.getVariable("workflowException"))
1220 WorkflowException wfex = execution.getVariable("workflowException")
1221 exceptionMessage = wfex.getErrorMessage()
1223 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1224 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1225 exceptionMessage = pwfex.getErrorMessage()
1228 // going to the Main flow: a-la-carte or macro
1229 msoLogger.debug(" ***** postProcessResponse(), BAD !!!")
1230 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1231 throw new BpmnError("MSOWorkflowException")
1234 } catch(BpmnError b){
1235 msoLogger.debug("Rethrowing MSOWorkflowException")
1239 } catch (Exception ex) {
1240 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1241 msoLogger.debug(exceptionMessage)
1242 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1249 public void prepareSDNCRollbackRequest (DelegateExecution execution) {
1251 execution.setVariable("prefix", Prefix)
1253 msoLogger.trace("Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ")
1256 // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException.
1257 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1259 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1260 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1261 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1262 String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1263 String networkId = utils.getNodeText(changeAssignSDNCResponse, "network-id")
1265 String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1267 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1268 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1269 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1270 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1271 msoLogger.debug(" Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" + sndcTopologyRollbackRequestAsString)
1273 } catch (Exception ex) {
1274 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1275 msoLogger.debug(exceptionMessage)
1276 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1282 public void prepareRollbackData(DelegateExecution execution) {
1284 execution.setVariable("prefix",Prefix)
1286 msoLogger.trace("Inside prepareRollbackData() of DoUpdateNetworkInstance ")
1290 Map<String, String> rollbackData = new HashMap<String, String>();
1291 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1292 if (rollbackSDNCRequest != null) {
1293 if (rollbackSDNCRequest != "") {
1294 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1297 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1298 if (rollbackNetworkRequest != null) {
1299 if (rollbackNetworkRequest != "") {
1300 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1303 execution.setVariable("rollbackData", rollbackData)
1304 msoLogger.debug("** rollbackData : " + rollbackData)
1306 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1307 msoLogger.debug("** WorkflowException : " + execution.getVariable("WorkflowException"))
1309 } catch (Exception ex) {
1310 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1311 msoLogger.debug(exceptionMessage)
1312 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1318 public void prepareSuccessRollbackData(DelegateExecution execution) {
1320 execution.setVariable("prefix",Prefix)
1322 msoLogger.trace("Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ")
1326 if (execution.getVariable("sdncVersion") != '1610') {
1327 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1329 prepareSDNCRollbackRequest(execution)
1332 Map<String, String> rollbackData = new HashMap<String, String>();
1333 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1334 if (rollbackSDNCRequest != null) {
1335 if (rollbackSDNCRequest != "") {
1336 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1339 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1340 if (rollbackNetworkRequest != null) {
1341 if (rollbackNetworkRequest != "") {
1342 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1345 execution.setVariable("rollbackData", rollbackData)
1347 msoLogger.debug("** 'rollbackData' for Full Rollback : " + rollbackData)
1348 execution.setVariable("WorkflowException", null)
1351 } catch (Exception ex) {
1352 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1353 msoLogger.debug(exceptionMessage)
1354 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1360 public void setExceptionFlag(DelegateExecution execution){
1362 execution.setVariable("prefix",Prefix)
1364 msoLogger.trace("Inside setExceptionFlag() of DoUpdateNetworkInstance ")
1368 execution.setVariable(Prefix + "isException", true)
1370 if (execution.getVariable("SavedWorkflowException1") != null) {
1371 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1373 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1375 msoLogger.debug(Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"))
1377 } catch(Exception ex){
1378 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1379 msoLogger.debug(exceptionMessage)
1380 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1386 // *******************************
1387 // Build Error Section
1388 // *******************************
1390 public void processJavaException(DelegateExecution execution){
1392 execution.setVariable("prefix",Prefix)
1394 msoLogger.debug("Caught a Java Exception")
1395 msoLogger.debug("Started processJavaException Method")
1396 msoLogger.debug("Variables List: " + execution.getVariables())
1397 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1398 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1400 }catch(Exception e){
1401 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
1402 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
1403 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1405 msoLogger.debug("Completed processJavaException Method")