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
40 import org.onap.so.client.aai.AAIResourcesClient
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.entities.AAIResultWrapper
43 import org.onap.so.client.aai.entities.Relationships
44 import org.onap.so.client.aai.entities.uri.AAIResourceUri
45 import org.onap.so.client.aai.entities.uri.AAIUriFactory
46 import org.json.JSONObject
47 import javax.ws.rs.NotFoundException
50 import groovy.xml.XmlUtil
53 * This groovy class supports the <class>DoUpdateNetworkInstance.bpmn</class> process.
56 public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor {
57 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoUpdateNetworkInstance.class);
59 String Prefix="UPDNETI_"
60 ExceptionUtil exceptionUtil = new ExceptionUtil()
61 JsonUtils jsonUtil = new JsonUtils()
62 VidUtils vidUtils = new VidUtils(this)
63 NetworkUtils networkUtils = new NetworkUtils()
64 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
67 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
70 public InitializeProcessVariables(DelegateExecution execution){
71 /* Initialize all the process variables in this block */
73 execution.setVariable(Prefix + "messageId", "")
74 execution.setVariable("BasicAuthHeaderValuePO", "")
75 execution.setVariable("BasicAuthHeaderValueSDNC", "")
76 execution.setVariable(Prefix + "networkRequest", "")
77 execution.setVariable(Prefix + "networkInputs", "")
78 execution.setVariable(Prefix + "networkOutputs", "")
79 execution.setVariable(Prefix + "requestId", "")
80 execution.setVariable(Prefix + "source", "")
81 execution.setVariable(Prefix + "networkId", "")
83 execution.setVariable(Prefix + "isPONR", false) // Point-of-no-return, means, rollback is not needed
85 // AAI query Cloud Region
86 execution.setVariable(Prefix + "queryCloudRegionRequest","")
87 execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
88 execution.setVariable(Prefix + "queryCloudRegionResponse","")
89 execution.setVariable(Prefix + "cloudRegionPo","")
90 execution.setVariable(Prefix + "cloudRegionSdnc","")
91 execution.setVariable(Prefix + "isCloudRegionGood", false)
94 execution.setVariable(Prefix + "queryIdAAIRequest","")
95 execution.setVariable(Prefix + "queryIdAAIResponse", "")
96 execution.setVariable(Prefix + "aaiIdReturnCode", "")
98 // AAI query vpn binding
99 execution.setVariable(Prefix + "queryVpnBindingAAIRequest","")
100 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", "")
101 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "")
102 execution.setVariable(Prefix + "vpnBindings", null)
103 execution.setVariable(Prefix + "vpnCount", 0)
104 execution.setVariable(Prefix + "routeCollection", "")
106 // AAI query network policy
107 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest","")
108 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", "")
109 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "")
110 execution.setVariable(Prefix + "networkPolicyUriList", null)
111 execution.setVariable(Prefix + "networkPolicyCount", 0)
112 execution.setVariable(Prefix + "networkCollection", "")
114 // AAI query route table reference
115 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest","")
116 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", "")
117 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "")
118 execution.setVariable(Prefix + "networkTableRefUriList", null)
119 execution.setVariable(Prefix + "networkTableRefCount", 0)
120 execution.setVariable(Prefix + "tableRefCollection", "")
123 execution.setVariable(Prefix + "requeryIdAAIRequest","")
124 execution.setVariable(Prefix + "requeryIdAAIResponse", "")
125 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
127 // AAI update contrail
128 execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
129 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
130 execution.setVariable(Prefix + "updateContrailAAIResponse", "")
131 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
133 execution.setVariable(Prefix + "updateNetworkRequest", "")
134 execution.setVariable(Prefix + "updateNetworkResponse", "")
135 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
136 execution.setVariable(Prefix + "networkReturnCode", "")
137 execution.setVariable(Prefix + "isNetworkRollbackNeeded", false)
139 execution.setVariable(Prefix + "changeAssignSDNCRequest", "")
140 execution.setVariable(Prefix + "changeAssignSDNCResponse", "")
141 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
142 execution.setVariable(Prefix + "sdncReturnCode", "")
143 execution.setVariable(Prefix + "isSdncRollbackNeeded", false)
144 execution.setVariable(Prefix + "sdncResponseSuccess", false)
146 execution.setVariable(Prefix + "isVnfBindingPresent", false)
147 execution.setVariable(Prefix + "Success", false)
148 execution.setVariable(Prefix + "serviceInstanceId", "")
150 execution.setVariable(Prefix + "isException", false)
154 // **************************************************
155 // Pre or Prepare Request Section
156 // **************************************************
158 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
161 public void preProcessRequest (DelegateExecution execution) {
163 execution.setVariable("prefix",Prefix)
165 msoLogger.trace("Inside preProcessRequest DoUpdateNetworkInstance Request ")
168 // initialize flow variables
169 InitializeProcessVariables(execution)
171 // GET Incoming request & validate 3 kinds of format.
172 execution.setVariable("action", "UPDATE")
173 String networkRequest = execution.getVariable("bpmnRequest")
174 if (networkRequest != null) {
175 if (networkRequest.contains("requestDetails")) {
176 // JSON format request is sent, create xml
178 def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
179 msoLogger.debug(" Incoming message formatted . . . : " + '\n' + prettyJson)
180 networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
182 } catch (Exception ex) {
183 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
184 msoLogger.debug(dataErrorMessage)
185 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
188 // XML format request is sent
192 // vIPR format request is sent, create xml from individual variables
193 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
196 networkRequest = utils.formatXml(networkRequest)
197 msoLogger.debug(networkRequest)
198 execution.setVariable(Prefix + "networkRequest", networkRequest)
199 msoLogger.debug(" network-request - " + '\n' + networkRequest)
201 // validate 'disableRollback' (aka, 'suppressRollback')
202 boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
203 execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
204 msoLogger.debug(Prefix + "rollbackEnabled - " + rollbackEnabled)
206 String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
207 execution.setVariable(Prefix + "networkInputs", networkInputs)
208 msoLogger.debug(Prefix + "networkInputs - " + '\n' + networkInputs)
211 String messageId = execution.getVariable(Prefix + "messageId") // for testing
212 if (messageId == null || messageId == "") {
213 messageId = UUID.randomUUID()
214 msoLogger.debug(" UPDNETI_messageId, random generated: " + messageId)
216 msoLogger.debug(" UPDNETI_messageId, pre-assigned: " + messageId)
218 execution.setVariable(Prefix + "messageId", messageId)
220 String source = utils.getNodeText(networkRequest, "source")
221 execution.setVariable(Prefix + "source", source)
222 msoLogger.debug(Prefix + "source - " + source)
224 String networkId = ""
225 if (utils.nodeExists(networkRequest, "network-id")) {
226 networkId = utils.getNodeText(networkRequest, "network-id")
227 if (networkId == 'null' || networkId == "") {
228 sendSyncError(execution)
229 // missing value of networkId
230 String dataErrorMessage = "Variable 'network-id' value/element is missing."
231 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
232 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
237 String lcpCloudRegion = ""
238 if (utils.nodeExists(networkRequest, "aic-cloud-region")) {
239 lcpCloudRegion = utils.getNodeText(networkRequest, "aic-cloud-region")
240 if ((lcpCloudRegion == 'null') || (lcpCloudRegion == "")) {
241 sendSyncError(execution)
242 String dataErrorMessage = "requestDetails has missing 'aic-cloud-region' value/element."
243 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
244 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
248 String serviceInstanceId = ""
249 if (utils.nodeExists(networkRequest, "service-instance-id")) {
250 serviceInstanceId = utils.getNodeText(networkRequest, "service-instance-id")
251 if ((serviceInstanceId == 'null') || (lcpCloudRegion == "")) {
252 sendSyncError(execution)
253 String dataErrorMessage = "Variable 'serviceInstanceId' value/element is missing."
254 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
255 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
259 // PO Authorization Info / headers Authorization=
260 String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution)
264 def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey", execution))
265 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
266 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
268 } catch (IOException ex) {
269 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - "
270 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
271 msoLogger.debug(dataErrorMessage)
272 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
275 // Set variables for Generic Get Sub Flow use
276 execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
277 msoLogger.debug(Prefix + "serviceInstanceId - " + serviceInstanceId)
279 msoLogger.debug(" Url for SDNC adapter: " + UrnPropertiesReader.getVariable("mso.adapters.sdnc.endpoint",execution))
281 String sdncVersion = execution.getVariable("sdncVersion")
282 msoLogger.debug("sdncVersion? : " + sdncVersion)
284 // build 'networkOutputs'
285 networkId = utils.getNodeText(networkRequest, "network-id")
286 if ((networkId == null) || (networkId == "null")) {
289 String networkName = utils.getNodeText(networkRequest, "network-name")
290 if ((networkName == null) || (networkName == "null")) {
293 String networkOutputs =
295 <network-id>${MsoUtils.xmlEscape(networkId)}</network-id>
296 <network-name>${MsoUtils.xmlEscape(networkName)}</network-name>
297 </network-outputs>"""
298 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
299 msoLogger.debug(Prefix + "networkOutputs - " + '\n' + networkOutputs)
300 execution.setVariable(Prefix + "networkId", networkId)
301 execution.setVariable(Prefix + "networkName", networkName)
304 } catch (BpmnError e) {
307 } catch (Exception ex){
308 sendSyncError(execution)
310 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - " + ex.getMessage()
311 msoLogger.debug(exceptionMessage)
312 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
318 * Gets the service instance uri from aai
321 public void getServiceInstance(DelegateExecution execution) {
322 msoLogger.trace("getServiceInstance ")
324 String serviceInstanceId = execution.getVariable('serviceInstanceId')
326 AAIResourcesClient resourceClient = new AAIResourcesClient()
327 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
329 if(!resourceClient.exists(uri)){
330 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Service Instance not found in aai")
333 }catch(BpmnError e) {
335 }catch (Exception ex){
336 String msg = "Exception in getServiceInstance. " + ex.getMessage()
338 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
342 public void callRESTQueryAAICloudRegion (DelegateExecution execution) {
344 execution.setVariable("prefix", Prefix)
346 msoLogger.debug(" ***** Inside callRESTQueryAAICloudRegion of DoUpdateNetworkInstance ***** " )
349 String networkInputs = execution.getVariable(Prefix + "networkInputs")
350 String cloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
351 cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
354 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
355 AaiUtil aaiUtil = new AaiUtil(this)
356 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
357 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
358 msoLogger.debug(queryCloudRegionRequest)
359 execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
360 msoLogger.debug(" UPDNETI_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest)
362 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
363 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
365 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
366 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
367 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
368 execution.setVariable(Prefix + "isCloudRegionGood", true)
371 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
372 msoLogger.debug(dataErrorMessage)
373 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
377 msoLogger.debug(" is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"))
379 } catch (BpmnError e) {
382 } catch (Exception ex) {
384 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
385 msoLogger.debug(exceptionMessage)
386 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
392 public void callRESTQueryAAINetworkId(DelegateExecution execution) {
394 execution.setVariable("prefix", Prefix)
396 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
400 String networkRequest = execution.getVariable(Prefix + "networkRequest")
401 String networkId = utils.getNodeText(networkRequest, "network-id")
402 networkId = UriUtils.encode(networkId,"UTF-8")
403 execution.setVariable(Prefix + "networkId", networkId)
406 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
407 AaiUtil aaiUriUtil = new AaiUtil(this)
408 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
409 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
410 msoLogger.debug(queryIdAAIRequest)
411 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
412 msoLogger.debug(Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest)
414 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
415 String returnCode = response.getStatusCode()
416 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
417 msoLogger.debug(" ***** AAI Response Code : " + returnCode)
419 String aaiResponseAsString = response.getResponseBodyAsString()
421 if (returnCode=='200') {
422 msoLogger.debug(aaiResponseAsString)
423 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
424 msoLogger.debug(" QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
427 if (returnCode=='404') {
428 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
429 msoLogger.debug(" AAI Query Failed. " + dataErrorMessage)
430 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
433 if (aaiResponseAsString.contains("RESTFault")) {
434 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
435 execution.setVariable("WorkflowException", exceptionObject)
436 throw new BpmnError("MSOWorkflowException")
440 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
441 msoLogger.debug("Unexpected Response from QueryAAINetworkId - " + dataErrorMessage)
442 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
448 } catch (BpmnError e) {
451 } catch (Exception ex) {
452 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
453 msoLogger.debug(exceptionMessage)
454 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
460 public void callRESTReQueryAAINetworkId(DelegateExecution execution) {
462 execution.setVariable("prefix", Prefix)
464 msoLogger.debug(" ***** Inside callRESTReQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
468 String networkRequest = execution.getVariable(Prefix + "networkRequest")
469 String networkId = utils.getNodeText(networkRequest, "network-id")
470 networkId = UriUtils.encode(networkId,"UTF-8")
473 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
474 AaiUtil aaiUriUtil = new AaiUtil(this)
475 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
476 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
477 msoLogger.debug(requeryIdAAIRequest)
478 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
479 msoLogger.debug(" UPDNETI_requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest)
481 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
482 String returnCode = response.getStatusCode()
483 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
484 msoLogger.debug(" ***** AAI ReQuery Response Code : " + returnCode)
486 String aaiResponseAsString = response.getResponseBodyAsString()
488 if (returnCode=='200') {
489 msoLogger.debug(aaiResponseAsString)
490 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
491 msoLogger.debug(" ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
493 String netId = utils.getNodeText(aaiResponseAsString, "network-id")
494 String netName = utils.getNodeText(aaiResponseAsString, "network-name")
495 String networkOutputs =
497 <network-id>${MsoUtils.xmlEscape(netId)}</network-id>
498 <network-name>${MsoUtils.xmlEscape(netName)}</network-name>
499 </network-outputs>"""
500 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
501 msoLogger.debug(" networkOutputs - " + '\n' + networkOutputs)
504 if (returnCode=='404') {
505 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
506 msoLogger.debug(" AAI ReQuery Failed. - " + dataErrorMessage)
507 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
510 if (aaiResponseAsString.contains("RESTFault")) {
511 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
512 execution.setVariable("WorkflowException", exceptionObject)
513 throw new BpmnError("MSOWorkflowException")
517 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
518 msoLogger.debug(dataErrorMessage)
519 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
525 } catch (BpmnError e) {
528 } catch (Exception ex) {
529 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
530 msoLogger.debug(exceptionMessage)
531 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
537 public void callRESTQueryAAINetworkVpnBinding(DelegateExecution execution) {
539 execution.setVariable("prefix", Prefix)
541 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkVpnBinding of DoUpdateNetworkInstance ***** " )
546 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
547 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
548 msoLogger.debug(" relationship - " + relationship)
550 // Check if Vnf Binding is present, then build a List of vnfBinding
551 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
552 int vpnCount = vpnBindingUri.size()
553 execution.setVariable(Prefix + "vpnCount", vpnCount)
554 msoLogger.debug(" UPDNETI_vpnCount - " + vpnCount)
556 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
557 AaiUtil aaiUriUtil = new AaiUtil(this)
560 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
561 msoLogger.debug(" vpnBindingUri List - " + vpnBindingUri)
563 String routeTargets = ""
564 // AII loop call using list vpnBindings
565 for (i in 0..vpnBindingUri.size()-1) {
569 // prepare url using vpnBinding
570 String queryVpnBindingAAIRequest = ""
571 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
573 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
574 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
575 if (aai_uri == null || aai_uri == "") {
576 // using value of 'related-link' from response
577 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
578 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1) + "?depth=all"
580 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i] + "?depth=all"
584 // using uri value in URN mapping
585 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
586 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
587 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
589 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId + "?depth=all"
592 msoLogger.debug(queryVpnBindingAAIRequest)
593 execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
594 msoLogger.debug(" UPDNETI_queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest)
596 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
597 String returnCode = response.getStatusCode()
598 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
599 msoLogger.debug(" ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode)
601 String aaiResponseAsString = response.getResponseBodyAsString()
603 if (returnCode=='200') {
604 msoLogger.debug(aaiResponseAsString)
605 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
606 msoLogger.debug(" AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString)
608 String routeTarget = ""
609 String routeRole = ""
610 if (utils.nodeExists(aaiResponseAsString, "route-targets")) {
611 String aaiRouteTargets = utils.getNodeXml(aaiResponseAsString, "route-targets", false)
612 def aaiRouteTargetsXml = new XmlSlurper().parseText(aaiRouteTargets)
613 def aaiRouteTarget = aaiRouteTargetsXml.'**'.findAll {it.name() == "route-target"}
614 for (j in 0..aaiRouteTarget.size()-1) {
615 routeTarget = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "global-route-target")
616 routeRole = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "route-target-role")
617 routeTargets += "<routeTargets>" + '\n' +
618 " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
619 " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
620 "</routeTargets>" + '\n'
625 if (returnCode=='404') {
626 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
627 msoLogger.debug(dataErrorMessage)
628 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
631 if (aaiResponseAsString.contains("RESTFault")) {
632 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
633 execution.setVariable("WorkflowException", exceptionObject)
634 throw new BpmnError("MSOWorkflowException")
638 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
639 msoLogger.debug(dataErrorMessage)
640 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
648 execution.setVariable(Prefix + "routeCollection", routeTargets)
649 msoLogger.debug(" UPDNETI_routeCollection - " + '\n' + routeTargets)
652 // reset return code to success
653 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
654 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
655 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
656 String aaiStubResponse =
657 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
658 <vpn-binding xmlns="${schemaVersion}">
659 <global-route-target/>
662 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
663 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
664 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
665 msoLogger.debug(" No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml)
669 } catch (BpmnError e) {
672 } catch (Exception ex) {
673 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
674 msoLogger.debug(exceptionMessage)
675 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
681 public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
683 execution.setVariable("prefix", Prefix)
685 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " )
689 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
690 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
691 msoLogger.debug(" relationship - " + relationship)
693 // Check if Network Policy is present, then build a List of network policy
694 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
695 int networkPolicyCount = networkPolicyUriList.size()
696 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
697 msoLogger.debug(" UPDNETI_networkPolicyCount - " + networkPolicyCount)
699 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
700 AaiUtil aaiUriUtil = new AaiUtil(this)
702 if (networkPolicyCount > 0) {
703 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
704 msoLogger.debug(" networkPolicyUri List - " + networkPolicyUriList)
706 String networkPolicies = ""
707 // AII loop call using list vpnBindings
708 for (i in 0..networkPolicyUriList.size()-1) {
712 // prepare url using vpnBinding
713 String queryNetworkPolicyAAIRequest = ""
715 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
717 // Note: By default, the network policy url is found in 'related-link' of the response,
718 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
719 if (aai_uri == null || aai_uri == "") {
720 // using value of 'related-link' from response
721 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
722 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1) + "?depth=all"
724 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i] + "?depth=all"
727 // using uri value in URN mapping
728 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
729 println " networkPolicyId - " + networkPolicyId
730 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
731 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
733 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId + "?depth=all"
738 msoLogger.debug(queryNetworkPolicyAAIRequest)
739 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
740 msoLogger.debug(" UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest)
742 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
743 String returnCode = response.getStatusCode()
744 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
745 msoLogger.debug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
747 String aaiResponseAsString = response.getResponseBodyAsString()
749 if (returnCode=='200') {
750 msoLogger.debug(aaiResponseAsString)
751 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
752 msoLogger.debug(" QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
754 String networkPolicy = ""
755 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
756 networkPolicy = utils.getNodeText(aaiResponseAsString, "network-policy-fqdn")
757 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
761 if (returnCode=='404') {
762 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
763 msoLogger.debug(dataErrorMessage)
764 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
767 if (aaiResponseAsString.contains("RESTFault")) {
768 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
769 execution.setVariable("WorkflowException", exceptionObject)
770 throw new BpmnError("MSOWorkflowException")
774 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
775 msoLogger.debug(dataErrorMessage)
776 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
784 execution.setVariable(Prefix + "networkCollection", networkPolicies)
785 msoLogger.debug(" UPDNETI_networkCollection - " + '\n' + networkPolicies)
788 // reset return code to success
789 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
790 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
791 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
792 String aaiStubResponse =
793 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
794 <network-policy xmlns="${schemaVersion}">
795 <network-policy-fqdn/>
798 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
799 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
800 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
801 msoLogger.debug(" No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml)
805 } catch (BpmnError e) {
808 } catch (Exception ex) {
809 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
810 msoLogger.debug(exceptionMessage)
811 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
817 public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
819 execution.setVariable("prefix", Prefix)
821 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " )
825 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
826 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
827 msoLogger.debug(" relationship - " + relationship)
829 // Check if Network TableREf is present, then build a List of network policy
830 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
831 int networkTableRefCount = networkTableRefUriList.size()
832 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
833 msoLogger.debug(" UPDNETI_networkTableRefCount - " + networkTableRefCount)
835 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
836 AaiUtil aaiUriUtil = new AaiUtil(this)
838 if (networkTableRefCount > 0) {
839 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
840 msoLogger.debug(" networkTableRefUri List - " + networkTableRefUriList)
842 // AII loop call using list vpnBindings
843 String networkTableRefs = ""
844 for (i in 0..networkTableRefUriList.size()-1) {
848 // prepare url using tableRef
849 String queryNetworkTableRefAAIRequest = ""
851 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
853 // Note: By default, the network policy url is found in 'related-link' of the response,
854 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
855 if (aai_uri == null || aai_uri == "") {
856 // using value of 'related-link' from response
857 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
858 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1) + "?depth=all"
860 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i] + "?depth=all"
863 // using uri value in URN mapping
864 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
866 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
867 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
869 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId + "?depth=all"
874 msoLogger.debug(queryNetworkTableRefAAIRequest)
875 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
876 msoLogger.debug(" UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest)
878 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
879 String returnCode = response.getStatusCode()
880 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
881 msoLogger.debug(" ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode)
883 String aaiResponseAsString = response.getResponseBodyAsString()
885 if (returnCode=='200') {
886 msoLogger.debug(aaiResponseAsString)
887 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
888 msoLogger.debug(" QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString)
890 String networkTableRef = ""
891 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
892 networkTableRef = utils.getNodeText(aaiResponseAsString, "route-table-reference-fqdn")
893 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
897 if (returnCode=='404') {
898 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
899 msoLogger.debug(dataErrorMessage)
900 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
903 if (aaiResponseAsString.contains("RESTFault")) {
904 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
905 execution.setVariable("WorkflowException", exceptionObject)
906 throw new BpmnError("MSOWorkflowException")
910 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
911 msoLogger.debug(dataErrorMessage)
912 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
920 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
921 msoLogger.debug(" UPDNETI_tableRefCollection - " + '\n' + networkTableRefs)
924 // reset return code to success
925 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
926 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
927 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
928 String aaiStubResponse =
929 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
930 <route-table-references xmlns="${schemaVersion}">
931 <route-table-reference-fqdn/>
932 </route-table-references>
934 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
935 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
936 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
937 msoLogger.debug(" No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml)
941 } catch (BpmnError e) {
944 } catch (Exception ex) {
945 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
946 msoLogger.debug(exceptionMessage)
947 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
953 public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
955 execution.setVariable("prefix", Prefix)
957 msoLogger.debug(" ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " )
961 String networkRequest = execution.getVariable(Prefix + "networkRequest")
962 String networkId = utils.getNodeText(networkRequest, "network-id")
963 networkId = UriUtils.encode(networkId,"UTF-8")
964 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
965 String updateNetworkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
968 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
969 AaiUtil aaiUriUtil = new AaiUtil(this)
970 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
971 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
973 msoLogger.debug(updateContrailAAIUrlRequest)
974 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
975 msoLogger.debug(" UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest)
977 //Prepare payload (PUT)
978 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
979 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
980 String payloadXml = utils.formatXml(payload)
981 msoLogger.debug(payloadXml)
982 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
983 msoLogger.debug(" 'payload' to Update Contrail - " + "\n" + payloadXml)
985 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
986 String returnCode = response.getStatusCode()
987 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
989 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
990 msoLogger.debug(" ***** AAI Update Contrail Response Code : " + returnCode)
993 if (returnCode=='200') {
994 msoLogger.debug(aaiUpdateContrailResponseAsString)
995 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
996 msoLogger.debug(" AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString)
997 // Point-of-no-return is set to false, rollback not needed.
998 execution.setVariable(Prefix + "isPONR", true)
1001 if (returnCode=='404') {
1002 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
1003 msoLogger.debug(dataErrorMessage)
1004 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1007 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
1008 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
1009 execution.setVariable("WorkflowException", exceptionObject)
1010 throw new BpmnError("MSOWorkflowException")
1014 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
1015 msoLogger.debug(errorMessage)
1016 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1021 } catch (BpmnError e) {
1024 } catch (Exception ex) {
1025 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
1026 msoLogger.debug(exceptionMessage)
1027 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1033 public void prepareUpdateNetworkRequest (DelegateExecution execution) {
1035 execution.setVariable("prefix", Prefix)
1037 msoLogger.trace("Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ")
1042 String requestId = execution.getVariable(Prefix + "requestId")
1043 String messageId = execution.getVariable(Prefix + "messageId")
1044 String source = execution.getVariable(Prefix + "source")
1046 String requestInput = execution.getVariable(Prefix + "networkRequest")
1047 String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1048 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1049 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1051 // Prepare Network request
1052 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1053 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1054 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1055 String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1057 String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
1058 buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1059 msoLogger.debug(buildUpdateNetworkRequestAsString)
1061 execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
1062 msoLogger.debug(" UPDNETI_updateNetworkRequest - " + "\n" + buildUpdateNetworkRequestAsString)
1064 } catch (Exception ex) {
1065 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
1066 msoLogger.debug(exceptionMessage)
1067 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1073 public void prepareSDNCRequest (DelegateExecution execution) {
1075 execution.setVariable("prefix", Prefix)
1077 msoLogger.trace("Inside prepareSDNCRequest of DoUpdateNetworkInstance ")
1081 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1082 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1083 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1085 String networkId = ""
1086 if (utils.nodeExists(updateNetworkInput, "network-id")) {
1087 networkId = utils.getNodeText(updateNetworkInput, "network-id")
1089 if (networkId == null) {networkId = ""}
1091 String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1093 String queryAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1095 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1096 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, queryAAIResponse, null)
1098 String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1099 msoLogger.debug(sndcTopologyUpdateRequesAsString)
1100 execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1101 msoLogger.debug(" UPDNETI_changeAssignSDNCRequest - " + "\n" + sndcTopologyUpdateRequesAsString)
1104 } catch (Exception ex) {
1105 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1106 msoLogger.debug(exceptionMessage)
1107 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1116 // **************************************************
1117 // Post or Validate Response Section
1118 // **************************************************
1120 public void validateUpdateNetworkResponse (DelegateExecution execution) {
1122 execution.setVariable("prefix", Prefix)
1124 msoLogger.trace("Inside validateUpdateNetworkResponse of DoUpdateNetworkInstance ")
1127 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1128 String networkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
1129 if (networkResponse==null) {
1130 networkResponse="" // reset
1133 msoLogger.debug(" Network Adapter update responseCode: " + returnCode)
1135 String errorMessage = ""
1136 if (returnCode == "200") {
1137 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1138 msoLogger.debug(networkResponse)
1139 execution.setVariable(Prefix + "updateNetworkResponse", networkResponse)
1140 msoLogger.debug(" Network Adapter update Success Response - " + "\n" + networkResponse)
1142 // prepare rollback data
1143 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1144 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1145 String rollbackNetwork =
1146 """<rollbackNetworkRequest>
1148 </rollbackNetworkRequest>"""
1149 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1150 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1151 msoLogger.debug(" Network Adapter rollback data - " + "\n" + rollbackNetworkXml)
1153 } else { // network error
1154 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1155 if (networkResponse.contains("updateNetworkError")) {
1156 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1157 errorMessage = utils.getNodeText(networkResponse, "message")
1158 errorMessage = "Received error from Network Adapter: " + errorMessage
1159 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1161 } else { // CatchAll exception
1162 if (returnCode == "500") {
1163 errorMessage = "JBWEB000065: HTTP Status 500."
1165 errorMessage = "Return code is " + returnCode
1167 errorMessage = "Received error from Network Adapter: " + errorMessage
1168 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1172 } else { // CatchAll exception
1173 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1174 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1180 } catch (BpmnError e) {
1183 } catch (Exception ex) {
1184 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1185 msoLogger.debug(exceptionMessage)
1186 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1193 public void validateSDNCResponse (DelegateExecution execution) {
1195 execution.setVariable("prefix", Prefix)
1197 msoLogger.trace("Inside validateSDNCResponse of DoUpdateNetworkInstance ")
1199 String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1200 WorkflowException workflowException = null
1202 workflowException = execution.getVariable(Prefix + "WorkflowException")
1203 //execution.setVariable("WorkflowException", workflowException)
1204 } catch (Exception ex) {
1205 msoLogger.debug(" Sdnc 'WorkflowException' object is empty or null. ")
1208 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1210 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1211 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1213 String changeAssignSDNCResponseDecodeXml = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1214 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1215 execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1217 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, prefix+'sdncResponseSuccess'
1218 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1219 msoLogger.debug("Successfully Validated SDNC Response")
1222 msoLogger.debug("Did NOT Successfully Validated SDNC Response")
1223 throw new BpmnError("MSOWorkflowException")
1229 public void postProcessResponse (DelegateExecution execution) {
1231 execution.setVariable("prefix", Prefix)
1233 msoLogger.trace("Inside postProcessResponse of DoUpdateNetworkInstance ")
1236 msoLogger.debug(" ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"))
1237 if (execution.getVariable(Prefix + "isException") == false) {
1238 // set rollback data
1239 execution.setVariable("orchestrationStatus", "")
1240 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1241 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1242 prepareSuccessRollbackData(execution) // populate rollbackData
1243 execution.setVariable("WorkflowException", null)
1244 execution.setVariable(Prefix + "Success", true)
1245 msoLogger.debug(" ***** postProcessResponse(), GOOD !!!")
1247 execution.setVariable(Prefix + "Success", false)
1248 execution.setVariable("rollbackData", null)
1249 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1250 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1251 msoLogger.debug(" ***** workflowException: " + execution.getVariable("workflowException"))
1252 WorkflowException wfex = execution.getVariable("workflowException")
1253 exceptionMessage = wfex.getErrorMessage()
1255 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1256 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1257 exceptionMessage = pwfex.getErrorMessage()
1260 // going to the Main flow: a-la-carte or macro
1261 msoLogger.debug(" ***** postProcessResponse(), BAD !!!")
1262 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1263 throw new BpmnError("MSOWorkflowException")
1266 } catch(BpmnError b){
1267 msoLogger.debug("Rethrowing MSOWorkflowException")
1271 } catch (Exception ex) {
1272 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1273 msoLogger.debug(exceptionMessage)
1274 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1281 public void prepareSDNCRollbackRequest (DelegateExecution execution) {
1283 execution.setVariable("prefix", Prefix)
1285 msoLogger.trace("Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ")
1288 // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException.
1289 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1291 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1292 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1293 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1294 String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1295 String networkId = utils.getNodeText(changeAssignSDNCResponse, "network-id")
1297 String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1299 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1300 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1301 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1302 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1303 msoLogger.debug(" Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" + sndcTopologyRollbackRequestAsString)
1305 } catch (Exception ex) {
1306 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1307 msoLogger.debug(exceptionMessage)
1308 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1314 public void prepareRollbackData(DelegateExecution execution) {
1316 execution.setVariable("prefix",Prefix)
1318 msoLogger.trace("Inside prepareRollbackData() of DoUpdateNetworkInstance ")
1322 Map<String, String> rollbackData = new HashMap<String, String>();
1323 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1324 if (rollbackSDNCRequest != null) {
1325 if (rollbackSDNCRequest != "") {
1326 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1329 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1330 if (rollbackNetworkRequest != null) {
1331 if (rollbackNetworkRequest != "") {
1332 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1335 execution.setVariable("rollbackData", rollbackData)
1336 msoLogger.debug("** rollbackData : " + rollbackData)
1338 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1339 msoLogger.debug("** WorkflowException : " + execution.getVariable("WorkflowException"))
1341 } catch (Exception ex) {
1342 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1343 msoLogger.debug(exceptionMessage)
1344 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1350 public void prepareSuccessRollbackData(DelegateExecution execution) {
1352 execution.setVariable("prefix",Prefix)
1354 msoLogger.trace("Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ")
1358 if (execution.getVariable("sdncVersion") != '1610') {
1359 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1361 prepareSDNCRollbackRequest(execution)
1364 Map<String, String> rollbackData = new HashMap<String, String>();
1365 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1366 if (rollbackSDNCRequest != null) {
1367 if (rollbackSDNCRequest != "") {
1368 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1371 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1372 if (rollbackNetworkRequest != null) {
1373 if (rollbackNetworkRequest != "") {
1374 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1377 execution.setVariable("rollbackData", rollbackData)
1379 msoLogger.debug("** 'rollbackData' for Full Rollback : " + rollbackData)
1380 execution.setVariable("WorkflowException", null)
1383 } catch (Exception ex) {
1384 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1385 msoLogger.debug(exceptionMessage)
1386 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1392 public void setExceptionFlag(DelegateExecution execution){
1394 execution.setVariable("prefix",Prefix)
1396 msoLogger.trace("Inside setExceptionFlag() of DoUpdateNetworkInstance ")
1400 execution.setVariable(Prefix + "isException", true)
1402 if (execution.getVariable("SavedWorkflowException1") != null) {
1403 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1405 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1407 msoLogger.debug(Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"))
1409 } catch(Exception ex){
1410 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1411 msoLogger.debug(exceptionMessage)
1412 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1418 // *******************************
1419 // Build Error Section
1420 // *******************************
1422 public void processJavaException(DelegateExecution execution){
1424 execution.setVariable("prefix",Prefix)
1426 msoLogger.debug("Caught a Java Exception")
1427 msoLogger.debug("Started processJavaException Method")
1428 msoLogger.debug("Variables List: " + execution.getVariables())
1429 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1430 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1432 }catch(Exception e){
1433 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
1434 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
1435 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1437 msoLogger.debug("Completed processJavaException Method")