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")
332 Map<String, String> keys = uri.getURIKeys()
333 execution.setVariable("serviceType", keys.get("service-type"))
334 execution.setVariable("subscriberName", keys.get("global-customer-id"))
337 }catch(BpmnError e) {
339 }catch (Exception ex){
340 String msg = "Exception in getServiceInstance. " + ex.getMessage()
342 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
346 public void callRESTQueryAAICloudRegion (DelegateExecution execution) {
348 execution.setVariable("prefix", Prefix)
350 msoLogger.debug(" ***** Inside callRESTQueryAAICloudRegion of DoUpdateNetworkInstance ***** " )
353 String networkInputs = execution.getVariable(Prefix + "networkInputs")
354 String cloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
355 cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
358 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
359 AaiUtil aaiUtil = new AaiUtil(this)
360 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
361 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
362 msoLogger.debug(queryCloudRegionRequest)
363 execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
364 msoLogger.debug(" UPDNETI_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest)
366 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
367 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
369 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
370 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
371 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
372 execution.setVariable(Prefix + "isCloudRegionGood", true)
375 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
376 msoLogger.debug(dataErrorMessage)
377 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
381 msoLogger.debug(" is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"))
383 } catch (BpmnError e) {
386 } catch (Exception ex) {
388 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
389 msoLogger.debug(exceptionMessage)
390 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
396 public void callRESTQueryAAINetworkId(DelegateExecution execution) {
398 execution.setVariable("prefix", Prefix)
400 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
404 String networkRequest = execution.getVariable(Prefix + "networkRequest")
405 String networkId = utils.getNodeText(networkRequest, "network-id")
406 networkId = UriUtils.encode(networkId,"UTF-8")
407 execution.setVariable(Prefix + "networkId", networkId)
410 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
411 AaiUtil aaiUriUtil = new AaiUtil(this)
412 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
413 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
414 msoLogger.debug(queryIdAAIRequest)
415 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
416 msoLogger.debug(Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest)
418 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
419 String returnCode = response.getStatusCode()
420 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
421 msoLogger.debug(" ***** AAI Response Code : " + returnCode)
423 String aaiResponseAsString = response.getResponseBodyAsString()
425 if (returnCode=='200') {
426 msoLogger.debug(aaiResponseAsString)
427 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
428 msoLogger.debug(" QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
431 if (returnCode=='404') {
432 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
433 msoLogger.debug(" AAI Query Failed. " + dataErrorMessage)
434 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
437 if (aaiResponseAsString.contains("RESTFault")) {
438 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
439 execution.setVariable("WorkflowException", exceptionObject)
440 throw new BpmnError("MSOWorkflowException")
444 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
445 msoLogger.debug("Unexpected Response from QueryAAINetworkId - " + dataErrorMessage)
446 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
452 } catch (BpmnError e) {
455 } catch (Exception ex) {
456 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
457 msoLogger.debug(exceptionMessage)
458 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
464 public void callRESTReQueryAAINetworkId(DelegateExecution execution) {
466 execution.setVariable("prefix", Prefix)
468 msoLogger.debug(" ***** Inside callRESTReQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
472 String networkRequest = execution.getVariable(Prefix + "networkRequest")
473 String networkId = utils.getNodeText(networkRequest, "network-id")
474 networkId = UriUtils.encode(networkId,"UTF-8")
477 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
478 AaiUtil aaiUriUtil = new AaiUtil(this)
479 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
480 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
481 msoLogger.debug(requeryIdAAIRequest)
482 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
483 msoLogger.debug(" UPDNETI_requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest)
485 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
486 String returnCode = response.getStatusCode()
487 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
488 msoLogger.debug(" ***** AAI ReQuery Response Code : " + returnCode)
490 String aaiResponseAsString = response.getResponseBodyAsString()
492 if (returnCode=='200') {
493 msoLogger.debug(aaiResponseAsString)
494 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
495 msoLogger.debug(" ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
497 String netId = utils.getNodeText(aaiResponseAsString, "network-id")
498 String netName = utils.getNodeText(aaiResponseAsString, "network-name")
499 String networkOutputs =
501 <network-id>${MsoUtils.xmlEscape(netId)}</network-id>
502 <network-name>${MsoUtils.xmlEscape(netName)}</network-name>
503 </network-outputs>"""
504 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
505 msoLogger.debug(" networkOutputs - " + '\n' + networkOutputs)
508 if (returnCode=='404') {
509 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
510 msoLogger.debug(" AAI ReQuery Failed. - " + dataErrorMessage)
511 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
514 if (aaiResponseAsString.contains("RESTFault")) {
515 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
516 execution.setVariable("WorkflowException", exceptionObject)
517 throw new BpmnError("MSOWorkflowException")
521 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
522 msoLogger.debug(dataErrorMessage)
523 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
529 } catch (BpmnError e) {
532 } catch (Exception ex) {
533 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
534 msoLogger.debug(exceptionMessage)
535 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
541 public void callRESTQueryAAINetworkVpnBinding(DelegateExecution execution) {
543 execution.setVariable("prefix", Prefix)
545 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkVpnBinding of DoUpdateNetworkInstance ***** " )
550 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
551 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
552 msoLogger.debug(" relationship - " + relationship)
554 // Check if Vnf Binding is present, then build a List of vnfBinding
555 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
556 int vpnCount = vpnBindingUri.size()
557 execution.setVariable(Prefix + "vpnCount", vpnCount)
558 msoLogger.debug(" UPDNETI_vpnCount - " + vpnCount)
560 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
561 AaiUtil aaiUriUtil = new AaiUtil(this)
564 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
565 msoLogger.debug(" vpnBindingUri List - " + vpnBindingUri)
567 String routeTargets = ""
568 // AII loop call using list vpnBindings
569 for (i in 0..vpnBindingUri.size()-1) {
573 // prepare url using vpnBinding
574 String queryVpnBindingAAIRequest = ""
575 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
577 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
578 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
579 if (aai_uri == null || aai_uri == "") {
580 // using value of 'related-link' from response
581 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
582 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1) + "?depth=all"
584 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i] + "?depth=all"
588 // using uri value in URN mapping
589 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
590 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
591 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
593 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId + "?depth=all"
596 msoLogger.debug(queryVpnBindingAAIRequest)
597 execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
598 msoLogger.debug(" UPDNETI_queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest)
600 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
601 String returnCode = response.getStatusCode()
602 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
603 msoLogger.debug(" ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode)
605 String aaiResponseAsString = response.getResponseBodyAsString()
607 if (returnCode=='200') {
608 msoLogger.debug(aaiResponseAsString)
609 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
610 msoLogger.debug(" AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString)
612 String routeTarget = ""
613 String routeRole = ""
614 if (utils.nodeExists(aaiResponseAsString, "route-targets")) {
615 String aaiRouteTargets = utils.getNodeXml(aaiResponseAsString, "route-targets", false)
616 def aaiRouteTargetsXml = new XmlSlurper().parseText(aaiRouteTargets)
617 def aaiRouteTarget = aaiRouteTargetsXml.'**'.findAll {it.name() == "route-target"}
618 for (j in 0..aaiRouteTarget.size()-1) {
619 routeTarget = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "global-route-target")
620 routeRole = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "route-target-role")
621 routeTargets += "<routeTargets>" + '\n' +
622 " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
623 " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
624 "</routeTargets>" + '\n'
629 if (returnCode=='404') {
630 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
631 msoLogger.debug(dataErrorMessage)
632 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
635 if (aaiResponseAsString.contains("RESTFault")) {
636 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
637 execution.setVariable("WorkflowException", exceptionObject)
638 throw new BpmnError("MSOWorkflowException")
642 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
643 msoLogger.debug(dataErrorMessage)
644 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
652 execution.setVariable(Prefix + "routeCollection", routeTargets)
653 msoLogger.debug(" UPDNETI_routeCollection - " + '\n' + routeTargets)
656 // reset return code to success
657 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
658 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
659 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
660 String aaiStubResponse =
661 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
662 <vpn-binding xmlns="${schemaVersion}">
663 <global-route-target/>
666 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
667 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
668 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
669 msoLogger.debug(" No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml)
673 } catch (BpmnError e) {
676 } catch (Exception ex) {
677 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
678 msoLogger.debug(exceptionMessage)
679 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
685 public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
687 execution.setVariable("prefix", Prefix)
689 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " )
693 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
694 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
695 msoLogger.debug(" relationship - " + relationship)
697 // Check if Network Policy is present, then build a List of network policy
698 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
699 int networkPolicyCount = networkPolicyUriList.size()
700 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
701 msoLogger.debug(" UPDNETI_networkPolicyCount - " + networkPolicyCount)
703 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
704 AaiUtil aaiUriUtil = new AaiUtil(this)
706 if (networkPolicyCount > 0) {
707 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
708 msoLogger.debug(" networkPolicyUri List - " + networkPolicyUriList)
710 String networkPolicies = ""
711 // AII loop call using list vpnBindings
712 for (i in 0..networkPolicyUriList.size()-1) {
716 // prepare url using vpnBinding
717 String queryNetworkPolicyAAIRequest = ""
719 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
721 // Note: By default, the network policy url is found in 'related-link' of the response,
722 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
723 if (aai_uri == null || aai_uri == "") {
724 // using value of 'related-link' from response
725 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
726 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1) + "?depth=all"
728 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i] + "?depth=all"
731 // using uri value in URN mapping
732 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
733 println " networkPolicyId - " + networkPolicyId
734 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
735 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
737 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId + "?depth=all"
742 msoLogger.debug(queryNetworkPolicyAAIRequest)
743 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
744 msoLogger.debug(" UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest)
746 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
747 String returnCode = response.getStatusCode()
748 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
749 msoLogger.debug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
751 String aaiResponseAsString = response.getResponseBodyAsString()
753 if (returnCode=='200') {
754 msoLogger.debug(aaiResponseAsString)
755 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
756 msoLogger.debug(" QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
758 String networkPolicy = ""
759 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
760 networkPolicy = utils.getNodeText(aaiResponseAsString, "network-policy-fqdn")
761 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
765 if (returnCode=='404') {
766 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
767 msoLogger.debug(dataErrorMessage)
768 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
771 if (aaiResponseAsString.contains("RESTFault")) {
772 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
773 execution.setVariable("WorkflowException", exceptionObject)
774 throw new BpmnError("MSOWorkflowException")
778 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
779 msoLogger.debug(dataErrorMessage)
780 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
788 execution.setVariable(Prefix + "networkCollection", networkPolicies)
789 msoLogger.debug(" UPDNETI_networkCollection - " + '\n' + networkPolicies)
792 // reset return code to success
793 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
794 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
795 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
796 String aaiStubResponse =
797 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
798 <network-policy xmlns="${schemaVersion}">
799 <network-policy-fqdn/>
802 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
803 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
804 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
805 msoLogger.debug(" No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml)
809 } catch (BpmnError e) {
812 } catch (Exception ex) {
813 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
814 msoLogger.debug(exceptionMessage)
815 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
821 public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
823 execution.setVariable("prefix", Prefix)
825 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " )
829 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
830 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
831 msoLogger.debug(" relationship - " + relationship)
833 // Check if Network TableREf is present, then build a List of network policy
834 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
835 int networkTableRefCount = networkTableRefUriList.size()
836 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
837 msoLogger.debug(" UPDNETI_networkTableRefCount - " + networkTableRefCount)
839 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
840 AaiUtil aaiUriUtil = new AaiUtil(this)
842 if (networkTableRefCount > 0) {
843 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
844 msoLogger.debug(" networkTableRefUri List - " + networkTableRefUriList)
846 // AII loop call using list vpnBindings
847 String networkTableRefs = ""
848 for (i in 0..networkTableRefUriList.size()-1) {
852 // prepare url using tableRef
853 String queryNetworkTableRefAAIRequest = ""
855 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
857 // Note: By default, the network policy url is found in 'related-link' of the response,
858 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
859 if (aai_uri == null || aai_uri == "") {
860 // using value of 'related-link' from response
861 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
862 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1) + "?depth=all"
864 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i] + "?depth=all"
867 // using uri value in URN mapping
868 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
870 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
871 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
873 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId + "?depth=all"
878 msoLogger.debug(queryNetworkTableRefAAIRequest)
879 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
880 msoLogger.debug(" UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest)
882 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
883 String returnCode = response.getStatusCode()
884 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
885 msoLogger.debug(" ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode)
887 String aaiResponseAsString = response.getResponseBodyAsString()
889 if (returnCode=='200') {
890 msoLogger.debug(aaiResponseAsString)
891 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
892 msoLogger.debug(" QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString)
894 String networkTableRef = ""
895 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
896 networkTableRef = utils.getNodeText(aaiResponseAsString, "route-table-reference-fqdn")
897 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
901 if (returnCode=='404') {
902 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
903 msoLogger.debug(dataErrorMessage)
904 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
907 if (aaiResponseAsString.contains("RESTFault")) {
908 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
909 execution.setVariable("WorkflowException", exceptionObject)
910 throw new BpmnError("MSOWorkflowException")
914 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
915 msoLogger.debug(dataErrorMessage)
916 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
924 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
925 msoLogger.debug(" UPDNETI_tableRefCollection - " + '\n' + networkTableRefs)
928 // reset return code to success
929 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
930 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
931 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
932 String aaiStubResponse =
933 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
934 <route-table-references xmlns="${schemaVersion}">
935 <route-table-reference-fqdn/>
936 </route-table-references>
938 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
939 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
940 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
941 msoLogger.debug(" No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml)
945 } catch (BpmnError e) {
948 } catch (Exception ex) {
949 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
950 msoLogger.debug(exceptionMessage)
951 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
957 public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
959 execution.setVariable("prefix", Prefix)
961 msoLogger.debug(" ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " )
965 String networkRequest = execution.getVariable(Prefix + "networkRequest")
966 String networkId = utils.getNodeText(networkRequest, "network-id")
967 networkId = UriUtils.encode(networkId,"UTF-8")
968 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
969 String updateNetworkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
972 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
973 AaiUtil aaiUriUtil = new AaiUtil(this)
974 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
975 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
977 msoLogger.debug(updateContrailAAIUrlRequest)
978 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
979 msoLogger.debug(" UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest)
981 //Prepare payload (PUT)
982 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
983 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
984 String payloadXml = utils.formatXml(payload)
985 msoLogger.debug(payloadXml)
986 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
987 msoLogger.debug(" 'payload' to Update Contrail - " + "\n" + payloadXml)
989 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
990 String returnCode = response.getStatusCode()
991 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
993 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
994 msoLogger.debug(" ***** AAI Update Contrail Response Code : " + returnCode)
997 if (returnCode=='200') {
998 msoLogger.debug(aaiUpdateContrailResponseAsString)
999 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
1000 msoLogger.debug(" AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString)
1001 // Point-of-no-return is set to false, rollback not needed.
1002 execution.setVariable(Prefix + "isPONR", true)
1005 if (returnCode=='404') {
1006 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
1007 msoLogger.debug(dataErrorMessage)
1008 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1011 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
1012 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
1013 execution.setVariable("WorkflowException", exceptionObject)
1014 throw new BpmnError("MSOWorkflowException")
1018 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
1019 msoLogger.debug(errorMessage)
1020 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1025 } catch (BpmnError e) {
1028 } catch (Exception ex) {
1029 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
1030 msoLogger.debug(exceptionMessage)
1031 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1037 public void prepareUpdateNetworkRequest (DelegateExecution execution) {
1039 execution.setVariable("prefix", Prefix)
1041 msoLogger.trace("Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ")
1046 String requestId = execution.getVariable(Prefix + "requestId")
1047 String messageId = execution.getVariable(Prefix + "messageId")
1048 String source = execution.getVariable(Prefix + "source")
1050 String requestInput = execution.getVariable(Prefix + "networkRequest")
1051 String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1052 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1053 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1055 // Prepare Network request
1056 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1057 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1058 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1059 String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1061 String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
1062 buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1063 msoLogger.debug(buildUpdateNetworkRequestAsString)
1065 execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
1066 msoLogger.debug(" UPDNETI_updateNetworkRequest - " + "\n" + buildUpdateNetworkRequestAsString)
1068 } catch (Exception ex) {
1069 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
1070 msoLogger.debug(exceptionMessage)
1071 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1077 public void prepareSDNCRequest (DelegateExecution execution) {
1079 execution.setVariable("prefix", Prefix)
1081 msoLogger.trace("Inside prepareSDNCRequest of DoUpdateNetworkInstance ")
1085 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1086 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1087 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1089 String networkId = ""
1090 if (utils.nodeExists(updateNetworkInput, "network-id")) {
1091 networkId = utils.getNodeText(updateNetworkInput, "network-id")
1093 if (networkId == null) {networkId = ""}
1095 String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1097 String queryAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1099 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1100 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, queryAAIResponse, null)
1102 String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1103 msoLogger.debug(sndcTopologyUpdateRequesAsString)
1104 execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1105 msoLogger.debug(" UPDNETI_changeAssignSDNCRequest - " + "\n" + sndcTopologyUpdateRequesAsString)
1108 } catch (Exception ex) {
1109 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1110 msoLogger.debug(exceptionMessage)
1111 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1120 // **************************************************
1121 // Post or Validate Response Section
1122 // **************************************************
1124 public void validateUpdateNetworkResponse (DelegateExecution execution) {
1126 execution.setVariable("prefix", Prefix)
1128 msoLogger.trace("Inside validateUpdateNetworkResponse of DoUpdateNetworkInstance ")
1131 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1132 String networkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
1133 if (networkResponse==null) {
1134 networkResponse="" // reset
1137 msoLogger.debug(" Network Adapter update responseCode: " + returnCode)
1139 String errorMessage = ""
1140 if (returnCode == "200") {
1141 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1142 msoLogger.debug(networkResponse)
1143 execution.setVariable(Prefix + "updateNetworkResponse", networkResponse)
1144 msoLogger.debug(" Network Adapter update Success Response - " + "\n" + networkResponse)
1146 // prepare rollback data
1147 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1148 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1149 String rollbackNetwork =
1150 """<rollbackNetworkRequest>
1152 </rollbackNetworkRequest>"""
1153 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1154 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1155 msoLogger.debug(" Network Adapter rollback data - " + "\n" + rollbackNetworkXml)
1157 } else { // network error
1158 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1159 if (networkResponse.contains("updateNetworkError")) {
1160 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1161 errorMessage = utils.getNodeText(networkResponse, "message")
1162 errorMessage = "Received error from Network Adapter: " + errorMessage
1163 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1165 } else { // CatchAll exception
1166 if (returnCode == "500") {
1167 errorMessage = "JBWEB000065: HTTP Status 500."
1169 errorMessage = "Return code is " + returnCode
1171 errorMessage = "Received error from Network Adapter: " + errorMessage
1172 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1176 } else { // CatchAll exception
1177 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1178 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1184 } catch (BpmnError e) {
1187 } catch (Exception ex) {
1188 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1189 msoLogger.debug(exceptionMessage)
1190 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1197 public void validateSDNCResponse (DelegateExecution execution) {
1199 execution.setVariable("prefix", Prefix)
1201 msoLogger.trace("Inside validateSDNCResponse of DoUpdateNetworkInstance ")
1203 String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1204 WorkflowException workflowException = null
1206 workflowException = execution.getVariable(Prefix + "WorkflowException")
1207 //execution.setVariable("WorkflowException", workflowException)
1208 } catch (Exception ex) {
1209 msoLogger.debug(" Sdnc 'WorkflowException' object is empty or null. ")
1212 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1214 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1215 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1217 String changeAssignSDNCResponseDecodeXml = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1218 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1219 execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1221 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, prefix+'sdncResponseSuccess'
1222 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1223 msoLogger.debug("Successfully Validated SDNC Response")
1226 msoLogger.debug("Did NOT Successfully Validated SDNC Response")
1227 throw new BpmnError("MSOWorkflowException")
1233 public void postProcessResponse (DelegateExecution execution) {
1235 execution.setVariable("prefix", Prefix)
1237 msoLogger.trace("Inside postProcessResponse of DoUpdateNetworkInstance ")
1240 msoLogger.debug(" ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"))
1241 if (execution.getVariable(Prefix + "isException") == false) {
1242 // set rollback data
1243 execution.setVariable("orchestrationStatus", "")
1244 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1245 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1246 prepareSuccessRollbackData(execution) // populate rollbackData
1247 execution.setVariable("WorkflowException", null)
1248 execution.setVariable(Prefix + "Success", true)
1249 msoLogger.debug(" ***** postProcessResponse(), GOOD !!!")
1251 execution.setVariable(Prefix + "Success", false)
1252 execution.setVariable("rollbackData", null)
1253 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1254 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1255 msoLogger.debug(" ***** workflowException: " + execution.getVariable("workflowException"))
1256 WorkflowException wfex = execution.getVariable("workflowException")
1257 exceptionMessage = wfex.getErrorMessage()
1259 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1260 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1261 exceptionMessage = pwfex.getErrorMessage()
1264 // going to the Main flow: a-la-carte or macro
1265 msoLogger.debug(" ***** postProcessResponse(), BAD !!!")
1266 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1267 throw new BpmnError("MSOWorkflowException")
1270 } catch(BpmnError b){
1271 msoLogger.debug("Rethrowing MSOWorkflowException")
1275 } catch (Exception ex) {
1276 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1277 msoLogger.debug(exceptionMessage)
1278 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1285 public void prepareSDNCRollbackRequest (DelegateExecution execution) {
1287 execution.setVariable("prefix", Prefix)
1289 msoLogger.trace("Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ")
1292 // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException.
1293 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1295 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1296 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1297 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1298 String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1299 String networkId = utils.getNodeText(changeAssignSDNCResponse, "network-id")
1301 String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1303 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1304 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1305 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1306 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1307 msoLogger.debug(" Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" + sndcTopologyRollbackRequestAsString)
1309 } catch (Exception ex) {
1310 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1311 msoLogger.debug(exceptionMessage)
1312 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1318 public void prepareRollbackData(DelegateExecution execution) {
1320 execution.setVariable("prefix",Prefix)
1322 msoLogger.trace("Inside prepareRollbackData() of DoUpdateNetworkInstance ")
1326 Map<String, String> rollbackData = new HashMap<String, String>();
1327 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1328 if (rollbackSDNCRequest != null) {
1329 if (rollbackSDNCRequest != "") {
1330 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1333 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1334 if (rollbackNetworkRequest != null) {
1335 if (rollbackNetworkRequest != "") {
1336 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1339 execution.setVariable("rollbackData", rollbackData)
1340 msoLogger.debug("** rollbackData : " + rollbackData)
1342 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1343 msoLogger.debug("** WorkflowException : " + execution.getVariable("WorkflowException"))
1345 } catch (Exception ex) {
1346 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1347 msoLogger.debug(exceptionMessage)
1348 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1354 public void prepareSuccessRollbackData(DelegateExecution execution) {
1356 execution.setVariable("prefix",Prefix)
1358 msoLogger.trace("Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ")
1362 if (execution.getVariable("sdncVersion") != '1610') {
1363 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1365 prepareSDNCRollbackRequest(execution)
1368 Map<String, String> rollbackData = new HashMap<String, String>();
1369 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1370 if (rollbackSDNCRequest != null) {
1371 if (rollbackSDNCRequest != "") {
1372 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1375 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1376 if (rollbackNetworkRequest != null) {
1377 if (rollbackNetworkRequest != "") {
1378 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1381 execution.setVariable("rollbackData", rollbackData)
1383 msoLogger.debug("** 'rollbackData' for Full Rollback : " + rollbackData)
1384 execution.setVariable("WorkflowException", null)
1387 } catch (Exception ex) {
1388 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1389 msoLogger.debug(exceptionMessage)
1390 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1396 public void setExceptionFlag(DelegateExecution execution){
1398 execution.setVariable("prefix",Prefix)
1400 msoLogger.trace("Inside setExceptionFlag() of DoUpdateNetworkInstance ")
1404 execution.setVariable(Prefix + "isException", true)
1406 if (execution.getVariable("SavedWorkflowException1") != null) {
1407 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1409 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1411 msoLogger.debug(Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"))
1413 } catch(Exception ex){
1414 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1415 msoLogger.debug(exceptionMessage)
1416 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1422 // *******************************
1423 // Build Error Section
1424 // *******************************
1426 public void processJavaException(DelegateExecution execution){
1428 execution.setVariable("prefix",Prefix)
1430 msoLogger.debug("Caught a Java Exception")
1431 msoLogger.debug("Started processJavaException Method")
1432 msoLogger.debug("Variables List: " + execution.getVariables())
1433 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1434 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1436 }catch(Exception e){
1437 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
1438 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
1439 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1441 msoLogger.debug("Completed processJavaException Method")