2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
22 import groovy.xml.XmlUtil
24 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
25 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
\r
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
28 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
\r
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
\r
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
31 import org.openecomp.mso.bpmn.core.WorkflowException
\r
32 import org.openecomp.mso.rest.APIResponse;
\r
33 import org.openecomp.mso.rest.RESTClient
\r
34 import org.openecomp.mso.rest.RESTConfig
\r
36 import java.util.HashMap;
38 import java.util.UUID;
40 import org.camunda.bpm.engine.delegate.BpmnError
41 import org.camunda.bpm.engine.runtime.Execution
42 import org.apache.commons.lang3.*
43 import org.apache.commons.codec.binary.Base64;
44 import org.springframework.web.util.UriUtils
47 * This groovy class supports the <class>DoCreateNetworkInstance.bpmn</class> process.
50 public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor {
51 String Prefix="CRENWKI_"
52 ExceptionUtil exceptionUtil = new ExceptionUtil()
53 JsonUtils jsonUtil = new JsonUtils()
54 VidUtils vidUtils = new VidUtils(this)
55 NetworkUtils networkUtils = new NetworkUtils()
56 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
58 def className = getClass().getSimpleName()
61 * This method is executed during the preProcessRequest task of the <class>DoCreateNetworkInstance.bpmn</class> process.
64 public InitializeProcessVariables(Execution execution){
65 /* Initialize all the process variables in this block */
67 execution.setVariable(Prefix + "networkRequest", "")
68 execution.setVariable(Prefix + "rollbackEnabled", null)
69 execution.setVariable(Prefix + "networkInputs", "")
70 //execution.setVariable(Prefix + "requestId", "")
71 execution.setVariable(Prefix + "messageId", "")
72 execution.setVariable(Prefix + "source", "")
73 execution.setVariable("BasicAuthHeaderValuePO", "")
74 execution.setVariable("BasicAuthHeaderValueSDNC", "")
75 execution.setVariable(Prefix + "serviceInstanceId","")
76 execution.setVariable("GENGS_type", "")
77 execution.setVariable(Prefix + "rsrc_endpoint", null)
78 execution.setVariable(Prefix + "networkOutputs", "")
79 execution.setVariable(Prefix + "networkId","")
80 execution.setVariable(Prefix + "networkName","")
83 execution.setVariable(Prefix + "queryNameAAIRequest","")
84 execution.setVariable(Prefix + "queryNameAAIResponse", "")
85 execution.setVariable(Prefix + "aaiNameReturnCode", "")
86 execution.setVariable(Prefix + "isAAIqueryNameGood", false)
88 // AAI query Cloud Region
89 execution.setVariable(Prefix + "queryCloudRegionRequest","")
90 execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
91 execution.setVariable(Prefix + "queryCloudRegionResponse","")
92 execution.setVariable(Prefix + "cloudRegionPo","")
93 execution.setVariable(Prefix + "cloudRegionSdnc","")
94 execution.setVariable(Prefix + "isCloudRegionGood", false)
97 execution.setVariable(Prefix + "queryIdAAIRequest","")
98 execution.setVariable(Prefix + "queryIdAAIResponse", "")
99 execution.setVariable(Prefix + "aaiIdReturnCode", "")
101 // AAI query vpn binding
102 execution.setVariable(Prefix + "queryVpnBindingAAIRequest","")
103 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", "")
104 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "")
105 execution.setVariable(Prefix + "vpnBindings", null)
106 execution.setVariable(Prefix + "vpnCount", 0)
107 execution.setVariable(Prefix + "routeCollection", "")
109 // AAI query network policy
110 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest","")
111 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", "")
112 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "")
113 execution.setVariable(Prefix + "networkPolicyUriList", null)
114 execution.setVariable(Prefix + "networkPolicyCount", 0)
115 execution.setVariable(Prefix + "networkCollection", "")
117 // AAI query route table reference
118 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest","")
119 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", "")
120 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "")
121 execution.setVariable(Prefix + "networkTableRefUriList", null)
122 execution.setVariable(Prefix + "networkTableRefCount", 0)
123 execution.setVariable(Prefix + "tableRefCollection", "")
126 execution.setVariable(Prefix + "requeryIdAAIRequest","")
127 execution.setVariable(Prefix + "requeryIdAAIResponse", "")
128 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
130 // AAI update contrail
131 execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
132 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
133 execution.setVariable(Prefix + "updateContrailAAIResponse", "")
134 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
136 execution.setVariable(Prefix + "createNetworkRequest", "")
137 execution.setVariable(Prefix + "createNetworkResponse", "")
138 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
139 //execution.setVariable(Prefix + "rollbackNetworkResponse", "")
140 execution.setVariable(Prefix + "networkReturnCode", "")
141 //execution.setVariable(Prefix + "rollbackNetworkReturnCode", "")
142 execution.setVariable(Prefix + "isNetworkRollbackNeeded", false)
144 execution.setVariable(Prefix + "assignSDNCRequest", "")
145 execution.setVariable(Prefix + "assignSDNCResponse", "")
146 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
147 //execution.setVariable(Prefix + "rollbackSDNCResponse", "")
148 execution.setVariable(Prefix + "sdncReturnCode", "")
149 //execution.setVariable(Prefix + "rollbackSDNCReturnCode", "")
150 execution.setVariable(Prefix + "isSdncRollbackNeeded", false)
151 execution.setVariable(Prefix + "sdncResponseSuccess", false)
153 execution.setVariable(Prefix + "activateSDNCRequest", "")
154 execution.setVariable(Prefix + "activateSDNCResponse", "")
155 execution.setVariable(Prefix + "rollbackActivateSDNCRequest", "")
156 //execution.setVariable(Prefix + "rollbackActivateSDNCResponse", "")
157 execution.setVariable(Prefix + "sdncActivateReturnCode", "")
158 //execution.setVariable(Prefix + "rollbackActivateSDNCReturnCode", "")
159 execution.setVariable(Prefix + "isSdncActivateRollbackNeeded", false)
160 execution.setVariable(Prefix + "sdncActivateResponseSuccess", false)
162 execution.setVariable(Prefix + "orchestrationStatus", "")
163 execution.setVariable(Prefix + "isVnfBindingPresent", false)
164 execution.setVariable(Prefix + "Success", false)
166 execution.setVariable(Prefix + "isException", false)
170 // **************************************************
171 // Pre or Prepare Request Section
172 // **************************************************
174 * This method is executed during the preProcessRequest task of the <class>DoCreateNetworkInstance.bpmn</class> process.
177 public void preProcessRequest (Execution execution) {
178 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
179 execution.setVariable("prefix",Prefix)
181 utils.log("DEBUG", " ***** Inside preProcessRequest() of " + className + ".groovy ***** ", isDebugEnabled)
184 // initialize flow variables
185 InitializeProcessVariables(execution)
187 // GET Incoming request & validate 3 kinds of format.
188 execution.setVariable("action", "CREATE")
189 String networkRequest = execution.getVariable("bpmnRequest")
190 if (networkRequest != null) {
191 if (networkRequest.contains("requestDetails")) {
192 // JSON format request is sent, create xml
194 def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
195 utils.log("DEBUG", " Incoming message formatted . . . : " + '\n' + prettyJson, isDebugEnabled)
196 networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
198 } catch (Exception ex) {
199 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
200 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
201 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
204 // XML format request is sent
208 // vIPR format request is sent, create xml from individual variables
209 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
212 networkRequest = utils.formatXml(networkRequest)
213 utils.logAudit(networkRequest)
214 execution.setVariable(Prefix + "networkRequest", networkRequest)
215 utils.log("DEBUG", Prefix + "networkRequest - " + '\n' + networkRequest, isDebugEnabled)
217 // validate 'backout-on-failure' to override 'URN_mso_rollback'
218 boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
219 execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
220 utils.log("DEBUG", Prefix + "rollbackEnabled - " + rollbackEnabled, isDebugEnabled)
222 String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
223 execution.setVariable(Prefix + "networkInputs", networkInputs)
224 utils.log("DEBUG", Prefix + "networkInputs - " + '\n' + networkInputs, isDebugEnabled)
227 String messageId = execution.getVariable("testMessageId") // for testing
228 if (messageId == null || messageId == "") {
229 messageId = UUID.randomUUID()
230 utils.log("DEBUG", Prefix + "messageId, random generated: " + messageId, isDebugEnabled)
232 utils.log("DEBUG", Prefix + "messageId, pre-assigned: " + messageId, isDebugEnabled)
234 execution.setVariable(Prefix + "messageId", messageId)
236 String source = utils.getNodeText1(networkRequest, "source")
237 execution.setVariable(Prefix + "source", source)
238 utils.log("DEBUG", Prefix + "source - " + source, isDebugEnabled)
240 // validate cloud region
241 String lcpCloudRegionId = utils.getNodeText1(networkRequest, "aic-cloud-region")
242 if ((lcpCloudRegionId == null) || (lcpCloudRegionId == "") || (lcpCloudRegionId == "null")) {
243 String dataErrorMessage = "Missing value/element: 'lcpCloudRegionId' or 'cloudConfiguration' or 'aic-cloud-region'."
244 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
245 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
248 // validate service instance id
249 String serviceInstanceId = utils.getNodeText1(networkRequest, "service-instance-id")
250 if ((serviceInstanceId == null) || (serviceInstanceId == "") || (serviceInstanceId == "null")) {
251 String dataErrorMessage = "Missing value/element: 'serviceInstanceId'."
252 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
253 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
256 // PO Authorization Info / headers Authorization=
257 String basicAuthValuePO = execution.getVariable("URN_mso_adapters_po_auth")
258 utils.log("DEBUG", " Obtained BasicAuth userid password for PO/SDNC adapter: " + basicAuthValuePO, isDebugEnabled)
260 def encodedString = utils.getBasicAuth(basicAuthValuePO, execution.getVariable("URN_mso_msoKey"))
261 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
262 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
264 } catch (IOException ex) {
265 String exceptionMessage = "Exception Encountered in DoCreateNetworkInstance, PreProcessRequest() - "
266 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
267 utils.log("DEBUG", dataErrorMessage, , isDebugEnabled)
268 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
271 // Set variables for Generic Get Sub Flow use
272 execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
273 utils.log("DEBUG", Prefix + "serviceInstanceId - " + serviceInstanceId, isDebugEnabled)
275 execution.setVariable("GENGS_type", "service-instance")
276 utils.log("DEBUG", "GENGS_type - " + "service-instance", isDebugEnabled)
277 utils.log("DEBUG", " Url for SDNC adapter: " + execution.getVariable("URN_mso_adapters_sdnc_endpoint"), isDebugEnabled)
279 String sdncVersion = execution.getVariable("sdncVersion")
280 utils.log("DEBUG", "sdncVersion? : " + sdncVersion, isDebugEnabled)
282 // build 'networkOutputs'
283 String networkId = utils.getNodeText1(networkRequest, "network-id")
284 if ((networkId == null) || (networkId == "null")) {
287 String networkName = utils.getNodeText1(networkRequest, "network-name")
288 if ((networkName == null) || (networkName == "null")) {
291 String networkOutputs =
293 <network-id>${networkId}</network-id>
294 <network-name>${networkName}</network-name>
295 </network-outputs>"""
296 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
297 utils.log("DEBUG", Prefix + "networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
298 execution.setVariable(Prefix + "networkId", networkId)
299 execution.setVariable(Prefix + "networkName", networkName)
301 } catch (BpmnError e) {
304 } catch (Exception ex) {
305 sendSyncError(execution)
307 String exceptionMessage = "Exception Encountered in PreProcessRequest() of " + className + ".groovy ***** : " + ex.getMessage()
308 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
309 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
315 public void callRESTQueryAAINetworkName (Execution execution) {
316 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
317 execution.setVariable("prefix",Prefix)
319 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkName() of DoCreateNetworkInstance ***** " , isDebugEnabled)
322 String networkInputs = execution.getVariable(Prefix + "networkInputs")
323 String networkName = utils.getNodeText1(networkInputs, "network-name")
324 networkName = UriUtils.encode(networkName,"UTF-8")
325 String messageId = execution.getVariable("messageId")
327 // Prepare AA&I url with network-name
328 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
329 AaiUtil aaiUriUtil = new AaiUtil(this)
330 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
331 String queryAAINameRequest = "${aai_endpoint}${aai_uri}" + "?network-name=" + networkName
332 utils.logAudit(queryAAINameRequest)
333 execution.setVariable(Prefix + "queryNameAAIRequest", queryAAINameRequest)
334 utils.log("DEBUG", Prefix + "queryNameAAIRequest - " + "\n" + queryAAINameRequest, isDebugEnabled)
336 RESTConfig config = new RESTConfig(queryAAINameRequest);
339 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
340 .addHeader("X-FromAppId", "MSO")
341 .addHeader("Content-Type", "application/xml")
342 .addHeader("Accept","application/xml");
343 APIResponse response = client.get()
344 String returnCode = response.getStatusCode()
345 execution.setVariable(Prefix + "aaiNameReturnCode", returnCode)
346 utils.log("DEBUG", " ***** AAI Query Name Response Code : " + returnCode, isDebugEnabled)
348 String aaiResponseAsString = response.getResponseBodyAsString()
349 utils.log("DEBUG", " ***** AAI Query Name Response : " +'\n'+ aaiResponseAsString, isDebugEnabled)
351 if (returnCode=='200') {
352 utils.logAudit(aaiResponseAsString)
353 execution.setVariable(Prefix + "queryNameAAIResponse", aaiResponseAsString)
354 execution.setVariable(Prefix + "isAAIqueryNameGood", true)
355 String orchestrationStatus = ""
357 // response is NOT empty
358 orchestrationStatus = utils.getNodeText1(aaiResponseAsString, "orchestration-status")
359 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus.toUpperCase())
360 utils.log("DEBUG", Prefix + "orchestrationStatus - " + orchestrationStatus.toUpperCase(), isDebugEnabled)
361 execution.setVariable("orchestrationStatus", orchestrationStatus)
363 } catch (Exception ex) {
365 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus)
366 utils.log("DEBUG", Prefix + "orchestrationStatus - " + orchestrationStatus, isDebugEnabled)
370 if (returnCode=='404') {
371 utils.log("DEBUG", " QueryAAINetworkName return code = '404' (Not Found). Proceed with the Create !!! ", isDebugEnabled)
375 String dataErrorMessage = "Unexpected Error Response from QueryAAINetworkName - " + returnCode
376 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
377 exceptionUtil.buildWorkflowException(execution, 2500, dataErrorMessage)
383 utils.log("DEBUG", Prefix + "isAAIqueryNameGood? : " + execution.getVariable(Prefix + "isAAIqueryNameGood"), isDebugEnabled)
385 } catch (BpmnError e) {
388 } catch (Exception ex) {
390 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAINetworkName() - " + ex.getMessage()
391 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
392 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
398 public void callRESTQueryAAICloudRegion (Execution execution) {
399 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
400 execution.setVariable("prefix",Prefix)
402 utils.log("DEBUG", " ***** Inside callRESTQueryAAICloudRegion() of DoCreateNetworkInstance ***** " , isDebugEnabled)
405 String networkInputs = execution.getVariable(Prefix + "networkInputs")
406 String cloudRegion = utils.getNodeText1(networkInputs, "aic-cloud-region")
407 cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
410 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
411 AaiUtil aaiUtil = new AaiUtil(this)
412 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
413 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
414 utils.logAudit(queryCloudRegionRequest)
415 execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
416 utils.log("DEBUG", Prefix + "queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugEnabled)
418 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
419 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
421 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
422 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
423 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
424 execution.setVariable(Prefix + "isCloudRegionGood", true)
427 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
428 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
429 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
433 utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"), isDebugEnabled)
435 } catch (BpmnError e) {
438 } catch (Exception ex) {
440 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
441 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
442 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
448 public void callRESTQueryAAINetworkId(Execution execution) {
449 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
450 execution.setVariable("prefix",Prefix)
452 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkId() of DoCreateNetworkInstance ***** " , isDebugEnabled)
456 String networkId = ""
457 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
458 if (execution.getVariable("sdncVersion") == "1702") {
459 String networkResponseInformation = ""
461 networkResponseInformation = utils.getNodeXml(assignSDNCResponse, "network-response-information", false).replace("tag0:","").replace(":tag0","")
462 networkId = utils.getNodeText1(networkResponseInformation, "instance-id")
463 } catch (Exception ex) {
464 String dataErrorMessage = " SNDC Response network validation for 'instance-id' (network-id) failed: Empty <network-response-information>"
465 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
466 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
470 networkId = utils.getNodeText1(assignSDNCResponse, "network-id")
472 if (networkId == null || networkId == "null") {
473 String dataErrorMessage = "SNDC Response did not contains 'instance-id' or 'network-id' element, or the value is null."
474 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
475 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
477 utils.log("DEBUG", " SNDC Response network validation for 'instance-id' (network-id)' is good: " + networkId, isDebugEnabled)
481 execution.setVariable(Prefix + "networkId", networkId)
482 String networkName = utils.getNodeText1(assignSDNCResponse, "network-name")
483 execution.setVariable(Prefix + "networkName", networkName)
485 networkId = UriUtils.encode(networkId,"UTF-8")
486 String messageId = execution.getVariable(Prefix + "messageId")
489 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
490 AaiUtil aaiUriUtil = new AaiUtil(this)
491 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
492 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
493 utils.logAudit(queryIdAAIRequest)
494 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
495 utils.log("DEBUG", Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest, isDebugEnabled)
497 RESTConfig config = new RESTConfig(queryIdAAIRequest);
498 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
499 .addHeader("X-FromAppId", "MSO")
500 .addHeader("Content-Type", "application/xml")
501 .addHeader("Accept","application/xml");
502 APIResponse response = client.get()
503 String returnCode = response.getStatusCode()
504 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
506 utils.log("DEBUG", " ***** AAI Response Code : " + returnCode, isDebugEnabled)
508 String aaiResponseAsString = response.getResponseBodyAsString()
510 if (returnCode=='200') {
511 utils.logAudit(aaiResponseAsString)
512 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
513 utils.log("DEBUG", " QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
515 String netId = utils.getNodeText1(aaiResponseAsString, "network-id")
516 execution.setVariable(Prefix + "networkId", netId)
517 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
518 execution.setVariable(Prefix + "networkName", netName)
521 if (returnCode=='404') {
522 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
523 utils.log("DEBUG", " AAI Query Failed. " + dataErrorMessage, isDebugEnabled)
524 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
527 if (aaiResponseAsString.contains("RESTFault")) {
528 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
529 execution.setVariable("WorkflowException", exceptionObject)
530 throw new BpmnError("MSOWorkflowException")
534 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
535 utils.log("DEBUG", "Unexpected Response from QueryAAINetworkId - " + dataErrorMessage, isDebugEnabled)
536 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
542 } catch (BpmnError e) {
545 } catch (Exception ex) {
546 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
547 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
548 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
554 public void callRESTReQueryAAINetworkId(Execution execution) {
555 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
556 execution.setVariable("prefix",Prefix)
558 utils.log("DEBUG", " ***** Inside callRESTReQueryAAINetworkId() of DoCreateNetworkInstance ***** " , isDebugEnabled)
562 String networkId = execution.getVariable(Prefix + "networkId")
563 String netId = networkId
564 networkId = UriUtils.encode(networkId,"UTF-8")
565 String messageId = execution.getVariable(Prefix + "messageId")
568 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
569 AaiUtil aaiUriUtil = new AaiUtil(this)
570 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
571 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
572 utils.logAudit(requeryIdAAIRequest)
573 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
574 utils.log("DEBUG", Prefix + "requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest, isDebugEnabled)
576 RESTConfig config = new RESTConfig(requeryIdAAIRequest);
577 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
578 .addHeader("X-FromAppId", "MSO")
579 .addHeader("Content-Type", "application/xml")
580 .addHeader("Accept","application/xml");
581 APIResponse response = client.get()
582 String returnCode = response.getStatusCode()
583 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
584 utils.log("DEBUG", " ***** AAI ReQuery Response Code : " + returnCode, isDebugEnabled)
586 String aaiResponseAsString = response.getResponseBodyAsString()
588 if (returnCode=='200') {
589 utils.logAudit(aaiResponseAsString)
590 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
591 utils.log("DEBUG", " ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
593 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
594 String networkOutputs =
596 <network-id>${netId}</network-id>
597 <network-name>${netName}</network-name>
598 </network-outputs>"""
599 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
600 utils.log("DEBUG", " networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
603 if (returnCode=='404') {
604 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
605 utils.log("DEBUG", " AAI ReQuery Failed. - " + dataErrorMessage, isDebugEnabled)
606 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
609 if (aaiResponseAsString.contains("RESTFault")) {
610 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
611 execution.setVariable("WorkflowException", exceptionObject)
612 throw new BpmnError("MSOWorkflowException")
616 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
617 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
618 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
624 } catch (BpmnError e) {
627 } catch (Exception ex) {
628 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
629 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
630 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
636 public void callRESTQueryAAINetworkVpnBinding(Execution execution) {
637 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
638 execution.setVariable("prefix",Prefix)
640 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkVpnBinding() of DoCreateNetworkInstance ***** " , isDebugEnabled)
645 String messageId = execution.getVariable(Prefix + "messageId")
646 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
647 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
648 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
650 // Check if Vnf Binding is present, then build a List of vnfBinding
651 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
652 int vpnCount = vpnBindingUri.size()
653 execution.setVariable(Prefix + "vpnCount", vpnCount)
654 utils.log("DEBUG", Prefix + "vpnCount - " + vpnCount, isDebugEnabled)
656 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
657 AaiUtil aaiUriUtil = new AaiUtil(this)
660 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
661 utils.log("DEBUG", " vpnBindingUri List - " + vpnBindingUri, isDebugEnabled)
663 String routeTargets = ""
664 // AII loop call using list vpnBindings
665 for (i in 0..vpnBindingUri.size()-1) {
669 // prepare url using vpnBinding
670 String queryVpnBindingAAIRequest = ""
671 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
673 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
674 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
675 if (aai_uri == null || aai_uri == "") {
676 // using value of 'related-link' from response
677 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
678 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1)
680 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i]
684 // using uri value in URN mapping
685 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
686 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
687 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
689 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId
692 utils.logAudit(queryVpnBindingAAIRequest)
693 execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
694 utils.log("DEBUG", Prefix + "queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest, isDebugEnabled)
696 RESTConfig config = new RESTConfig(queryVpnBindingAAIRequest);
697 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
698 .addHeader("X-FromAppId", "MSO")
699 .addHeader("Content-Type", "application/xml")
700 .addHeader("Accept","application/xml");
701 APIResponse response = client.get()
702 String returnCode = response.getStatusCode()
703 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
704 utils.log("DEBUG", " ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode, isDebugEnabled)
706 String aaiResponseAsString = response.getResponseBodyAsString()
708 if (returnCode=='200') {
709 utils.logAudit(aaiResponseAsString)
710 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
711 utils.log("DEBUG", " AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
713 String routeTarget = ""
714 if (utils.nodeExists(aaiResponseAsString, "global-route-target")) {
715 routeTarget = utils.getNodeText1(aaiResponseAsString, "global-route-target")
716 routeTargets += "<routeTargets>" + routeTarget + "</routeTargets>" + '\n'
720 if (returnCode=='404') {
721 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
722 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
723 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
726 if (aaiResponseAsString.contains("RESTFault")) {
727 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
728 execution.setVariable("WorkflowException", exceptionObject)
729 throw new BpmnError("MSOWorkflowException")
733 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
734 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
735 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
743 execution.setVariable(Prefix + "routeCollection", routeTargets)
744 utils.log("DEBUG", Prefix + "routeCollection - " + '\n' + routeTargets, isDebugEnabled)
747 // reset return code to success
748 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
749 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
750 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
751 String aaiStubResponse =
752 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
753 <vpn-binding xmlns="${schemaVersion}">
754 <global-route-target/>
757 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
758 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
759 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
760 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
764 } catch (BpmnError e) {
767 } catch (Exception ex) {
768 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
769 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
770 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
776 public void callRESTQueryAAINetworkPolicy(Execution execution) {
777 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
778 execution.setVariable("prefix",Prefix)
780 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy() of DoCreateNetworkInstance ***** " , isDebugEnabled)
784 String messageId = execution.getVariable(Prefix + "messageId")
785 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
786 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
787 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
789 // Check if Network Policy is present, then build a List of network policy
790 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
791 int networkPolicyCount = networkPolicyUriList.size()
792 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
793 utils.log("DEBUG", Prefix + "networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
795 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
796 AaiUtil aaiUriUtil = new AaiUtil(this)
798 if (networkPolicyCount > 0) {
799 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
800 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
802 String networkPolicies = ""
803 // AII loop call using list vpnBindings
804 for (i in 0..networkPolicyUriList.size()-1) {
808 // prepare url using vpnBinding
809 String queryNetworkPolicyAAIRequest = ""
811 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
813 // Note: By default, the network policy url is found in 'related-link' of the response,
814 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
815 if (aai_uri == null || aai_uri == "") {
816 // using value of 'related-link' from response
817 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
818 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1)
820 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i]
823 // using uri value in URN mapping
824 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
825 println " networkPolicyId - " + networkPolicyId
826 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
827 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
829 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId
834 utils.logAudit(queryNetworkPolicyAAIRequest)
835 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
836 utils.log("DEBUG", Prefix + "queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
838 RESTConfig config = new RESTConfig(queryNetworkPolicyAAIRequest);
839 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
840 .addHeader("X-FromAppId", "MSO")
841 .addHeader("Content-Type", "application/xml")
842 .addHeader("Accept","application/xml");
843 APIResponse response = client.get()
844 String returnCode = response.getStatusCode()
845 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
846 utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
848 String aaiResponseAsString = response.getResponseBodyAsString()
850 if (returnCode=='200') {
851 utils.logAudit(aaiResponseAsString)
852 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
853 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
855 String networkPolicy = ""
856 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
857 networkPolicy = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
858 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
862 if (returnCode=='404') {
863 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
864 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
865 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
868 if (aaiResponseAsString.contains("RESTFault")) {
869 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
870 execution.setVariable("WorkflowException", exceptionObject)
871 throw new BpmnError("MSOWorkflowException")
875 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
876 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
877 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
885 execution.setVariable(Prefix + "networkCollection", networkPolicies)
886 utils.log("DEBUG", Prefix + "networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
889 // reset return code to success
890 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
891 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
892 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
893 String aaiStubResponse =
894 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
895 <network-policy xmlns="${schemaVersion}">
896 <network-policy-fqdn/>
899 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
900 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
901 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
902 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
906 } catch (BpmnError e) {
909 } catch (Exception ex) {
910 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
911 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
912 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
918 public void callRESTQueryAAINetworkTableRef(Execution execution) {
919 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
920 execution.setVariable("prefix",Prefix)
922 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef() of DoCreateNetworkInstance ***** " , isDebugEnabled)
926 String messageId = execution.getVariable(Prefix + "messageId")
927 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
928 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
929 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
931 // Check if Network TableREf is present, then build a List of network policy
932 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
933 int networkTableRefCount = networkTableRefUriList.size()
934 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
935 utils.log("DEBUG", Prefix + "networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
937 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
938 AaiUtil aaiUriUtil = new AaiUtil(this)
940 if (networkTableRefCount > 0) {
941 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
942 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
944 // AII loop call using list vpnBindings
945 String networkTableRefs = ""
946 for (i in 0..networkTableRefUriList.size()-1) {
950 // prepare url using tableRef
951 String queryNetworkTableRefAAIRequest = ""
953 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
955 // Note: By default, the network policy url is found in 'related-link' of the response,
956 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
957 if (aai_uri == null || aai_uri == "") {
958 // using value of 'related-link' from response
959 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
960 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1)
962 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i]
965 // using uri value in URN mapping
966 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
968 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
969 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
971 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId
976 utils.logAudit(queryNetworkTableRefAAIRequest)
977 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
978 utils.log("DEBUG", Prefix + "queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
980 RESTConfig config = new RESTConfig(queryNetworkTableRefAAIRequest);
981 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
982 .addHeader("X-FromAppId", "MSO")
983 .addHeader("Content-Type", "application/xml")
984 .addHeader("Accept","application/xml");
985 APIResponse response = client.get()
986 String returnCode = response.getStatusCode()
987 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
988 utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
990 String aaiResponseAsString = response.getResponseBodyAsString()
992 if (returnCode=='200') {
993 utils.logAudit(aaiResponseAsString)
994 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
995 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
997 String networkTableRef = ""
998 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
999 networkTableRef = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
1000 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
1004 if (returnCode=='404') {
1005 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
1006 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
1007 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1010 if (aaiResponseAsString.contains("RESTFault")) {
1011 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
1012 execution.setVariable("WorkflowException", exceptionObject)
1013 throw new BpmnError("MSOWorkflowException")
1017 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
1018 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
1019 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1027 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
1028 utils.log("DEBUG", Prefix + "tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
1031 // reset return code to success
1032 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
1033 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1034 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
1035 String aaiStubResponse =
1036 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
1037 <route-table-references xmlns="${schemaVersion}">
1038 <route-table-reference-fqdn/>
1039 </route-table-references>
1041 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
1042 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
1043 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
1044 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
1048 } catch (BpmnError e) {
1051 } catch (Exception ex) {
1052 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
1053 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1054 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1061 public void callRESTUpdateContrailAAINetwork(Execution execution) {
1062 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1063 execution.setVariable("prefix",Prefix)
1065 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork() of DoCreateNetworkInstance ***** " , isDebugEnabled)
1069 String networkId = execution.getVariable(Prefix + "networkId")
1070 networkId = UriUtils.encode(networkId,"UTF-8")
1071 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1072 String createNetworkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1073 String messageId = execution.getVariable(Prefix + "messageId")
1076 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1077 AaiUtil aaiUriUtil = new AaiUtil(this)
1078 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1079 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
1081 utils.logAudit(updateContrailAAIUrlRequest)
1082 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
1083 utils.log("DEBUG", Prefix + "updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
1085 //Prepare payload (PUT)
1086 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
1087 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, createNetworkResponse, schemaVersion)
1088 String payloadXml = utils.formatXml(payload)
1089 utils.logAudit(payloadXml)
1090 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
1091 utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
1093 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payloadXml)
1095 String returnCode = response.getStatusCode()
1096 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
1097 utils.log("DEBUG", " ***** AAI Update Contrail Response Code : " + returnCode, isDebugEnabled)
1098 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
1100 if (returnCode=='200') {
1101 utils.logAudit(aaiUpdateContrailResponseAsString)
1102 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
1103 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
1104 // Point-of-no-return is set to false, rollback not needed.
1105 String rollbackEnabled = execution.getVariable(Prefix + "rollbackEnabled")
1106 if (rollbackEnabled == "true") {
1107 execution.setVariable(Prefix + "isPONR", false)
1109 execution.setVariable(Prefix + "isPONR", true)
1111 utils.log("DEBUG", Prefix + "isPONR" + ": " + execution.getVariable(Prefix + "isPONR"), isDebugEnabled)
1113 if (returnCode=='404') {
1114 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
1115 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
1116 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1119 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
1120 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
1121 execution.setVariable("WorkflowException", exceptionObject)
1122 throw new BpmnError("MSOWorkflowException")
1126 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
1127 utils.log("DEBUG", errorMessage, isDebugEnabled)
1128 exceptionUtil.buildAndThrowWorkflowException(execution, "2500", errorMessage)
1133 } catch (BpmnError e) {
1136 } catch (Exception ex) {
1137 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
1138 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1139 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1145 public void prepareCreateNetworkRequest (Execution execution) {
1146 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1147 execution.setVariable("prefix",Prefix)
1149 utils.log("DEBUG", " ***** Inside prepareCreateNetworkRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1154 String requestId = execution.getVariable("msoRequestId")
1155 if (requestId == null) {
1156 requestId = execution.getVariable("mso-request-id")
\r
1158 String messageId = execution.getVariable(Prefix + "messageId")
1159 String source = execution.getVariable(Prefix + "source")
1161 String requestInput = execution.getVariable(Prefix + "networkRequest")
1162 String queryIdResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1163 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1164 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1166 // Prepare Network request
1167 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1168 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1169 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1170 String createNetworkRequest = networkUtils.CreateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1172 String buildDeleteNetworkRequestAsString = utils.formatXml(createNetworkRequest)
1173 buildDeleteNetworkRequestAsString = buildDeleteNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1174 utils.logAudit(buildDeleteNetworkRequestAsString)
1176 execution.setVariable(Prefix + "createNetworkRequest", buildDeleteNetworkRequestAsString)
1177 utils.log("DEBUG", Prefix + "createNetworkRequest - " + "\n" + buildDeleteNetworkRequestAsString, isDebugEnabled)
1179 } catch (Exception ex) {
1180 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareCreateNetworkRequest() - " + ex.getMessage()
1181 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1182 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1188 public void prepareSDNCRequest (Execution execution) {
1189 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1190 execution.setVariable("prefix",Prefix)
1192 utils.log("DEBUG", " ***** Inside prepareSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1196 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1197 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1198 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1200 String networkId = execution.getVariable(Prefix + "networkId")
1201 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1203 // get/set 'msoRequestId' and 'mso-request-id'
\r
1204 String requestId = execution.getVariable("msoRequestId")
1205 if (requestId != null) {
1206 execution.setVariable("mso-request-id", requestId)
\r
1208 requestId = execution.getVariable("mso-request-id")
\r
1210 execution.setVariable(Prefix + "requestId", requestId)
1212 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1213 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1215 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1216 utils.logAudit(sndcTopologyCreateRequesAsString)
1217 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1218 utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1221 } catch (Exception ex) {
1222 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1223 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1224 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1230 public void prepareRpcSDNCRequest (Execution execution) {
1231 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1232 execution.setVariable("prefix",Prefix)
1234 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1239 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1240 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1241 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1243 String networkId = execution.getVariable(Prefix + "networkId")
1244 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1246 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1247 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "CreateNetworkInstance", cloudRegionId, networkId, null)
1249 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1250 utils.logAudit(sndcTopologyCreateRequesAsString)
1251 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1252 utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1254 } catch (Exception ex) {
1255 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRequest() - " + ex.getMessage()
1256 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1257 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1263 public void prepareRpcSDNCActivateRequest (Execution execution) {
1264 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1265 execution.setVariable("prefix",Prefix)
1267 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1271 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1272 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1273 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1274 String networkId = execution.getVariable(Prefix + "networkId")
1275 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1277 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1278 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "activate", "ActivateNetworkInstance", cloudRegionId, networkId, null)
1280 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1281 utils.logAudit(sndcTopologyCreateRequesAsString)
1282 execution.setVariable(Prefix + "activateSDNCRequest", sndcTopologyCreateRequesAsString)
1283 utils.log("DEBUG", Prefix + "activateSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString, isDebugEnabled)
1286 } catch (Exception ex) {
1287 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRequest() - " + ex.getMessage()
1288 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1289 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1298 // **************************************************
1299 // Post or Validate Response Section
1300 // **************************************************
1302 public void validateCreateNetworkResponse (Execution execution) {
1303 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1304 execution.setVariable("prefix",Prefix)
1306 utils.log("DEBUG", " ***** Inside validateNetworkResponse() of DoCreateNetworkInstance *****", isDebugEnabled)
1309 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1310 String networkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1311 if (networkResponse==null) {
1312 networkResponse="" // reset
1315 utils.log("DEBUG", " Network Adapter create responseCode: " + returnCode, isDebugEnabled)
1317 String errorMessage = ""
1318 if (returnCode == "200") {
1319 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1320 utils.logAudit(networkResponse)
1321 execution.setVariable(Prefix + "createNetworkResponse", networkResponse)
1322 utils.log("DEBUG", " Network Adapter create Success Response - " + "\n" + networkResponse, isDebugEnabled)
1324 // prepare rollback data
1325 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1326 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1327 String rollbackNetwork =
1328 """<rollbackNetworkRequest>
1330 </rollbackNetworkRequest>"""
1331 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1332 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1333 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1335 } else { // network error
1336 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1337 if (networkResponse.contains("createNetworkError")) {
1338 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1339 errorMessage = utils.getNodeText1(networkResponse, "message")
1340 errorMessage = "Received error from Network Adapter: " + errorMessage
1341 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1343 } else { // CatchAll exception
1344 if (returnCode == "500") {
1345 errorMessage = "JBWEB000065: HTTP Status 500."
1347 errorMessage = "Return code is " + returnCode
1349 errorMessage = "Received error from Network Adapter: " + errorMessage
1350 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1354 } else { // CatchAll exception
1355 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1356 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1362 } catch (BpmnError e) {
1365 } catch (Exception ex) {
1366 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. validateCreateNetworkResponse() - " + ex.getMessage()
1367 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1368 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1375 public void validateSDNCResponse (Execution execution) {
1376 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1377 execution.setVariable("prefix",Prefix)
1379 utils.log("DEBUG", " ***** Inside validateSDNCResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1381 String response = execution.getVariable(Prefix + "assignSDNCResponse")
1382 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1383 WorkflowException workflowException = execution.getVariable("WorkflowException")
1385 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1386 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1388 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "assignSDNCResponse"))
1389 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1390 execution.setVariable(Prefix + "assignSDNCResponse", assignSDNCResponseDecodeXml)
1392 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1393 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1394 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1397 utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1398 throw new BpmnError("MSOWorkflowException")
1403 public void validateRpcSDNCActivateResponse (Execution execution) {
1404 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1405 execution.setVariable("prefix",Prefix)
1407 utils.log("DEBUG", " ***** Inside validateRpcSDNCActivateResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1409 String response = execution.getVariable(Prefix + "activateSDNCResponse")
1410 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1411 WorkflowException workflowException = execution.getVariable("WorkflowException")
1413 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1414 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1416 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "activateSDNCResponse"))
1417 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1418 execution.setVariable(Prefix + "activateSDNCResponse", assignSDNCResponseDecodeXml)
1420 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1421 execution.setVariable(Prefix + "isSdncActivateRollbackNeeded", true)
1422 utils.log("DEBUG", "Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1425 utils.log("DEBUG", "Did NOT Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1426 throw new BpmnError("MSOWorkflowException")
1432 public void prepareSDNCRollbackRequest (Execution execution) {
1433 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1434 execution.setVariable("prefix",Prefix)
1436 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1440 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1441 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1442 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1443 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1444 String networkId = execution.getVariable(Prefix + "networkId")
1445 if (networkId == 'null') {networkId = ""}
1446 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1448 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1449 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1450 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1451 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1452 utils.log("DEBUG", " Preparing request for SDNC Topology 'rollback-NetworkActivateRequest' rollback . . . - " + "\n" + sndcTopologyRollbackRequestAsString, isDebugEnabled)
1455 } catch (Exception ex) {
1456 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1457 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1458 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1464 public void prepareRpcSDNCRollbackRequest (Execution execution) {
1465 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1466 execution.setVariable("prefix",Prefix)
1468 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1472 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1473 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1474 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1475 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1476 String networkId = execution.getVariable(Prefix + "networkId")
1477 if (networkId == 'null') {networkId = ""}
1478 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1480 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1481 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "unassign", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1482 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1483 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1484 utils.log("DEBUG", " Preparing request for SDNC Topology 'unassign-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1487 } catch (Exception ex) {
1488 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRollbackRequest() - " + ex.getMessage()
1489 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1490 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1496 public void prepareRpcSDNCActivateRollback(Execution execution) {
1497 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1498 execution.setVariable("prefix",Prefix)
1500 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRollback() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1505 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1506 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1507 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1508 String activateSDNCResponse = execution.getVariable(Prefix + "activateSDNCResponse")
1509 String networkId = execution.getVariable(Prefix + "networkId")
1510 if (networkId == 'null') {networkId = ""}
1511 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1513 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1514 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "deactivate", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1515 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1516 execution.setVariable(Prefix + "rollbackActivateSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1517 utils.log("DEBUG", " Preparing request for RPC SDNC Topology 'deactivate-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1520 } catch (Exception ex) {
1521 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRollback() - " + ex.getMessage()
1522 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1523 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1529 public void prepareRollbackData(Execution execution) {
1530 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1531 execution.setVariable("prefix",Prefix)
1533 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1537 Map<String, String> rollbackData = new HashMap<String, String>();
1538 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1539 if (rollbackSDNCRequest != null) {
1540 if (rollbackSDNCRequest != "") {
1541 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1544 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1545 if (rollbackNetworkRequest != null) {
1546 if (rollbackNetworkRequest != "") {
1547 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1550 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1551 if (rollbackActivateSDNCRequest != null) {
1552 if (rollbackActivateSDNCRequest != "") {
1553 rollbackData.put("rollbackActivateSDNCRequest", execution.getVariable(Prefix + "rollbackActivateSDNCRequest"))
1556 execution.setVariable("rollbackData", rollbackData)
1557 utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
1559 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1560 utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
1562 } catch (Exception ex) {
1563 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1564 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1565 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1571 public void postProcessResponse(Execution execution) {
1572 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1573 execution.setVariable("prefix",Prefix)
1575 utils.log("DEBUG", " ***** Inside postProcessResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1580 // 1. Silent Success: execution.getVariable("CRENWKI_orchestrationStatus") == "ACTIVE"
1581 // 2. Success: execution.getVariable("WorkflowException") == null (NULL)
1582 // 3. WorkflowException: execution.getVariable("WorkflowException") != null (NOT NULL)
1584 utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
1586 if (execution.getVariable(Prefix + "isException") == false) {
1587 // set rollback data
1588 execution.setVariable("orchestrationStatus", "")
1589 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1590 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1591 prepareSuccessRollbackData(execution) // populate rollbackData
1592 execution.setVariable("WorkflowException", null)
1593 execution.setVariable(Prefix + "Success", true)
1594 utils.log("DEBUG", " ***** postProcessResponse(), GOOD !!!", isDebugEnabled)
1596 // inside sub-flow logic
1597 execution.setVariable(Prefix + "Success", false)
1598 execution.setVariable("rollbackData", null)
1599 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1600 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1601 utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
1602 WorkflowException wfex = execution.getVariable("workflowException")
1603 exceptionMessage = wfex.getErrorMessage()
1605 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1606 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1607 exceptionMessage = pwfex.getErrorMessage()
1610 // going to the Main flow: a-la-carte or macro
1611 utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
1612 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1613 throw new BpmnError("MSOWorkflowException")
1616 } catch(BpmnError b){
1617 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
1620 } catch (Exception ex) {
1621 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1622 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1623 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1624 throw new BpmnError("MSOWorkflowException")
1632 public void prepareSuccessRollbackData(Execution execution) {
1633 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1634 execution.setVariable("prefix",Prefix)
1636 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1640 if (execution.getVariable("sdncVersion") == '1702') {
1641 prepareRpcSDNCRollbackRequest(execution)
1642 prepareRpcSDNCActivateRollback(execution)
1644 prepareSDNCRollbackRequest(execution)
1647 Map<String, String> rollbackData = new HashMap<String, String>();
1648 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1649 if (rollbackSDNCRequest != null) {
1650 if (rollbackSDNCRequest != "") {
1651 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1654 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1655 if (rollbackNetworkRequest != null) {
1656 if (rollbackNetworkRequest != "") {
1657 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1660 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1661 if (rollbackActivateSDNCRequest != null) {
1662 if (rollbackActivateSDNCRequest != "") {
1663 rollbackData.put("rollbackActivateSDNCRequest", rollbackActivateSDNCRequest)
1666 execution.setVariable("rollbackData", rollbackData)
1668 utils.log("DEBUG", "** 'rollbackData' for Full Rollback : " + rollbackData, isDebugEnabled)
1669 execution.setVariable("WorkflowException", null)
1672 } catch (Exception ex) {
1673 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1674 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1675 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1681 public void setExceptionFlag(Execution execution){
1682 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1683 execution.setVariable("prefix",Prefix)
1685 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1689 execution.setVariable(Prefix + "isException", true)
1691 if (execution.getVariable("SavedWorkflowException1") != null) {
1692 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1694 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1696 utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1698 } catch(Exception ex){
1699 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1700 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1701 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1707 // *******************************
1708 // Build Error Section
1709 // *******************************
1713 public void processJavaException(Execution execution){
1714 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1715 execution.setVariable("prefix",Prefix)
1718 utils.log("DEBUG", "Caught a Java Exception in " + Prefix, isDebugEnabled)
1719 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1720 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1721 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1722 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1724 }catch(Exception e){
1725 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1726 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1727 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
1729 utils.log("DEBUG", "Completed processJavaException Method in " + Prefix, isDebugEnabled)