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.delegate.DelegateExecution
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(DelegateExecution 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 (DelegateExecution 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 (DelegateExecution 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(DelegateExecution 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=all"
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(DelegateExecution 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=all"
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(DelegateExecution 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 String routeRole = ""
574 if (utils.nodeExists(aaiResponseAsString, "route-targets")) {
575 String aaiRouteTargets = utils.getNodeXml(aaiResponseAsString, "route-targets", false)
576 def aaiRouteTargetsXml = new XmlSlurper().parseText(aaiRouteTargets)
577 def aaiRouteTarget = aaiRouteTargetsXml.'**'.findAll {it.name() == "route-target"}
578 for (j in 0..aaiRouteTarget.size()-1) {
579 routeTarget = utils.getNodeText1(XmlUtil.serialize(aaiRouteTarget[j]), "global-route-target")
580 routeRole = utils.getNodeText1(XmlUtil.serialize(aaiRouteTarget[j]), "route-target-role")
581 routeTargets += "<routeTargets>" + '\n' +
582 " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
583 " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
584 "</routeTargets>" + '\n'
589 if (returnCode=='404') {
590 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
591 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
592 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
595 if (aaiResponseAsString.contains("RESTFault")) {
596 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
597 execution.setVariable("WorkflowException", exceptionObject)
598 throw new BpmnError("MSOWorkflowException")
602 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
603 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
604 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
612 execution.setVariable(Prefix + "routeCollection", routeTargets)
613 utils.log("DEBUG", " UPDNETI_routeCollection - " + '\n' + routeTargets, isDebugEnabled)
616 // reset return code to success
617 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
618 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
619 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
620 String aaiStubResponse =
621 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
622 <vpn-binding xmlns="${schemaVersion}">
623 <global-route-target/>
626 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
627 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
628 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
629 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
633 } catch (BpmnError e) {
636 } catch (Exception ex) {
637 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
638 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
639 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
645 public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
646 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
647 execution.setVariable("prefix", Prefix)
649 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " , isDebugEnabled)
653 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
654 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
655 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
657 // Check if Network Policy is present, then build a List of network policy
658 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
659 int networkPolicyCount = networkPolicyUriList.size()
660 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
661 utils.log("DEBUG", " UPDNETI_networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
663 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
664 AaiUtil aaiUriUtil = new AaiUtil(this)
666 if (networkPolicyCount > 0) {
667 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
668 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
670 String networkPolicies = ""
671 // AII loop call using list vpnBindings
672 for (i in 0..networkPolicyUriList.size()-1) {
676 // prepare url using vpnBinding
677 String queryNetworkPolicyAAIRequest = ""
679 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
681 // Note: By default, the network policy url is found in 'related-link' of the response,
682 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
683 if (aai_uri == null || aai_uri == "") {
684 // using value of 'related-link' from response
685 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
686 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1) + "?depth=all"
688 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i] + "?depth=all"
691 // using uri value in URN mapping
692 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
693 println " networkPolicyId - " + networkPolicyId
694 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
695 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
697 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId + "?depth=all"
702 utils.logAudit(queryNetworkPolicyAAIRequest)
703 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
704 utils.log("DEBUG", " UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
706 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
707 String returnCode = response.getStatusCode()
708 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
709 utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
711 String aaiResponseAsString = response.getResponseBodyAsString()
713 if (returnCode=='200') {
714 utils.logAudit(aaiResponseAsString)
715 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
716 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
718 String networkPolicy = ""
719 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
720 networkPolicy = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
721 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
725 if (returnCode=='404') {
726 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
727 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
728 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
731 if (aaiResponseAsString.contains("RESTFault")) {
732 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
733 execution.setVariable("WorkflowException", exceptionObject)
734 throw new BpmnError("MSOWorkflowException")
738 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
739 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
740 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
748 execution.setVariable(Prefix + "networkCollection", networkPolicies)
749 utils.log("DEBUG", " UPDNETI_networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
752 // reset return code to success
753 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
754 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
755 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
756 String aaiStubResponse =
757 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
758 <network-policy xmlns="${schemaVersion}">
759 <network-policy-fqdn/>
762 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
763 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
764 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
765 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
769 } catch (BpmnError e) {
772 } catch (Exception ex) {
773 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
774 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
775 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
781 public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
782 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
783 execution.setVariable("prefix", Prefix)
785 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " , isDebugEnabled)
789 String queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
790 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
791 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
793 // Check if Network TableREf is present, then build a List of network policy
794 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
795 int networkTableRefCount = networkTableRefUriList.size()
796 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
797 utils.log("DEBUG", " UPDNETI_networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
799 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
800 AaiUtil aaiUriUtil = new AaiUtil(this)
802 if (networkTableRefCount > 0) {
803 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
804 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
806 // AII loop call using list vpnBindings
807 String networkTableRefs = ""
808 for (i in 0..networkTableRefUriList.size()-1) {
812 // prepare url using tableRef
813 String queryNetworkTableRefAAIRequest = ""
815 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
817 // Note: By default, the network policy url is found in 'related-link' of the response,
818 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
819 if (aai_uri == null || aai_uri == "") {
820 // using value of 'related-link' from response
821 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
822 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1) + "?depth=all"
824 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i] + "?depth=all"
827 // using uri value in URN mapping
828 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
830 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
831 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
833 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId + "?depth=all"
838 utils.logAudit(queryNetworkTableRefAAIRequest)
839 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
840 utils.log("DEBUG", " UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
842 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
843 String returnCode = response.getStatusCode()
844 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
845 utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
847 String aaiResponseAsString = response.getResponseBodyAsString()
849 if (returnCode=='200') {
850 utils.logAudit(aaiResponseAsString)
851 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
852 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
854 String networkTableRef = ""
855 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
856 networkTableRef = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
857 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
861 if (returnCode=='404') {
862 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
863 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
864 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
867 if (aaiResponseAsString.contains("RESTFault")) {
868 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
869 execution.setVariable("WorkflowException", exceptionObject)
870 throw new BpmnError("MSOWorkflowException")
874 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
875 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
876 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
884 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
885 utils.log("DEBUG", " UPDNETI_tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
888 // reset return code to success
889 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
890 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
891 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
892 String aaiStubResponse =
893 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
894 <route-table-references xmlns="${schemaVersion}">
895 <route-table-reference-fqdn/>
896 </route-table-references>
898 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
899 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
900 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
901 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
905 } catch (BpmnError e) {
908 } catch (Exception ex) {
909 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
910 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
911 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
917 public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
918 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
919 execution.setVariable("prefix", Prefix)
921 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " , isDebugEnabled)
925 String networkRequest = execution.getVariable(Prefix + "networkRequest")
926 String networkId = utils.getNodeText1(networkRequest, "network-id")
927 networkId = UriUtils.encode(networkId,"UTF-8")
928 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
929 String updateNetworkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
932 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
933 AaiUtil aaiUriUtil = new AaiUtil(this)
934 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
935 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
937 utils.logAudit(updateContrailAAIUrlRequest)
938 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
939 utils.log("DEBUG", " UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
941 //Prepare payload (PUT)
942 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
943 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
944 String payloadXml = utils.formatXml(payload)
945 utils.logAudit(payloadXml)
946 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
947 utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
949 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
950 String returnCode = response.getStatusCode()
951 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
953 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
954 utils.log("DEBUG", " ***** AAI Update Contrail Response Code : " + returnCode, isDebugEnabled)
957 if (returnCode=='200') {
958 utils.logAudit(aaiUpdateContrailResponseAsString)
959 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
960 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
961 // Point-of-no-return is set to false, rollback not needed.
962 execution.setVariable(Prefix + "isPONR", true)
965 if (returnCode=='404') {
966 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
967 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
968 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
971 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
972 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
973 execution.setVariable("WorkflowException", exceptionObject)
974 throw new BpmnError("MSOWorkflowException")
978 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
979 utils.log("DEBUG", errorMessage, isDebugEnabled)
980 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
985 } catch (BpmnError e) {
988 } catch (Exception ex) {
989 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
990 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
991 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
997 public void prepareUpdateNetworkRequest (DelegateExecution execution) {
998 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
999 execution.setVariable("prefix", Prefix)
1001 utils.log("DEBUG", " ***** Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1006 String requestId = execution.getVariable(Prefix + "requestId")
1007 String messageId = execution.getVariable(Prefix + "messageId")
1008 String source = execution.getVariable(Prefix + "source")
1010 String requestInput = execution.getVariable(Prefix + "networkRequest")
1011 String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1012 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1013 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1015 // Prepare Network request
1016 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1017 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1018 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1019 String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1021 String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
1022 buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1023 utils.logAudit(buildUpdateNetworkRequestAsString)
1025 execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
1026 utils.log("DEBUG", " UPDNETI_updateNetworkRequest - " + "\n" + buildUpdateNetworkRequestAsString, isDebugEnabled)
1028 } catch (Exception ex) {
1029 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
1030 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1031 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1037 public void prepareSDNCRequest (DelegateExecution execution) {
1038 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1039 execution.setVariable("prefix", Prefix)
1041 utils.log("DEBUG", " ***** Inside prepareSDNCRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1045 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1046 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1047 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1049 String networkId = ""
1050 if (utils.nodeExists(updateNetworkInput, "network-id")) {
1051 networkId = utils.getNodeText1(updateNetworkInput, "network-id")
1053 if (networkId == null) {networkId = ""}
1055 String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1057 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1058 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1060 String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1061 utils.logAudit(sndcTopologyUpdateRequesAsString)
1062 execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1063 utils.log("DEBUG", " UPDNETI_changeAssignSDNCRequest - " + "\n" + sndcTopologyUpdateRequesAsString, isDebugEnabled)
1066 } catch (Exception ex) {
1067 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1068 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1069 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1078 // **************************************************
1079 // Post or Validate Response Section
1080 // **************************************************
1082 public void validateUpdateNetworkResponse (DelegateExecution execution) {
1083 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1084 execution.setVariable("prefix", Prefix)
1086 utils.log("DEBUG", " ***** Inside validateUpdateNetworkResponse of DoUpdateNetworkInstance *****", isDebugEnabled)
1089 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1090 String networkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
1091 if (networkResponse==null) {
1092 networkResponse="" // reset
1095 utils.log("DEBUG", " Network Adapter update responseCode: " + returnCode, isDebugEnabled)
1097 String errorMessage = ""
1098 if (returnCode == "200") {
1099 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1100 utils.logAudit(networkResponse)
1101 execution.setVariable(Prefix + "updateNetworkResponse", networkResponse)
1102 utils.log("DEBUG", " Network Adapter update Success Response - " + "\n" + networkResponse, isDebugEnabled)
1104 // prepare rollback data
1105 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1106 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1107 String rollbackNetwork =
1108 """<rollbackNetworkRequest>
1110 </rollbackNetworkRequest>"""
1111 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1112 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1113 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1115 } else { // network error
1116 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1117 if (networkResponse.contains("updateNetworkError")) {
1118 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1119 errorMessage = utils.getNodeText1(networkResponse, "message")
1120 errorMessage = "Received error from Network Adapter: " + errorMessage
1121 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1123 } else { // CatchAll exception
1124 if (returnCode == "500") {
1125 errorMessage = "JBWEB000065: HTTP Status 500."
1127 errorMessage = "Return code is " + returnCode
1129 errorMessage = "Received error from Network Adapter: " + errorMessage
1130 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1134 } else { // CatchAll exception
1135 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1136 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1142 } catch (BpmnError e) {
1145 } catch (Exception ex) {
1146 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1147 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1148 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1155 public void validateSDNCResponse (DelegateExecution execution) {
1156 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1157 execution.setVariable("prefix", Prefix)
1159 utils.log("DEBUG", " ***** Inside validateSDNCResponse of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1161 String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1162 WorkflowException workflowException = null
1164 workflowException = execution.getVariable(Prefix + "WorkflowException")
1165 //execution.setVariable("WorkflowException", workflowException)
1166 } catch (Exception ex) {
1167 utils.log("DEBUG", " Sdnc 'WorkflowException' object is empty or null. ", isDebugEnabled)
1170 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1172 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1173 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1175 String changeAssignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "changeAssignSDNCResponse"))
1176 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1177 execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1179 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, prefix+'sdncResponseSuccess'
1180 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1181 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1184 utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1185 throw new BpmnError("MSOWorkflowException")
1191 public void postProcessResponse (DelegateExecution execution) {
1192 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1193 execution.setVariable("prefix", Prefix)
1195 utils.log("DEBUG", " ***** Inside postProcessResponse of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1198 utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
1199 if (execution.getVariable(Prefix + "isException") == false) {
1200 // set rollback data
1201 execution.setVariable("orchestrationStatus", "")
1202 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1203 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1204 prepareSuccessRollbackData(execution) // populate rollbackData
1205 execution.setVariable("WorkflowException", null)
1206 execution.setVariable(Prefix + "Success", true)
1207 utils.log("DEBUG", " ***** postProcessResponse(), GOOD !!!", isDebugEnabled)
1209 execution.setVariable(Prefix + "Success", false)
1210 execution.setVariable("rollbackData", null)
1211 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1212 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1213 utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
1214 WorkflowException wfex = execution.getVariable("workflowException")
1215 exceptionMessage = wfex.getErrorMessage()
1217 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1218 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1219 exceptionMessage = pwfex.getErrorMessage()
1222 // going to the Main flow: a-la-carte or macro
1223 utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
1224 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1225 throw new BpmnError("MSOWorkflowException")
1228 } catch(BpmnError b){
1229 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
1233 } catch (Exception ex) {
1234 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1235 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1236 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1243 public void prepareSDNCRollbackRequest (DelegateExecution execution) {
1244 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1245 execution.setVariable("prefix", Prefix)
1247 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1250 // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException.
1251 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1253 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1254 String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1255 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1256 String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1257 String networkId = utils.getNodeText1(changeAssignSDNCResponse, "network-id")
1259 String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1261 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1262 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1263 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1264 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1265 utils.log("DEBUG", " Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" + sndcTopologyRollbackRequestAsString, isDebugEnabled)
1268 } catch (Exception ex) {
1269 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1270 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1271 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1277 public void prepareRollbackData(DelegateExecution execution) {
1278 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1279 execution.setVariable("prefix",Prefix)
1281 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1285 Map<String, String> rollbackData = new HashMap<String, String>();
1286 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1287 if (rollbackSDNCRequest != null) {
1288 if (rollbackSDNCRequest != "") {
1289 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1292 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1293 if (rollbackNetworkRequest != null) {
1294 if (rollbackNetworkRequest != "") {
1295 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1298 execution.setVariable("rollbackData", rollbackData)
1299 utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
1301 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1302 utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
1304 } catch (Exception ex) {
1305 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1306 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1307 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1313 public void prepareSuccessRollbackData(DelegateExecution execution) {
1314 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1315 execution.setVariable("prefix",Prefix)
1317 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1321 if (execution.getVariable("sdncVersion") != '1610') {
1322 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1324 prepareSDNCRollbackRequest(execution)
1327 Map<String, String> rollbackData = new HashMap<String, String>();
1328 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1329 if (rollbackSDNCRequest != null) {
1330 if (rollbackSDNCRequest != "") {
1331 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1334 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1335 if (rollbackNetworkRequest != null) {
1336 if (rollbackNetworkRequest != "") {
1337 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1340 execution.setVariable("rollbackData", rollbackData)
1342 utils.log("DEBUG", "** 'rollbackData' for Full Rollback : " + rollbackData, isDebugEnabled)
1343 execution.setVariable("WorkflowException", null)
1346 } catch (Exception ex) {
1347 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1348 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1349 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1355 public void setExceptionFlag(DelegateExecution execution){
1356 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1357 execution.setVariable("prefix",Prefix)
1359 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1363 execution.setVariable(Prefix + "isException", true)
1365 if (execution.getVariable("SavedWorkflowException1") != null) {
1366 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1368 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1370 utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1372 } catch(Exception ex){
1373 String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1374 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1375 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1381 // *******************************
1382 // Build Error Section
1383 // *******************************
1385 public void processJavaException(DelegateExecution execution){
1386 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1387 execution.setVariable("prefix",Prefix)
1389 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
1390 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1391 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1392 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1393 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1395 }catch(Exception e){
1396 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1397 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
1398 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1400 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)