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.core.json.JsonUtils
25 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
28 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.rest.APIResponse;
33 import org.openecomp.mso.rest.RESTClient
34 import org.openecomp.mso.rest.RESTConfig
36 import java.util.HashMap;
38 import java.util.UUID;
40 import org.camunda.bpm.engine.delegate.BpmnError
41 import org.camunda.bpm.engine.runtime.Execution
42 import org.apache.commons.lang3.*
43 import org.apache.commons.codec.binary.Base64;
44 import org.springframework.web.util.UriUtils
47 * This groovy class supports the <class>DoCreateNetworkInstance.bpmn</class> process.
50 public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor {
51 String Prefix="CRENWKI_"
52 ExceptionUtil exceptionUtil = new ExceptionUtil()
53 JsonUtils jsonUtil = new JsonUtils()
54 VidUtils vidUtils = new VidUtils(this)
55 NetworkUtils networkUtils = new NetworkUtils()
56 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
58 def className = getClass().getSimpleName()
61 * This method is executed during the preProcessRequest task of the <class>DoCreateNetworkInstance.bpmn</class> process.
64 public InitializeProcessVariables(Execution execution){
65 /* Initialize all the process variables in this block */
67 execution.setVariable(Prefix + "networkRequest", "")
68 execution.setVariable(Prefix + "rollbackEnabled", null)
69 execution.setVariable(Prefix + "networkInputs", "")
70 //execution.setVariable(Prefix + "requestId", "")
71 execution.setVariable(Prefix + "messageId", "")
72 execution.setVariable(Prefix + "source", "")
73 execution.setVariable("BasicAuthHeaderValuePO", "")
74 execution.setVariable("BasicAuthHeaderValueSDNC", "")
75 execution.setVariable(Prefix + "serviceInstanceId","")
76 execution.setVariable("GENGS_type", "")
77 execution.setVariable(Prefix + "rsrc_endpoint", null)
78 execution.setVariable(Prefix + "networkOutputs", "")
79 execution.setVariable(Prefix + "networkId","")
80 execution.setVariable(Prefix + "networkName","")
83 execution.setVariable(Prefix + "queryNameAAIRequest","")
84 execution.setVariable(Prefix + "queryNameAAIResponse", "")
85 execution.setVariable(Prefix + "aaiNameReturnCode", "")
86 execution.setVariable(Prefix + "isAAIqueryNameGood", false)
88 // AAI query Cloud Region
89 execution.setVariable(Prefix + "queryCloudRegionRequest","")
90 execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
91 execution.setVariable(Prefix + "queryCloudRegionResponse","")
92 execution.setVariable(Prefix + "cloudRegionPo","")
93 execution.setVariable(Prefix + "cloudRegionSdnc","")
94 execution.setVariable(Prefix + "isCloudRegionGood", false)
97 execution.setVariable(Prefix + "queryIdAAIRequest","")
98 execution.setVariable(Prefix + "queryIdAAIResponse", "")
99 execution.setVariable(Prefix + "aaiIdReturnCode", "")
101 // AAI query vpn binding
102 execution.setVariable(Prefix + "queryVpnBindingAAIRequest","")
103 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", "")
104 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "")
105 execution.setVariable(Prefix + "vpnBindings", null)
106 execution.setVariable(Prefix + "vpnCount", 0)
107 execution.setVariable(Prefix + "routeCollection", "")
109 // AAI query network policy
110 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest","")
111 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", "")
112 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "")
113 execution.setVariable(Prefix + "networkPolicyUriList", null)
114 execution.setVariable(Prefix + "networkPolicyCount", 0)
115 execution.setVariable(Prefix + "networkCollection", "")
117 // AAI query route table reference
118 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest","")
119 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", "")
120 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "")
121 execution.setVariable(Prefix + "networkTableRefUriList", null)
122 execution.setVariable(Prefix + "networkTableRefCount", 0)
123 execution.setVariable(Prefix + "tableRefCollection", "")
126 execution.setVariable(Prefix + "requeryIdAAIRequest","")
127 execution.setVariable(Prefix + "requeryIdAAIResponse", "")
128 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
130 // AAI update contrail
131 execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
132 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
133 execution.setVariable(Prefix + "updateContrailAAIResponse", "")
134 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
136 execution.setVariable(Prefix + "createNetworkRequest", "")
137 execution.setVariable(Prefix + "createNetworkResponse", "")
138 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
139 //execution.setVariable(Prefix + "rollbackNetworkResponse", "")
140 execution.setVariable(Prefix + "networkReturnCode", "")
141 //execution.setVariable(Prefix + "rollbackNetworkReturnCode", "")
142 execution.setVariable(Prefix + "isNetworkRollbackNeeded", false)
144 execution.setVariable(Prefix + "assignSDNCRequest", "")
145 execution.setVariable(Prefix + "assignSDNCResponse", "")
146 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
147 //execution.setVariable(Prefix + "rollbackSDNCResponse", "")
148 execution.setVariable(Prefix + "sdncReturnCode", "")
149 //execution.setVariable(Prefix + "rollbackSDNCReturnCode", "")
150 execution.setVariable(Prefix + "isSdncRollbackNeeded", false)
151 execution.setVariable(Prefix + "sdncResponseSuccess", false)
153 execution.setVariable(Prefix + "activateSDNCRequest", "")
154 execution.setVariable(Prefix + "activateSDNCResponse", "")
155 execution.setVariable(Prefix + "rollbackActivateSDNCRequest", "")
156 //execution.setVariable(Prefix + "rollbackActivateSDNCResponse", "")
157 execution.setVariable(Prefix + "sdncActivateReturnCode", "")
158 //execution.setVariable(Prefix + "rollbackActivateSDNCReturnCode", "")
159 execution.setVariable(Prefix + "isSdncActivateRollbackNeeded", false)
160 execution.setVariable(Prefix + "sdncActivateResponseSuccess", false)
162 execution.setVariable(Prefix + "orchestrationStatus", "")
163 execution.setVariable(Prefix + "isVnfBindingPresent", false)
164 execution.setVariable(Prefix + "Success", false)
166 execution.setVariable(Prefix + "isException", false)
170 // **************************************************
171 // Pre or Prepare Request Section
172 // **************************************************
174 * This method is executed during the preProcessRequest task of the <class>DoCreateNetworkInstance.bpmn</class> process.
177 public void preProcessRequest (Execution execution) {
178 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
179 execution.setVariable("prefix",Prefix)
181 utils.log("DEBUG", " ***** Inside preProcessRequest() of " + className + ".groovy ***** ", isDebugEnabled)
184 // initialize flow variables
185 InitializeProcessVariables(execution)
187 // GET Incoming request & validate 3 kinds of format.
188 execution.setVariable("action", "CREATE")
189 String networkRequest = execution.getVariable("bpmnRequest")
190 if (networkRequest != null) {
191 if (networkRequest.contains("requestDetails")) {
192 // JSON format request is sent, create xml
194 def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
195 utils.log("DEBUG", " Incoming message formatted . . . : " + '\n' + prettyJson, isDebugEnabled)
196 networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
198 } catch (Exception ex) {
199 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
200 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
201 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
204 // XML format request is sent
208 // vIPR format request is sent, create xml from individual variables
209 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
212 networkRequest = utils.formatXml(networkRequest)
213 utils.logAudit(networkRequest)
214 execution.setVariable(Prefix + "networkRequest", networkRequest)
215 utils.log("DEBUG", Prefix + "networkRequest - " + '\n' + networkRequest, isDebugEnabled)
217 // validate 'backout-on-failure' to override 'URN_mso_rollback'
218 boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
219 execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
220 utils.log("DEBUG", Prefix + "rollbackEnabled - " + rollbackEnabled, isDebugEnabled)
222 String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
223 execution.setVariable(Prefix + "networkInputs", networkInputs)
224 utils.log("DEBUG", Prefix + "networkInputs - " + '\n' + networkInputs, isDebugEnabled)
227 String messageId = execution.getVariable("testMessageId") // for testing
228 if (messageId == null || messageId == "") {
229 messageId = UUID.randomUUID()
230 utils.log("DEBUG", Prefix + "messageId, random generated: " + messageId, isDebugEnabled)
232 utils.log("DEBUG", Prefix + "messageId, pre-assigned: " + messageId, isDebugEnabled)
234 execution.setVariable(Prefix + "messageId", messageId)
236 String source = utils.getNodeText1(networkRequest, "source")
237 execution.setVariable(Prefix + "source", source)
238 utils.log("DEBUG", Prefix + "source - " + source, isDebugEnabled)
240 // validate cloud region
241 String lcpCloudRegionId = utils.getNodeText1(networkRequest, "aic-cloud-region")
242 if ((lcpCloudRegionId == null) || (lcpCloudRegionId == "") || (lcpCloudRegionId == "null")) {
243 String dataErrorMessage = "Missing value/element: 'lcpCloudRegionId' or 'cloudConfiguration' or 'aic-cloud-region'."
244 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
245 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
248 // validate service instance id
249 String serviceInstanceId = utils.getNodeText1(networkRequest, "service-instance-id")
250 if ((serviceInstanceId == null) || (serviceInstanceId == "") || (serviceInstanceId == "null")) {
251 String dataErrorMessage = "Missing value/element: 'serviceInstanceId'."
252 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
253 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
256 // PO Authorization Info / headers Authorization=
257 String basicAuthValuePO = execution.getVariable("URN_mso_adapters_po_auth")
258 utils.log("DEBUG", " Obtained BasicAuth userid password for PO/SDNC adapter: " + basicAuthValuePO, isDebugEnabled)
260 def encodedString = utils.getBasicAuth(basicAuthValuePO, execution.getVariable("URN_mso_msoKey"))
261 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
262 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
264 } catch (IOException ex) {
265 String exceptionMessage = "Exception Encountered in DoCreateNetworkInstance, PreProcessRequest() - "
266 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
267 utils.log("DEBUG", dataErrorMessage, , isDebugEnabled)
268 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
271 // Set variables for Generic Get Sub Flow use
272 execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
273 utils.log("DEBUG", Prefix + "serviceInstanceId - " + serviceInstanceId, isDebugEnabled)
275 execution.setVariable("GENGS_type", "service-instance")
276 utils.log("DEBUG", "GENGS_type - " + "service-instance", isDebugEnabled)
277 utils.log("DEBUG", " Url for SDNC adapter: " + execution.getVariable("URN_mso_adapters_sdnc_endpoint"), isDebugEnabled)
279 String sdncVersion = execution.getVariable("sdncVersion")
280 utils.log("DEBUG", "sdncVersion? : " + sdncVersion, isDebugEnabled)
282 // build 'networkOutputs'
283 String networkId = utils.getNodeText1(networkRequest, "network-id")
284 if ((networkId == null) || (networkId == "null")) {
287 String networkName = utils.getNodeText1(networkRequest, "network-name")
288 if ((networkName == null) || (networkName == "null")) {
291 String networkOutputs =
293 <network-id>${networkId}</network-id>
294 <network-name>${networkName}</network-name>
295 </network-outputs>"""
296 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
297 utils.log("DEBUG", Prefix + "networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
298 execution.setVariable(Prefix + "networkId", networkId)
299 execution.setVariable(Prefix + "networkName", networkName)
301 } catch (BpmnError e) {
304 } catch (Exception ex) {
305 sendSyncError(execution)
307 String exceptionMessage = "Exception Encountered in PreProcessRequest() of " + className + ".groovy ***** : " + ex.getMessage()
308 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
309 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
315 public void callRESTQueryAAINetworkName (Execution execution) {
316 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
317 execution.setVariable("prefix",Prefix)
319 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkName() of DoCreateNetworkInstance ***** " , isDebugEnabled)
322 String networkInputs = execution.getVariable(Prefix + "networkInputs")
323 String networkName = utils.getNodeText1(networkInputs, "network-name")
324 networkName = UriUtils.encode(networkName,"UTF-8")
326 // Prepare AA&I url with network-name
327 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
328 AaiUtil aaiUriUtil = new AaiUtil(this)
329 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
330 String queryAAINameRequest = "${aai_endpoint}${aai_uri}" + "?network-name=" + networkName
331 utils.logAudit(queryAAINameRequest)
332 execution.setVariable(Prefix + "queryNameAAIRequest", queryAAINameRequest)
333 utils.log("DEBUG", Prefix + "queryNameAAIRequest - " + "\n" + queryAAINameRequest, isDebugEnabled)
336 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryAAINameRequest)
337 String returnCode = response.getStatusCode()
338 execution.setVariable(Prefix + "aaiNameReturnCode", returnCode)
339 utils.log("DEBUG", " ***** AAI Query Name Response Code : " + returnCode, isDebugEnabled)
341 String aaiResponseAsString = response.getResponseBodyAsString()
342 utils.log("DEBUG", " ***** AAI Query Name Response : " +'\n'+ aaiResponseAsString, isDebugEnabled)
344 if (returnCode=='200') {
345 utils.logAudit(aaiResponseAsString)
346 execution.setVariable(Prefix + "queryNameAAIResponse", aaiResponseAsString)
347 execution.setVariable(Prefix + "isAAIqueryNameGood", true)
348 String orchestrationStatus = ""
350 // response is NOT empty
351 orchestrationStatus = utils.getNodeText1(aaiResponseAsString, "orchestration-status")
352 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus.toUpperCase())
353 utils.log("DEBUG", Prefix + "orchestrationStatus - " + orchestrationStatus.toUpperCase(), isDebugEnabled)
354 execution.setVariable("orchestrationStatus", orchestrationStatus)
356 } catch (Exception ex) {
358 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus)
359 utils.log("DEBUG", Prefix + "orchestrationStatus - " + orchestrationStatus, isDebugEnabled)
363 if (returnCode=='404') {
364 utils.log("DEBUG", " QueryAAINetworkName return code = '404' (Not Found). Proceed with the Create !!! ", isDebugEnabled)
368 String dataErrorMessage = "Unexpected Error Response from QueryAAINetworkName - " + returnCode
369 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
370 exceptionUtil.buildWorkflowException(execution, 2500, dataErrorMessage)
376 utils.log("DEBUG", Prefix + "isAAIqueryNameGood? : " + execution.getVariable(Prefix + "isAAIqueryNameGood"), isDebugEnabled)
378 } catch (BpmnError e) {
381 } catch (Exception ex) {
383 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAINetworkName() - " + ex.getMessage()
384 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
385 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
391 public void callRESTQueryAAICloudRegion (Execution execution) {
392 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
393 execution.setVariable("prefix",Prefix)
395 utils.log("DEBUG", " ***** Inside callRESTQueryAAICloudRegion() of DoCreateNetworkInstance ***** " , isDebugEnabled)
398 String networkInputs = execution.getVariable(Prefix + "networkInputs")
399 String cloudRegion = utils.getNodeText1(networkInputs, "aic-cloud-region")
400 cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
403 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
404 AaiUtil aaiUtil = new AaiUtil(this)
405 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
406 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
407 utils.logAudit(queryCloudRegionRequest)
408 execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
409 utils.log("DEBUG", Prefix + "queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugEnabled)
411 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
412 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
414 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
415 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
416 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
417 execution.setVariable(Prefix + "isCloudRegionGood", true)
420 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
421 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
422 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
426 utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"), isDebugEnabled)
428 } catch (BpmnError e) {
431 } catch (Exception ex) {
433 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
434 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
435 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
441 public void callRESTQueryAAINetworkId(Execution execution) {
442 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
443 execution.setVariable("prefix",Prefix)
445 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkId() of DoCreateNetworkInstance ***** " , isDebugEnabled)
449 String networkId = ""
450 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
451 if (execution.getVariable("sdncVersion") == "1702") {
452 String networkResponseInformation = ""
454 networkResponseInformation = utils.getNodeXml(assignSDNCResponse, "network-response-information", false).replace("tag0:","").replace(":tag0","")
455 networkId = utils.getNodeText1(networkResponseInformation, "instance-id")
456 } catch (Exception ex) {
457 String dataErrorMessage = " SNDC Response network validation for 'instance-id' (network-id) failed: Empty <network-response-information>"
458 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
459 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
463 networkId = utils.getNodeText1(assignSDNCResponse, "network-id")
465 if (networkId == null || networkId == "null") {
466 String dataErrorMessage = "SNDC Response did not contains 'instance-id' or 'network-id' element, or the value is null."
467 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
468 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
470 utils.log("DEBUG", " SNDC Response network validation for 'instance-id' (network-id)' is good: " + networkId, isDebugEnabled)
474 execution.setVariable(Prefix + "networkId", networkId)
475 String networkName = utils.getNodeText1(assignSDNCResponse, "network-name")
476 execution.setVariable(Prefix + "networkName", networkName)
478 networkId = UriUtils.encode(networkId,"UTF-8")
481 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
482 AaiUtil aaiUriUtil = new AaiUtil(this)
483 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
484 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
485 utils.logAudit(queryIdAAIRequest)
486 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
487 utils.log("DEBUG", Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest, isDebugEnabled)
489 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
490 String returnCode = response.getStatusCode()
491 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
493 utils.log("DEBUG", " ***** AAI Response Code : " + returnCode, isDebugEnabled)
495 String aaiResponseAsString = response.getResponseBodyAsString()
497 if (returnCode=='200') {
498 utils.logAudit(aaiResponseAsString)
499 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
500 utils.log("DEBUG", " QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
502 String netId = utils.getNodeText1(aaiResponseAsString, "network-id")
503 execution.setVariable(Prefix + "networkId", netId)
504 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
505 execution.setVariable(Prefix + "networkName", netName)
508 if (returnCode=='404') {
509 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
510 utils.log("DEBUG", " AAI Query Failed. " + dataErrorMessage, isDebugEnabled)
511 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
514 if (aaiResponseAsString.contains("RESTFault")) {
515 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
516 execution.setVariable("WorkflowException", exceptionObject)
517 throw new BpmnError("MSOWorkflowException")
521 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
522 utils.log("DEBUG", "Unexpected Response from QueryAAINetworkId - " + dataErrorMessage, isDebugEnabled)
523 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
529 } catch (BpmnError e) {
532 } catch (Exception ex) {
533 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
534 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
535 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
541 public void callRESTReQueryAAINetworkId(Execution execution) {
542 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
543 execution.setVariable("prefix",Prefix)
545 utils.log("DEBUG", " ***** Inside callRESTReQueryAAINetworkId() of DoCreateNetworkInstance ***** " , isDebugEnabled)
549 String networkId = execution.getVariable(Prefix + "networkId")
550 String netId = networkId
551 networkId = UriUtils.encode(networkId,"UTF-8")
554 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
555 AaiUtil aaiUriUtil = new AaiUtil(this)
556 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
557 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
558 utils.logAudit(requeryIdAAIRequest)
559 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
560 utils.log("DEBUG", Prefix + "requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest, isDebugEnabled)
562 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
563 String returnCode = response.getStatusCode()
564 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
565 utils.log("DEBUG", " ***** AAI ReQuery Response Code : " + returnCode, isDebugEnabled)
567 String aaiResponseAsString = response.getResponseBodyAsString()
569 if (returnCode=='200') {
570 utils.logAudit(aaiResponseAsString)
571 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
572 utils.log("DEBUG", " ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
574 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
575 String networkOutputs =
577 <network-id>${netId}</network-id>
578 <network-name>${netName}</network-name>
579 </network-outputs>"""
580 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
581 utils.log("DEBUG", " networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
584 if (returnCode=='404') {
585 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
586 utils.log("DEBUG", " AAI ReQuery Failed. - " + dataErrorMessage, isDebugEnabled)
587 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
590 if (aaiResponseAsString.contains("RESTFault")) {
591 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
592 execution.setVariable("WorkflowException", exceptionObject)
593 throw new BpmnError("MSOWorkflowException")
597 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
598 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
599 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
605 } catch (BpmnError e) {
608 } catch (Exception ex) {
609 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
610 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
611 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
617 public void callRESTQueryAAINetworkVpnBinding(Execution execution) {
618 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
619 execution.setVariable("prefix",Prefix)
621 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkVpnBinding() of DoCreateNetworkInstance ***** " , isDebugEnabled)
626 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
627 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
628 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
630 // Check if Vnf Binding is present, then build a List of vnfBinding
631 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
632 int vpnCount = vpnBindingUri.size()
633 execution.setVariable(Prefix + "vpnCount", vpnCount)
634 utils.log("DEBUG", Prefix + "vpnCount - " + vpnCount, isDebugEnabled)
636 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
637 AaiUtil aaiUriUtil = new AaiUtil(this)
640 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
641 utils.log("DEBUG", " vpnBindingUri List - " + vpnBindingUri, isDebugEnabled)
643 String routeTargets = ""
644 // AII loop call using list vpnBindings
645 for (i in 0..vpnBindingUri.size()-1) {
649 // prepare url using vpnBinding
650 String queryVpnBindingAAIRequest = ""
651 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
653 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
654 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
655 if (aai_uri == null || aai_uri == "") {
656 // using value of 'related-link' from response
657 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
658 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1)
660 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i]
664 // using uri value in URN mapping
665 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
666 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
667 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
669 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId
672 utils.logAudit(queryVpnBindingAAIRequest)
673 execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
674 utils.log("DEBUG", Prefix + "queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest, isDebugEnabled)
676 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
677 String returnCode = response.getStatusCode()
678 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
679 utils.log("DEBUG", " ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode, isDebugEnabled)
681 String aaiResponseAsString = response.getResponseBodyAsString()
683 if (returnCode=='200') {
684 utils.logAudit(aaiResponseAsString)
685 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
686 utils.log("DEBUG", " AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
688 String routeTarget = ""
689 if (utils.nodeExists(aaiResponseAsString, "global-route-target")) {
690 routeTarget = utils.getNodeText1(aaiResponseAsString, "global-route-target")
691 routeTargets += "<routeTargets>" + routeTarget + "</routeTargets>" + '\n'
695 if (returnCode=='404') {
696 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
697 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
698 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
701 if (aaiResponseAsString.contains("RESTFault")) {
702 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
703 execution.setVariable("WorkflowException", exceptionObject)
704 throw new BpmnError("MSOWorkflowException")
708 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
709 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
710 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
718 execution.setVariable(Prefix + "routeCollection", routeTargets)
719 utils.log("DEBUG", Prefix + "routeCollection - " + '\n' + routeTargets, isDebugEnabled)
722 // reset return code to success
723 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
724 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
725 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
726 String aaiStubResponse =
727 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
728 <vpn-binding xmlns="${schemaVersion}">
729 <global-route-target/>
732 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
733 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
734 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
735 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
739 } catch (BpmnError e) {
742 } catch (Exception ex) {
743 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
744 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
745 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
751 public void callRESTQueryAAINetworkPolicy(Execution execution) {
752 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
753 execution.setVariable("prefix",Prefix)
755 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy() of DoCreateNetworkInstance ***** " , isDebugEnabled)
759 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
760 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
761 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
763 // Check if Network Policy is present, then build a List of network policy
764 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
765 int networkPolicyCount = networkPolicyUriList.size()
766 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
767 utils.log("DEBUG", Prefix + "networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
769 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
770 AaiUtil aaiUriUtil = new AaiUtil(this)
772 if (networkPolicyCount > 0) {
773 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
774 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
776 String networkPolicies = ""
777 // AII loop call using list vpnBindings
778 for (i in 0..networkPolicyUriList.size()-1) {
782 // prepare url using vpnBinding
783 String queryNetworkPolicyAAIRequest = ""
785 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
787 // Note: By default, the network policy url is found in 'related-link' of the response,
788 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
789 if (aai_uri == null || aai_uri == "") {
790 // using value of 'related-link' from response
791 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
792 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1)
794 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i]
797 // using uri value in URN mapping
798 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
799 println " networkPolicyId - " + networkPolicyId
800 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
801 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
803 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId
808 utils.logAudit(queryNetworkPolicyAAIRequest)
809 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
810 utils.log("DEBUG", Prefix + "queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
812 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
813 String returnCode = response.getStatusCode()
814 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
815 utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
817 String aaiResponseAsString = response.getResponseBodyAsString()
819 if (returnCode=='200') {
820 utils.logAudit(aaiResponseAsString)
821 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
822 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
824 String networkPolicy = ""
825 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
826 networkPolicy = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
827 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
831 if (returnCode=='404') {
832 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
833 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
834 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
837 if (aaiResponseAsString.contains("RESTFault")) {
838 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
839 execution.setVariable("WorkflowException", exceptionObject)
840 throw new BpmnError("MSOWorkflowException")
844 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
845 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
846 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
854 execution.setVariable(Prefix + "networkCollection", networkPolicies)
855 utils.log("DEBUG", Prefix + "networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
858 // reset return code to success
859 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
860 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
861 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
862 String aaiStubResponse =
863 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
864 <network-policy xmlns="${schemaVersion}">
865 <network-policy-fqdn/>
868 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
869 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
870 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
871 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
875 } catch (BpmnError e) {
878 } catch (Exception ex) {
879 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
880 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
881 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
887 public void callRESTQueryAAINetworkTableRef(Execution execution) {
888 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
889 execution.setVariable("prefix",Prefix)
891 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef() of DoCreateNetworkInstance ***** " , isDebugEnabled)
895 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
896 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
897 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
899 // Check if Network TableREf is present, then build a List of network policy
900 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
901 int networkTableRefCount = networkTableRefUriList.size()
902 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
903 utils.log("DEBUG", Prefix + "networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
905 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
906 AaiUtil aaiUriUtil = new AaiUtil(this)
908 if (networkTableRefCount > 0) {
909 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
910 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
912 // AII loop call using list vpnBindings
913 String networkTableRefs = ""
914 for (i in 0..networkTableRefUriList.size()-1) {
918 // prepare url using tableRef
919 String queryNetworkTableRefAAIRequest = ""
921 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
923 // Note: By default, the network policy url is found in 'related-link' of the response,
924 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
925 if (aai_uri == null || aai_uri == "") {
926 // using value of 'related-link' from response
927 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
928 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1)
930 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i]
933 // using uri value in URN mapping
934 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
936 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
937 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
939 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId
944 utils.logAudit(queryNetworkTableRefAAIRequest)
945 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
946 utils.log("DEBUG", Prefix + "queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
948 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
949 String returnCode = response.getStatusCode()
950 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
951 utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
953 String aaiResponseAsString = response.getResponseBodyAsString()
955 if (returnCode=='200') {
956 utils.logAudit(aaiResponseAsString)
957 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
958 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
960 String networkTableRef = ""
961 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
962 networkTableRef = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
963 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
967 if (returnCode=='404') {
968 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
969 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
970 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
973 if (aaiResponseAsString.contains("RESTFault")) {
974 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
975 execution.setVariable("WorkflowException", exceptionObject)
976 throw new BpmnError("MSOWorkflowException")
980 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
981 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
982 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
990 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
991 utils.log("DEBUG", Prefix + "tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
994 // reset return code to success
995 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
996 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
997 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
998 String aaiStubResponse =
999 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
1000 <route-table-references xmlns="${schemaVersion}">
1001 <route-table-reference-fqdn/>
1002 </route-table-references>
1004 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
1005 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
1006 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
1007 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
1011 } catch (BpmnError e) {
1014 } catch (Exception ex) {
1015 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
1016 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1017 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1024 public void callRESTUpdateContrailAAINetwork(Execution execution) {
1025 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1026 execution.setVariable("prefix",Prefix)
1028 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork() of DoCreateNetworkInstance ***** " , isDebugEnabled)
1032 String networkId = execution.getVariable(Prefix + "networkId")
1033 networkId = UriUtils.encode(networkId,"UTF-8")
1034 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1035 String createNetworkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1038 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1039 AaiUtil aaiUriUtil = new AaiUtil(this)
1040 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1041 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
1043 utils.logAudit(updateContrailAAIUrlRequest)
1044 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
1045 utils.log("DEBUG", Prefix + "updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
1047 //Prepare payload (PUT)
1048 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
1049 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, createNetworkResponse, schemaVersion)
1050 String payloadXml = utils.formatXml(payload)
1051 utils.logAudit(payloadXml)
1052 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
1053 utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
1055 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payloadXml)
1057 String returnCode = response.getStatusCode()
1058 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
1059 utils.log("DEBUG", " ***** AAI Update Contrail Response Code : " + returnCode, isDebugEnabled)
1060 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
1061 if (returnCode=='200') {
1062 utils.logAudit(aaiUpdateContrailResponseAsString)
1063 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
1064 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
1065 // Point-of-no-return is set to false, rollback not needed.
1066 String rollbackEnabled = execution.getVariable(Prefix + "rollbackEnabled")
1067 if (rollbackEnabled == "true") {
1068 execution.setVariable(Prefix + "isPONR", false)
1070 execution.setVariable(Prefix + "isPONR", true)
1072 utils.log("DEBUG", Prefix + "isPONR" + ": " + execution.getVariable(Prefix + "isPONR"), isDebugEnabled)
1074 if (returnCode=='404') {
1075 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
1076 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
1077 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1080 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
1081 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
1082 execution.setVariable("WorkflowException", exceptionObject)
1083 throw new BpmnError("MSOWorkflowException")
1087 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
1088 utils.log("DEBUG", errorMessage, isDebugEnabled)
1089 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1094 } catch (BpmnError e) {
1097 } catch (Exception ex) {
1098 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
1099 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1100 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1106 public void prepareCreateNetworkRequest (Execution execution) {
1107 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1108 execution.setVariable("prefix",Prefix)
1110 utils.log("DEBUG", " ***** Inside prepareCreateNetworkRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1115 String requestId = execution.getVariable("msoRequestId")
1116 if (requestId == null) {
1117 requestId = execution.getVariable("mso-request-id")
1119 String messageId = execution.getVariable(Prefix + "messageId")
1120 String source = execution.getVariable(Prefix + "source")
1122 String requestInput = execution.getVariable(Prefix + "networkRequest")
1123 String queryIdResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1124 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1125 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1127 // Prepare Network request
1128 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1129 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1130 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1131 String createNetworkRequest = networkUtils.CreateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1133 String buildDeleteNetworkRequestAsString = utils.formatXml(createNetworkRequest)
1134 buildDeleteNetworkRequestAsString = buildDeleteNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1135 utils.logAudit(buildDeleteNetworkRequestAsString)
1137 execution.setVariable(Prefix + "createNetworkRequest", buildDeleteNetworkRequestAsString)
1138 utils.log("DEBUG", Prefix + "createNetworkRequest - " + "\n" + buildDeleteNetworkRequestAsString, isDebugEnabled)
1140 } catch (Exception ex) {
1141 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareCreateNetworkRequest() - " + ex.getMessage()
1142 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1143 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1149 public void prepareSDNCRequest (Execution execution) {
1150 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1151 execution.setVariable("prefix",Prefix)
1153 utils.log("DEBUG", " ***** Inside prepareSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1157 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1158 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1159 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1161 String networkId = execution.getVariable(Prefix + "networkId")
1162 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1164 // get/set 'msoRequestId' and 'mso-request-id'
1165 String requestId = execution.getVariable("msoRequestId")
1166 if (requestId != null) {
1167 execution.setVariable("mso-request-id", requestId)
1169 requestId = execution.getVariable("mso-request-id")
1171 execution.setVariable(Prefix + "requestId", requestId)
1173 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1174 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1176 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1177 utils.logAudit(sndcTopologyCreateRequesAsString)
1178 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1179 utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1182 } catch (Exception ex) {
1183 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1184 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1185 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1191 public void prepareRpcSDNCRequest (Execution execution) {
1192 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1193 execution.setVariable("prefix",Prefix)
1195 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1200 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1201 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1202 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1204 String networkId = execution.getVariable(Prefix + "networkId")
1205 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1207 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1208 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "CreateNetworkInstance", cloudRegionId, networkId, null)
1210 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1211 utils.logAudit(sndcTopologyCreateRequesAsString)
1212 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1213 utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1215 } catch (Exception ex) {
1216 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRequest() - " + ex.getMessage()
1217 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1218 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1224 public void prepareRpcSDNCActivateRequest (Execution execution) {
1225 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1226 execution.setVariable("prefix",Prefix)
1228 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1232 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1233 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1234 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1235 String networkId = execution.getVariable(Prefix + "networkId")
1236 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1238 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1239 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "activate", "ActivateNetworkInstance", cloudRegionId, networkId, null)
1241 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1242 utils.logAudit(sndcTopologyCreateRequesAsString)
1243 execution.setVariable(Prefix + "activateSDNCRequest", sndcTopologyCreateRequesAsString)
1244 utils.log("DEBUG", Prefix + "activateSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1247 } catch (Exception ex) {
1248 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRequest() - " + ex.getMessage()
1249 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1250 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1259 // **************************************************
1260 // Post or Validate Response Section
1261 // **************************************************
1263 public void validateCreateNetworkResponse (Execution execution) {
1264 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1265 execution.setVariable("prefix",Prefix)
1267 utils.log("DEBUG", " ***** Inside validateNetworkResponse() of DoCreateNetworkInstance *****", isDebugEnabled)
1270 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1271 String networkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1272 if (networkResponse==null) {
1273 networkResponse="" // reset
1276 utils.log("DEBUG", " Network Adapter create responseCode: " + returnCode, isDebugEnabled)
1278 String errorMessage = ""
1279 if (returnCode == "200") {
1280 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1281 utils.logAudit(networkResponse)
1282 execution.setVariable(Prefix + "createNetworkResponse", networkResponse)
1283 utils.log("DEBUG", " Network Adapter create Success Response - " + "\n" + networkResponse, isDebugEnabled)
1285 // prepare rollback data
1286 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1287 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1288 String rollbackNetwork =
1289 """<rollbackNetworkRequest>
1291 </rollbackNetworkRequest>"""
1292 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1293 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1294 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1296 } else { // network error
1297 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1298 if (networkResponse.contains("createNetworkError")) {
1299 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1300 errorMessage = utils.getNodeText1(networkResponse, "message")
1301 errorMessage = "Received error from Network Adapter: " + errorMessage
1302 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1304 } else { // CatchAll exception
1305 if (returnCode == "500") {
1306 errorMessage = "JBWEB000065: HTTP Status 500."
1308 errorMessage = "Return code is " + returnCode
1310 errorMessage = "Received error from Network Adapter: " + errorMessage
1311 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1315 } else { // CatchAll exception
1316 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1317 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1323 } catch (BpmnError e) {
1326 } catch (Exception ex) {
1327 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. validateCreateNetworkResponse() - " + ex.getMessage()
1328 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1329 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1336 public void validateSDNCResponse (Execution execution) {
1337 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1338 execution.setVariable("prefix",Prefix)
1340 utils.log("DEBUG", " ***** Inside validateSDNCResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1342 String response = execution.getVariable(Prefix + "assignSDNCResponse")
1343 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1344 WorkflowException workflowException = execution.getVariable("WorkflowException")
1346 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1347 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1349 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "assignSDNCResponse"))
1350 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1351 execution.setVariable(Prefix + "assignSDNCResponse", assignSDNCResponseDecodeXml)
1353 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1354 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1355 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1358 utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1359 throw new BpmnError("MSOWorkflowException")
1364 public void validateRpcSDNCActivateResponse (Execution execution) {
1365 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1366 execution.setVariable("prefix",Prefix)
1368 utils.log("DEBUG", " ***** Inside validateRpcSDNCActivateResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1370 String response = execution.getVariable(Prefix + "activateSDNCResponse")
1371 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1372 WorkflowException workflowException = execution.getVariable("WorkflowException")
1374 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1375 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1377 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "activateSDNCResponse"))
1378 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1379 execution.setVariable(Prefix + "activateSDNCResponse", assignSDNCResponseDecodeXml)
1381 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1382 execution.setVariable(Prefix + "isSdncActivateRollbackNeeded", true)
1383 utils.log("DEBUG", "Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1386 utils.log("DEBUG", "Did NOT Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1387 throw new BpmnError("MSOWorkflowException")
1393 public void prepareSDNCRollbackRequest (Execution execution) {
1394 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1395 execution.setVariable("prefix",Prefix)
1397 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1401 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1402 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1403 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1404 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1405 String networkId = execution.getVariable(Prefix + "networkId")
1406 if (networkId == 'null') {networkId = ""}
1407 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1409 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1410 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1411 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1412 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1413 utils.log("DEBUG", " Preparing request for SDNC Topology 'rollback-NetworkActivateRequest' rollback . . . - " + "\n" + sndcTopologyRollbackRequestAsString, isDebugEnabled)
1416 } catch (Exception ex) {
1417 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1418 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1419 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1425 public void prepareRpcSDNCRollbackRequest (Execution execution) {
1426 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1427 execution.setVariable("prefix",Prefix)
1429 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1433 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1434 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1435 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1436 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1437 String networkId = execution.getVariable(Prefix + "networkId")
1438 if (networkId == 'null') {networkId = ""}
1439 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1441 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1442 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "unassign", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1443 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1444 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1445 utils.log("DEBUG", " Preparing request for SDNC Topology 'unassign-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1448 } catch (Exception ex) {
1449 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRollbackRequest() - " + ex.getMessage()
1450 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1451 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1457 public void prepareRpcSDNCActivateRollback(Execution execution) {
1458 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1459 execution.setVariable("prefix",Prefix)
1461 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRollback() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1466 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1467 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1468 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1469 String activateSDNCResponse = execution.getVariable(Prefix + "activateSDNCResponse")
1470 String networkId = execution.getVariable(Prefix + "networkId")
1471 if (networkId == 'null') {networkId = ""}
1472 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1474 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1475 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "deactivate", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1476 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1477 execution.setVariable(Prefix + "rollbackActivateSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1478 utils.log("DEBUG", " Preparing request for RPC SDNC Topology 'deactivate-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1481 } catch (Exception ex) {
1482 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRollback() - " + ex.getMessage()
1483 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1484 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1490 public void prepareRollbackData(Execution execution) {
1491 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1492 execution.setVariable("prefix",Prefix)
1494 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1498 Map<String, String> rollbackData = new HashMap<String, String>();
1499 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1500 if (rollbackSDNCRequest != null) {
1501 if (rollbackSDNCRequest != "") {
1502 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1505 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1506 if (rollbackNetworkRequest != null) {
1507 if (rollbackNetworkRequest != "") {
1508 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1511 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1512 if (rollbackActivateSDNCRequest != null) {
1513 if (rollbackActivateSDNCRequest != "") {
1514 rollbackData.put("rollbackActivateSDNCRequest", execution.getVariable(Prefix + "rollbackActivateSDNCRequest"))
1517 execution.setVariable("rollbackData", rollbackData)
1518 utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
1520 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1521 utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
1523 } catch (Exception ex) {
1524 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1525 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1526 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1532 public void postProcessResponse(Execution execution) {
1533 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1534 execution.setVariable("prefix",Prefix)
1536 utils.log("DEBUG", " ***** Inside postProcessResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1541 // 1. Silent Success: execution.getVariable("CRENWKI_orchestrationStatus") == "ACTIVE"
1542 // 2. Success: execution.getVariable("WorkflowException") == null (NULL)
1543 // 3. WorkflowException: execution.getVariable("WorkflowException") != null (NOT NULL)
1545 utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
1547 if (execution.getVariable(Prefix + "isException") == false) {
1548 // set rollback data
1549 execution.setVariable("orchestrationStatus", "")
1550 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1551 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1552 prepareSuccessRollbackData(execution) // populate rollbackData
1553 execution.setVariable("WorkflowException", null)
1554 execution.setVariable(Prefix + "Success", true)
1555 utils.log("DEBUG", " ***** postProcessResponse(), GOOD !!!", isDebugEnabled)
1557 // inside sub-flow logic
1558 execution.setVariable(Prefix + "Success", false)
1559 execution.setVariable("rollbackData", null)
1560 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1561 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1562 utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
1563 WorkflowException wfex = execution.getVariable("workflowException")
1564 exceptionMessage = wfex.getErrorMessage()
1566 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1567 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1568 exceptionMessage = pwfex.getErrorMessage()
1571 // going to the Main flow: a-la-carte or macro
1572 utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
1573 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1574 throw new BpmnError("MSOWorkflowException")
1577 } catch(BpmnError b){
1578 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
1581 } catch (Exception ex) {
1582 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1583 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1584 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1585 throw new BpmnError("MSOWorkflowException")
1593 public void prepareSuccessRollbackData(Execution execution) {
1594 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1595 execution.setVariable("prefix",Prefix)
1597 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1601 if (execution.getVariable("sdncVersion") == '1702') {
1602 prepareRpcSDNCRollbackRequest(execution)
1603 prepareRpcSDNCActivateRollback(execution)
1605 prepareSDNCRollbackRequest(execution)
1608 Map<String, String> rollbackData = new HashMap<String, String>();
1609 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1610 if (rollbackSDNCRequest != null) {
1611 if (rollbackSDNCRequest != "") {
1612 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1615 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1616 if (rollbackNetworkRequest != null) {
1617 if (rollbackNetworkRequest != "") {
1618 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1621 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1622 if (rollbackActivateSDNCRequest != null) {
1623 if (rollbackActivateSDNCRequest != "") {
1624 rollbackData.put("rollbackActivateSDNCRequest", rollbackActivateSDNCRequest)
1627 execution.setVariable("rollbackData", rollbackData)
1629 utils.log("DEBUG", "** 'rollbackData' for Full Rollback : " + rollbackData, isDebugEnabled)
1630 execution.setVariable("WorkflowException", null)
1633 } catch (Exception ex) {
1634 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1635 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1636 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1642 public void setExceptionFlag(Execution execution){
1643 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1644 execution.setVariable("prefix",Prefix)
1646 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1650 execution.setVariable(Prefix + "isException", true)
1652 if (execution.getVariable("SavedWorkflowException1") != null) {
1653 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1655 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1657 utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1659 } catch(Exception ex){
1660 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1661 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1662 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1668 // *******************************
1669 // Build Error Section
1670 // *******************************
1674 public void processJavaException(Execution execution){
1675 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1676 execution.setVariable("prefix",Prefix)
1679 utils.log("DEBUG", "Caught a Java Exception in " + Prefix, isDebugEnabled)
1680 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1681 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1682 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1683 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1685 }catch(Exception e){
1686 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1687 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1688 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
1690 utils.log("DEBUG", "Completed processJavaException Method in " + Prefix, isDebugEnabled)