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.delegate.DelegateExecution
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(DelegateExecution 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 (DelegateExecution 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 (DelegateExecution 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 (DelegateExecution 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(DelegateExecution 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") != "1610") {
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=all"
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(DelegateExecution 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=all"
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(DelegateExecution 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) + "?depth=all"
660 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i] + "?depth=all"
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 + "?depth=all"
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 String routeRole = ""
690 if (utils.nodeExists(aaiResponseAsString, "route-targets")) {
691 String aaiRouteTargets = utils.getNodeXml(aaiResponseAsString, "route-targets", false)
692 def aaiRouteTargetsXml = new XmlSlurper().parseText(aaiRouteTargets)
693 def aaiRouteTarget = aaiRouteTargetsXml.'**'.findAll {it.name() == "route-target"}
694 for (j in 0..aaiRouteTarget.size()-1) {
695 routeTarget = utils.getNodeText1(XmlUtil.serialize(aaiRouteTarget[j]), "global-route-target")
696 routeRole = utils.getNodeText1(XmlUtil.serialize(aaiRouteTarget[j]), "route-target-role")
697 routeTargets += "<routeTargets>" + '\n' +
698 " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
699 " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
700 "</routeTargets>" + '\n'
705 if (returnCode=='404') {
706 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
707 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
708 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
711 if (aaiResponseAsString.contains("RESTFault")) {
712 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
713 execution.setVariable("WorkflowException", exceptionObject)
714 throw new BpmnError("MSOWorkflowException")
718 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
719 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
720 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
728 execution.setVariable(Prefix + "routeCollection", routeTargets)
729 utils.log("DEBUG", Prefix + "routeCollection - " + '\n' + routeTargets, isDebugEnabled)
732 // reset return code to success
733 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
734 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
735 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
736 String aaiStubResponse =
737 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
738 <vpn-binding xmlns="${schemaVersion}">
739 <global-route-target/>
742 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
743 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
744 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
745 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
749 } catch (BpmnError e) {
752 } catch (Exception ex) {
753 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
754 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
755 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
761 public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
762 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
763 execution.setVariable("prefix",Prefix)
765 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy() of DoCreateNetworkInstance ***** " , isDebugEnabled)
769 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
770 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
771 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
773 // Check if Network Policy is present, then build a List of network policy
774 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
775 int networkPolicyCount = networkPolicyUriList.size()
776 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
777 utils.log("DEBUG", Prefix + "networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
779 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
780 AaiUtil aaiUriUtil = new AaiUtil(this)
782 if (networkPolicyCount > 0) {
783 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
784 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
786 String networkPolicies = ""
787 // AII loop call using list vpnBindings
788 for (i in 0..networkPolicyUriList.size()-1) {
792 // prepare url using vpnBinding
793 String queryNetworkPolicyAAIRequest = ""
795 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
797 // Note: By default, the network policy url is found in 'related-link' of the response,
798 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
799 if (aai_uri == null || aai_uri == "") {
800 // using value of 'related-link' from response
801 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
802 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1) + "?depth=all"
804 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i] + "?depth=all"
807 // using uri value in URN mapping
808 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
809 println " networkPolicyId - " + networkPolicyId
810 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
811 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
813 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId + "?depth=all"
818 utils.logAudit(queryNetworkPolicyAAIRequest)
819 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
820 utils.log("DEBUG", Prefix + "queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
822 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
823 String returnCode = response.getStatusCode()
824 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
825 utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
827 String aaiResponseAsString = response.getResponseBodyAsString()
829 if (returnCode=='200') {
830 utils.logAudit(aaiResponseAsString)
831 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
832 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
834 String networkPolicy = ""
835 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
836 networkPolicy = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
837 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
841 if (returnCode=='404') {
842 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
843 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
844 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
847 if (aaiResponseAsString.contains("RESTFault")) {
848 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
849 execution.setVariable("WorkflowException", exceptionObject)
850 throw new BpmnError("MSOWorkflowException")
854 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
855 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
856 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
864 execution.setVariable(Prefix + "networkCollection", networkPolicies)
865 utils.log("DEBUG", Prefix + "networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
868 // reset return code to success
869 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
870 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
871 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
872 String aaiStubResponse =
873 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
874 <network-policy xmlns="${schemaVersion}">
875 <network-policy-fqdn/>
878 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
879 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
880 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
881 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
885 } catch (BpmnError e) {
888 } catch (Exception ex) {
889 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
890 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
891 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
897 public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
898 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
899 execution.setVariable("prefix",Prefix)
901 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef() of DoCreateNetworkInstance ***** " , isDebugEnabled)
905 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
906 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
907 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
909 // Check if Network TableREf is present, then build a List of network policy
910 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
911 int networkTableRefCount = networkTableRefUriList.size()
912 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
913 utils.log("DEBUG", Prefix + "networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
915 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
916 AaiUtil aaiUriUtil = new AaiUtil(this)
918 if (networkTableRefCount > 0) {
919 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
920 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
922 // AII loop call using list vpnBindings
923 String networkTableRefs = ""
924 for (i in 0..networkTableRefUriList.size()-1) {
928 // prepare url using tableRef
929 String queryNetworkTableRefAAIRequest = ""
931 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
933 // Note: By default, the network policy url is found in 'related-link' of the response,
934 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
935 if (aai_uri == null || aai_uri == "") {
936 // using value of 'related-link' from response
937 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
938 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1) + "?depth=all"
940 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i] + "?depth=all"
943 // using uri value in URN mapping
944 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
946 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
947 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
949 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId + "?depth=all"
954 utils.logAudit(queryNetworkTableRefAAIRequest)
955 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
956 utils.log("DEBUG", Prefix + "queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
958 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
959 String returnCode = response.getStatusCode()
960 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
961 utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
963 String aaiResponseAsString = response.getResponseBodyAsString()
965 if (returnCode=='200') {
966 utils.logAudit(aaiResponseAsString)
967 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
968 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
970 String networkTableRef = ""
971 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
972 networkTableRef = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
973 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
977 if (returnCode=='404') {
978 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
979 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
980 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
983 if (aaiResponseAsString.contains("RESTFault")) {
984 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
985 execution.setVariable("WorkflowException", exceptionObject)
986 throw new BpmnError("MSOWorkflowException")
990 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
991 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
992 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1000 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
1001 utils.log("DEBUG", Prefix + "tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
1004 // reset return code to success
1005 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
1006 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1007 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
1008 String aaiStubResponse =
1009 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
1010 <route-table-references xmlns="${schemaVersion}">
1011 <route-table-reference-fqdn/>
1012 </route-table-references>
1014 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
1015 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
1016 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
1017 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
1021 } catch (BpmnError e) {
1024 } catch (Exception ex) {
1025 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
1026 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1027 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1034 public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
1035 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1036 execution.setVariable("prefix",Prefix)
1038 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork() of DoCreateNetworkInstance ***** " , isDebugEnabled)
1042 String networkId = execution.getVariable(Prefix + "networkId")
1043 networkId = UriUtils.encode(networkId,"UTF-8")
1044 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1045 String createNetworkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1048 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1049 AaiUtil aaiUriUtil = new AaiUtil(this)
1050 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1051 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
1053 utils.logAudit(updateContrailAAIUrlRequest)
1054 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
1055 utils.log("DEBUG", Prefix + "updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
1057 //Prepare payload (PUT)
1058 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
1059 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, createNetworkResponse, schemaVersion)
1060 String payloadXml = utils.formatXml(payload)
1061 utils.logAudit(payloadXml)
1062 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
1063 utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
1065 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payloadXml)
1067 String returnCode = response.getStatusCode()
1068 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
1069 utils.log("DEBUG", " ***** AAI Update Contrail Response Code : " + returnCode, isDebugEnabled)
1070 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
1071 if (returnCode=='200') {
1072 utils.logAudit(aaiUpdateContrailResponseAsString)
1073 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
1074 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
1075 // Point-of-no-return is set to false, rollback not needed.
1076 String rollbackEnabled = execution.getVariable(Prefix + "rollbackEnabled")
1077 if (rollbackEnabled == "true") {
1078 execution.setVariable(Prefix + "isPONR", false)
1080 execution.setVariable(Prefix + "isPONR", true)
1082 utils.log("DEBUG", Prefix + "isPONR" + ": " + execution.getVariable(Prefix + "isPONR"), isDebugEnabled)
1084 if (returnCode=='404') {
1085 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
1086 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
1087 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1090 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
1091 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
1092 execution.setVariable("WorkflowException", exceptionObject)
1093 throw new BpmnError("MSOWorkflowException")
1097 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
1098 utils.log("DEBUG", errorMessage, isDebugEnabled)
1099 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1104 } catch (BpmnError e) {
1107 } catch (Exception ex) {
1108 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
1109 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1110 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1116 public void prepareCreateNetworkRequest (DelegateExecution execution) {
1117 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1118 execution.setVariable("prefix",Prefix)
1120 utils.log("DEBUG", " ***** Inside prepareCreateNetworkRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1125 String requestId = execution.getVariable("msoRequestId")
1126 if (requestId == null) {
1127 requestId = execution.getVariable("mso-request-id")
1129 String messageId = execution.getVariable(Prefix + "messageId")
1130 String source = execution.getVariable(Prefix + "source")
1132 String requestInput = execution.getVariable(Prefix + "networkRequest")
1133 String queryIdResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1134 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1135 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1137 // Prepare Network request
1138 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1139 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1140 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1141 String createNetworkRequest = networkUtils.CreateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1143 String buildDeleteNetworkRequestAsString = utils.formatXml(createNetworkRequest)
1144 buildDeleteNetworkRequestAsString = buildDeleteNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1145 utils.logAudit(buildDeleteNetworkRequestAsString)
1147 execution.setVariable(Prefix + "createNetworkRequest", buildDeleteNetworkRequestAsString)
1148 utils.log("DEBUG", Prefix + "createNetworkRequest - " + "\n" + buildDeleteNetworkRequestAsString, isDebugEnabled)
1150 } catch (Exception ex) {
1151 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareCreateNetworkRequest() - " + ex.getMessage()
1152 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1153 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1159 public void prepareSDNCRequest (DelegateExecution execution) {
1160 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1161 execution.setVariable("prefix",Prefix)
1163 utils.log("DEBUG", " ***** Inside prepareSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1167 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1168 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1169 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1171 String networkId = execution.getVariable(Prefix + "networkId")
1172 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1174 // get/set 'msoRequestId' and 'mso-request-id'
1175 String requestId = execution.getVariable("msoRequestId")
1176 if (requestId != null) {
1177 execution.setVariable("mso-request-id", requestId)
1179 requestId = execution.getVariable("mso-request-id")
1181 execution.setVariable(Prefix + "requestId", requestId)
1183 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1184 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1186 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1187 utils.logAudit(sndcTopologyCreateRequesAsString)
1188 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1189 utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1192 } catch (Exception ex) {
1193 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1194 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1195 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1201 public void prepareRpcSDNCRequest (DelegateExecution execution) {
1202 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1203 execution.setVariable("prefix",Prefix)
1205 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1210 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1211 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1212 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1214 String networkId = execution.getVariable(Prefix + "networkId")
1215 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1217 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1218 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "CreateNetworkInstance", cloudRegionId, networkId, null)
1220 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1221 utils.logAudit(sndcTopologyCreateRequesAsString)
1222 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1223 utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1225 } catch (Exception ex) {
1226 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRequest() - " + ex.getMessage()
1227 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1228 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1234 public void prepareRpcSDNCActivateRequest (DelegateExecution execution) {
1235 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1236 execution.setVariable("prefix",Prefix)
1238 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1242 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1243 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1244 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1245 String networkId = execution.getVariable(Prefix + "networkId")
1246 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1248 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1249 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "activate", "CreateNetworkInstance", cloudRegionId, networkId, null)
1251 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1252 utils.logAudit(sndcTopologyCreateRequesAsString)
1253 execution.setVariable(Prefix + "activateSDNCRequest", sndcTopologyCreateRequesAsString)
1254 utils.log("DEBUG", Prefix + "activateSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1257 } catch (Exception ex) {
1258 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRequest() - " + ex.getMessage()
1259 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1260 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1269 // **************************************************
1270 // Post or Validate Response Section
1271 // **************************************************
1273 public void validateCreateNetworkResponse (DelegateExecution execution) {
1274 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1275 execution.setVariable("prefix",Prefix)
1277 utils.log("DEBUG", " ***** Inside validateNetworkResponse() of DoCreateNetworkInstance *****", isDebugEnabled)
1280 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1281 String networkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1282 if (networkResponse==null) {
1283 networkResponse="" // reset
1286 utils.log("DEBUG", " Network Adapter create responseCode: " + returnCode, isDebugEnabled)
1288 String errorMessage = ""
1289 if (returnCode == "200") {
1290 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1291 utils.logAudit(networkResponse)
1292 execution.setVariable(Prefix + "createNetworkResponse", networkResponse)
1293 utils.log("DEBUG", " Network Adapter create Success Response - " + "\n" + networkResponse, isDebugEnabled)
1295 // prepare rollback data
1296 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1297 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1298 String rollbackNetwork =
1299 """<rollbackNetworkRequest>
1301 </rollbackNetworkRequest>"""
1302 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1303 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1304 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1306 } else { // network error
1307 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1308 if (networkResponse.contains("createNetworkError")) {
1309 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1310 errorMessage = utils.getNodeText1(networkResponse, "message")
1311 errorMessage = "Received error from Network Adapter: " + errorMessage
1312 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1314 } else { // CatchAll exception
1315 if (returnCode == "500") {
1316 errorMessage = "JBWEB000065: HTTP Status 500."
1318 errorMessage = "Return code is " + returnCode
1320 errorMessage = "Received error from Network Adapter: " + errorMessage
1321 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1325 } else { // CatchAll exception
1326 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1327 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1333 } catch (BpmnError e) {
1336 } catch (Exception ex) {
1337 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. validateCreateNetworkResponse() - " + ex.getMessage()
1338 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1339 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1346 public void validateSDNCResponse (DelegateExecution execution) {
1347 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1348 execution.setVariable("prefix",Prefix)
1350 utils.log("DEBUG", " ***** Inside validateSDNCResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1352 String response = execution.getVariable(Prefix + "assignSDNCResponse")
1353 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1354 WorkflowException workflowException = execution.getVariable("WorkflowException")
1356 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1357 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1359 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "assignSDNCResponse"))
1360 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1361 execution.setVariable(Prefix + "assignSDNCResponse", assignSDNCResponseDecodeXml)
1363 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1364 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1365 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1368 utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1369 throw new BpmnError("MSOWorkflowException")
1374 public void validateRpcSDNCActivateResponse (DelegateExecution execution) {
1375 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1376 execution.setVariable("prefix",Prefix)
1378 utils.log("DEBUG", " ***** Inside validateRpcSDNCActivateResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1380 String response = execution.getVariable(Prefix + "activateSDNCResponse")
1381 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1382 WorkflowException workflowException = execution.getVariable("WorkflowException")
1384 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1385 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1387 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "activateSDNCResponse"))
1388 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1389 execution.setVariable(Prefix + "activateSDNCResponse", assignSDNCResponseDecodeXml)
1391 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1392 execution.setVariable(Prefix + "isSdncActivateRollbackNeeded", true)
1393 utils.log("DEBUG", "Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1396 utils.log("DEBUG", "Did NOT Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1397 throw new BpmnError("MSOWorkflowException")
1403 public void prepareSDNCRollbackRequest (DelegateExecution execution) {
1404 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1405 execution.setVariable("prefix",Prefix)
1407 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1411 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1412 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1413 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1414 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1415 String networkId = execution.getVariable(Prefix + "networkId")
1416 if (networkId == 'null') {networkId = ""}
1417 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1419 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1420 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1421 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1422 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1423 utils.log("DEBUG", " Preparing request for SDNC Topology 'rollback-NetworkActivateRequest' rollback . . . - " + "\n" + sndcTopologyRollbackRequestAsString, isDebugEnabled)
1426 } catch (Exception ex) {
1427 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1428 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1429 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1435 public void prepareRpcSDNCRollbackRequest (DelegateExecution execution) {
1436 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1437 execution.setVariable("prefix",Prefix)
1439 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1443 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1444 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1445 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1446 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1447 String networkId = execution.getVariable(Prefix + "networkId")
1448 if (networkId == 'null') {networkId = ""}
1449 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1451 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1452 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "unassign", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1453 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1454 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1455 utils.log("DEBUG", " Preparing request for SDNC Topology 'unassign-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1458 } catch (Exception ex) {
1459 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRollbackRequest() - " + ex.getMessage()
1460 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1461 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1467 public void prepareRpcSDNCActivateRollback(DelegateExecution execution) {
1468 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1469 execution.setVariable("prefix",Prefix)
1471 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRollback() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1476 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1477 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1478 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1479 String activateSDNCResponse = execution.getVariable(Prefix + "activateSDNCResponse")
1480 String networkId = execution.getVariable(Prefix + "networkId")
1481 if (networkId == 'null') {networkId = ""}
1482 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1484 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1485 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "deactivate", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1486 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1487 execution.setVariable(Prefix + "rollbackActivateSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1488 utils.log("DEBUG", " Preparing request for RPC SDNC Topology 'deactivate-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1491 } catch (Exception ex) {
1492 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRollback() - " + ex.getMessage()
1493 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1494 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1500 public void prepareRollbackData(DelegateExecution execution) {
1501 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1502 execution.setVariable("prefix",Prefix)
1504 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1508 Map<String, String> rollbackData = new HashMap<String, String>();
1509 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1510 if (rollbackSDNCRequest != null) {
1511 if (rollbackSDNCRequest != "") {
1512 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1515 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1516 if (rollbackNetworkRequest != null) {
1517 if (rollbackNetworkRequest != "") {
1518 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1521 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1522 if (rollbackActivateSDNCRequest != null) {
1523 if (rollbackActivateSDNCRequest != "") {
1524 rollbackData.put("rollbackActivateSDNCRequest", execution.getVariable(Prefix + "rollbackActivateSDNCRequest"))
1527 execution.setVariable("rollbackData", rollbackData)
1528 utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
1530 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1531 utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
1533 } catch (Exception ex) {
1534 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1535 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1536 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1542 public void postProcessResponse(DelegateExecution execution) {
1543 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1544 execution.setVariable("prefix",Prefix)
1546 utils.log("DEBUG", " ***** Inside postProcessResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1551 // 1. Silent Success: execution.getVariable("CRENWKI_orchestrationStatus") == "ACTIVE"
1552 // 2. Success: execution.getVariable("WorkflowException") == null (NULL)
1553 // 3. WorkflowException: execution.getVariable("WorkflowException") != null (NOT NULL)
1555 utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
1557 if (execution.getVariable(Prefix + "isException") == false) {
1558 // set rollback data
1559 execution.setVariable("orchestrationStatus", "")
1560 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1561 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1562 prepareSuccessRollbackData(execution) // populate rollbackData
1563 execution.setVariable("WorkflowException", null)
1564 execution.setVariable(Prefix + "Success", true)
1565 utils.log("DEBUG", " ***** postProcessResponse(), GOOD !!!", isDebugEnabled)
1567 // inside sub-flow logic
1568 execution.setVariable(Prefix + "Success", false)
1569 execution.setVariable("rollbackData", null)
1570 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1571 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1572 utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
1573 WorkflowException wfex = execution.getVariable("workflowException")
1574 exceptionMessage = wfex.getErrorMessage()
1576 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1577 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1578 exceptionMessage = pwfex.getErrorMessage()
1581 // going to the Main flow: a-la-carte or macro
1582 utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
1583 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1584 throw new BpmnError("MSOWorkflowException")
1587 } catch(BpmnError b){
1588 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
1591 } catch (Exception ex) {
1592 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1593 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1594 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1595 throw new BpmnError("MSOWorkflowException")
1603 public void prepareSuccessRollbackData(DelegateExecution execution) {
1604 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1605 execution.setVariable("prefix",Prefix)
1607 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1611 if (execution.getVariable("sdncVersion") != '1610') {
1612 prepareRpcSDNCRollbackRequest(execution)
1613 prepareRpcSDNCActivateRollback(execution)
1615 prepareSDNCRollbackRequest(execution)
1618 Map<String, String> rollbackData = new HashMap<String, String>();
1619 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1620 if (rollbackSDNCRequest != null) {
1621 if (rollbackSDNCRequest != "") {
1622 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1625 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1626 if (rollbackNetworkRequest != null) {
1627 if (rollbackNetworkRequest != "") {
1628 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1631 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1632 if (rollbackActivateSDNCRequest != null) {
1633 if (rollbackActivateSDNCRequest != "") {
1634 rollbackData.put("rollbackActivateSDNCRequest", rollbackActivateSDNCRequest)
1637 execution.setVariable("rollbackData", rollbackData)
1639 utils.log("DEBUG", "** 'rollbackData' for Full Rollback : " + rollbackData, isDebugEnabled)
1640 execution.setVariable("WorkflowException", null)
1643 } catch (Exception ex) {
1644 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1645 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1646 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1652 public void setExceptionFlag(DelegateExecution execution){
1653 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1654 execution.setVariable("prefix",Prefix)
1656 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1660 execution.setVariable(Prefix + "isException", true)
1662 if (execution.getVariable("SavedWorkflowException1") != null) {
1663 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1665 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1667 utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1669 } catch(Exception ex){
1670 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1671 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1672 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1678 // *******************************
1679 // Build Error Section
1680 // *******************************
1684 public void processJavaException(DelegateExecution execution){
1685 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1686 execution.setVariable("prefix",Prefix)
1689 utils.log("DEBUG", "Caught a Java Exception in " + Prefix, isDebugEnabled)
1690 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1691 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1692 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1693 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1695 }catch(Exception e){
1696 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1697 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1698 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
1700 utils.log("DEBUG", "Completed processJavaException Method in " + Prefix, isDebugEnabled)