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=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
22 import groovy.xml.XmlUtil
24 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
25 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
26 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
27 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
28 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
29 import org.openecomp.mso.bpmn.common.scripts.VidUtils
30 import org.openecomp.mso.bpmn.core.WorkflowException
31 import org.openecomp.mso.bpmn.core.json.JsonUtils
32 import org.openecomp.mso.rest.APIResponse
34 import java.util.UUID;
36 import org.camunda.bpm.engine.delegate.BpmnError
37 import org.camunda.bpm.engine.runtime.Execution
38 import org.apache.commons.lang3.*
39 import org.apache.commons.codec.binary.Base64;
40 import org.springframework.web.util.UriUtils
43 * This groovy class supports the <class>DoUpdateNetworkInstance.bpmn</class> process.
46 public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor {
47 String Prefix="UPDNETI_"
48 ExceptionUtil exceptionUtil = new ExceptionUtil()
49 JsonUtils jsonUtil = new JsonUtils()
50 VidUtils vidUtils = new VidUtils(this)
51 NetworkUtils networkUtils = new NetworkUtils()
52 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
55 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
58 public InitializeProcessVariables(Execution execution){
59 /* Initialize all the process variables in this block */
61 execution.setVariable(Prefix + "messageId", "")
62 execution.setVariable("BasicAuthHeaderValuePO", "")
63 execution.setVariable("BasicAuthHeaderValueSDNC", "")
64 execution.setVariable(Prefix + "networkRequest", "")
65 execution.setVariable(Prefix + "networkInputs", "")
66 execution.setVariable(Prefix + "networkOutputs", "")
67 execution.setVariable(Prefix + "requestId", "")
68 execution.setVariable(Prefix + "source", "")
69 execution.setVariable(Prefix + "networkId", "")
71 execution.setVariable(Prefix + "isPONR", false) // Point-of-no-return, means, rollback is not needed
73 // AAI query Cloud Region
74 execution.setVariable(Prefix + "queryCloudRegionRequest","")
75 execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
76 execution.setVariable(Prefix + "queryCloudRegionResponse","")
77 execution.setVariable(Prefix + "cloudRegionPo","")
78 execution.setVariable(Prefix + "cloudRegionSdnc","")
79 execution.setVariable(Prefix + "isCloudRegionGood", false)
82 execution.setVariable(Prefix + "queryIdAAIRequest","")
83 execution.setVariable(Prefix + "queryIdAAIResponse", "")
84 execution.setVariable(Prefix + "aaiIdReturnCode", "")
86 // AAI query vpn binding
87 execution.setVariable(Prefix + "queryVpnBindingAAIRequest","")
88 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", "")
89 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "")
90 execution.setVariable(Prefix + "vpnBindings", null)
91 execution.setVariable(Prefix + "vpnCount", 0)
92 execution.setVariable(Prefix + "routeCollection", "")
94 // AAI query network policy
95 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest","")
96 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", "")
97 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "")
98 execution.setVariable(Prefix + "networkPolicyUriList", null)
99 execution.setVariable(Prefix + "networkPolicyCount", 0)
100 execution.setVariable(Prefix + "networkCollection", "")
102 // AAI query route table reference
103 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest","")
104 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", "")
105 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "")
106 execution.setVariable(Prefix + "networkTableRefUriList", null)
107 execution.setVariable(Prefix + "networkTableRefCount", 0)
108 execution.setVariable(Prefix + "tableRefCollection", "")
111 execution.setVariable(Prefix + "requeryIdAAIRequest","")
112 execution.setVariable(Prefix + "requeryIdAAIResponse", "")
113 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
115 // AAI update contrail
116 execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
117 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
118 execution.setVariable(Prefix + "updateContrailAAIResponse", "")
119 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
121 execution.setVariable(Prefix + "updateNetworkRequest", "")
122 execution.setVariable(Prefix + "updateNetworkResponse", "")
123 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
124 execution.setVariable(Prefix + "networkReturnCode", "")
125 execution.setVariable(Prefix + "isNetworkRollbackNeeded", false)
127 execution.setVariable(Prefix + "changeAssignSDNCRequest", "")
128 execution.setVariable(Prefix + "changeAssignSDNCResponse", "")
129 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
130 execution.setVariable(Prefix + "sdncReturnCode", "")
131 execution.setVariable(Prefix + "isSdncRollbackNeeded", false)
132 execution.setVariable(Prefix + "sdncResponseSuccess", false)
134 execution.setVariable(Prefix + "isVnfBindingPresent", false)
135 execution.setVariable(Prefix + "Success", false)
136 execution.setVariable(Prefix + "serviceInstanceId", "")
138 execution.setVariable(Prefix + "isException", false)
142 // **************************************************
143 // Pre or Prepare Request Section
144 // **************************************************
146 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
149 public void preProcessRequest (Execution execution) {
150 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
151 execution.setVariable("prefix",Prefix)
153 utils.log("DEBUG", " ***** Inside preProcessRequest DoUpdateNetworkInstance Request ***** ", isDebugEnabled)
156 // initialize flow variables
157 InitializeProcessVariables(execution)
159 // GET Incoming request & validate 3 kinds of format.
160 execution.setVariable("action", "UPDATE")
161 String networkRequest = execution.getVariable("bpmnRequest")
162 if (networkRequest != null) {
163 if (networkRequest.contains("requestDetails")) {
164 // JSON format request is sent, create xml
166 def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
167 utils.log("DEBUG", " Incoming message formatted . . . : " + '\n' + prettyJson, isDebugEnabled)
168 networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
170 } catch (Exception ex) {
171 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
172 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
173 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
176 // XML format request is sent
180 // vIPR format request is sent, create xml from individual variables
181 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
184 networkRequest = utils.formatXml(networkRequest)
185 utils.logAudit(networkRequest)
186 execution.setVariable(Prefix + "networkRequest", networkRequest)
187 utils.log("DEBUG", " network-request - " + '\n' + networkRequest, isDebugEnabled)
189 // validate 'disableRollback' (aka, 'suppressRollback')
190 boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
191 execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
192 utils.log("DEBUG", Prefix + "rollbackEnabled - " + rollbackEnabled, isDebugEnabled)
194 String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
195 execution.setVariable(Prefix + "networkInputs", networkInputs)
196 utils.log("DEBUG", Prefix + "networkInputs - " + '\n' + networkInputs, isDebugEnabled)
199 String messageId = execution.getVariable(Prefix + "messageId") // for testing
200 if (messageId == null || messageId == "") {
201 messageId = UUID.randomUUID()
202 utils.log("DEBUG", " UPDNETI_messageId, random generated: " + messageId, isDebugEnabled)
204 utils.log("DEBUG", " UPDNETI_messageId, pre-assigned: " + messageId, isDebugEnabled)
206 execution.setVariable(Prefix + "messageId", messageId)
208 String source = utils.getNodeText1(networkRequest, "source")
209 execution.setVariable(Prefix + "source", source)
210 utils.log("DEBUG", Prefix + "source - " + source, isDebugEnabled)
212 String networkId = ""
213 if (utils.nodeExists(networkRequest, "network-id")) {
214 networkId = utils.getNodeText1(networkRequest, "network-id")
215 if (networkId == 'null' || networkId == "") {
216 sendSyncError(execution)
217 // missing value of networkId
218 String dataErrorMessage = "Variable 'network-id' value/element is missing."
219 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
220 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
225 String lcpCloudRegion = ""
226 if (utils.nodeExists(networkRequest, "aic-cloud-region")) {
227 lcpCloudRegion = utils.getNodeText1(networkRequest, "aic-cloud-region")
228 if ((lcpCloudRegion == 'null') || (lcpCloudRegion == "")) {
229 sendSyncError(execution)
230 String dataErrorMessage = "requestDetails has missing 'aic-cloud-region' value/element."
231 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
232 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
236 String serviceInstanceId = ""
237 if (utils.nodeExists(networkRequest, "service-instance-id")) {
238 serviceInstanceId = utils.getNodeText1(networkRequest, "service-instance-id")
239 if ((serviceInstanceId == 'null') || (lcpCloudRegion == "")) {
240 sendSyncError(execution)
241 String dataErrorMessage = "Variable 'serviceInstanceId' value/element is missing."
242 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
243 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
247 // PO Authorization Info / headers Authorization=
248 String basicAuthValuePO = execution.getVariable("URN_mso_adapters_po_auth")
249 utils.log("DEBUG", " Obtained BasicAuth userid password for PO/SDNC adapter: " + basicAuthValuePO, isDebugEnabled)
251 def encodedString = utils.getBasicAuth(basicAuthValuePO, execution.getVariable("URN_mso_msoKey"))
252 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
253 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
255 } catch (IOException ex) {
256 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - "
257 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
258 utils.log("DEBUG", dataErrorMessage, , isDebugEnabled)
259 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
262 // Set variables for Generic Get Sub Flow use
263 execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
264 utils.log("DEBUG", Prefix + "serviceInstanceId - " + serviceInstanceId, isDebugEnabled)
266 execution.setVariable("GENGS_type", "service-instance")
267 utils.log("DEBUG", "GENGS_type - " + "service-instance", isDebugEnabled)
268 utils.log("DEBUG", " Url for SDNC adapter: " + execution.getVariable("URN_mso_adapters_sdnc_endpoint"), isDebugEnabled)
270 String sdncVersion = execution.getVariable("sdncVersion")
271 utils.log("DEBUG", "sdncVersion? : " + sdncVersion, isDebugEnabled)
273 // build 'networkOutputs'
274 networkId = utils.getNodeText1(networkRequest, "network-id")
275 if ((networkId == null) || (networkId == "null")) {
278 String networkName = utils.getNodeText1(networkRequest, "network-name")
279 if ((networkName == null) || (networkName == "null")) {
282 String networkOutputs =
284 <network-id>${networkId}</network-id>
285 <network-name>${networkName}</network-name>
286 </network-outputs>"""
287 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
288 utils.log("DEBUG", Prefix + "networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
289 execution.setVariable(Prefix + "networkId", networkId)
290 execution.setVariable(Prefix + "networkName", networkName)
293 } catch (BpmnError e) {
296 } catch (Exception ex){
297 sendSyncError(execution)
299 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - " + ex.getMessage()
300 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
301 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
306 public void callRESTQueryAAICloudRegion (Execution execution) {
307 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
308 execution.setVariable("prefix", Prefix)
310 utils.log("DEBUG", " ***** Inside callRESTQueryAAICloudRegion of DoUpdateNetworkInstance ***** " , isDebugEnabled)
313 String networkInputs = execution.getVariable(Prefix + "networkInputs")
314 String cloudRegion = utils.getNodeText1(networkInputs, "aic-cloud-region")
315 cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
318 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
319 AaiUtil aaiUtil = new AaiUtil(this)
320 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
321 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
322 utils.logAudit(queryCloudRegionRequest)
323 execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
324 utils.log("DEBUG", " UPDNETI_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugEnabled)
326 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
327 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
329 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
330 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
331 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
332 execution.setVariable(Prefix + "isCloudRegionGood", true)
335 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
336 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
337 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
341 utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"), isDebugEnabled)
343 } catch (BpmnError e) {
346 } catch (Exception ex) {
348 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
349 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
350 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
356 public void callRESTQueryAAINetworkId(Execution execution) {
357 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
358 execution.setVariable("prefix", Prefix)
360 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkId of DoUpdateNetworkInstance ***** " , isDebugEnabled)
364 String networkRequest = execution.getVariable(Prefix + "networkRequest")
365 String networkId = utils.getNodeText1(networkRequest, "network-id")
366 networkId = UriUtils.encode(networkId,"UTF-8")
367 execution.setVariable(Prefix + "networkId", networkId)
368 String messageId = execution.getVariable(Prefix + "messageId")
371 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
372 AaiUtil aaiUriUtil = new AaiUtil(this)
373 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
374 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
375 utils.logAudit(queryIdAAIRequest)
376 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
377 utils.log("DEBUG", Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest, isDebugEnabled)
379 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
380 String returnCode = response.getStatusCode()
381 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
382 utils.log("DEBUG", " ***** AAI Response Code : " + returnCode, isDebugEnabled)
384 String aaiResponseAsString = response.getResponseBodyAsString()
386 if (returnCode=='200') {
387 utils.logAudit(aaiResponseAsString)
388 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
389 utils.log("DEBUG", " QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
392 if (returnCode=='404') {
393 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
394 utils.log("DEBUG", " AAI Query Failed. " + dataErrorMessage, isDebugEnabled)
395 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
398 if (aaiResponseAsString.contains("RESTFault")) {
399 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
400 execution.setVariable("WorkflowException", exceptionObject)
401 throw new BpmnError("MSOWorkflowException")
405 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
406 utils.log("DEBUG", "Unexpected Response from QueryAAINetworkId - " + dataErrorMessage, isDebugEnabled)
407 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
413 } catch (BpmnError e) {
416 } catch (Exception ex) {
417 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
418 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
419 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
425 public void callRESTReQueryAAINetworkId(Execution execution) {
426 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
427 execution.setVariable("prefix", Prefix)
429 utils.log("DEBUG", " ***** Inside callRESTReQueryAAINetworkId of DoUpdateNetworkInstance ***** " , isDebugEnabled)
433 String networkRequest = execution.getVariable(Prefix + "networkRequest")
434 String networkId = utils.getNodeText1(networkRequest, "network-id")
435 networkId = UriUtils.encode(networkId,"UTF-8")
436 String messageId = execution.getVariable(Prefix + "messageId")
439 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
440 AaiUtil aaiUriUtil = new AaiUtil(this)
441 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
442 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
443 utils.logAudit(requeryIdAAIRequest)
444 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
445 utils.log("DEBUG", " UPDNETI_requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest, isDebugEnabled)
447 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
448 String returnCode = response.getStatusCode()
449 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
450 utils.log("DEBUG", " ***** AAI ReQuery Response Code : " + returnCode, isDebugEnabled)
452 String aaiResponseAsString = response.getResponseBodyAsString()
454 if (returnCode=='200') {
455 utils.logAudit(aaiResponseAsString)
456 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
457 utils.log("DEBUG", " ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
459 String netId = utils.getNodeText1(aaiResponseAsString, "network-id")
460 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
461 String networkOutputs =
463 <network-id>${netId}</network-id>
464 <network-name>${netName}</network-name>
465 </network-outputs>"""
466 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
467 utils.log("DEBUG", " networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
470 if (returnCode=='404') {
471 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
472 utils.log("DEBUG", " AAI ReQuery Failed. - " + dataErrorMessage, isDebugEnabled)
473 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
476 if (aaiResponseAsString.contains("RESTFault")) {
477 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
478 execution.setVariable("WorkflowException", exceptionObject)
479 throw new BpmnError("MSOWorkflowException")
483 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
484 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
485 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
491 } catch (BpmnError e) {
494 } catch (Exception ex) {
495 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
496 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
497 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
503 public void callRESTQueryAAINetworkVpnBinding(Execution execution) {
504 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
505 execution.setVariable("prefix", Prefix)
507 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkVpnBinding of DoUpdateNetworkInstance ***** " , isDebugEnabled)
512 String messageId = execution.getVariable(Prefix + "messageId")
513 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
514 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
515 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
517 // Check if Vnf Binding is present, then build a List of vnfBinding
518 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
519 int vpnCount = vpnBindingUri.size()
520 execution.setVariable(Prefix + "vpnCount", vpnCount)
521 utils.log("DEBUG", " UPDNETI_vpnCount - " + vpnCount, isDebugEnabled)
523 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
524 AaiUtil aaiUriUtil = new AaiUtil(this)
527 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
528 utils.log("DEBUG", " vpnBindingUri List - " + vpnBindingUri, isDebugEnabled)
530 String routeTargets = ""
531 // AII loop call using list vpnBindings
532 for (i in 0..vpnBindingUri.size()-1) {
536 // prepare url using vpnBinding
537 String queryVpnBindingAAIRequest = ""
538 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
540 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
541 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
542 if (aai_uri == null || aai_uri == "") {
543 // using value of 'related-link' from response
544 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
545 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1)
547 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i]
551 // using uri value in URN mapping
552 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
553 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
554 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
556 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId
559 utils.logAudit(queryVpnBindingAAIRequest)
560 execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
561 utils.log("DEBUG", " UPDNETI_queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest, isDebugEnabled)
563 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
564 String returnCode = response.getStatusCode()
565 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
566 utils.log("DEBUG", " ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode, isDebugEnabled)
568 String aaiResponseAsString = response.getResponseBodyAsString()
570 if (returnCode=='200') {
571 utils.logAudit(aaiResponseAsString)
572 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
573 utils.log("DEBUG", " AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
575 String routeTarget = ""
576 if (utils.nodeExists(aaiResponseAsString, "global-route-target")) {
577 routeTarget = utils.getNodeText1(aaiResponseAsString, "global-route-target")
578 routeTargets += "<routeTargets>" + routeTarget + "</routeTargets>" + '\n'
582 if (returnCode=='404') {
583 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
584 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
585 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
588 if (aaiResponseAsString.contains("RESTFault")) {
589 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
590 execution.setVariable("WorkflowException", exceptionObject)
591 throw new BpmnError("MSOWorkflowException")
595 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
596 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
597 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
605 execution.setVariable(Prefix + "routeCollection", routeTargets)
606 utils.log("DEBUG", " UPDNETI_routeCollection - " + '\n' + routeTargets, isDebugEnabled)
609 // reset return code to success
610 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
611 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
612 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
613 String aaiStubResponse =
614 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
615 <vpn-binding xmlns="${schemaVersion}">
616 <global-route-target/>
619 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
620 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
621 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
622 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
626 } catch (BpmnError e) {
629 } catch (Exception ex) {
630 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
631 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
632 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
638 public void callRESTQueryAAINetworkPolicy(Execution execution) {
639 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
640 execution.setVariable("prefix", Prefix)
642 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " , isDebugEnabled)
646 String messageId = execution.getVariable(Prefix + "messageId")
647 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
648 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
649 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
651 // Check if Network Policy is present, then build a List of network policy
652 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
653 int networkPolicyCount = networkPolicyUriList.size()
654 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
655 utils.log("DEBUG", " UPDNETI_networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
657 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
658 AaiUtil aaiUriUtil = new AaiUtil(this)
660 if (networkPolicyCount > 0) {
661 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
662 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
664 String networkPolicies = ""
665 // AII loop call using list vpnBindings
666 for (i in 0..networkPolicyUriList.size()-1) {
670 // prepare url using vpnBinding
671 String queryNetworkPolicyAAIRequest = ""
673 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
675 // Note: By default, the network policy url is found in 'related-link' of the response,
676 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
677 if (aai_uri == null || aai_uri == "") {
678 // using value of 'related-link' from response
679 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
680 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1)
682 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i]
685 // using uri value in URN mapping
686 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
687 println " networkPolicyId - " + networkPolicyId
688 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
689 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
691 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId
696 utils.logAudit(queryNetworkPolicyAAIRequest)
697 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
698 utils.log("DEBUG", " UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
700 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
701 String returnCode = response.getStatusCode()
702 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
703 utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
705 String aaiResponseAsString = response.getResponseBodyAsString()
707 if (returnCode=='200') {
708 utils.logAudit(aaiResponseAsString)
709 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
710 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
712 String networkPolicy = ""
713 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
714 networkPolicy = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
715 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
719 if (returnCode=='404') {
720 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
721 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
722 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
725 if (aaiResponseAsString.contains("RESTFault")) {
726 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
727 execution.setVariable("WorkflowException", exceptionObject)
728 throw new BpmnError("MSOWorkflowException")
732 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
733 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
734 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
742 execution.setVariable(Prefix + "networkCollection", networkPolicies)
743 utils.log("DEBUG", " UPDNETI_networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
746 // reset return code to success
747 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
748 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
749 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
750 String aaiStubResponse =
751 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
752 <network-policy xmlns="${schemaVersion}">
753 <network-policy-fqdn/>
756 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
757 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
758 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
759 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
763 } catch (BpmnError e) {
766 } catch (Exception ex) {
767 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
768 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
769 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
775 public void callRESTQueryAAINetworkTableRef(Execution execution) {
776 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
777 execution.setVariable("prefix", Prefix)
779 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " , isDebugEnabled)
783 String messageId = execution.getVariable(Prefix + "messageId")
784 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
785 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
786 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
788 // Check if Network TableREf is present, then build a List of network policy
789 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
790 int networkTableRefCount = networkTableRefUriList.size()
791 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
792 utils.log("DEBUG", " UPDNETI_networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
794 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
795 AaiUtil aaiUriUtil = new AaiUtil(this)
797 if (networkTableRefCount > 0) {
798 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
799 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
801 // AII loop call using list vpnBindings
802 String networkTableRefs = ""
803 for (i in 0..networkTableRefUriList.size()-1) {
807 // prepare url using tableRef
808 String queryNetworkTableRefAAIRequest = ""
810 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
812 // Note: By default, the network policy url is found in 'related-link' of the response,
813 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
814 if (aai_uri == null || aai_uri == "") {
815 // using value of 'related-link' from response
816 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
817 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1)
819 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i]
822 // using uri value in URN mapping
823 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
825 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
826 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
828 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId
833 utils.logAudit(queryNetworkTableRefAAIRequest)
834 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
835 utils.log("DEBUG", " UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
837 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
838 String returnCode = response.getStatusCode()
839 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
840 utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
842 String aaiResponseAsString = response.getResponseBodyAsString()
844 if (returnCode=='200') {
845 utils.logAudit(aaiResponseAsString)
846 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
847 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
849 String networkTableRef = ""
850 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
851 networkTableRef = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
852 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
856 if (returnCode=='404') {
857 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
858 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
859 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
862 if (aaiResponseAsString.contains("RESTFault")) {
863 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
864 execution.setVariable("WorkflowException", exceptionObject)
865 throw new BpmnError("MSOWorkflowException")
869 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
870 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
871 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
879 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
880 utils.log("DEBUG", " UPDNETI_tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
883 // reset return code to success
884 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
885 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
886 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
887 String aaiStubResponse =
888 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
889 <route-table-references xmlns="${schemaVersion}">
890 <route-table-reference-fqdn/>
891 </route-table-references>
893 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
894 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
895 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
896 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
900 } catch (BpmnError e) {
903 } catch (Exception ex) {
904 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
905 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
906 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
912 public void callRESTUpdateContrailAAINetwork(Execution execution) {
913 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
914 execution.setVariable("prefix", Prefix)
916 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " , isDebugEnabled)
920 String networkRequest = execution.getVariable(Prefix + "networkRequest")
921 String networkId = utils.getNodeText1(networkRequest, "network-id")
922 networkId = UriUtils.encode(networkId,"UTF-8")
923 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
924 String updateNetworkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
925 String messageId = execution.getVariable(Prefix + "messageId")
928 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
929 AaiUtil aaiUriUtil = new AaiUtil(this)
930 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
931 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
933 utils.logAudit(updateContrailAAIUrlRequest)
934 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
935 utils.log("DEBUG", " UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
937 //Prepare payload (PUT)
938 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
939 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
940 String payloadXml = utils.formatXml(payload)
941 utils.logAudit(payloadXml)
942 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
943 utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
945 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
946 String returnCode = response.getStatusCode()
947 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
949 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
950 utils.log("DEBUG", " ***** AAI Update Contrail Response Code : " + returnCode, isDebugEnabled)
953 if (returnCode=='200') {
954 utils.logAudit(aaiUpdateContrailResponseAsString)
955 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
956 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
957 // Point-of-no-return is set to false, rollback not needed.
958 execution.setVariable(Prefix + "isPONR", true)
961 if (returnCode=='404') {
962 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
963 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
964 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
967 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
968 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
969 execution.setVariable("WorkflowException", exceptionObject)
970 throw new BpmnError("MSOWorkflowException")
974 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
975 utils.log("DEBUG", errorMessage, isDebugEnabled)
976 exceptionUtil.buildAndThrowWorkflowException(execution, "2500", errorMessage)
981 } catch (BpmnError e) {
984 } catch (Exception ex) {
985 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
986 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
987 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
993 public void prepareUpdateNetworkRequest (Execution execution) {
994 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
995 execution.setVariable("prefix", Prefix)
997 utils.log("DEBUG", " ***** Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1002 String requestId = execution.getVariable(Prefix + "requestId")
1003 String messageId = execution.getVariable(Prefix + "messageId")
1004 String source = execution.getVariable(Prefix + "source")
1006 String requestInput = execution.getVariable(Prefix + "networkRequest")
1007 String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1008 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1009 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1011 // Prepare Network request
1012 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1013 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1014 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1015 String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1017 String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
1018 buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1019 utils.logAudit(buildUpdateNetworkRequestAsString)
1021 execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
1022 utils.log("DEBUG", " UPDNETI_updateNetworkRequest - " + "\n" + buildUpdateNetworkRequestAsString, isDebugEnabled)
1024 } catch (Exception ex) {
1025 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
1026 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1027 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1033 public void prepareSDNCRequest (Execution execution) {
1034 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1035 execution.setVariable("prefix", Prefix)
1037 utils.log("DEBUG", " ***** Inside prepareSDNCRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1041 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1042 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1043 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1045 String networkId = ""
1046 if (utils.nodeExists(updateNetworkInput, "network-id")) {
1047 networkId = utils.getNodeText1(updateNetworkInput, "network-id")
1049 if (networkId == null) {networkId = ""}
1051 String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1053 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1054 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1056 String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1057 utils.logAudit(sndcTopologyUpdateRequesAsString)
1058 execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1059 utils.log("DEBUG", " UPDNETI_changeAssignSDNCRequest - " + "\n" + sndcTopologyUpdateRequesAsString, isDebugEnabled)
1062 } catch (Exception ex) {
1063 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1064 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1065 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1074 // **************************************************
1075 // Post or Validate Response Section
1076 // **************************************************
1078 public void validateUpdateNetworkResponse (Execution execution) {
1079 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1080 execution.setVariable("prefix", Prefix)
1082 utils.log("DEBUG", " ***** Inside validateUpdateNetworkResponse of DoUpdateNetworkInstance *****", isDebugEnabled)
1085 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1086 String networkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
1087 if (networkResponse==null) {
1088 networkResponse="" // reset
1091 utils.log("DEBUG", " Network Adapter update responseCode: " + returnCode, isDebugEnabled)
1093 String errorMessage = ""
1094 if (returnCode == "200") {
1095 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1096 utils.logAudit(networkResponse)
1097 execution.setVariable(Prefix + "updateNetworkResponse", networkResponse)
1098 utils.log("DEBUG", " Network Adapter update Success Response - " + "\n" + networkResponse, isDebugEnabled)
1100 // prepare rollback data
1101 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1102 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1103 String rollbackNetwork =
1104 """<rollbackNetworkRequest>
1106 </rollbackNetworkRequest>"""
1107 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1108 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1109 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1111 } else { // network error
1112 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1113 if (networkResponse.contains("updateNetworkError")) {
1114 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1115 errorMessage = utils.getNodeText1(networkResponse, "message")
1116 errorMessage = "Received error from Network Adapter: " + errorMessage
1117 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1119 } else { // CatchAll exception
1120 if (returnCode == "500") {
1121 errorMessage = "JBWEB000065: HTTP Status 500."
1123 errorMessage = "Return code is " + returnCode
1125 errorMessage = "Received error from Network Adapter: " + errorMessage
1126 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1130 } else { // CatchAll exception
1131 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1132 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1138 } catch (BpmnError e) {
1141 } catch (Exception ex) {
1142 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1143 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1144 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1151 public void validateSDNCResponse (Execution execution) {
1152 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1153 execution.setVariable("prefix", Prefix)
1155 utils.log("DEBUG", " ***** Inside validateSDNCResponse of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1157 String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1158 WorkflowException workflowException = null
1160 workflowException = execution.getVariable(Prefix + "WorkflowException")
1161 //execution.setVariable("WorkflowException", workflowException)
1162 } catch (Exception ex) {
1163 utils.log("DEBUG", " Sdnc 'WorkflowException' object is empty or null. ", isDebugEnabled)
1166 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1168 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1169 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1171 String changeAssignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "changeAssignSDNCResponse"))
1172 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1173 execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1175 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, prefix+'sdncResponseSuccess'
1176 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1177 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1180 utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1181 throw new BpmnError("MSOWorkflowException")
1187 public void postProcessResponse (Execution execution) {
1188 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1189 execution.setVariable("prefix", Prefix)
1191 utils.log("DEBUG", " ***** Inside postProcessResponse of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1194 utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
1195 if (execution.getVariable(Prefix + "isException") == false) {
1196 // set rollback data
1197 execution.setVariable("orchestrationStatus", "")
1198 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1199 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1200 prepareSuccessRollbackData(execution) // populate rollbackData
1201 execution.setVariable("WorkflowException", null)
1202 execution.setVariable(Prefix + "Success", true)
1203 utils.log("DEBUG", " ***** postProcessResponse(), GOOD !!!", isDebugEnabled)
1205 execution.setVariable(Prefix + "Success", false)
1206 execution.setVariable("rollbackData", null)
1207 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1208 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1209 utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
1210 WorkflowException wfex = execution.getVariable("workflowException")
1211 exceptionMessage = wfex.getErrorMessage()
1213 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1214 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1215 exceptionMessage = pwfex.getErrorMessage()
1218 // going to the Main flow: a-la-carte or macro
1219 utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
1220 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1221 throw new BpmnError("MSOWorkflowException")
1224 } catch(BpmnError b){
1225 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
1229 } catch (Exception ex) {
1230 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1231 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1232 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1239 public void prepareSDNCRollbackRequest (Execution execution) {
1240 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1241 execution.setVariable("prefix", Prefix)
1243 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1246 // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException.
1247 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1249 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1250 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1251 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1252 String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1253 String networkId = utils.getNodeText1(changeAssignSDNCResponse, "network-id")
1255 String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1257 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1258 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1259 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1260 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1261 utils.log("DEBUG", " Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" + sndcTopologyRollbackRequestAsString, isDebugEnabled)
1264 } catch (Exception ex) {
1265 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1266 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1267 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1273 public void prepareRollbackData(Execution execution) {
1274 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1275 execution.setVariable("prefix",Prefix)
1277 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1281 Map<String, String> rollbackData = new HashMap<String, String>();
1282 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1283 if (rollbackSDNCRequest != null) {
1284 if (rollbackSDNCRequest != "") {
1285 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1288 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1289 if (rollbackNetworkRequest != null) {
1290 if (rollbackNetworkRequest != "") {
1291 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1294 execution.setVariable("rollbackData", rollbackData)
1295 utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
1297 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1298 utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
1300 } catch (Exception ex) {
1301 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1302 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1303 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1309 public void prepareSuccessRollbackData(Execution execution) {
1310 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1311 execution.setVariable("prefix",Prefix)
1313 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1317 if (execution.getVariable("sdncVersion") == '1702') {
1318 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1320 prepareSDNCRollbackRequest(execution)
1323 Map<String, String> rollbackData = new HashMap<String, String>();
1324 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1325 if (rollbackSDNCRequest != null) {
1326 if (rollbackSDNCRequest != "") {
1327 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1330 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1331 if (rollbackNetworkRequest != null) {
1332 if (rollbackNetworkRequest != "") {
1333 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1336 execution.setVariable("rollbackData", rollbackData)
1338 utils.log("DEBUG", "** 'rollbackData' for Full Rollback : " + rollbackData, isDebugEnabled)
1339 execution.setVariable("WorkflowException", null)
1342 } catch (Exception ex) {
1343 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1344 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1345 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1351 public void setExceptionFlag(Execution execution){
1352 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1353 execution.setVariable("prefix",Prefix)
1355 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1359 execution.setVariable(Prefix + "isException", true)
1361 if (execution.getVariable("SavedWorkflowException1") != null) {
1362 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1364 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1366 utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1368 } catch(Exception ex){
1369 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1370 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1371 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1377 // *******************************
1378 // Build Error Section
1379 // *******************************
1381 public void processJavaException(Execution execution){
1382 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1383 execution.setVariable("prefix",Prefix)
1385 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
1386 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1387 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1388 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1389 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1391 }catch(Exception e){
1392 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1393 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
1394 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1396 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)