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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts;
23 import org.apache.commons.lang3.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.so.bpmn.common.scripts.AaiUtil
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.NetworkUtils
31 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
32 import org.onap.so.bpmn.common.scripts.VidUtils
33 import org.onap.so.bpmn.core.UrnPropertiesReader
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.onap.so.logger.MsoLogger
37 import org.onap.so.rest.APIResponse;
38 import org.springframework.web.util.UriUtils
39 import org.onap.so.client.aai.AAIResourcesClient
40 import org.onap.so.client.aai.AAIObjectType
41 import org.onap.so.client.aai.entities.AAIResultWrapper
42 import org.onap.so.client.aai.entities.Relationships
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri
44 import org.onap.so.client.aai.entities.uri.AAIUriFactory
45 import org.json.JSONObject
46 import javax.ws.rs.NotFoundException
49 import groovy.xml.XmlUtil
53 * This groovy class supports the <class>DoCreateNetworkInstance.bpmn</class> process.
56 public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor {
57 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateNetworkInstance.class);
59 String Prefix="CRENWKI_"
60 ExceptionUtil exceptionUtil = new ExceptionUtil()
61 JsonUtils jsonUtil = new JsonUtils()
62 VidUtils vidUtils = new VidUtils(this)
63 NetworkUtils networkUtils = new NetworkUtils()
64 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
66 def className = getClass().getSimpleName()
69 * This method is executed during the preProcessRequest task of the <class>DoCreateNetworkInstance.bpmn</class> process.
72 public InitializeProcessVariables(DelegateExecution execution){
73 /* Initialize all the process variables in this block */
75 execution.setVariable(Prefix + "networkRequest", "")
76 execution.setVariable(Prefix + "rollbackEnabled", null)
77 execution.setVariable(Prefix + "networkInputs", "")
78 //execution.setVariable(Prefix + "requestId", "")
79 execution.setVariable(Prefix + "messageId", "")
80 execution.setVariable(Prefix + "source", "")
81 execution.setVariable("BasicAuthHeaderValuePO", "")
82 execution.setVariable("BasicAuthHeaderValueSDNC", "")
83 execution.setVariable(Prefix + "serviceInstanceId","")
84 execution.setVariable("GENGS_type", "")
85 execution.setVariable(Prefix + "rsrc_endpoint", null)
86 execution.setVariable(Prefix + "networkOutputs", "")
87 execution.setVariable(Prefix + "networkId","")
88 execution.setVariable(Prefix + "networkName","")
91 execution.setVariable(Prefix + "queryNameAAIRequest","")
92 execution.setVariable(Prefix + "queryNameAAIResponse", "")
93 execution.setVariable(Prefix + "aaiNameReturnCode", "")
94 execution.setVariable(Prefix + "isAAIqueryNameGood", false)
96 // AAI query Cloud Region
97 execution.setVariable(Prefix + "queryCloudRegionRequest","")
98 execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
99 execution.setVariable(Prefix + "queryCloudRegionResponse","")
100 execution.setVariable(Prefix + "cloudRegionPo","")
101 execution.setVariable(Prefix + "cloudRegionSdnc","")
102 execution.setVariable(Prefix + "isCloudRegionGood", false)
105 execution.setVariable(Prefix + "queryIdAAIRequest","")
106 execution.setVariable(Prefix + "queryIdAAIResponse", "")
107 execution.setVariable(Prefix + "aaiIdReturnCode", "")
109 // AAI query vpn binding
110 execution.setVariable(Prefix + "queryVpnBindingAAIRequest","")
111 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", "")
112 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "")
113 execution.setVariable(Prefix + "vpnBindings", null)
114 execution.setVariable(Prefix + "vpnCount", 0)
115 execution.setVariable(Prefix + "routeCollection", "")
117 // AAI query network policy
118 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest","")
119 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", "")
120 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "")
121 execution.setVariable(Prefix + "networkPolicyUriList", null)
122 execution.setVariable(Prefix + "networkPolicyCount", 0)
123 execution.setVariable(Prefix + "networkCollection", "")
125 // AAI query route table reference
126 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest","")
127 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", "")
128 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "")
129 execution.setVariable(Prefix + "networkTableRefUriList", null)
130 execution.setVariable(Prefix + "networkTableRefCount", 0)
131 execution.setVariable(Prefix + "tableRefCollection", "")
134 execution.setVariable(Prefix + "requeryIdAAIRequest","")
135 execution.setVariable(Prefix + "requeryIdAAIResponse", "")
136 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
138 // AAI update contrail
139 execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
140 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
141 execution.setVariable(Prefix + "updateContrailAAIResponse", "")
142 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
144 execution.setVariable(Prefix + "createNetworkRequest", "")
145 execution.setVariable(Prefix + "createNetworkResponse", "")
146 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
147 //execution.setVariable(Prefix + "rollbackNetworkResponse", "")
148 execution.setVariable(Prefix + "networkReturnCode", "")
149 //execution.setVariable(Prefix + "rollbackNetworkReturnCode", "")
150 execution.setVariable(Prefix + "isNetworkRollbackNeeded", false)
152 execution.setVariable(Prefix + "assignSDNCRequest", "")
153 execution.setVariable(Prefix + "assignSDNCResponse", "")
154 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
155 //execution.setVariable(Prefix + "rollbackSDNCResponse", "")
156 execution.setVariable(Prefix + "sdncReturnCode", "")
157 //execution.setVariable(Prefix + "rollbackSDNCReturnCode", "")
158 execution.setVariable(Prefix + "isSdncRollbackNeeded", false)
159 execution.setVariable(Prefix + "sdncResponseSuccess", false)
161 execution.setVariable(Prefix + "activateSDNCRequest", "")
162 execution.setVariable(Prefix + "activateSDNCResponse", "")
163 execution.setVariable(Prefix + "rollbackActivateSDNCRequest", "")
164 //execution.setVariable(Prefix + "rollbackActivateSDNCResponse", "")
165 execution.setVariable(Prefix + "sdncActivateReturnCode", "")
166 //execution.setVariable(Prefix + "rollbackActivateSDNCReturnCode", "")
167 execution.setVariable(Prefix + "isSdncActivateRollbackNeeded", false)
168 execution.setVariable(Prefix + "sdncActivateResponseSuccess", false)
170 execution.setVariable(Prefix + "orchestrationStatus", "")
171 execution.setVariable(Prefix + "isVnfBindingPresent", false)
172 execution.setVariable(Prefix + "Success", false)
174 execution.setVariable(Prefix + "isException", false)
178 // **************************************************
179 // Pre or Prepare Request Section
180 // **************************************************
182 * This method is executed during the preProcessRequest task of the <class>DoCreateNetworkInstance.bpmn</class> process.
185 public void preProcessRequest (DelegateExecution execution) {
187 execution.setVariable("prefix",Prefix)
188 msoLogger.trace("Inside preProcessRequest() of " + className + ".groovy")
191 // initialize flow variables
192 InitializeProcessVariables(execution)
194 // GET Incoming request & validate 3 kinds of format.
195 execution.setVariable("action", "CREATE")
196 String networkRequest = execution.getVariable("bpmnRequest")
197 if (networkRequest != null) {
198 if (networkRequest.contains("requestDetails")) {
199 // JSON format request is sent, create xml
201 def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
202 msoLogger.debug(" Incoming message formatted . . . : " + '\n' + prettyJson)
203 networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
205 } catch (Exception ex) {
206 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
207 msoLogger.debug(dataErrorMessage)
208 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
211 // XML format request is sent
215 // vIPR format request is sent, create xml from individual variables
216 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
219 networkRequest = utils.formatXml(networkRequest)
220 execution.setVariable(Prefix + "networkRequest", networkRequest)
221 msoLogger.debug(Prefix + "networkRequest - " + '\n' + networkRequest)
223 // validate 'backout-on-failure' to override 'mso.rollback'
224 boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
225 execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
226 msoLogger.debug(Prefix + "rollbackEnabled - " + rollbackEnabled)
228 String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
229 execution.setVariable(Prefix + "networkInputs", networkInputs)
230 msoLogger.debug(Prefix + "networkInputs - " + '\n' + networkInputs)
233 String messageId = execution.getVariable("testMessageId") // for testing
234 if (messageId == null || messageId == "") {
235 messageId = UUID.randomUUID()
236 msoLogger.debug(Prefix + "messageId, random generated: " + messageId)
238 msoLogger.debug(Prefix + "messageId, pre-assigned: " + messageId)
240 execution.setVariable(Prefix + "messageId", messageId)
242 String source = utils.getNodeText(networkRequest, "source")
243 execution.setVariable(Prefix + "source", source)
244 msoLogger.debug(Prefix + "source - " + source)
246 // validate cloud region
247 String lcpCloudRegionId = utils.getNodeText(networkRequest, "aic-cloud-region")
248 if ((lcpCloudRegionId == null) || (lcpCloudRegionId == "") || (lcpCloudRegionId == "null")) {
249 String dataErrorMessage = "Missing value/element: 'lcpCloudRegionId' or 'cloudConfiguration' or 'aic-cloud-region'."
250 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
251 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
254 // validate service instance id
255 String serviceInstanceId = utils.getNodeText(networkRequest, "service-instance-id")
256 if ((serviceInstanceId == null) || (serviceInstanceId == "") || (serviceInstanceId == "null")) {
257 String dataErrorMessage = "Missing value/element: 'serviceInstanceId'."
258 msoLogger.debug(" Invalid Request - " + dataErrorMessage)
259 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
262 // PO Authorization Info / headers Authorization=
263 String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution)
266 def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey",execution))
267 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
268 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
270 } catch (IOException ex) {
271 String exceptionMessage = "Exception Encountered in DoCreateNetworkInstance, PreProcessRequest() - "
272 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
273 msoLogger.debug(dataErrorMessage)
274 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
277 // Set variables for Generic Get Sub Flow use
278 execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
279 msoLogger.debug(Prefix + "serviceInstanceId - " + serviceInstanceId)
281 execution.setVariable("GENGS_type", "service-instance")
282 msoLogger.debug("GENGS_type - " + "service-instance")
283 msoLogger.debug(" Url for SDNC adapter: " + UrnPropertiesReader.getVariable("mso.adapters.sdnc.endpoint",execution))
285 String sdncVersion = execution.getVariable("sdncVersion")
286 msoLogger.debug("sdncVersion? : " + sdncVersion)
288 // build 'networkOutputs'
289 String networkId = utils.getNodeText(networkRequest, "network-id")
290 if ((networkId == null) || (networkId == "null")) {
293 String networkName = utils.getNodeText(networkRequest, "network-name")
294 if ((networkName == null) || (networkName == "null")) {
297 String networkOutputs =
299 <network-id>${MsoUtils.xmlEscape(networkId)}</network-id>
300 <network-name>${MsoUtils.xmlEscape(networkName)}</network-name>
301 </network-outputs>"""
302 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
303 msoLogger.debug(Prefix + "networkOutputs - " + '\n' + networkOutputs)
304 execution.setVariable(Prefix + "networkId", networkId)
305 execution.setVariable(Prefix + "networkName", networkName)
307 } catch (BpmnError e) {
310 } catch (Exception ex) {
311 sendSyncError(execution)
313 String exceptionMessage = "Exception Encountered in PreProcessRequest() of " + className + ".groovy ***** : " + ex.getMessage()
314 msoLogger.debug(exceptionMessage)
315 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
322 * Gets the service instance uri from aai
324 public void getServiceInstance(DelegateExecution execution) {
326 String serviceInstanceId = execution.getVariable('CRENWKI_serviceInstanceId')
328 AAIResourcesClient resourceClient = new AAIResourcesClient()
329 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
331 if(!resourceClient.exists(uri)){
332 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai")
334 Map<String, String> keys = uri.getURIKeys()
335 execution.setVariable("serviceType", keys.get("service-type"))
336 execution.setVariable("subscriberName", keys.get("global-customer-id"))
339 }catch(BpmnError e) {
341 }catch (Exception ex){
342 String msg = "Exception in getServiceInstance. " + ex.getMessage()
344 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
349 public void callRESTQueryAAINetworkName (DelegateExecution execution) {
351 execution.setVariable("prefix",Prefix)
353 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkName() of DoCreateNetworkInstance ***** " )
356 String networkInputs = execution.getVariable(Prefix + "networkInputs")
357 String networkName = utils.getNodeText(networkInputs, "network-name")
358 networkName = UriUtils.encode(networkName,"UTF-8")
360 // Prepare AA&I url with network-name
361 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
362 AaiUtil aaiUriUtil = new AaiUtil(this)
363 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
364 String queryAAINameRequest = "${aai_endpoint}${aai_uri}" + "?network-name=" + networkName
365 execution.setVariable(Prefix + "queryNameAAIRequest", queryAAINameRequest)
366 msoLogger.debug(Prefix + "queryNameAAIRequest - " + "\n" + queryAAINameRequest)
369 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryAAINameRequest)
370 String returnCode = response.getStatusCode()
371 execution.setVariable(Prefix + "aaiNameReturnCode", returnCode)
372 msoLogger.debug(" ***** AAI Query Name Response Code : " + returnCode)
374 String aaiResponseAsString = response.getResponseBodyAsString()
375 msoLogger.debug(" ***** AAI Query Name Response : " +'\n'+ aaiResponseAsString)
377 if (returnCode=='200') {
378 execution.setVariable(Prefix + "queryNameAAIResponse", aaiResponseAsString)
379 execution.setVariable(Prefix + "isAAIqueryNameGood", true)
380 String orchestrationStatus = ""
382 // response is NOT empty
383 orchestrationStatus = utils.getNodeText(aaiResponseAsString, "orchestration-status")
384 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus.toUpperCase())
385 msoLogger.debug(Prefix + "orchestrationStatus - " + orchestrationStatus.toUpperCase())
386 execution.setVariable("orchestrationStatus", orchestrationStatus)
388 } catch (Exception ex) {
390 execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus)
391 msoLogger.debug(Prefix + "orchestrationStatus - " + orchestrationStatus)
395 if (returnCode=='404') {
396 msoLogger.debug(" QueryAAINetworkName return code = '404' (Not Found). Proceed with the Create !!! ")
400 String dataErrorMessage = "Unexpected Error Response from QueryAAINetworkName - " + returnCode
401 msoLogger.debug(dataErrorMessage)
402 exceptionUtil.buildWorkflowException(execution, 2500, dataErrorMessage)
408 msoLogger.debug(Prefix + "isAAIqueryNameGood? : " + execution.getVariable(Prefix + "isAAIqueryNameGood"))
410 } catch (BpmnError e) {
413 } catch (Exception ex) {
415 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAINetworkName() - " + ex.getMessage()
416 msoLogger.debug(exceptionMessage)
417 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
423 public void callRESTQueryAAICloudRegion (DelegateExecution execution) {
425 execution.setVariable("prefix",Prefix)
427 msoLogger.debug(" ***** Inside callRESTQueryAAICloudRegion() of DoCreateNetworkInstance ***** " )
430 String networkInputs = execution.getVariable(Prefix + "networkInputs")
431 String cloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
432 cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
435 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
436 AaiUtil aaiUtil = new AaiUtil(this)
437 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
438 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
439 execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
440 msoLogger.debug(Prefix + "queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest)
442 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
443 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
445 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
446 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
447 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
448 execution.setVariable(Prefix + "isCloudRegionGood", true)
451 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
452 msoLogger.debug(dataErrorMessage)
453 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
457 msoLogger.debug(" is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"))
459 } catch (BpmnError e) {
462 } catch (Exception ex) {
464 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
465 msoLogger.debug(exceptionMessage)
466 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
472 public void callRESTQueryAAINetworkId(DelegateExecution execution) {
474 execution.setVariable("prefix",Prefix)
476 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkId() of DoCreateNetworkInstance ***** " )
480 String networkId = ""
481 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
482 if (execution.getVariable("sdncVersion") != "1610") {
483 String networkResponseInformation = ""
485 networkResponseInformation = utils.getNodeXml(assignSDNCResponse, "network-response-information", false).replace("tag0:","").replace(":tag0","")
486 networkId = utils.getNodeText(networkResponseInformation, "instance-id")
487 } catch (Exception ex) {
488 String dataErrorMessage = " SNDC Response network validation for 'instance-id' (network-id) failed: Empty <network-response-information>"
489 msoLogger.debug(dataErrorMessage)
490 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
494 networkId = utils.getNodeText(assignSDNCResponse, "network-id")
496 if (networkId == null || networkId == "null") {
497 String dataErrorMessage = "SNDC Response did not contains 'instance-id' or 'network-id' element, or the value is null."
498 msoLogger.debug(dataErrorMessage)
499 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
501 msoLogger.debug(" SNDC Response network validation for 'instance-id' (network-id)' is good: " + networkId)
505 execution.setVariable(Prefix + "networkId", networkId)
506 String networkName = utils.getNodeText(assignSDNCResponse, "network-name")
507 execution.setVariable(Prefix + "networkName", networkName)
509 networkId = UriUtils.encode(networkId,"UTF-8")
512 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
513 AaiUtil aaiUriUtil = new AaiUtil(this)
514 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
515 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
516 execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
517 msoLogger.debug(Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest)
519 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
520 String returnCode = response.getStatusCode()
521 execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
523 msoLogger.debug(" ***** AAI Response Code : " + returnCode)
525 String aaiResponseAsString = response.getResponseBodyAsString()
527 if (returnCode=='200') {
528 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
529 msoLogger.debug(" QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
531 String netId = utils.getNodeText(aaiResponseAsString, "network-id")
532 execution.setVariable(Prefix + "networkId", netId)
533 String netName = utils.getNodeText(aaiResponseAsString, "network-name")
534 execution.setVariable(Prefix + "networkName", netName)
537 if (returnCode=='404') {
538 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
539 msoLogger.debug(" AAI Query Failed. " + dataErrorMessage)
540 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
543 if (aaiResponseAsString.contains("RESTFault")) {
544 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
545 execution.setVariable("WorkflowException", exceptionObject)
546 throw new BpmnError("MSOWorkflowException")
550 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
551 msoLogger.debug("Unexpected Response from QueryAAINetworkId - " + dataErrorMessage)
552 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
558 } catch (BpmnError e) {
561 } catch (Exception ex) {
562 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
563 msoLogger.debug(exceptionMessage)
564 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
570 public void callRESTReQueryAAINetworkId(DelegateExecution execution) {
572 execution.setVariable("prefix",Prefix)
574 msoLogger.debug(" ***** Inside callRESTReQueryAAINetworkId() of DoCreateNetworkInstance ***** " )
578 String networkId = execution.getVariable(Prefix + "networkId")
579 String netId = networkId
580 networkId = UriUtils.encode(networkId,"UTF-8")
583 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
584 AaiUtil aaiUriUtil = new AaiUtil(this)
585 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
586 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
587 execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
588 msoLogger.debug(Prefix + "requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest)
590 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
591 String returnCode = response.getStatusCode()
592 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
593 msoLogger.debug(" ***** AAI ReQuery Response Code : " + returnCode)
595 String aaiResponseAsString = response.getResponseBodyAsString()
597 if (returnCode=='200') {
598 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
599 msoLogger.debug(" ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
601 String netName = utils.getNodeText(aaiResponseAsString, "network-name")
602 String networkOutputs =
604 <network-id>${MsoUtils.xmlEscape(netId)}</network-id>
605 <network-name>${MsoUtils.xmlEscape(netName)}</network-name>
606 </network-outputs>"""
607 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
608 msoLogger.debug(" networkOutputs - " + '\n' + networkOutputs)
611 if (returnCode=='404') {
612 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
613 msoLogger.debug(" AAI ReQuery Failed. - " + dataErrorMessage)
614 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
617 if (aaiResponseAsString.contains("RESTFault")) {
618 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
619 execution.setVariable("WorkflowException", exceptionObject)
620 throw new BpmnError("MSOWorkflowException")
624 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
625 msoLogger.debug(dataErrorMessage)
626 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
632 } catch (BpmnError e) {
635 } catch (Exception ex) {
636 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
637 msoLogger.debug(exceptionMessage)
638 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
644 public void callRESTQueryAAINetworkVpnBinding(DelegateExecution execution) {
646 execution.setVariable("prefix",Prefix)
648 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkVpnBinding() of DoCreateNetworkInstance ***** " )
653 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
654 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
655 msoLogger.debug(" relationship - " + relationship)
657 // Check if Vnf Binding is present, then build a List of vnfBinding
658 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
659 int vpnCount = vpnBindingUri.size()
660 execution.setVariable(Prefix + "vpnCount", vpnCount)
661 msoLogger.debug(Prefix + "vpnCount - " + vpnCount)
663 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
664 AaiUtil aaiUriUtil = new AaiUtil(this)
667 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
668 msoLogger.debug(" vpnBindingUri List - " + vpnBindingUri)
670 String routeTargets = ""
671 // AII loop call using list vpnBindings
672 for (i in 0..vpnBindingUri.size()-1) {
676 // prepare url using vpnBinding
677 String queryVpnBindingAAIRequest = ""
678 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
680 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
681 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
682 if (aai_uri == null || aai_uri == "") {
683 // using value of 'related-link' from response
684 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
685 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1) + "?depth=all"
687 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i] + "?depth=all"
691 // using uri value in URN mapping
692 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
693 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
694 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
696 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId + "?depth=all"
699 execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
700 msoLogger.debug(Prefix + "queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest)
702 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
703 String returnCode = response.getStatusCode()
704 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
705 msoLogger.debug(" ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode)
707 String aaiResponseAsString = response.getResponseBodyAsString()
709 if (returnCode=='200') {
710 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
711 msoLogger.debug(" AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString)
713 String routeTarget = ""
714 String routeRole = ""
715 if (utils.nodeExists(aaiResponseAsString, "route-targets")) {
716 String aaiRouteTargets = utils.getNodeXml(aaiResponseAsString, "route-targets", false)
717 def aaiRouteTargetsXml = new XmlSlurper().parseText(aaiRouteTargets)
718 def aaiRouteTarget = aaiRouteTargetsXml.'**'.findAll {it.name() == "route-target"}
719 for (j in 0..aaiRouteTarget.size()-1) {
720 routeTarget = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "global-route-target")
721 routeRole = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "route-target-role")
722 routeTargets += "<routeTargets>" + '\n' +
723 " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
724 " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
725 "</routeTargets>" + '\n'
730 if (returnCode=='404') {
731 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
732 msoLogger.debug(dataErrorMessage)
733 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
736 if (aaiResponseAsString.contains("RESTFault")) {
737 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
738 execution.setVariable("WorkflowException", exceptionObject)
739 throw new BpmnError("MSOWorkflowException")
743 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
744 msoLogger.debug(dataErrorMessage)
745 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
753 execution.setVariable(Prefix + "routeCollection", routeTargets)
754 msoLogger.debug(Prefix + "routeCollection - " + '\n' + routeTargets)
757 // reset return code to success
758 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
759 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
760 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
761 String aaiStubResponse =
762 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
763 <vpn-binding xmlns="${schemaVersion}">
764 <global-route-target/>
767 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
768 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
769 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
770 msoLogger.debug(" No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml)
774 } catch (BpmnError e) {
777 } catch (Exception ex) {
778 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
779 msoLogger.debug(exceptionMessage)
780 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
786 public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
788 execution.setVariable("prefix",Prefix)
790 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkPolicy() of DoCreateNetworkInstance ***** " )
794 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
795 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
796 msoLogger.debug(" relationship - " + relationship)
798 // Check if Network Policy is present, then build a List of network policy
799 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
800 int networkPolicyCount = networkPolicyUriList.size()
801 execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
802 msoLogger.debug(Prefix + "networkPolicyCount - " + networkPolicyCount)
804 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
805 AaiUtil aaiUriUtil = new AaiUtil(this)
807 if (networkPolicyCount > 0) {
808 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
809 msoLogger.debug(" networkPolicyUri List - " + networkPolicyUriList)
811 String networkPolicies = ""
812 // AII loop call using list vpnBindings
813 for (i in 0..networkPolicyUriList.size()-1) {
817 // prepare url using vpnBinding
818 String queryNetworkPolicyAAIRequest = ""
820 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
822 // Note: By default, the network policy url is found in 'related-link' of the response,
823 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
824 if (aai_uri == null || aai_uri == "") {
825 // using value of 'related-link' from response
826 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
827 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1) + "?depth=all"
829 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i] + "?depth=all"
832 // using uri value in URN mapping
833 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
834 println " networkPolicyId - " + networkPolicyId
835 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
836 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
838 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId + "?depth=all"
843 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
844 msoLogger.debug(Prefix + "queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest)
846 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
847 String returnCode = response.getStatusCode()
848 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
849 msoLogger.debug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
851 String aaiResponseAsString = response.getResponseBodyAsString()
853 if (returnCode=='200') {
854 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
855 msoLogger.debug(" QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
857 String networkPolicy = ""
858 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
859 networkPolicy = utils.getNodeText(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 msoLogger.debug(dataErrorMessage)
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 msoLogger.debug(dataErrorMessage)
879 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
887 execution.setVariable(Prefix + "networkCollection", networkPolicies)
888 msoLogger.debug(Prefix + "networkCollection - " + '\n' + networkPolicies)
891 // reset return code to success
892 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
893 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
894 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, 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 msoLogger.debug(" No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml)
908 } catch (BpmnError e) {
911 } catch (Exception ex) {
912 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
913 msoLogger.debug(exceptionMessage)
914 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
920 public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
922 execution.setVariable("prefix",Prefix)
924 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkTableRef() of DoCreateNetworkInstance ***** " )
928 String queryIdAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
929 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
930 msoLogger.debug(" relationship - " + relationship)
932 // Check if Network TableREf is present, then build a List of network policy
933 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
934 int networkTableRefCount = networkTableRefUriList.size()
935 execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
936 msoLogger.debug(Prefix + "networkTableRefCount - " + networkTableRefCount)
938 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
939 AaiUtil aaiUriUtil = new AaiUtil(this)
941 if (networkTableRefCount > 0) {
942 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
943 msoLogger.debug(" networkTableRefUri List - " + networkTableRefUriList)
945 // AII loop call using list vpnBindings
946 String networkTableRefs = ""
947 for (i in 0..networkTableRefUriList.size()-1) {
951 // prepare url using tableRef
952 String queryNetworkTableRefAAIRequest = ""
954 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
956 // Note: By default, the network policy url is found in 'related-link' of the response,
957 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
958 if (aai_uri == null || aai_uri == "") {
959 // using value of 'related-link' from response
960 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
961 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1) + "?depth=all"
963 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i] + "?depth=all"
966 // using uri value in URN mapping
967 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
969 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
970 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
972 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId + "?depth=all"
977 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
978 msoLogger.debug(Prefix + "queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest)
980 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
981 String returnCode = response.getStatusCode()
982 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
983 msoLogger.debug(" ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode)
985 String aaiResponseAsString = response.getResponseBodyAsString()
987 if (returnCode=='200') {
988 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
989 msoLogger.debug(" QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString)
991 String networkTableRef = ""
992 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
993 networkTableRef = utils.getNodeText(aaiResponseAsString, "route-table-reference-fqdn")
994 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
998 if (returnCode=='404') {
999 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
1000 msoLogger.debug(dataErrorMessage)
1001 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1004 if (aaiResponseAsString.contains("RESTFault")) {
1005 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
1006 execution.setVariable("WorkflowException", exceptionObject)
1007 throw new BpmnError("MSOWorkflowException")
1011 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
1012 msoLogger.debug(dataErrorMessage)
1013 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1021 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
1022 msoLogger.debug(Prefix + "tableRefCollection - " + '\n' + networkTableRefs)
1025 // reset return code to success
1026 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
1027 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1028 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
1029 String aaiStubResponse =
1030 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
1031 <route-table-references xmlns="${schemaVersion}">
1032 <route-table-reference-fqdn/>
1033 </route-table-references>
1035 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
1036 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
1037 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
1038 msoLogger.debug(" No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml)
1042 } catch (BpmnError e) {
1045 } catch (Exception ex) {
1046 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
1047 msoLogger.debug(exceptionMessage)
1048 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1055 public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
1057 execution.setVariable("prefix",Prefix)
1059 msoLogger.debug(" ***** Inside callRESTUpdateContrailAAINetwork() of DoCreateNetworkInstance ***** " )
1063 String networkId = execution.getVariable(Prefix + "networkId")
1064 networkId = UriUtils.encode(networkId,"UTF-8")
1065 String requeryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1066 String createNetworkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1069 String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
1070 AaiUtil aaiUriUtil = new AaiUtil(this)
1071 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1072 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
1074 execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
1075 msoLogger.debug(Prefix + "updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest)
1077 //Prepare payload (PUT)
1078 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
1079 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, createNetworkResponse, schemaVersion)
1080 String payloadXml = utils.formatXml(payload)
1081 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
1082 msoLogger.debug(" 'payload' to Update Contrail - " + "\n" + payloadXml)
1084 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payloadXml)
1086 String returnCode = response.getStatusCode()
1087 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
1088 msoLogger.debug(" ***** AAI Update Contrail Response Code : " + returnCode)
1089 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
1090 if (returnCode=='200') {
1091 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
1092 msoLogger.debug(" AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString)
1093 // Point-of-no-return is set to false, rollback not needed.
1094 String rollbackEnabled = execution.getVariable(Prefix + "rollbackEnabled")
1095 if (rollbackEnabled == "true") {
1096 execution.setVariable(Prefix + "isPONR", false)
1098 execution.setVariable(Prefix + "isPONR", true)
1100 msoLogger.debug(Prefix + "isPONR" + ": " + execution.getVariable(Prefix + "isPONR"))
1102 if (returnCode=='404') {
1103 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
1104 msoLogger.debug(dataErrorMessage)
1105 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1108 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
1109 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
1110 execution.setVariable("WorkflowException", exceptionObject)
1111 throw new BpmnError("MSOWorkflowException")
1115 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
1116 msoLogger.debug(errorMessage)
1117 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1122 } catch (BpmnError e) {
1125 } catch (Exception ex) {
1126 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
1127 msoLogger.debug(exceptionMessage)
1128 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1134 public void prepareCreateNetworkRequest (DelegateExecution execution) {
1136 execution.setVariable("prefix",Prefix)
1138 msoLogger.trace("Inside prepareCreateNetworkRequest() of DoCreateNetworkInstance")
1143 String requestId = execution.getVariable("msoRequestId")
1144 if (requestId == null) {
1145 requestId = execution.getVariable("mso-request-id")
1147 String messageId = execution.getVariable(Prefix + "messageId")
1148 String source = execution.getVariable(Prefix + "source")
1150 String requestInput = execution.getVariable(Prefix + "networkRequest")
1151 String queryIdResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1152 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1153 String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1155 // Prepare Network request
1156 String routeCollection = execution.getVariable(Prefix + "routeCollection")
1157 String policyCollection = execution.getVariable(Prefix + "networkCollection")
1158 String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1159 String createNetworkRequest = networkUtils.CreateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1161 String buildDeleteNetworkRequestAsString = utils.formatXml(createNetworkRequest)
1162 buildDeleteNetworkRequestAsString = buildDeleteNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1164 execution.setVariable(Prefix + "createNetworkRequest", buildDeleteNetworkRequestAsString)
1165 msoLogger.debug(Prefix + "createNetworkRequest - " + "\n" + buildDeleteNetworkRequestAsString)
1167 } catch (Exception ex) {
1168 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareCreateNetworkRequest() - " + ex.getMessage()
1169 msoLogger.debug(exceptionMessage)
1170 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1176 public void prepareSDNCRequest (DelegateExecution execution) {
1178 execution.setVariable("prefix",Prefix)
1180 msoLogger.trace("Inside prepareSDNCRequest() of DoCreateNetworkInstance")
1184 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1185 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1186 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1188 String networkId = execution.getVariable(Prefix + "networkId")
1189 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1191 // get/set 'msoRequestId' and 'mso-request-id'
1192 String requestId = execution.getVariable("msoRequestId")
1193 if (requestId != null) {
1194 execution.setVariable("mso-request-id", requestId)
1196 requestId = execution.getVariable("mso-request-id")
1198 execution.setVariable(Prefix + "requestId", requestId)
1200 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1201 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1203 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1204 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1205 msoLogger.debug(Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString)
1208 } catch (Exception ex) {
1209 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1210 msoLogger.debug(exceptionMessage)
1211 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1217 public void prepareRpcSDNCRequest (DelegateExecution execution) {
1219 execution.setVariable("prefix",Prefix)
1221 msoLogger.trace("Inside prepareRpcSDNCRequest() of DoCreateNetworkInstance")
1226 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1227 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1228 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1230 String networkId = execution.getVariable(Prefix + "networkId")
1231 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1233 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1234 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "CreateNetworkInstance", cloudRegionId, networkId, null)
1236 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1237 execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1238 msoLogger.debug(Prefix + "assignSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString)
1240 } catch (Exception ex) {
1241 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRequest() - " + ex.getMessage()
1242 msoLogger.debug(exceptionMessage)
1243 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1249 public void prepareRpcSDNCActivateRequest (DelegateExecution execution) {
1251 execution.setVariable("prefix",Prefix)
1253 msoLogger.trace("Inside prepareRpcSDNCActivateRequest() of DoCreateNetworkInstance")
1257 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1258 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1259 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1260 String networkId = execution.getVariable(Prefix + "networkId")
1261 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1263 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1264 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "activate", "CreateNetworkInstance", cloudRegionId, networkId, null)
1266 String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1267 execution.setVariable(Prefix + "activateSDNCRequest", sndcTopologyCreateRequesAsString)
1268 msoLogger.debug(Prefix + "activateSDNCRequest - " + "\n" + sndcTopologyCreateRequesAsString)
1271 } catch (Exception ex) {
1272 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRequest() - " + ex.getMessage()
1273 msoLogger.debug(exceptionMessage)
1274 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1283 // **************************************************
1284 // Post or Validate Response Section
1285 // **************************************************
1287 public void validateCreateNetworkResponse (DelegateExecution execution) {
1289 execution.setVariable("prefix",Prefix)
1291 msoLogger.trace("Inside validateNetworkResponse() of DoCreateNetworkInstance")
1294 String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1295 String networkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1296 if (networkResponse==null) {
1297 networkResponse="" // reset
1300 msoLogger.debug(" Network Adapter create responseCode: " + returnCode)
1302 String errorMessage = ""
1303 if (returnCode == "200") {
1304 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1305 execution.setVariable(Prefix + "createNetworkResponse", networkResponse)
1306 msoLogger.debug(" Network Adapter create Success Response - " + "\n" + networkResponse)
1308 // prepare rollback data
1309 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1310 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1311 String rollbackNetwork =
1312 """<rollbackNetworkRequest>
1314 </rollbackNetworkRequest>"""
1315 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1316 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1317 msoLogger.debug(" Network Adapter rollback data - " + "\n" + rollbackNetworkXml)
1319 } else { // network error
1320 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1321 if (networkResponse.contains("createNetworkError")) {
1322 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1323 errorMessage = utils.getNodeText(networkResponse, "message")
1324 errorMessage = "Received error from Network Adapter: " + errorMessage
1325 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1327 } else { // CatchAll exception
1328 if (returnCode == "500") {
1329 errorMessage = "JBWEB000065: HTTP Status 500."
1331 errorMessage = "Return code is " + returnCode
1333 errorMessage = "Received error from Network Adapter: " + errorMessage
1334 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1338 } else { // CatchAll exception
1339 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1340 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1346 } catch (BpmnError e) {
1349 } catch (Exception ex) {
1350 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. validateCreateNetworkResponse() - " + ex.getMessage()
1351 msoLogger.debug(exceptionMessage)
1352 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1359 public void validateSDNCResponse (DelegateExecution execution) {
1361 execution.setVariable("prefix",Prefix)
1363 msoLogger.trace("Inside validateSDNCResponse() of DoCreateNetworkInstance")
1365 String response = execution.getVariable(Prefix + "assignSDNCResponse")
1366 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1367 WorkflowException workflowException = execution.getVariable("WorkflowException")
1369 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1370 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1372 String assignSDNCResponseDecodeXml = execution.getVariable(Prefix + "assignSDNCResponse")
1373 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1374 execution.setVariable(Prefix + "assignSDNCResponse", assignSDNCResponseDecodeXml)
1376 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1377 execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1378 msoLogger.debug("Successfully Validated SDNC Response")
1381 msoLogger.debug("Did NOT Successfully Validated SDNC Response")
1382 throw new BpmnError("MSOWorkflowException")
1387 public void validateRpcSDNCActivateResponse (DelegateExecution execution) {
1389 execution.setVariable("prefix",Prefix)
1391 msoLogger.trace("Inside validateRpcSDNCActivateResponse() of DoCreateNetworkInstance")
1393 String response = execution.getVariable(Prefix + "activateSDNCResponse")
1394 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1395 WorkflowException workflowException = execution.getVariable("WorkflowException")
1397 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1398 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1400 String assignSDNCResponseDecodeXml = execution.getVariable(Prefix + "activateSDNCResponse")
1401 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1402 execution.setVariable(Prefix + "activateSDNCResponse", assignSDNCResponseDecodeXml)
1404 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) { // from sdnc util, Prefix+'sdncResponseSuccess'
1405 execution.setVariable(Prefix + "isSdncActivateRollbackNeeded", true)
1406 msoLogger.debug("Successfully Validated Rpc SDNC Activate Response")
1409 msoLogger.debug("Did NOT Successfully Validated Rpc SDNC Activate Response")
1410 throw new BpmnError("MSOWorkflowException")
1416 public void prepareSDNCRollbackRequest (DelegateExecution execution) {
1418 execution.setVariable("prefix",Prefix)
1420 msoLogger.trace("Inside prepareSDNCRollbackRequest() of DoCreateNetworkInstance")
1424 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1425 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1426 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1427 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1428 String networkId = execution.getVariable(Prefix + "networkId")
1429 if (networkId == 'null') {networkId = ""}
1430 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1432 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1433 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1434 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1435 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1436 msoLogger.debug(" Preparing request for SDNC Topology 'rollback-NetworkActivateRequest' rollback . . . - " + "\n" + sndcTopologyRollbackRequestAsString)
1439 } catch (Exception ex) {
1440 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1441 msoLogger.debug(exceptionMessage)
1442 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1448 public void prepareRpcSDNCRollbackRequest (DelegateExecution execution) {
1450 execution.setVariable("prefix",Prefix)
1452 msoLogger.trace("Inside prepareRpcSDNCRollbackRequest() of DoCreateNetworkInstance")
1456 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1457 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1458 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1459 String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1460 String networkId = execution.getVariable(Prefix + "networkId")
1461 if (networkId == 'null') {networkId = ""}
1462 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1464 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1465 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "unassign", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1466 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1467 execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1468 msoLogger.debug(" Preparing request for SDNC Topology 'unassign-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString)
1471 } catch (Exception ex) {
1472 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRollbackRequest() - " + ex.getMessage()
1473 msoLogger.debug(exceptionMessage)
1474 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1480 public void prepareRpcSDNCActivateRollback(DelegateExecution execution) {
1482 execution.setVariable("prefix",Prefix)
1484 msoLogger.trace("Inside prepareRpcSDNCActivateRollback() of DoCreateNetworkInstance")
1489 String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1490 String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1491 String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1492 String activateSDNCResponse = execution.getVariable(Prefix + "activateSDNCResponse")
1493 String networkId = execution.getVariable(Prefix + "networkId")
1494 if (networkId == 'null') {networkId = ""}
1495 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1497 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1498 String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "deactivate", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1499 String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1500 execution.setVariable(Prefix + "rollbackActivateSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1501 msoLogger.debug(" Preparing request for RPC SDNC Topology 'deactivate-DeleteNetworkInstance' rollback . . . - " + "\n" + sndcTopologyRollbackRpcRequestAsString)
1504 } catch (Exception ex) {
1505 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRollback() - " + ex.getMessage()
1506 msoLogger.debug(exceptionMessage)
1507 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1513 public void prepareRollbackData(DelegateExecution execution) {
1515 execution.setVariable("prefix",Prefix)
1517 msoLogger.trace("Inside prepareRollbackData() of DoCreateNetworkInstance")
1521 Map<String, String> rollbackData = new HashMap<String, String>();
1522 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1523 if (rollbackSDNCRequest != null) {
1524 if (rollbackSDNCRequest != "") {
1525 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1528 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1529 if (rollbackNetworkRequest != null) {
1530 if (rollbackNetworkRequest != "") {
1531 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1534 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1535 if (rollbackActivateSDNCRequest != null) {
1536 if (rollbackActivateSDNCRequest != "") {
1537 rollbackData.put("rollbackActivateSDNCRequest", execution.getVariable(Prefix + "rollbackActivateSDNCRequest"))
1540 execution.setVariable("rollbackData", rollbackData)
1541 msoLogger.debug("** rollbackData : " + rollbackData)
1543 execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1544 msoLogger.debug("** WorkflowException : " + execution.getVariable("WorkflowException"))
1546 } catch (Exception ex) {
1547 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1548 msoLogger.debug(exceptionMessage)
1549 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1555 public void postProcessResponse(DelegateExecution execution) {
1557 execution.setVariable("prefix",Prefix)
1559 msoLogger.trace("Inside postProcessResponse() of DoCreateNetworkInstance")
1564 // 1. Silent Success: execution.getVariable("CRENWKI_orchestrationStatus") == "ACTIVE"
1565 // 2. Success: execution.getVariable("WorkflowException") == null (NULL)
1566 // 3. WorkflowException: execution.getVariable("WorkflowException") != null (NOT NULL)
1568 msoLogger.debug(" ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"))
1570 if (execution.getVariable(Prefix + "isException") == false) {
1571 // set rollback data
1572 execution.setVariable("orchestrationStatus", "")
1573 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1574 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1575 prepareSuccessRollbackData(execution) // populate rollbackData
1576 execution.setVariable("WorkflowException", null)
1577 execution.setVariable(Prefix + "Success", true)
1578 msoLogger.debug(" ***** postProcessResponse(), GOOD !!!")
1580 // inside sub-flow logic
1581 execution.setVariable(Prefix + "Success", false)
1582 execution.setVariable("rollbackData", null)
1583 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1584 if (execution.getVariable("workflowException") != null) { // Output of Rollback flow.
1585 msoLogger.debug(" ***** workflowException: " + execution.getVariable("workflowException"))
1586 WorkflowException wfex = execution.getVariable("workflowException")
1587 exceptionMessage = wfex.getErrorMessage()
1589 if (execution.getVariable(Prefix + "WorkflowException") != null) {
1590 WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1591 exceptionMessage = pwfex.getErrorMessage()
1594 // going to the Main flow: a-la-carte or macro
1595 msoLogger.debug(" ***** postProcessResponse(), BAD !!!")
1596 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1597 throw new BpmnError("MSOWorkflowException")
1600 } catch(BpmnError b){
1601 msoLogger.debug("Rethrowing MSOWorkflowException")
1604 } catch (Exception ex) {
1605 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1606 msoLogger.debug(exceptionMessage)
1607 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1608 throw new BpmnError("MSOWorkflowException")
1616 public void prepareSuccessRollbackData(DelegateExecution execution) {
1618 execution.setVariable("prefix",Prefix)
1620 msoLogger.trace("Inside prepareSuccessRollbackData() of DoCreateNetworkInstance")
1624 if (execution.getVariable("sdncVersion") != '1610') {
1625 prepareRpcSDNCRollbackRequest(execution)
1626 prepareRpcSDNCActivateRollback(execution)
1628 prepareSDNCRollbackRequest(execution)
1631 Map<String, String> rollbackData = new HashMap<String, String>();
1632 String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1633 if (rollbackSDNCRequest != null) {
1634 if (rollbackSDNCRequest != "") {
1635 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1638 String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1639 if (rollbackNetworkRequest != null) {
1640 if (rollbackNetworkRequest != "") {
1641 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1644 String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1645 if (rollbackActivateSDNCRequest != null) {
1646 if (rollbackActivateSDNCRequest != "") {
1647 rollbackData.put("rollbackActivateSDNCRequest", rollbackActivateSDNCRequest)
1650 execution.setVariable("rollbackData", rollbackData)
1652 msoLogger.debug("** 'rollbackData' for Full Rollback : " + rollbackData)
1653 execution.setVariable("WorkflowException", null)
1656 } catch (Exception ex) {
1657 String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1658 msoLogger.debug(exceptionMessage)
1659 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1665 public void setExceptionFlag(DelegateExecution execution){
1667 execution.setVariable("prefix",Prefix)
1669 msoLogger.trace("Inside setExceptionFlag() of DoCreateNetworkInstance")
1673 execution.setVariable(Prefix + "isException", true)
1675 if (execution.getVariable("SavedWorkflowException1") != null) {
1676 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1678 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1680 msoLogger.debug(Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"))
1682 } catch(Exception ex){
1683 String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1684 msoLogger.debug(exceptionMessage)
1685 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1691 // *******************************
1692 // Build Error Section
1693 // *******************************
1697 public void processJavaException(DelegateExecution execution){
1699 execution.setVariable("prefix",Prefix)
1702 msoLogger.debug( "Caught a Java Exception in " + Prefix)
1703 msoLogger.debug("Started processJavaException Method")
1704 msoLogger.debug("Variables List: " + execution.getVariables())
1705 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1706 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1708 }catch(Exception e){
1709 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
1710 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
1711 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
1713 msoLogger.debug( "Completed processJavaException Method in " + Prefix)