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)
229 String messageId = execution.getVariable("testMessageId") // for testing
230 if (messageId == null || messageId == "") {
231 messageId = UUID.randomUUID()
232 utils.log("DEBUG", Prefix + "messageId, random generated: " + messageId, isDebugEnabled)
234 utils.log("DEBUG", Prefix + "messageId, pre-assigned: " + messageId, isDebugEnabled)
236 execution.setVariable(Prefix + "messageId", messageId)
238 String source = utils.getNodeText1(networkRequest, "source")
239 execution.setVariable(Prefix + "source", source)
240 utils.log("DEBUG", Prefix + "source - " + source, isDebugEnabled)
242 // validate cloud region
243 String lcpCloudRegionId = utils.getNodeText1(networkRequest, "aic-cloud-region")
244 if ((lcpCloudRegionId == null) || (lcpCloudRegionId == "") || (lcpCloudRegionId == "null")) {
245 String dataErrorMessage = "Missing value/element: 'lcpCloudRegionId' or 'cloudConfiguration' or 'aic-cloud-region'."
246 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
247 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
250 // validate service instance id
251 String serviceInstanceId = utils.getNodeText1(networkRequest, "service-instance-id")
252 if ((serviceInstanceId == null) || (serviceInstanceId == "") || (serviceInstanceId == "null")) {
253 String dataErrorMessage = "Missing value/element: 'serviceInstanceId'."
254 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
255 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
258 // PO Authorization Info / headers Authorization=
259 String basicAuthValuePO = execution.getVariable("URN_mso_adapters_po_auth")
260 utils.log("DEBUG", " Obtained BasicAuth userid password for PO/SDNC adapter: " + basicAuthValuePO, isDebugEnabled)
262 def encodedString = utils.getBasicAuth(basicAuthValuePO, execution.getVariable("URN_mso_msoKey"))
263 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
264 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
266 } catch (IOException ex) {
267 String exceptionMessage = "Exception Encountered in DoCreateNetworkInstance, PreProcessRequest() - "
268 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
269 utils.log("DEBUG", dataErrorMessage, , isDebugEnabled)
270 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
273 // Set variables for Generic Get Sub Flow use
274 execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
275 utils.log("DEBUG", Prefix + "serviceInstanceId - " + serviceInstanceId, isDebugEnabled)
277 execution.setVariable("GENGS_type", "service-instance")
278 utils.log("DEBUG", "GENGS_type - " + "service-instance", isDebugEnabled)
279 utils.log("DEBUG", " Url for SDNC adapter: " + execution.getVariable("URN_mso_adapters_sdnc_endpoint"), isDebugEnabled)
281 String sdncVersion = execution.getVariable("sdncVersion")
282 utils.log("DEBUG", "sdncVersion? : " + sdncVersion, isDebugEnabled)
284 // build 'networkOutputs'
285 String networkId = utils.getNodeText1(networkRequest, "network-id")
286 if ((networkId == null) || (networkId == "null")) {
289 String networkName = utils.getNodeText1(networkRequest, "network-name")
290 if ((networkName == null) || (networkName == "null")) {
293 String networkOutputs =
295 <network-id>${networkId}</network-id>
296 <network-name>${networkName}</network-name>
297 </network-outputs>"""
298 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
299 utils.log("DEBUG", Prefix + "networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
300 execution.setVariable(Prefix + "networkId", networkId)
301 execution.setVariable(Prefix + "networkName", networkName)
303 } catch (BpmnError e) {
306 } catch (Exception ex) {
307 sendSyncError(execution)
309 String exceptionMessage = "Exception Encountered in PreProcessRequest() of " + className + ".groovy ***** : " + ex.getMessage()
310 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
311 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
317 public void callRESTQueryAAINetworkName (Execution execution) {
318 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
319 execution.setVariable("prefix",Prefix)
321 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkName() of DoCreateNetworkInstance ***** " , isDebugEnabled)
324 String networkInputs = execution.getVariable(Prefix + "networkInputs")
325 String networkName = utils.getNodeText1(networkInputs, "network-name")
326 networkName = UriUtils.encode(networkName,"UTF-8")
327 String messageId = execution.getVariable("messageId")
329 // Prepare AA&I url with network-name
330 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
331 AaiUtil aaiUriUtil = new AaiUtil(this)
332 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
333 String queryAAINameRequest = "${aai_endpoint}${aai_uri}" + "?network-name=" + networkName
334 utils.logAudit(queryAAINameRequest)
335 execution.setVariable(Prefix + "queryNameAAIRequest", queryAAINameRequest)
336 utils.log("DEBUG", Prefix + "queryNameAAIRequest - " + "\n" + queryAAINameRequest, isDebugEnabled)
338 RESTConfig config = new RESTConfig(queryAAINameRequest);
341 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
342 .addHeader("X-FromAppId", "MSO")
343 .addHeader("Content-Type", "application/xml")
344 .addHeader("Accept","application/xml");
345 APIResponse response = client.get()
346 String returnCode = response.getStatusCode()
347 execution.setVariable(Prefix + "aaiNameReturnCode", returnCode)
348 utils.log("DEBUG", " ***** AAI Query Name Response Code : " + returnCode, isDebugEnabled)
350 String aaiResponseAsString = response.getResponseBodyAsString()
351 utils.log("DEBUG", " ***** AAI Query Name Response : " +'\n'+ aaiResponseAsString, isDebugEnabled)
353 if (returnCode=='200') {
354 utils.logAudit(aaiResponseAsString)
355 execution.setVariable(Prefix + "queryNameAAIResponse", aaiResponseAsString)
356 execution.setVariable(Prefix + "isAAIqueryNameGood", true)
357 String orchestrationStatus = ""
359 // response is NOT empty
360 orchestrationStatus = utils.getNodeText1(aaiResponseAsString, "orchestration-status")
361 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus.toUpperCase())
362 utils.log("DEBUG", Prefix + "orchestrationStatus - " + orchestrationStatus.toUpperCase(), isDebugEnabled)
363 execution.setVariable("orchestrationStatus", orchestrationStatus)
365 } catch (Exception ex) {
367 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus)
368 utils.log("DEBUG", Prefix + "orchestrationStatus - " + orchestrationStatus, isDebugEnabled)
372 if (returnCode=='404') {
373 utils.log("DEBUG", " QueryAAINetworkName return code = '404' (Not Found). Proceed with the Create !!! ", isDebugEnabled)
377 String dataErrorMessage = "Unexpected Error Response from QueryAAINetworkName - " + returnCode
378 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
379 exceptionUtil.buildWorkflowException(execution, 2500, dataErrorMessage)
385 utils.log("DEBUG", Prefix + "isAAIqueryNameGood? : " + execution.getVariable(Prefix + "isAAIqueryNameGood"), isDebugEnabled)
387 } catch (BpmnError e) {
390 } catch (Exception ex) {
392 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAINetworkName() - " + ex.getMessage()
393 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
394 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
400 public void callRESTQueryAAICloudRegion (Execution execution) {
401 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
402 execution.setVariable("prefix",Prefix)
404 utils.log("DEBUG", " ***** Inside callRESTQueryAAICloudRegion() of DoCreateNetworkInstance ***** " , isDebugEnabled)
407 String networkInputs = execution.getVariable(Prefix + "networkInputs")
408 String cloudRegion = utils.getNodeText1(networkInputs, "aic-cloud-region")
409 cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
412 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
413 AaiUtil aaiUtil = new AaiUtil(this)
414 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
415 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
416 utils.logAudit(queryCloudRegionRequest)
417 execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
418 utils.log("DEBUG", Prefix + "queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugEnabled)
420 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
421 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
423 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
424 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
425 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
426 execution.setVariable(Prefix + "isCloudRegionGood", true)
429 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
430 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
431 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
435 utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"), isDebugEnabled)
437 } catch (BpmnError e) {
440 } catch (Exception ex) {
442 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
443 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
444 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
450 public void callRESTQueryAAINetworkId(Execution execution) {
451 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
452 execution.setVariable("prefix",Prefix)
454 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkId() of DoCreateNetworkInstance ***** " , isDebugEnabled)
458 String networkId = ""
459 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
460 if (execution.getVariable("sdncVersion") == "1702") {
461 String networkResponseInformation = ""
463 networkResponseInformation = utils.getNodeXml(assignSDNCResponse, "network-response-information", false).replace("tag0:","").replace(":tag0","")
464 networkId = utils.getNodeText1(networkResponseInformation, "instance-id")
465 } catch (Exception ex) {
466 String dataErrorMessage = " SNDC Response network validation for 'instance-id' (network-id) failed: Empty <network-response-information>"
467 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
468 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
472 networkId = utils.getNodeText1(assignSDNCResponse, "network-id")
474 if (networkId == null || networkId == "null") {
475 String dataErrorMessage = "SNDC Response did not contains 'instance-id' or 'network-id' element, or the value is null."
476 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
477 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
479 utils.log("DEBUG", " SNDC Response network validation for 'instance-id' (network-id)' is good: " + networkId, isDebugEnabled)
483 execution.setVariable(Prefix + "networkId", networkId)
484 String networkName = utils.getNodeText1(assignSDNCResponse, "network-name")
485 execution.setVariable(Prefix + "networkName", networkName)
487 networkId = UriUtils.encode(networkId,"UTF-8")
488 String messageId = execution.getVariable(Prefix + "messageId")
491 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
492 AaiUtil aaiUriUtil = new AaiUtil(this)
493 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
494 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId
495 utils.logAudit(queryIdAAIRequest)
496 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
497 utils.log("DEBUG", Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest, isDebugEnabled)
499 RESTConfig config = new RESTConfig(queryIdAAIRequest);
500 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
501 .addHeader("X-FromAppId", "MSO")
502 .addHeader("Content-Type", "application/xml")
503 .addHeader("Accept","application/xml");
504 APIResponse response = client.get()
505 String returnCode = response.getStatusCode()
506 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
508 utils.log("DEBUG", " ***** AAI Response Code : " + returnCode, isDebugEnabled)
510 String aaiResponseAsString = response.getResponseBodyAsString()
512 if (returnCode=='200') {
513 utils.logAudit(aaiResponseAsString)
514 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
515 utils.log("DEBUG", " QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
517 String netId = utils.getNodeText1(aaiResponseAsString, "network-id")
518 execution.setVariable(Prefix + "networkId", netId)
519 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
520 execution.setVariable(Prefix + "networkName", netName)
523 if (returnCode=='404') {
524 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
525 utils.log("DEBUG", " AAI Query Failed. " + dataErrorMessage, isDebugEnabled)
526 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
529 if (aaiResponseAsString.contains("RESTFault")) {
530 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
531 execution.setVariable("WorkflowException", exceptionObject)
532 throw new BpmnError("MSOWorkflowException")
536 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
537 utils.log("DEBUG", "Unexpected Response from QueryAAINetworkId - " + dataErrorMessage, isDebugEnabled)
538 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
544 } catch (BpmnError e) {
547 } catch (Exception ex) {
548 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
549 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
550 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
556 public void callRESTReQueryAAINetworkId(Execution execution) {
557 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
558 execution.setVariable("prefix",Prefix)
560 utils.log("DEBUG", " ***** Inside callRESTReQueryAAINetworkId() of DoCreateNetworkInstance ***** " , isDebugEnabled)
564 String networkId = execution.getVariable(Prefix + "networkId")
565 String netId = networkId
566 networkId = UriUtils.encode(networkId,"UTF-8")
567 String messageId = execution.getVariable(Prefix + "messageId")
570 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
571 AaiUtil aaiUriUtil = new AaiUtil(this)
572 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
573 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId
574 utils.logAudit(requeryIdAAIRequest)
575 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
576 utils.log("DEBUG", Prefix + "requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest, isDebugEnabled)
578 RESTConfig config = new RESTConfig(requeryIdAAIRequest);
579 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
580 .addHeader("X-FromAppId", "MSO")
581 .addHeader("Content-Type", "application/xml")
582 .addHeader("Accept","application/xml");
583 APIResponse response = client.get()
584 String returnCode = response.getStatusCode()
585 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
586 utils.log("DEBUG", " ***** AAI ReQuery Response Code : " + returnCode, isDebugEnabled)
588 String aaiResponseAsString = response.getResponseBodyAsString()
590 if (returnCode=='200') {
591 utils.logAudit(aaiResponseAsString)
592 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
593 utils.log("DEBUG", " ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
595 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
596 String networkOutputs =
598 <network-id>${netId}</network-id>
599 <network-name>${netName}</network-name>
600 </network-outputs>"""
601 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
602 utils.log("DEBUG", " networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
605 if (returnCode=='404') {
606 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
607 utils.log("DEBUG", " AAI ReQuery Failed. - " + dataErrorMessage, isDebugEnabled)
608 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
611 if (aaiResponseAsString.contains("RESTFault")) {
612 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
613 execution.setVariable("WorkflowException", exceptionObject)
614 throw new BpmnError("MSOWorkflowException")
618 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
619 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
620 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
626 } catch (BpmnError e) {
629 } catch (Exception ex) {
630 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
631 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
632 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
638 public void callRESTQueryAAINetworkVpnBinding(Execution execution) {
639 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
640 execution.setVariable("prefix",Prefix)
642 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkVpnBinding() of DoCreateNetworkInstance ***** " , isDebugEnabled)
647 String messageId = execution.getVariable(Prefix + "messageId")
648 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
649 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
650 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
652 // Check if Vnf Binding is present, then build a List of vnfBinding
653 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
654 int vpnCount = vpnBindingUri.size()
655 execution.setVariable(Prefix + "vpnCount", vpnCount)
656 utils.log("DEBUG", Prefix + "vpnCount - " + vpnCount, isDebugEnabled)
658 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
659 AaiUtil aaiUriUtil = new AaiUtil(this)
662 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
663 utils.log("DEBUG", " vpnBindingUri List - " + vpnBindingUri, isDebugEnabled)
665 String routeTargets = ""
666 // AII loop call using list vpnBindings
667 for (i in 0..vpnBindingUri.size()-1) {
671 // prepare url using vpnBinding
672 String queryVpnBindingAAIRequest = ""
673 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
675 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
676 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
677 if (aai_uri == null || aai_uri == "") {
678 // using value of 'related-link' from response
679 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
680 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1)
682 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i]
686 // using uri value in URN mapping
687 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
688 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
689 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
691 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId
694 utils.logAudit(queryVpnBindingAAIRequest)
695 execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
696 utils.log("DEBUG", Prefix + "queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest, isDebugEnabled)
698 RESTConfig config = new RESTConfig(queryVpnBindingAAIRequest);
699 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
700 .addHeader("X-FromAppId", "MSO")
701 .addHeader("Content-Type", "application/xml")
702 .addHeader("Accept","application/xml");
703 APIResponse response = client.get()
704 String returnCode = response.getStatusCode()
705 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
706 utils.log("DEBUG", " ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode, isDebugEnabled)
708 String aaiResponseAsString = response.getResponseBodyAsString()
710 if (returnCode=='200') {
711 utils.logAudit(aaiResponseAsString)
712 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
713 utils.log("DEBUG", " AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
715 String routeTarget = ""
716 if (utils.nodeExists(aaiResponseAsString, "global-route-target")) {
717 routeTarget = utils.getNodeText1(aaiResponseAsString, "global-route-target")
718 routeTargets += "<routeTargets>" + routeTarget + "</routeTargets>" + '\n'
722 if (returnCode=='404') {
723 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
724 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
725 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
728 if (aaiResponseAsString.contains("RESTFault")) {
729 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
730 execution.setVariable("WorkflowException", exceptionObject)
731 throw new BpmnError("MSOWorkflowException")
735 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
736 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
737 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
745 execution.setVariable(Prefix + "routeCollection", routeTargets)
746 utils.log("DEBUG", Prefix + "routeCollection - " + '\n' + routeTargets, isDebugEnabled)
749 // reset return code to success
750 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
751 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
752 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
753 String aaiStubResponse =
754 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
755 <vpn-binding xmlns="${schemaVersion}">
756 <global-route-target/>
759 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
760 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
761 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
762 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
766 } catch (BpmnError e) {
769 } catch (Exception ex) {
770 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
771 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
772 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
778 public void callRESTQueryAAINetworkPolicy(Execution execution) {
779 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
780 execution.setVariable("prefix",Prefix)
782 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy() of DoCreateNetworkInstance ***** " , isDebugEnabled)
786 String messageId = execution.getVariable(Prefix + "messageId")
787 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
788 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
789 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
791 // Check if Network Policy is present, then build a List of network policy
792 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
793 int networkPolicyCount = networkPolicyUriList.size()
794 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
795 utils.log("DEBUG", Prefix + "networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
797 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
798 AaiUtil aaiUriUtil = new AaiUtil(this)
800 if (networkPolicyCount > 0) {
801 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
802 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
804 String networkPolicies = ""
805 // AII loop call using list vpnBindings
806 for (i in 0..networkPolicyUriList.size()-1) {
810 // prepare url using vpnBinding
811 String queryNetworkPolicyAAIRequest = ""
813 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
815 // Note: By default, the network policy url is found in 'related-link' of the response,
816 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
817 if (aai_uri == null || aai_uri == "") {
818 // using value of 'related-link' from response
819 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
820 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1)
822 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i]
825 // using uri value in URN mapping
826 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
827 println " networkPolicyId - " + networkPolicyId
828 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
829 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
831 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId
836 utils.logAudit(queryNetworkPolicyAAIRequest)
837 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
838 utils.log("DEBUG", Prefix + "queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
840 RESTConfig config = new RESTConfig(queryNetworkPolicyAAIRequest);
841 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
842 .addHeader("X-FromAppId", "MSO")
843 .addHeader("Content-Type", "application/xml")
844 .addHeader("Accept","application/xml");
845 APIResponse response = client.get()
846 String returnCode = response.getStatusCode()
847 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
848 utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
850 String aaiResponseAsString = response.getResponseBodyAsString()
852 if (returnCode=='200') {
853 utils.logAudit(aaiResponseAsString)
854 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
855 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
857 String networkPolicy = ""
858 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
859 networkPolicy = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
860 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
864 if (returnCode=='404') {
865 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
866 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
867 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
870 if (aaiResponseAsString.contains("RESTFault")) {
871 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
872 execution.setVariable("WorkflowException", exceptionObject)
873 throw new BpmnError("MSOWorkflowException")
877 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
878 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
879 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
887 execution.setVariable(Prefix + "networkCollection", networkPolicies)
888 utils.log("DEBUG", Prefix + "networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
891 // reset return code to success
892 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
893 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
894 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
895 String aaiStubResponse =
896 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
897 <network-policy xmlns="${schemaVersion}">
898 <network-policy-fqdn/>
901 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
902 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
903 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
904 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
908 } catch (BpmnError e) {
911 } catch (Exception ex) {
912 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
913 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
914 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
920 public void callRESTQueryAAINetworkTableRef(Execution execution) {
921 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
922 execution.setVariable("prefix",Prefix)
924 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef() of DoCreateNetworkInstance ***** " , isDebugEnabled)
928 String messageId = execution.getVariable(Prefix + "messageId")
929 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
930 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
931 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
933 // Check if Network TableREf is present, then build a List of network policy
934 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
935 int networkTableRefCount = networkTableRefUriList.size()
936 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
937 utils.log("DEBUG", Prefix + "networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
939 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
940 AaiUtil aaiUriUtil = new AaiUtil(this)
942 if (networkTableRefCount > 0) {
943 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
944 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
946 // AII loop call using list vpnBindings
947 String networkTableRefs = ""
948 for (i in 0..networkTableRefUriList.size()-1) {
952 // prepare url using tableRef
953 String queryNetworkTableRefAAIRequest = ""
955 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
957 // Note: By default, the network policy url is found in 'related-link' of the response,
958 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
959 if (aai_uri == null || aai_uri == "") {
960 // using value of 'related-link' from response
961 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
962 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1)
964 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i]
967 // using uri value in URN mapping
968 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
970 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
971 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
973 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId
978 utils.logAudit(queryNetworkTableRefAAIRequest)
979 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
980 utils.log("DEBUG", Prefix + "queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
982 RESTConfig config = new RESTConfig(queryNetworkTableRefAAIRequest);
983 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
984 .addHeader("X-FromAppId", "MSO")
985 .addHeader("Content-Type", "application/xml")
986 .addHeader("Accept","application/xml");
987 APIResponse response = client.get()
988 String returnCode = response.getStatusCode()
989 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
990 utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
992 String aaiResponseAsString = response.getResponseBodyAsString()
994 if (returnCode=='200') {
995 utils.logAudit(aaiResponseAsString)
996 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
997 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
999 String networkTableRef = ""
1000 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
1001 networkTableRef = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
1002 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
1006 if (returnCode=='404') {
1007 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
1008 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
1009 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1012 if (aaiResponseAsString.contains("RESTFault")) {
1013 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
1014 execution.setVariable("WorkflowException", exceptionObject)
1015 throw new BpmnError("MSOWorkflowException")
1019 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
1020 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
1021 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1029 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
1030 utils.log("DEBUG", Prefix + "tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
1033 // reset return code to success
1034 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
1035 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1036 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
1037 String aaiStubResponse =
1038 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
1039 <route-table-references xmlns="${schemaVersion}">
1040 <route-table-reference-fqdn/>
1041 </route-table-references>
1043 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
1044 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
1045 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
1046 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
1050 } catch (BpmnError e) {
1053 } catch (Exception ex) {
1054 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
1055 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1056 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1063 public void callRESTUpdateContrailAAINetwork(Execution execution) {
1064 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1065 execution.setVariable("prefix",Prefix)
1067 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork() of DoCreateNetworkInstance ***** " , isDebugEnabled)
1071 String networkId = execution.getVariable(Prefix + "networkId")
1072 networkId = UriUtils.encode(networkId,"UTF-8")
1073 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1074 String createNetworkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1075 String messageId = execution.getVariable(Prefix + "messageId")
1078 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1079 AaiUtil aaiUriUtil = new AaiUtil(this)
1080 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1081 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId
1083 utils.logAudit(updateContrailAAIUrlRequest)
1084 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
1085 utils.log("DEBUG", Prefix + "updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
1087 //Prepare payload (PUT)
1088 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
1089 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, createNetworkResponse, schemaVersion)
1090 String payloadXml = utils.formatXml(payload)
1091 utils.logAudit(payloadXml)
1092 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
1093 utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
1095 RESTConfig config = new RESTConfig(updateContrailAAIUrlRequest);
1096 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
1097 .addHeader("X-FromAppId", "MSO")
1098 .addHeader("Content-Type", "application/xml")
1099 .addHeader("Accept","application/xml");
1101 APIResponse response = client.httpPut(payload)
1102 String returnCode = response.getStatusCode()
1103 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
1105 utils.log("DEBUG", " ***** AAI Update Contrail Response Code : " + returnCode, isDebugEnabled)
1107 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
1109 if (returnCode=='200') {
1110 utils.logAudit(aaiUpdateContrailResponseAsString)
1111 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
1112 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
1113 // Point-of-no-return is set to false, rollback not needed.
1114 String rollbackEnabled = execution.getVariable(Prefix + "rollbackEnabled")
1115 if (rollbackEnabled == "true") {
1116 execution.setVariable(Prefix + "isPONR", false)
1118 execution.setVariable(Prefix + "isPONR", true)
1122 if (returnCode=='404') {
1123 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
1124 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
1125 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1128 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
1129 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
1130 execution.setVariable("WorkflowException", exceptionObject)
1131 throw new BpmnError("MSOWorkflowException")
1135 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
1136 utils.log("DEBUG", errorMessage, isDebugEnabled)
1137 exceptionUtil.buildAndThrowWorkflowException(execution, "2500", errorMessage)
1142 } catch (BpmnError e) {
1145 } catch (Exception ex) {
1146 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
1147 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1148 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1154 public void prepareCreateNetworkRequest (Execution execution) {
1155 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1156 execution.setVariable("prefix",Prefix)
1158 utils.log("DEBUG", " ***** Inside prepareCreateNetworkRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1163 String requestId = execution.getVariable("msoRequestId")
1164 if (requestId == null) {
1165 requestId = execution.getVariable("mso-request-id")
1167 String messageId = execution.getVariable(Prefix + "messageId")
1168 String source = execution.getVariable(Prefix + "source")
1170 String requestInput = execution.getVariable(Prefix + "networkRequest")
1171 String queryIdResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1172 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1173 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1175 // Prepare Network request
1176 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1177 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1178 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1179 String createNetworkRequest = networkUtils.CreateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1181 String buildDeleteNetworkRequestAsString = utils.formatXml(createNetworkRequest)
1182 buildDeleteNetworkRequestAsString = buildDeleteNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1183 utils.logAudit(buildDeleteNetworkRequestAsString)
1185 execution.setVariable(Prefix + "createNetworkRequest", buildDeleteNetworkRequestAsString)
1186 utils.log("DEBUG", Prefix + "createNetworkRequest - " + "\n" + buildDeleteNetworkRequestAsString, isDebugEnabled)
1188 } catch (Exception ex) {
1189 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareCreateNetworkRequest() - " + ex.getMessage()
1190 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1191 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1197 public void prepareSDNCRequest (Execution execution) {
1198 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1199 execution.setVariable("prefix",Prefix)
1201 utils.log("DEBUG", " ***** Inside prepareSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1205 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1206 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1207 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1209 String networkId = execution.getVariable(Prefix + "networkId")
1210 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1212 // get/set 'msoRequestId' and 'mso-request-id'
1213 String requestId = execution.getVariable("msoRequestId")
1214 if (requestId != null) {
1215 execution.setVariable("mso-request-id", requestId)
1217 requestId = execution.getVariable("mso-request-id")
1219 execution.setVariable(Prefix + "requestId", requestId)
1221 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1222 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1224 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1225 utils.logAudit(sndcTopologyCreateRequesAsString)
1226 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1227 utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1230 } catch (Exception ex) {
1231 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1232 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1233 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1239 public void prepareRpcSDNCRequest (Execution execution) {
1240 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1241 execution.setVariable("prefix",Prefix)
1243 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1248 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1249 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1250 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1252 String networkId = execution.getVariable(Prefix + "networkId")
1253 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1255 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1256 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "CreateNetworkInstance", cloudRegionId, networkId, null)
1258 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1259 utils.logAudit(sndcTopologyCreateRequesAsString)
1260 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1261 utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1263 } catch (Exception ex) {
1264 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRequest() - " + ex.getMessage()
1265 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1266 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1272 public void prepareRpcSDNCActivateRequest (Execution execution) {
1273 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1274 execution.setVariable("prefix",Prefix)
1276 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1280 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1281 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1282 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1283 String networkId = execution.getVariable(Prefix + "networkId")
1284 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1286 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1287 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "activate", "ActivateNetworkInstance", cloudRegionId, networkId, null)
1289 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1290 utils.logAudit(sndcTopologyCreateRequesAsString)
1291 execution.setVariable(Prefix + "activateSDNCRequest", sndcTopologyCreateRequesAsString)
1292 utils.log("DEBUG", Prefix + "activateSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1295 } catch (Exception ex) {
1296 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRequest() - " + ex.getMessage()
1297 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1298 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1307 // **************************************************
1308 // Post or Validate Response Section
1309 // **************************************************
1311 public void validateCreateNetworkResponse (Execution execution) {
1312 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1313 execution.setVariable("prefix",Prefix)
1315 utils.log("DEBUG", " ***** Inside validateNetworkResponse() of DoCreateNetworkInstance *****", isDebugEnabled)
1318 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1319 String networkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1320 if (networkResponse==null) {
1321 networkResponse="" // reset
1324 utils.log("DEBUG", " Network Adapter create responseCode: " + returnCode, isDebugEnabled)
1326 String errorMessage = ""
1327 if (returnCode == "200") {
1328 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1329 utils.logAudit(networkResponse)
1330 execution.setVariable(Prefix + "createNetworkResponse", networkResponse)
1331 utils.log("DEBUG", " Network Adapter create Success Response - " + "\n" + networkResponse, isDebugEnabled)
1333 // prepare rollback data
1334 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1335 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1336 String rollbackNetwork =
1337 """<rollbackNetworkRequest>
1339 </rollbackNetworkRequest>"""
1340 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1341 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1342 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1344 } else { // network error
1345 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1346 if (networkResponse.contains("createNetworkError")) {
1347 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1348 errorMessage = utils.getNodeText1(networkResponse, "message")
1349 errorMessage = "Received error from Network Adapter: " + errorMessage
1350 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1352 } else { // CatchAll exception
1353 if (returnCode == "500") {
1354 errorMessage = "JBWEB000065: HTTP Status 500."
1356 errorMessage = "Return code is " + returnCode
1358 errorMessage = "Received error from Network Adapter: " + errorMessage
1359 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1363 } else { // CatchAll exception
1364 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1365 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1371 } catch (BpmnError e) {
1374 } catch (Exception ex) {
1375 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. validateCreateNetworkResponse() - " + ex.getMessage()
1376 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1377 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1384 public void validateSDNCResponse (Execution execution) {
1385 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1386 execution.setVariable("prefix",Prefix)
1388 utils.log("DEBUG", " ***** Inside validateSDNCResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1390 String response = execution.getVariable(Prefix + "assignSDNCResponse")
1391 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1392 WorkflowException workflowException = execution.getVariable("WorkflowException")
1394 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1395 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1397 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "assignSDNCResponse"))
1398 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1399 execution.setVariable(Prefix + "assignSDNCResponse", assignSDNCResponseDecodeXml)
1401 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1402 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1403 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1406 utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1407 throw new BpmnError("MSOWorkflowException")
1412 public void validateRpcSDNCActivateResponse (Execution execution) {
1413 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1414 execution.setVariable("prefix",Prefix)
1416 utils.log("DEBUG", " ***** Inside validateRpcSDNCActivateResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1418 String response = execution.getVariable(Prefix + "activateSDNCResponse")
1419 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1420 WorkflowException workflowException = execution.getVariable("WorkflowException")
1422 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1423 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1425 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "activateSDNCResponse"))
1426 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1427 execution.setVariable(Prefix + "activateSDNCResponse", assignSDNCResponseDecodeXml)
1429 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1430 execution.setVariable(Prefix + "isSdncActivateRollbackNeeded", true)
1431 utils.log("DEBUG", "Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1434 utils.log("DEBUG", "Did NOT Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1435 throw new BpmnError("MSOWorkflowException")
1441 public void prepareSDNCRollbackRequest (Execution execution) {
1442 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1443 execution.setVariable("prefix",Prefix)
1445 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1449 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1450 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1451 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1452 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1453 String networkId = execution.getVariable(Prefix + "networkId")
1454 if (networkId == 'null') {networkId = ""}
1455 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1457 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1458 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1459 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1460 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1461 utils.log("DEBUG", " Preparing request for SDNC Topology 'rollback-NetworkActivateRequest' rollback . . . - " + "\n" + sndcTopologyRollbackRequestAsString, isDebugEnabled)
1464 } catch (Exception ex) {
1465 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1466 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1467 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1473 public void prepareRpcSDNCRollbackRequest (Execution execution) {
1474 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1475 execution.setVariable("prefix",Prefix)
1477 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1481 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1482 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1483 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1484 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1485 String networkId = execution.getVariable(Prefix + "networkId")
1486 if (networkId == 'null') {networkId = ""}
1487 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1489 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1490 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "unassign", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1491 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1492 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1493 utils.log("DEBUG", " Preparing request for SDNC Topology 'unassign-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1496 } catch (Exception ex) {
1497 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRollbackRequest() - " + ex.getMessage()
1498 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1499 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1505 public void prepareRpcSDNCActivateRollback(Execution execution) {
1506 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1507 execution.setVariable("prefix",Prefix)
1509 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRollback() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1514 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1515 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1516 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1517 String activateSDNCResponse = execution.getVariable(Prefix + "activateSDNCResponse")
1518 String networkId = execution.getVariable(Prefix + "networkId")
1519 if (networkId == 'null') {networkId = ""}
1520 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1522 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1523 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "deactivate", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1524 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1525 execution.setVariable(Prefix + "rollbackActivateSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1526 utils.log("DEBUG", " Preparing request for RPC SDNC Topology 'deactivate-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1529 } catch (Exception ex) {
1530 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRollback() - " + ex.getMessage()
1531 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1532 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1538 public void prepareRollbackData(Execution execution) {
1539 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1540 execution.setVariable("prefix",Prefix)
1542 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1546 Map<String, String> rollbackData = new HashMap<String, String>();
1547 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1548 if (rollbackSDNCRequest != null) {
1549 if (rollbackSDNCRequest != "") {
1550 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1553 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1554 if (rollbackNetworkRequest != null) {
1555 if (rollbackNetworkRequest != "") {
1556 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1559 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1560 if (rollbackActivateSDNCRequest != null) {
1561 if (rollbackActivateSDNCRequest != "") {
1562 rollbackData.put("rollbackActivateSDNCRequest", execution.getVariable(Prefix + "rollbackActivateSDNCRequest"))
1565 execution.setVariable("rollbackData", rollbackData)
1566 utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
1568 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1569 utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
1571 } catch (Exception ex) {
1572 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1573 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1574 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1580 public void postProcessResponse(Execution execution) {
1581 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1582 execution.setVariable("prefix",Prefix)
1584 utils.log("DEBUG", " ***** Inside postProcessResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1589 // 1. Silent Success: execution.getVariable("CRENWKI_orchestrationStatus") == "ACTIVE"
1590 // 2. Success: execution.getVariable("WorkflowException") == null (NULL)
1591 // 3. WorkflowException: execution.getVariable("WorkflowException") != null (NOT NULL)
1593 utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
1595 if (execution.getVariable(Prefix + "isException") == false) {
1596 // set rollback data
1597 execution.setVariable("orchestrationStatus", "")
1598 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1599 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1600 prepareSuccessRollbackData(execution) // populate rollbackData
1601 execution.setVariable("WorkflowException", null)
1602 execution.setVariable(Prefix + "Success", true)
1603 utils.log("DEBUG", " ***** postProcessResponse(), GOOD !!!", isDebugEnabled)
1605 // inside sub-flow logic
1606 execution.setVariable(Prefix + "Success", false)
1607 execution.setVariable("rollbackData", null)
1608 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1609 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1610 utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
1611 WorkflowException wfex = execution.getVariable("workflowException")
1612 exceptionMessage = wfex.getErrorMessage()
1614 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1615 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1616 exceptionMessage = pwfex.getErrorMessage()
1619 // going to the Main flow: a-la-carte or macro
1620 utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
1621 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1622 throw new BpmnError("MSOWorkflowException")
1625 } catch(BpmnError b){
1626 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
1629 } catch (Exception ex) {
1630 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1631 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1632 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1633 throw new BpmnError("MSOWorkflowException")
1641 public void prepareSuccessRollbackData(Execution execution) {
1642 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1643 execution.setVariable("prefix",Prefix)
1645 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1649 if (execution.getVariable("sdncVersion") == '1702') {
1650 prepareRpcSDNCRollbackRequest(execution)
1651 prepareRpcSDNCActivateRollback(execution)
1653 prepareSDNCRollbackRequest(execution)
1656 Map<String, String> rollbackData = new HashMap<String, String>();
1657 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1658 if (rollbackSDNCRequest != null) {
1659 if (rollbackSDNCRequest != "") {
1660 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1663 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1664 if (rollbackNetworkRequest != null) {
1665 if (rollbackNetworkRequest != "") {
1666 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1669 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1670 if (rollbackActivateSDNCRequest != null) {
1671 if (rollbackActivateSDNCRequest != "") {
1672 rollbackData.put("rollbackActivateSDNCRequest", rollbackActivateSDNCRequest)
1675 execution.setVariable("rollbackData", rollbackData)
1677 utils.log("DEBUG", "** 'rollbackData' for Full Rollback : " + rollbackData, isDebugEnabled)
1678 execution.setVariable("WorkflowException", null)
1681 } catch (Exception ex) {
1682 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1683 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1684 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1690 public void setExceptionFlag(Execution execution){
1691 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1692 execution.setVariable("prefix",Prefix)
1694 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1698 execution.setVariable(Prefix + "isException", true)
1700 if (execution.getVariable("SavedWorkflowException1") != null) {
1701 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1703 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1705 utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1707 } catch(Exception ex){
1708 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1709 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1710 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1716 // *******************************
1717 // Build Error Section
1718 // *******************************
1722 public void processJavaException(Execution execution){
1723 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1724 execution.setVariable("prefix",Prefix)
1727 utils.log("DEBUG", "Caught a Java Exception in " + Prefix, isDebugEnabled)
1728 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1729 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1730 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1731 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1733 }catch(Exception e){
1734 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1735 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1736 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
1738 utils.log("DEBUG", "Completed processJavaException Method in " + Prefix, isDebugEnabled)