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)
370 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
371 AaiUtil aaiUriUtil = new AaiUtil(this)
372 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
373 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
374 utils.logAudit(queryIdAAIRequest)
375 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
376 utils.log("DEBUG", Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest, isDebugEnabled)
378 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
379 String returnCode = response.getStatusCode()
380 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
381 utils.log("DEBUG", " ***** AAI Response Code : " + returnCode, isDebugEnabled)
383 String aaiResponseAsString = response.getResponseBodyAsString()
385 if (returnCode=='200') {
386 utils.logAudit(aaiResponseAsString)
387 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
388 utils.log("DEBUG", " QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
391 if (returnCode=='404') {
392 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
393 utils.log("DEBUG", " AAI Query Failed. " + dataErrorMessage, isDebugEnabled)
394 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
397 if (aaiResponseAsString.contains("RESTFault")) {
398 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
399 execution.setVariable("WorkflowException", exceptionObject)
400 throw new BpmnError("MSOWorkflowException")
404 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
405 utils.log("DEBUG", "Unexpected Response from QueryAAINetworkId - " + dataErrorMessage, isDebugEnabled)
406 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
412 } catch (BpmnError e) {
415 } catch (Exception ex) {
416 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
417 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
418 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
424 public void callRESTReQueryAAINetworkId(Execution execution) {
425 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
426 execution.setVariable("prefix", Prefix)
428 utils.log("DEBUG", " ***** Inside callRESTReQueryAAINetworkId of DoUpdateNetworkInstance ***** " , isDebugEnabled)
432 String networkRequest = execution.getVariable(Prefix + "networkRequest")
433 String networkId = utils.getNodeText1(networkRequest, "network-id")
434 networkId = UriUtils.encode(networkId,"UTF-8")
437 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
438 AaiUtil aaiUriUtil = new AaiUtil(this)
439 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
440 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
441 utils.logAudit(requeryIdAAIRequest)
442 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
443 utils.log("DEBUG", " UPDNETI_requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest, isDebugEnabled)
445 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
446 String returnCode = response.getStatusCode()
447 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
448 utils.log("DEBUG", " ***** AAI ReQuery Response Code : " + returnCode, isDebugEnabled)
450 String aaiResponseAsString = response.getResponseBodyAsString()
452 if (returnCode=='200') {
453 utils.logAudit(aaiResponseAsString)
454 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
455 utils.log("DEBUG", " ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
457 String netId = utils.getNodeText1(aaiResponseAsString, "network-id")
458 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
459 String networkOutputs =
461 <network-id>${netId}</network-id>
462 <network-name>${netName}</network-name>
463 </network-outputs>"""
464 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
465 utils.log("DEBUG", " networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
468 if (returnCode=='404') {
469 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
470 utils.log("DEBUG", " AAI ReQuery Failed. - " + dataErrorMessage, isDebugEnabled)
471 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
474 if (aaiResponseAsString.contains("RESTFault")) {
475 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
476 execution.setVariable("WorkflowException", exceptionObject)
477 throw new BpmnError("MSOWorkflowException")
481 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
482 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
483 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
489 } catch (BpmnError e) {
492 } catch (Exception ex) {
493 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
494 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
495 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
501 public void callRESTQueryAAINetworkVpnBinding(Execution execution) {
502 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
503 execution.setVariable("prefix", Prefix)
505 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkVpnBinding of DoUpdateNetworkInstance ***** " , isDebugEnabled)
510 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
511 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
512 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
514 // Check if Vnf Binding is present, then build a List of vnfBinding
515 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
516 int vpnCount = vpnBindingUri.size()
517 execution.setVariable(Prefix + "vpnCount", vpnCount)
518 utils.log("DEBUG", " UPDNETI_vpnCount - " + vpnCount, isDebugEnabled)
520 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
521 AaiUtil aaiUriUtil = new AaiUtil(this)
524 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
525 utils.log("DEBUG", " vpnBindingUri List - " + vpnBindingUri, isDebugEnabled)
527 String routeTargets = ""
528 // AII loop call using list vpnBindings
529 for (i in 0..vpnBindingUri.size()-1) {
533 // prepare url using vpnBinding
534 String queryVpnBindingAAIRequest = ""
535 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
537 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
538 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
539 if (aai_uri == null || aai_uri == "") {
540 // using value of 'related-link' from response
541 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
542 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1) + "?depth=all"
544 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i] + "?depth=all"
548 // using uri value in URN mapping
549 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
550 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
551 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
553 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId + "?depth=all"
556 utils.logAudit(queryVpnBindingAAIRequest)
557 execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
558 utils.log("DEBUG", " UPDNETI_queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest, isDebugEnabled)
560 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
561 String returnCode = response.getStatusCode()
562 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
563 utils.log("DEBUG", " ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode, isDebugEnabled)
565 String aaiResponseAsString = response.getResponseBodyAsString()
567 if (returnCode=='200') {
568 utils.logAudit(aaiResponseAsString)
569 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
570 utils.log("DEBUG", " AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
572 String routeTarget = ""
573 if (utils.nodeExists(aaiResponseAsString, "global-route-target")) {
574 routeTarget = utils.getNodeText1(aaiResponseAsString, "global-route-target")
575 routeTargets += "<routeTargets>" + routeTarget + "</routeTargets>" + '\n'
579 if (returnCode=='404') {
580 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
581 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
582 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
585 if (aaiResponseAsString.contains("RESTFault")) {
586 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
587 execution.setVariable("WorkflowException", exceptionObject)
588 throw new BpmnError("MSOWorkflowException")
592 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
593 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
594 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
602 execution.setVariable(Prefix + "routeCollection", routeTargets)
603 utils.log("DEBUG", " UPDNETI_routeCollection - " + '\n' + routeTargets, isDebugEnabled)
606 // reset return code to success
607 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
608 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
609 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
610 String aaiStubResponse =
611 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
612 <vpn-binding xmlns="${schemaVersion}">
613 <global-route-target/>
616 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
617 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
618 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
619 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
623 } catch (BpmnError e) {
626 } catch (Exception ex) {
627 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
628 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
629 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
635 public void callRESTQueryAAINetworkPolicy(Execution execution) {
636 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
637 execution.setVariable("prefix", Prefix)
639 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " , isDebugEnabled)
643 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
644 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
645 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
647 // Check if Network Policy is present, then build a List of network policy
648 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
649 int networkPolicyCount = networkPolicyUriList.size()
650 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
651 utils.log("DEBUG", " UPDNETI_networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
653 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
654 AaiUtil aaiUriUtil = new AaiUtil(this)
656 if (networkPolicyCount > 0) {
657 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
658 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
660 String networkPolicies = ""
661 // AII loop call using list vpnBindings
662 for (i in 0..networkPolicyUriList.size()-1) {
666 // prepare url using vpnBinding
667 String queryNetworkPolicyAAIRequest = ""
669 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
671 // Note: By default, the network policy url is found in 'related-link' of the response,
672 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
673 if (aai_uri == null || aai_uri == "") {
674 // using value of 'related-link' from response
675 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
676 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1) + "?depth=all"
678 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i] + "?depth=all"
681 // using uri value in URN mapping
682 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
683 println " networkPolicyId - " + networkPolicyId
684 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
685 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
687 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId + "?depth=all"
692 utils.logAudit(queryNetworkPolicyAAIRequest)
693 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
694 utils.log("DEBUG", " UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
696 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
697 String returnCode = response.getStatusCode()
698 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
699 utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
701 String aaiResponseAsString = response.getResponseBodyAsString()
703 if (returnCode=='200') {
704 utils.logAudit(aaiResponseAsString)
705 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
706 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
708 String networkPolicy = ""
709 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
710 networkPolicy = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
711 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
715 if (returnCode=='404') {
716 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
717 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
718 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
721 if (aaiResponseAsString.contains("RESTFault")) {
722 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
723 execution.setVariable("WorkflowException", exceptionObject)
724 throw new BpmnError("MSOWorkflowException")
728 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
729 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
730 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
738 execution.setVariable(Prefix + "networkCollection", networkPolicies)
739 utils.log("DEBUG", " UPDNETI_networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
742 // reset return code to success
743 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
744 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
745 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
746 String aaiStubResponse =
747 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
748 <network-policy xmlns="${schemaVersion}">
749 <network-policy-fqdn/>
752 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
753 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
754 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
755 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
759 } catch (BpmnError e) {
762 } catch (Exception ex) {
763 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
764 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
765 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
771 public void callRESTQueryAAINetworkTableRef(Execution execution) {
772 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
773 execution.setVariable("prefix", Prefix)
775 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " , isDebugEnabled)
779 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
780 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
781 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
783 // Check if Network TableREf is present, then build a List of network policy
784 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
785 int networkTableRefCount = networkTableRefUriList.size()
786 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
787 utils.log("DEBUG", " UPDNETI_networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
789 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
790 AaiUtil aaiUriUtil = new AaiUtil(this)
792 if (networkTableRefCount > 0) {
793 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
794 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
796 // AII loop call using list vpnBindings
797 String networkTableRefs = ""
798 for (i in 0..networkTableRefUriList.size()-1) {
802 // prepare url using tableRef
803 String queryNetworkTableRefAAIRequest = ""
805 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
807 // Note: By default, the network policy url is found in 'related-link' of the response,
808 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
809 if (aai_uri == null || aai_uri == "") {
810 // using value of 'related-link' from response
811 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
812 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1) + "?depth=all"
814 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i] + "?depth=all"
817 // using uri value in URN mapping
818 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
820 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
821 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
823 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId + "?depth=all"
828 utils.logAudit(queryNetworkTableRefAAIRequest)
829 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
830 utils.log("DEBUG", " UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
832 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
833 String returnCode = response.getStatusCode()
834 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
835 utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
837 String aaiResponseAsString = response.getResponseBodyAsString()
839 if (returnCode=='200') {
840 utils.logAudit(aaiResponseAsString)
841 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
842 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
844 String networkTableRef = ""
845 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
846 networkTableRef = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
847 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
851 if (returnCode=='404') {
852 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
853 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
854 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
857 if (aaiResponseAsString.contains("RESTFault")) {
858 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
859 execution.setVariable("WorkflowException", exceptionObject)
860 throw new BpmnError("MSOWorkflowException")
864 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
865 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
866 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
874 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
875 utils.log("DEBUG", " UPDNETI_tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
878 // reset return code to success
879 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
880 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
881 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
882 String aaiStubResponse =
883 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
884 <route-table-references xmlns="${schemaVersion}">
885 <route-table-reference-fqdn/>
886 </route-table-references>
888 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
889 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
890 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
891 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
895 } catch (BpmnError e) {
898 } catch (Exception ex) {
899 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
900 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
901 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
907 public void callRESTUpdateContrailAAINetwork(Execution execution) {
908 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
909 execution.setVariable("prefix", Prefix)
911 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " , isDebugEnabled)
915 String networkRequest = execution.getVariable(Prefix + "networkRequest")
916 String networkId = utils.getNodeText1(networkRequest, "network-id")
917 networkId = UriUtils.encode(networkId,"UTF-8")
918 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
919 String updateNetworkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
922 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
923 AaiUtil aaiUriUtil = new AaiUtil(this)
924 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
925 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
927 utils.logAudit(updateContrailAAIUrlRequest)
928 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
929 utils.log("DEBUG", " UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
931 //Prepare payload (PUT)
932 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
933 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
934 String payloadXml = utils.formatXml(payload)
935 utils.logAudit(payloadXml)
936 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
937 utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
939 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
940 String returnCode = response.getStatusCode()
941 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
943 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
944 utils.log("DEBUG", " ***** AAI Update Contrail Response Code : " + returnCode, isDebugEnabled)
947 if (returnCode=='200') {
948 utils.logAudit(aaiUpdateContrailResponseAsString)
949 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
950 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
951 // Point-of-no-return is set to false, rollback not needed.
952 execution.setVariable(Prefix + "isPONR", true)
955 if (returnCode=='404') {
956 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
957 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
958 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
961 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
962 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
963 execution.setVariable("WorkflowException", exceptionObject)
964 throw new BpmnError("MSOWorkflowException")
968 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
969 utils.log("DEBUG", errorMessage, isDebugEnabled)
970 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
975 } catch (BpmnError e) {
978 } catch (Exception ex) {
979 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
980 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
981 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
987 public void prepareUpdateNetworkRequest (Execution execution) {
988 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
989 execution.setVariable("prefix", Prefix)
991 utils.log("DEBUG", " ***** Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
996 String requestId = execution.getVariable(Prefix + "requestId")
997 String messageId = execution.getVariable(Prefix + "messageId")
998 String source = execution.getVariable(Prefix + "source")
1000 String requestInput = execution.getVariable(Prefix + "networkRequest")
1001 String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1002 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1003 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1005 // Prepare Network request
1006 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1007 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1008 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1009 String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1011 String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
1012 buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1013 utils.logAudit(buildUpdateNetworkRequestAsString)
1015 execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
1016 utils.log("DEBUG", " UPDNETI_updateNetworkRequest - " + "\n" + buildUpdateNetworkRequestAsString, isDebugEnabled)
1018 } catch (Exception ex) {
1019 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
1020 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1021 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1027 public void prepareSDNCRequest (Execution execution) {
1028 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1029 execution.setVariable("prefix", Prefix)
1031 utils.log("DEBUG", " ***** Inside prepareSDNCRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1035 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1036 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1037 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1039 String networkId = ""
1040 if (utils.nodeExists(updateNetworkInput, "network-id")) {
1041 networkId = utils.getNodeText1(updateNetworkInput, "network-id")
1043 if (networkId == null) {networkId = ""}
1045 String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1047 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1048 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1050 String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1051 utils.logAudit(sndcTopologyUpdateRequesAsString)
1052 execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1053 utils.log("DEBUG", " UPDNETI_changeAssignSDNCRequest - " + "\n" + sndcTopologyUpdateRequesAsString, isDebugEnabled)
1056 } catch (Exception ex) {
1057 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1058 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1059 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1068 // **************************************************
1069 // Post or Validate Response Section
1070 // **************************************************
1072 public void validateUpdateNetworkResponse (Execution execution) {
1073 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1074 execution.setVariable("prefix", Prefix)
1076 utils.log("DEBUG", " ***** Inside validateUpdateNetworkResponse of DoUpdateNetworkInstance *****", isDebugEnabled)
1079 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1080 String networkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
1081 if (networkResponse==null) {
1082 networkResponse="" // reset
1085 utils.log("DEBUG", " Network Adapter update responseCode: " + returnCode, isDebugEnabled)
1087 String errorMessage = ""
1088 if (returnCode == "200") {
1089 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1090 utils.logAudit(networkResponse)
1091 execution.setVariable(Prefix + "updateNetworkResponse", networkResponse)
1092 utils.log("DEBUG", " Network Adapter update Success Response - " + "\n" + networkResponse, isDebugEnabled)
1094 // prepare rollback data
1095 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1096 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1097 String rollbackNetwork =
1098 """<rollbackNetworkRequest>
1100 </rollbackNetworkRequest>"""
1101 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1102 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1103 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1105 } else { // network error
1106 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1107 if (networkResponse.contains("updateNetworkError")) {
1108 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1109 errorMessage = utils.getNodeText1(networkResponse, "message")
1110 errorMessage = "Received error from Network Adapter: " + errorMessage
1111 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1113 } else { // CatchAll exception
1114 if (returnCode == "500") {
1115 errorMessage = "JBWEB000065: HTTP Status 500."
1117 errorMessage = "Return code is " + returnCode
1119 errorMessage = "Received error from Network Adapter: " + errorMessage
1120 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1124 } else { // CatchAll exception
1125 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1126 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1132 } catch (BpmnError e) {
1135 } catch (Exception ex) {
1136 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1137 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1138 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1145 public void validateSDNCResponse (Execution execution) {
1146 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1147 execution.setVariable("prefix", Prefix)
1149 utils.log("DEBUG", " ***** Inside validateSDNCResponse of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1151 String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1152 WorkflowException workflowException = null
1154 workflowException = execution.getVariable(Prefix + "WorkflowException")
1155 //execution.setVariable("WorkflowException", workflowException)
1156 } catch (Exception ex) {
1157 utils.log("DEBUG", " Sdnc 'WorkflowException' object is empty or null. ", isDebugEnabled)
1160 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1162 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1163 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1165 String changeAssignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "changeAssignSDNCResponse"))
1166 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1167 execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1169 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, prefix+'sdncResponseSuccess'
1170 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1171 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1174 utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1175 throw new BpmnError("MSOWorkflowException")
1181 public void postProcessResponse (Execution execution) {
1182 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1183 execution.setVariable("prefix", Prefix)
1185 utils.log("DEBUG", " ***** Inside postProcessResponse of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1188 utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
1189 if (execution.getVariable(Prefix + "isException") == false) {
1190 // set rollback data
1191 execution.setVariable("orchestrationStatus", "")
1192 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1193 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1194 prepareSuccessRollbackData(execution) // populate rollbackData
1195 execution.setVariable("WorkflowException", null)
1196 execution.setVariable(Prefix + "Success", true)
1197 utils.log("DEBUG", " ***** postProcessResponse(), GOOD !!!", isDebugEnabled)
1199 execution.setVariable(Prefix + "Success", false)
1200 execution.setVariable("rollbackData", null)
1201 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1202 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1203 utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
1204 WorkflowException wfex = execution.getVariable("workflowException")
1205 exceptionMessage = wfex.getErrorMessage()
1207 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1208 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1209 exceptionMessage = pwfex.getErrorMessage()
1212 // going to the Main flow: a-la-carte or macro
1213 utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
1214 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1215 throw new BpmnError("MSOWorkflowException")
1218 } catch(BpmnError b){
1219 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
1223 } catch (Exception ex) {
1224 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1225 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1226 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1233 public void prepareSDNCRollbackRequest (Execution execution) {
1234 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1235 execution.setVariable("prefix", Prefix)
1237 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1240 // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException.
1241 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1243 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1244 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1245 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1246 String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1247 String networkId = utils.getNodeText1(changeAssignSDNCResponse, "network-id")
1249 String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1251 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1252 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1253 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1254 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1255 utils.log("DEBUG", " Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" + sndcTopologyRollbackRequestAsString, isDebugEnabled)
1258 } catch (Exception ex) {
1259 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1260 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1261 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1267 public void prepareRollbackData(Execution execution) {
1268 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1269 execution.setVariable("prefix",Prefix)
1271 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1275 Map<String, String> rollbackData = new HashMap<String, String>();
1276 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1277 if (rollbackSDNCRequest != null) {
1278 if (rollbackSDNCRequest != "") {
1279 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1282 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1283 if (rollbackNetworkRequest != null) {
1284 if (rollbackNetworkRequest != "") {
1285 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1288 execution.setVariable("rollbackData", rollbackData)
1289 utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
1291 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1292 utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
1294 } catch (Exception ex) {
1295 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1296 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1297 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1303 public void prepareSuccessRollbackData(Execution execution) {
1304 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1305 execution.setVariable("prefix",Prefix)
1307 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1311 if (execution.getVariable("sdncVersion") != '1610') {
1312 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1314 prepareSDNCRollbackRequest(execution)
1317 Map<String, String> rollbackData = new HashMap<String, String>();
1318 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1319 if (rollbackSDNCRequest != null) {
1320 if (rollbackSDNCRequest != "") {
1321 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1324 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1325 if (rollbackNetworkRequest != null) {
1326 if (rollbackNetworkRequest != "") {
1327 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1330 execution.setVariable("rollbackData", rollbackData)
1332 utils.log("DEBUG", "** 'rollbackData' for Full Rollback : " + rollbackData, isDebugEnabled)
1333 execution.setVariable("WorkflowException", null)
1336 } catch (Exception ex) {
1337 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1338 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1339 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1345 public void setExceptionFlag(Execution execution){
1346 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1347 execution.setVariable("prefix",Prefix)
1349 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1353 execution.setVariable(Prefix + "isException", true)
1355 if (execution.getVariable("SavedWorkflowException1") != null) {
1356 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1358 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1360 utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1362 } catch(Exception ex){
1363 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1364 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1365 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1371 // *******************************
1372 // Build Error Section
1373 // *******************************
1375 public void processJavaException(Execution execution){
1376 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1377 execution.setVariable("prefix",Prefix)
1379 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
1380 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1381 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1382 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1383 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1385 }catch(Exception e){
1386 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1387 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
1388 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1390 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)