AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateNetworkInstance.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
21
22 import groovy.xml.XmlUtil
23 import groovy.json.*
24 import org.openecomp.mso.bpmn.core.json.JsonUtils
25 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
28 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.rest.APIResponse;
33 import org.openecomp.mso.rest.RESTClient
34 import org.openecomp.mso.rest.RESTConfig
35
36 import java.util.HashMap;
37 import java.util.Map;
38 import java.util.UUID;
39
40 import org.camunda.bpm.engine.delegate.BpmnError
41 import org.camunda.bpm.engine.delegate.DelegateExecution
42 import org.apache.commons.lang3.*
43 import org.apache.commons.codec.binary.Base64;
44 import org.springframework.web.util.UriUtils
45
46 /**
47  * This groovy class supports the <class>DoCreateNetworkInstance.bpmn</class> process.
48  *
49  */
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()
57
58         def className = getClass().getSimpleName()
59         
60         /**
61          * This method is executed during the preProcessRequest task of the <class>DoCreateNetworkInstance.bpmn</class> process.
62          * @param execution
63          */
64         public InitializeProcessVariables(DelegateExecution execution){
65                 /* Initialize all the process variables in this block */
66
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","")
81                 
82                 // AAI query Name
83                 execution.setVariable(Prefix + "queryNameAAIRequest","")
84                 execution.setVariable(Prefix + "queryNameAAIResponse", "")
85                 execution.setVariable(Prefix + "aaiNameReturnCode", "")
86                 execution.setVariable(Prefix + "isAAIqueryNameGood", false)
87
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)
95
96                 // AAI query Id
97                 execution.setVariable(Prefix + "queryIdAAIRequest","")
98                 execution.setVariable(Prefix + "queryIdAAIResponse", "")
99                 execution.setVariable(Prefix + "aaiIdReturnCode", "")
100
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", "")
108
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", "")
116
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", "")
124
125                 // AAI requery Id
126                 execution.setVariable(Prefix + "requeryIdAAIRequest","")
127                 execution.setVariable(Prefix + "requeryIdAAIResponse", "")
128                 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
129
130                 // AAI update contrail
131                 execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
132                 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
133                 execution.setVariable(Prefix + "updateContrailAAIResponse", "")
134                 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
135
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)
143
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)
152                 
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)
161
162                 execution.setVariable(Prefix + "orchestrationStatus", "")
163                 execution.setVariable(Prefix + "isVnfBindingPresent", false)
164                 execution.setVariable(Prefix + "Success", false)
165
166                 execution.setVariable(Prefix + "isException", false)
167                 
168         }
169
170         // **************************************************
171         //     Pre or Prepare Request Section
172         // **************************************************
173         /**
174          * This method is executed during the preProcessRequest task of the <class>DoCreateNetworkInstance.bpmn</class> process.
175          * @param execution
176          */
177         public void preProcessRequest (DelegateExecution execution) {
178                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
179                 execution.setVariable("prefix",Prefix)
180                 
181                 utils.log("DEBUG", " ***** Inside preProcessRequest() of " + className + ".groovy ***** ", isDebugEnabled)
182
183                 try {
184                         // initialize flow variables
185                         InitializeProcessVariables(execution)
186                         
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 
193                                         try {
194                                                 def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
195                                                 utils.log("DEBUG", " Incoming message formatted . . . : " + '\n' + prettyJson, isDebugEnabled)
196                                                 networkRequest =  vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
197                 
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)
202                                         }
203                                 } else {
204                                    // XML format request is sent
205                                    
206                                 }
207                         } else {
208                                 // vIPR format request is sent, create xml from individual variables
209                                 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
210                         }
211                                 
212                         networkRequest = utils.formatXml(networkRequest)
213                         utils.logAudit(networkRequest)
214                         execution.setVariable(Prefix + "networkRequest", networkRequest)
215                         utils.log("DEBUG", Prefix + "networkRequest - " + '\n' + networkRequest, isDebugEnabled)
216                         
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)
221                                                                                 
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)
225                         
226                         // prepare messageId
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)
231                         } else {
232                                 utils.log("DEBUG", Prefix + "messageId, pre-assigned: " + messageId, isDebugEnabled)
233                         }
234                         execution.setVariable(Prefix + "messageId", messageId)
235                         
236                         String source = utils.getNodeText1(networkRequest, "source")
237                         execution.setVariable(Prefix + "source", source)
238                         utils.log("DEBUG", Prefix + "source - " + source, isDebugEnabled)
239                         
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)
246                         }
247
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)
254                         }
255
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)
259                         try {
260                                 def encodedString = utils.getBasicAuth(basicAuthValuePO, execution.getVariable("URN_mso_msoKey"))
261                                 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
262                                 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
263         
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)
269                         }
270
271                         // Set variables for Generic Get Sub Flow use
272                         execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
273                         utils.log("DEBUG", Prefix + "serviceInstanceId - " + serviceInstanceId, isDebugEnabled)
274
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)
278                         
279                         String sdncVersion = execution.getVariable("sdncVersion")
280                         utils.log("DEBUG", "sdncVersion? : " + sdncVersion, isDebugEnabled)
281                         
282                         // build 'networkOutputs'                       
283                         String networkId = utils.getNodeText1(networkRequest, "network-id")
284                         if ((networkId == null) || (networkId == "null")) {
285                                 networkId = ""
286                         }
287                         String networkName = utils.getNodeText1(networkRequest, "network-name")
288                         if ((networkName == null) || (networkName == "null")) {
289                                 networkName = ""
290                         }
291                         String networkOutputs =
292                            """<network-outputs>
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)
300                 
301                 } catch (BpmnError e) {
302                 throw e;
303                 
304                 } catch (Exception ex) {
305                         sendSyncError(execution)
306                         // caught exception
307                         String exceptionMessage = "Exception Encountered in PreProcessRequest() of " + className + ".groovy ***** : " + ex.getMessage()
308                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
309                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
310                 
311                 }
312
313         }
314         
315         public void callRESTQueryAAINetworkName (DelegateExecution execution) {
316                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
317                 execution.setVariable("prefix",Prefix)
318                 
319                 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkName() of DoCreateNetworkInstance ***** " , isDebugEnabled)
320
321                 // get variables
322                 String networkInputs  = execution.getVariable(Prefix + "networkInputs")
323                 String networkName   = utils.getNodeText1(networkInputs, "network-name")
324                 networkName = UriUtils.encode(networkName,"UTF-8")
325
326                 // Prepare AA&I url with network-name
327                 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
328                 AaiUtil aaiUriUtil = new AaiUtil(this)
329                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
330                 String queryAAINameRequest = "${aai_endpoint}${aai_uri}" + "?network-name=" + networkName
331                 utils.logAudit(queryAAINameRequest)
332                 execution.setVariable(Prefix + "queryNameAAIRequest", queryAAINameRequest)
333                 utils.log("DEBUG", Prefix + "queryNameAAIRequest - " + "\n" + queryAAINameRequest, isDebugEnabled)
334
335                 try {
336                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryAAINameRequest)
337                         String returnCode = response.getStatusCode()
338                         execution.setVariable(Prefix + "aaiNameReturnCode", returnCode)
339                         utils.log("DEBUG", " ***** AAI Query Name Response Code  : " + returnCode, isDebugEnabled)
340
341                         String aaiResponseAsString = response.getResponseBodyAsString()
342                         utils.log("DEBUG", " ***** AAI Query Name Response : " +'\n'+ aaiResponseAsString, isDebugEnabled)
343
344                         if (returnCode=='200') {
345                                 utils.logAudit(aaiResponseAsString)
346                                 execution.setVariable(Prefix + "queryNameAAIResponse", aaiResponseAsString)
347                                 execution.setVariable(Prefix + "isAAIqueryNameGood", true)
348                                 String orchestrationStatus = ""
349                                 try {
350                                         // response is NOT empty
351                                         orchestrationStatus = utils.getNodeText1(aaiResponseAsString, "orchestration-status")
352                                         execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus.toUpperCase())
353                                         utils.log("DEBUG", Prefix + "orchestrationStatus - " + orchestrationStatus.toUpperCase(), isDebugEnabled)
354                                         execution.setVariable("orchestrationStatus", orchestrationStatus)
355                                         
356                                 } catch (Exception ex) {
357                                     // response is empty
358                                         execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus)
359                                         utils.log("DEBUG", Prefix + "orchestrationStatus - " + orchestrationStatus, isDebugEnabled)
360                                 }
361
362                         } else {
363                             if (returnCode=='404') {
364                                         utils.log("DEBUG", " QueryAAINetworkName return code = '404' (Not Found).  Proceed with the Create !!! ", isDebugEnabled)
365
366                             } else {
367                                 // aai all errors
368                                         String dataErrorMessage = "Unexpected Error Response from QueryAAINetworkName - " + returnCode
369                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
370                                         exceptionUtil.buildWorkflowException(execution, 2500, dataErrorMessage)
371
372                       }
373
374                         }
375
376                         utils.log("DEBUG", Prefix + "isAAIqueryNameGood? : " + execution.getVariable(Prefix + "isAAIqueryNameGood"), isDebugEnabled)
377
378                 } catch (BpmnError e) {
379                 throw e;
380
381                 } catch (Exception ex) {
382                         // try error
383                         String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAINetworkName() -  " + ex.getMessage()
384                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
385                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
386
387                 }
388
389         }
390
391         public void callRESTQueryAAICloudRegion (DelegateExecution execution) {
392                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
393                 execution.setVariable("prefix",Prefix)
394                                 
395                 utils.log("DEBUG", " ***** Inside callRESTQueryAAICloudRegion() of DoCreateNetworkInstance ***** " , isDebugEnabled)
396
397                 try {
398                         String networkInputs  = execution.getVariable(Prefix + "networkInputs")
399                         String cloudRegion = utils.getNodeText1(networkInputs, "aic-cloud-region")
400                         cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
401
402                         // Prepare AA&I url
403                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
404                         AaiUtil aaiUtil = new AaiUtil(this)
405                         String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
406                         String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
407                         utils.logAudit(queryCloudRegionRequest)
408                         execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
409                         utils.log("DEBUG", Prefix + "queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugEnabled)
410
411                         String cloudRegionPo = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
412                         String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "SDNC", cloudRegion)
413
414                         if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
415                                 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
416                                 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
417                                 execution.setVariable(Prefix + "isCloudRegionGood", true)
418
419                         } else {
420                             String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
421                             utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
422                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
423
424                         }
425
426                         utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"), isDebugEnabled)
427
428                 } catch (BpmnError e) {
429                         throw e;
430
431                 } catch (Exception ex) {
432                         // try error
433                         String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
434                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
435                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
436
437                 }
438
439         }
440
441         public void callRESTQueryAAINetworkId(DelegateExecution execution) {
442                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
443                 execution.setVariable("prefix",Prefix)
444
445                 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkId() of DoCreateNetworkInstance ***** " , isDebugEnabled)
446
447                 try {
448                         // get variables
449                         String networkId = ""
450                         String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
451                         if (execution.getVariable("sdncVersion") != "1610") {
452                            String networkResponseInformation = ""
453                            try {        
454                               networkResponseInformation = utils.getNodeXml(assignSDNCResponse, "network-response-information", false).replace("tag0:","").replace(":tag0","")
455                                   networkId = utils.getNodeText1(networkResponseInformation, "instance-id")
456                            } catch (Exception ex) {
457                               String dataErrorMessage = " SNDC Response network validation for 'instance-id' (network-id) failed: Empty <network-response-information>"
458                               utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
459                                   exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
460                            }      
461                                   
462                         } else {
463                            networkId = utils.getNodeText1(assignSDNCResponse, "network-id")
464                         }
465                         if (networkId == null || networkId == "null") {
466                                 String dataErrorMessage = "SNDC Response did not contains 'instance-id' or 'network-id' element, or the value is null."
467                                 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
468                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
469                         } else {
470                            utils.log("DEBUG", " SNDC Response network validation for 'instance-id' (network-id)' is good: " + networkId, isDebugEnabled)
471                         }
472
473     
474                         execution.setVariable(Prefix + "networkId", networkId)
475                         String networkName   = utils.getNodeText1(assignSDNCResponse, "network-name")
476                         execution.setVariable(Prefix + "networkName", networkName)
477                         
478                         networkId = UriUtils.encode(networkId,"UTF-8")
479
480                         // Prepare AA&I url
481                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
482                         AaiUtil aaiUriUtil = new AaiUtil(this)
483                         String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
484                         String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
485                         utils.logAudit(queryIdAAIRequest)
486                         execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
487                         utils.log("DEBUG", Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest, isDebugEnabled)
488
489                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
490                         String returnCode = response.getStatusCode()
491                         execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
492
493                         utils.log("DEBUG", " ***** AAI Response Code  : " + returnCode, isDebugEnabled)
494
495                         String aaiResponseAsString = response.getResponseBodyAsString()
496
497                         if (returnCode=='200') {
498                                 utils.logAudit(aaiResponseAsString)
499                                 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
500                                 utils.log("DEBUG", " QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
501                                 
502                                 String netId   = utils.getNodeText1(aaiResponseAsString, "network-id")
503                                 execution.setVariable(Prefix + "networkId", netId)
504                                 String netName   = utils.getNodeText1(aaiResponseAsString, "network-name")
505                                 execution.setVariable(Prefix + "networkName", netName)
506
507                         } else {
508                                 if (returnCode=='404') {
509                                         String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
510                                         utils.log("DEBUG", " AAI Query Failed. " + dataErrorMessage, isDebugEnabled)
511                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
512
513                                 } else {
514                                    if (aaiResponseAsString.contains("RESTFault")) {
515                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
516                                            execution.setVariable("WorkflowException", exceptionObject)
517                                            throw new BpmnError("MSOWorkflowException")
518
519                                    } else {
520                                                         // aai all errors
521                                                         String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
522                                                         utils.log("DEBUG", "Unexpected Response from QueryAAINetworkId - " + dataErrorMessage, isDebugEnabled)
523                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
524
525                                   }
526                                 }
527                         }
528
529                 } catch (BpmnError e) {
530                         throw e;
531
532                 } catch (Exception ex) {
533                         String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
534                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
535                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
536
537                 }
538
539         }
540
541         public void callRESTReQueryAAINetworkId(DelegateExecution execution) {
542                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
543                 execution.setVariable("prefix",Prefix)
544
545                 utils.log("DEBUG", " ***** Inside callRESTReQueryAAINetworkId() of DoCreateNetworkInstance ***** " , isDebugEnabled)
546
547                 try {
548                         // get variables
549                         String networkId   = execution.getVariable(Prefix + "networkId")
550                         String netId = networkId 
551                         networkId = UriUtils.encode(networkId,"UTF-8")
552
553                         // Prepare AA&I url
554                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
555                         AaiUtil aaiUriUtil = new AaiUtil(this)
556                         String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
557                         String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
558                         utils.logAudit(requeryIdAAIRequest)
559                         execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
560                         utils.log("DEBUG", Prefix + "requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest, isDebugEnabled)
561
562                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
563                         String returnCode = response.getStatusCode()
564                         execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
565                         utils.log("DEBUG", " ***** AAI ReQuery Response Code  : " + returnCode, isDebugEnabled)
566
567                         String aaiResponseAsString = response.getResponseBodyAsString()
568
569                         if (returnCode=='200') {
570                                 utils.logAudit(aaiResponseAsString)
571                                 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
572                                 utils.log("DEBUG", " ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
573
574                                 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
575                                 String networkOutputs =
576                                    """<network-outputs>
577                    <network-id>${netId}</network-id>
578                    <network-name>${netName}</network-name>
579                  </network-outputs>"""
580                                 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
581                                 utils.log("DEBUG", " networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
582
583                         } else {
584                                 if (returnCode=='404') {
585                                         String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
586                                         utils.log("DEBUG", " AAI ReQuery Failed. - " + dataErrorMessage, isDebugEnabled)
587                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
588
589                                 } else {
590                                    if (aaiResponseAsString.contains("RESTFault")) {
591                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
592                                            execution.setVariable("WorkflowException", exceptionObject)
593                                            throw new BpmnError("MSOWorkflowException")
594
595                                            } else {
596                                                         // aai all errors
597                                                         String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
598                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
599                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
600
601                                         }
602                                 }
603                         }
604
605                 } catch (BpmnError e) {
606                         throw e;
607
608                 } catch (Exception ex) {
609                         String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
610                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
611                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
612
613                 }
614
615         }
616
617         public void callRESTQueryAAINetworkVpnBinding(DelegateExecution execution) {
618                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
619                 execution.setVariable("prefix",Prefix)
620
621                 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkVpnBinding() of DoCreateNetworkInstance ***** " , isDebugEnabled)
622
623                 try {
624
625                         // get variables
626                         String queryIdAAIResponse   = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
627                         String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
628                         utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
629
630                         // Check if Vnf Binding is present, then build a List of vnfBinding
631                         List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
632                         int vpnCount = vpnBindingUri.size()
633                         execution.setVariable(Prefix + "vpnCount", vpnCount)
634                         utils.log("DEBUG", Prefix + "vpnCount - " + vpnCount, isDebugEnabled)
635
636                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
637                         AaiUtil aaiUriUtil = new AaiUtil(this)
638
639                         if (vpnCount > 0) {
640                                 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
641                                 utils.log("DEBUG", " vpnBindingUri List - " + vpnBindingUri, isDebugEnabled)
642
643                                 String routeTargets = ""
644                                 // AII loop call using list vpnBindings
645                                 for (i in 0..vpnBindingUri.size()-1) {
646
647                                         int counting = i+1
648
649                                         // prepare url using vpnBinding
650                                         String queryVpnBindingAAIRequest = ""
651                                         String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
652
653                                         // Note: By default, the vpnBinding url is found in 'related-link' of the response,
654                                         //       so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
655                                         if (aai_uri == null || aai_uri == "") {
656                                                 // using value of 'related-link' from response
657                                                 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
658                                                     queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1) + "?depth=all"
659                                                 } else {
660                                                     queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i] + "?depth=all"
661                                                 }
662
663                                         } else {
664                                             // using uri value in URN mapping
665                                                 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
666                                                 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
667                                                         vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
668                                                 }
669                                             queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId + "?depth=all"
670                                         }
671
672                                         utils.logAudit(queryVpnBindingAAIRequest)
673                                         execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
674                                         utils.log("DEBUG", Prefix + "queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest, isDebugEnabled)
675
676                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
677                                         String returnCode = response.getStatusCode()
678                                         execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
679                                         utils.log("DEBUG", " ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode, isDebugEnabled)
680
681                                         String aaiResponseAsString = response.getResponseBodyAsString()
682
683                                         if (returnCode=='200') {
684                                                 utils.logAudit(aaiResponseAsString)
685                                                 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
686                                                 utils.log("DEBUG", " AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
687
688                                                 String routeTarget = ""
689                                                 String routeRole = ""
690                                                 if (utils.nodeExists(aaiResponseAsString, "route-targets")) {
691                                                         String aaiRouteTargets = utils.getNodeXml(aaiResponseAsString, "route-targets", false)
692                                                         def aaiRouteTargetsXml = new XmlSlurper().parseText(aaiRouteTargets)
693                                                         def aaiRouteTarget = aaiRouteTargetsXml.'**'.findAll {it.name() == "route-target"}
694                                                         for (j in 0..aaiRouteTarget.size()-1) {
695                                                                 routeTarget  = utils.getNodeText1(XmlUtil.serialize(aaiRouteTarget[j]), "global-route-target")
696                                                                 routeRole  = utils.getNodeText1(XmlUtil.serialize(aaiRouteTarget[j]), "route-target-role")
697                                                                 routeTargets += "<routeTargets>" + '\n' +
698                                                                                 " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
699                                                                                                 " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
700                                                                                                 "</routeTargets>" + '\n'
701                                                         }
702                                                 }
703
704                                         } else {
705                                                 if (returnCode=='404') {
706                                                         String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
707                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
708                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
709
710                                                 } else {
711                                                    if (aaiResponseAsString.contains("RESTFault")) {
712                                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
713                                                            execution.setVariable("WorkflowException", exceptionObject)
714                                                            throw new BpmnError("MSOWorkflowException")
715
716                                                            } else {
717                                                                         // aai all errors
718                                                                         String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
719                                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
720                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
721
722                                                           }
723                                                 }
724                                         }
725
726                                 } // end loop
727
728                                 execution.setVariable(Prefix + "routeCollection", routeTargets)
729                                 utils.log("DEBUG", Prefix + "routeCollection - " + '\n' + routeTargets, isDebugEnabled)
730
731                         } else {
732                                 // reset return code to success
733                                 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
734                             String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
735                                 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
736                             String aaiStubResponse =
737                                         """     <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
738                                                         <vpn-binding xmlns="${schemaVersion}">
739                                                       <global-route-target/>
740                                                         </vpn-binding>
741                                                 </rest:payload>"""
742                                 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
743                                 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
744                                 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
745                                 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
746
747                         }
748
749                 } catch (BpmnError e) {
750                         throw e;
751
752                 } catch (Exception ex) {
753                         String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
754                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
755                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
756
757                 }
758
759         }
760
761         public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
762                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
763                 execution.setVariable("prefix",Prefix)
764
765                 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy() of DoCreateNetworkInstance ***** " , isDebugEnabled)
766
767                 try {
768                         // get variables
769                         String queryIdAAIResponse   = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
770                         String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
771                         utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
772
773                         // Check if Network Policy is present, then build a List of network policy
774                         List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
775                         int networkPolicyCount = networkPolicyUriList.size()
776                         execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
777                         utils.log("DEBUG", Prefix + "networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
778
779                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
780                         AaiUtil aaiUriUtil = new AaiUtil(this)
781
782                         if (networkPolicyCount > 0) {
783                                 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
784                                 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
785
786                                 String networkPolicies = ""
787                                 // AII loop call using list vpnBindings
788                                 for (i in 0..networkPolicyUriList.size()-1) {
789
790                                         int counting = i+1
791
792                                         // prepare url using vpnBinding
793                                         String queryNetworkPolicyAAIRequest = ""
794
795                                         String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
796
797                                         // Note: By default, the network policy url is found in 'related-link' of the response,
798                                         //       so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
799                                         if (aai_uri == null || aai_uri == "") {
800                                                 // using value of 'related-link' from response
801                                                 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
802                                                         queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1) + "?depth=all"
803                                                 } else {
804                                                         queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i] + "?depth=all"
805                                                 }
806                                         } else {
807                                                 // using uri value in URN mapping
808                                                 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
809                                                 println " networkPolicyId - " + networkPolicyId
810                                                 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
811                                                         networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
812                                                 }
813                                                 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId + "?depth=all"
814
815                                         }
816
817
818                                         utils.logAudit(queryNetworkPolicyAAIRequest)
819                                         execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
820                                         utils.log("DEBUG", Prefix + "queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
821
822                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
823                                         String returnCode = response.getStatusCode()
824                                         execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
825                                         utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
826
827                                         String aaiResponseAsString = response.getResponseBodyAsString()
828
829                                         if (returnCode=='200') {
830                                                 utils.logAudit(aaiResponseAsString)
831                                                 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
832                                                 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
833
834                                                 String networkPolicy = ""
835                                                 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
836                                                         networkPolicy  = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
837                                                         networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
838                                                 }
839
840                                         } else {
841                                                 if (returnCode=='404') {
842                                                         String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
843                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
844                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
845
846                                                 } else {
847                                                    if (aaiResponseAsString.contains("RESTFault")) {
848                                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
849                                                            execution.setVariable("WorkflowException", exceptionObject)
850                                                            throw new BpmnError("MSOWorkflowException")
851
852                                                            } else {
853                                                                         // aai all errors
854                                                                         String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
855                                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
856                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
857
858                                                           }
859                                                 }
860                                         }
861
862                                 } // end loop
863
864                                 execution.setVariable(Prefix + "networkCollection", networkPolicies)
865                                 utils.log("DEBUG", Prefix + "networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
866
867                         } else {
868                                 // reset return code to success
869                                 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
870                                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
871                                 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
872                                 String aaiStubResponse =
873                                         """     <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
874                                                         <network-policy xmlns="${schemaVersion}">
875                                                           <network-policy-fqdn/>
876                             </network-policy>
877                                                 </rest:payload>"""
878                                 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
879                                 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
880                                 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
881                                 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
882
883                         }
884
885                 } catch (BpmnError e) {
886                         throw e;
887
888                 } catch (Exception ex) {
889                         String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
890                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
891                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
892
893                 }
894
895         }
896
897         public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
898                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
899                 execution.setVariable("prefix",Prefix)
900
901                 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef() of DoCreateNetworkInstance ***** " , isDebugEnabled)
902
903                 try {
904                         // get variables
905                         String queryIdAAIResponse   = execution.getVariable(Prefix + "queryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
906                         String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
907                         utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
908
909                         // Check if Network TableREf is present, then build a List of network policy
910                         List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
911                         int networkTableRefCount = networkTableRefUriList.size()
912                         execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
913                         utils.log("DEBUG", Prefix + "networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
914
915                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
916                         AaiUtil aaiUriUtil = new AaiUtil(this)
917
918                         if (networkTableRefCount > 0) {
919                                 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
920                                 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
921
922                                 // AII loop call using list vpnBindings
923                                 String networkTableRefs = ""
924                                 for (i in 0..networkTableRefUriList.size()-1) {
925
926                                         int counting = i+1
927
928                                         // prepare url using tableRef
929                                         String queryNetworkTableRefAAIRequest = ""
930
931                                         String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
932
933                                         // Note: By default, the network policy url is found in 'related-link' of the response,
934                                         //       so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
935                                         if (aai_uri == null || aai_uri == "") {
936                                                 // using value of 'related-link' from response
937                                                 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
938                                                         queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1) + "?depth=all"
939                                                 } else {
940                                                         queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i] + "?depth=all"
941                                                 }
942                                         } else {
943                                                 // using uri value in URN mapping
944                                                 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
945
946                                                 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
947                                                         networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
948                                                 }
949                                                 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId + "?depth=all"
950
951                                         }
952
953
954                                         utils.logAudit(queryNetworkTableRefAAIRequest)
955                                         execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
956                                         utils.log("DEBUG", Prefix + "queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
957
958                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
959                                         String returnCode = response.getStatusCode()
960                                         execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
961                                         utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
962
963                                         String aaiResponseAsString = response.getResponseBodyAsString()
964
965                                         if (returnCode=='200') {
966                                                 utils.logAudit(aaiResponseAsString)
967                                                 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
968                                                 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
969
970                                                 String networkTableRef = ""
971                                                 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
972                                                         networkTableRef  = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
973                                                         networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
974                                                 }
975
976                                         } else {
977                                                 if (returnCode=='404') {
978                                                         String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
979                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
980                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
981
982                                                 } else {
983                                                    if (aaiResponseAsString.contains("RESTFault")) {
984                                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
985                                                            execution.setVariable("WorkflowException", exceptionObject)
986                                                            throw new BpmnError("MSOWorkflowException")
987
988                                                            } else {
989                                                                         // aai all errors
990                                                                         String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
991                                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
992                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
993
994                                                           }
995                                                 }
996                                         }
997
998                                 } // end loop
999
1000                                 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
1001                                 utils.log("DEBUG", Prefix + "tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
1002
1003                         } else {
1004                                 // reset return code to success
1005                                 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
1006                                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1007                                 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
1008                                 String aaiStubResponse =
1009                                         """     <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
1010                                                         <route-table-references xmlns="${schemaVersion}">
1011                                                           <route-table-reference-fqdn/>
1012                             </route-table-references>
1013                                                 </rest:payload>"""
1014                                 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
1015                                 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
1016                                 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
1017                                 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
1018
1019                         }
1020
1021                 } catch (BpmnError e) {
1022                         throw e;
1023
1024                 } catch (Exception ex) {
1025                         String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
1026                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1027                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1028
1029                 }
1030
1031         }
1032
1033
1034         public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
1035                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1036                 execution.setVariable("prefix",Prefix)
1037
1038                 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork() of DoCreateNetworkInstance ***** " , isDebugEnabled)
1039
1040                 try {
1041                         // get variables
1042                         String networkId   = execution.getVariable(Prefix + "networkId")
1043                         networkId = UriUtils.encode(networkId,"UTF-8")
1044                         String requeryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse")
1045                         String createNetworkResponse   = execution.getVariable(Prefix + "createNetworkResponse")
1046
1047                         // Prepare url
1048                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
1049                         AaiUtil aaiUriUtil = new AaiUtil(this)
1050                         String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
1051                         String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
1052
1053                         utils.logAudit(updateContrailAAIUrlRequest)
1054                         execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
1055                         utils.log("DEBUG", Prefix + "updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
1056
1057                         //Prepare payload (PUT)
1058                         String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
1059                         String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, createNetworkResponse, schemaVersion)
1060                         String payloadXml = utils.formatXml(payload)
1061                         utils.logAudit(payloadXml)
1062                         execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
1063                         utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
1064
1065                         APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payloadXml)
1066                                                 
1067                         String returnCode = response.getStatusCode()
1068                         execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
1069                         utils.log("DEBUG", " ***** AAI Update Contrail Response Code  : " + returnCode, isDebugEnabled)
1070                         String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
1071                         if (returnCode=='200') {
1072                                 utils.logAudit(aaiUpdateContrailResponseAsString)
1073                                 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
1074                                 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
1075                                 // Point-of-no-return is set to false, rollback not needed.
1076                                 String rollbackEnabled = execution.getVariable(Prefix + "rollbackEnabled")
1077                                 if (rollbackEnabled == "true") {
1078                                    execution.setVariable(Prefix + "isPONR", false)
1079                                 } else {
1080                                    execution.setVariable(Prefix + "isPONR", true)
1081                                 }  
1082                                 utils.log("DEBUG", Prefix + "isPONR" + ": " + execution.getVariable(Prefix + "isPONR"), isDebugEnabled)
1083                         } else {
1084                                 if (returnCode=='404') {
1085                                         String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
1086                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
1087                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1088
1089                                 } else {
1090                                    if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
1091                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
1092                                            execution.setVariable("WorkflowException", exceptionObject)
1093                                            throw new BpmnError("MSOWorkflowException")
1094
1095                                            } else {
1096                                                         // aai all errors
1097                                                         String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
1098                                                         utils.log("DEBUG", errorMessage, isDebugEnabled)
1099                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1100                                           }
1101                                 }
1102                         }
1103
1104                 } catch (BpmnError e) {
1105                         throw e;
1106
1107                 } catch (Exception ex) {
1108                         String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
1109                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1110                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1111
1112                 }
1113
1114         }
1115
1116         public void prepareCreateNetworkRequest (DelegateExecution execution) {
1117                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1118                 execution.setVariable("prefix",Prefix)
1119
1120                 utils.log("DEBUG", " ***** Inside prepareCreateNetworkRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1121
1122                 try {
1123
1124                         // get variables
1125                         String requestId = execution.getVariable("msoRequestId")
1126                         if (requestId == null) {
1127                                 requestId = execution.getVariable("mso-request-id") 
1128                         }
1129                         String messageId = execution.getVariable(Prefix + "messageId")
1130                         String source    = execution.getVariable(Prefix + "source")
1131
1132                         String requestInput = execution.getVariable(Prefix + "networkRequest")
1133                         String queryIdResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1134                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1135                         String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1136                         
1137                         // Prepare Network request
1138                         String routeCollection = execution.getVariable(Prefix + "routeCollection")
1139                         String policyCollection = execution.getVariable(Prefix + "networkCollection")
1140                         String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1141                         String createNetworkRequest = networkUtils.CreateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1142                         // Format Response
1143                         String buildDeleteNetworkRequestAsString = utils.formatXml(createNetworkRequest)
1144                         buildDeleteNetworkRequestAsString = buildDeleteNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1145                         utils.logAudit(buildDeleteNetworkRequestAsString)
1146
1147                         execution.setVariable(Prefix + "createNetworkRequest", buildDeleteNetworkRequestAsString)
1148                         utils.log("DEBUG", Prefix + "createNetworkRequest - " + "\n" +  buildDeleteNetworkRequestAsString, isDebugEnabled)
1149
1150                 } catch (Exception ex) {
1151                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareCreateNetworkRequest() - " + ex.getMessage()
1152                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1153                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1154
1155                 }
1156
1157         }
1158
1159         public void prepareSDNCRequest (DelegateExecution execution) {
1160                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1161                 execution.setVariable("prefix",Prefix)
1162
1163                 utils.log("DEBUG", " ***** Inside prepareSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1164
1165                 try {
1166                         // get variables
1167                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1168                         String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1169                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1170
1171                         String networkId = execution.getVariable(Prefix + "networkId")
1172                         String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1173
1174                         // get/set 'msoRequestId' and 'mso-request-id'
1175                         String requestId = execution.getVariable("msoRequestId")
1176                         if (requestId != null) {
1177                                 execution.setVariable("mso-request-id", requestId)
1178                         } else {
1179                             requestId = execution.getVariable("mso-request-id")
1180                         }       
1181                         execution.setVariable(Prefix + "requestId", requestId)
1182                         
1183                         // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1184                         String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1185
1186                         String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1187                         utils.logAudit(sndcTopologyCreateRequesAsString)
1188                         execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1189                         utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" +  sndcTopologyCreateRequesAsString, isDebugEnabled)
1190
1191
1192                 } catch (Exception ex) {
1193                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1194                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1195                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1196
1197                 }
1198
1199         }
1200
1201         public void prepareRpcSDNCRequest (DelegateExecution execution) {
1202                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1203                 execution.setVariable("prefix",Prefix)
1204
1205                 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1206
1207                 try {
1208                         // get variables
1209                         
1210                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1211                         String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1212                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1213
1214                         String networkId = execution.getVariable(Prefix + "networkId")
1215                         String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1216                         
1217                         // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1218                         String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "CreateNetworkInstance", cloudRegionId, networkId, null)
1219
1220                         String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1221                         utils.logAudit(sndcTopologyCreateRequesAsString)
1222                         execution.setVariable(Prefix + "assignSDNCRequest", sndcTopologyCreateRequesAsString)
1223                         utils.log("DEBUG", Prefix + "assignSDNCRequest - " + "\n" +  sndcTopologyCreateRequesAsString, isDebugEnabled)
1224
1225                 } catch (Exception ex) {
1226                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRequest() - " + ex.getMessage()
1227                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1228                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1229
1230                 }
1231
1232         }
1233         
1234         public void prepareRpcSDNCActivateRequest (DelegateExecution execution) {
1235                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1236                 execution.setVariable("prefix",Prefix)
1237                 
1238                 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1239
1240                 try {
1241                         // get variables
1242                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1243                         String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1244                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1245                         String networkId = execution.getVariable(Prefix + "networkId")
1246                         String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1247                         
1248                         // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1249                         String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "activate", "CreateNetworkInstance", cloudRegionId, networkId, null)
1250
1251                         String sndcTopologyCreateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1252                         utils.logAudit(sndcTopologyCreateRequesAsString)
1253                         execution.setVariable(Prefix + "activateSDNCRequest", sndcTopologyCreateRequesAsString)
1254                         utils.log("DEBUG", Prefix + "activateSDNCRequest - " + "\n" +  sndcTopologyCreateRequesAsString, isDebugEnabled)
1255
1256
1257                 } catch (Exception ex) {
1258                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRequest() - " + ex.getMessage()
1259                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1260                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1261
1262                 }
1263
1264         }
1265         
1266
1267
1268
1269         // **************************************************
1270         //     Post or Validate Response Section
1271         // **************************************************
1272
1273         public void validateCreateNetworkResponse (DelegateExecution execution) {
1274                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1275                 execution.setVariable("prefix",Prefix)
1276
1277                 utils.log("DEBUG", " ***** Inside validateNetworkResponse() of DoCreateNetworkInstance *****", isDebugEnabled)
1278
1279                 try {
1280                         String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1281                         String networkResponse = execution.getVariable(Prefix + "createNetworkResponse")
1282                         if (networkResponse==null)      {
1283                                 networkResponse="" // reset
1284                         }
1285
1286                         utils.log("DEBUG", " Network Adapter create responseCode: " + returnCode, isDebugEnabled)
1287
1288                         String errorMessage = ""
1289                         if (returnCode == "200") {
1290                                 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1291                                 utils.logAudit(networkResponse)
1292                                 execution.setVariable(Prefix + "createNetworkResponse", networkResponse)
1293                                 utils.log("DEBUG", " Network Adapter create Success Response - " + "\n" + networkResponse, isDebugEnabled)
1294
1295                                 // prepare rollback data
1296                                 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1297                                 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1298                                 String rollbackNetwork =
1299                                         """<rollbackNetworkRequest>
1300                                                         ${rollbackData}
1301                                                 </rollbackNetworkRequest>"""
1302                                 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1303                                 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1304                                 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1305
1306                         } else { // network error
1307                            if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) {   //4xx, 5xx
1308                                    if (networkResponse.contains("createNetworkError")) {
1309                                            networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1310                                            errorMessage = utils.getNodeText1(networkResponse, "message")
1311                                            errorMessage  = "Received error from Network Adapter: " + errorMessage
1312                                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1313
1314                                    } else { // CatchAll exception
1315                                            if (returnCode == "500") {
1316                                                    errorMessage = "JBWEB000065: HTTP Status 500."
1317                                        } else {
1318                                                errorMessage = "Return code is " + returnCode
1319                                        }
1320                                            errorMessage  = "Received error from Network Adapter: " + errorMessage
1321                                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1322
1323                                    }
1324
1325                            } else { // CatchAll exception
1326                                    String dataErrorMessage  = "Received error from Network Adapter. Return code is: " + returnCode
1327                                    exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1328
1329                            }
1330
1331                         }
1332
1333                 } catch (BpmnError e) {
1334                         throw e;
1335
1336                 } catch (Exception ex) {
1337                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. validateCreateNetworkResponse() - " + ex.getMessage()
1338                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1339                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1340
1341                 }
1342
1343
1344         }
1345
1346         public void validateSDNCResponse (DelegateExecution execution) {
1347                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1348                 execution.setVariable("prefix",Prefix)
1349
1350                 utils.log("DEBUG", " ***** Inside validateSDNCResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1351
1352                 String response = execution.getVariable(Prefix + "assignSDNCResponse")
1353                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1354                 WorkflowException workflowException = execution.getVariable("WorkflowException")
1355                 
1356                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1357                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1358                 // reset variable
1359                 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "assignSDNCResponse"))
1360                 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&amp;").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1361                 execution.setVariable(Prefix + "assignSDNCResponse", assignSDNCResponseDecodeXml)
1362
1363                 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) {  // from sdnc util, Prefix+'sdncResponseSuccess'
1364                         execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1365                         utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1366
1367                 } else {
1368                         utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1369                         throw new BpmnError("MSOWorkflowException")
1370                 }
1371
1372         }
1373
1374         public void validateRpcSDNCActivateResponse (DelegateExecution execution) {
1375                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1376                 execution.setVariable("prefix",Prefix)
1377
1378                 utils.log("DEBUG", " ***** Inside validateRpcSDNCActivateResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1379
1380                 String response = execution.getVariable(Prefix + "activateSDNCResponse")
1381                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1382                 WorkflowException workflowException = execution.getVariable("WorkflowException")
1383
1384                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1385                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1386                 // reset variable
1387                 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "activateSDNCResponse"))
1388                 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&amp;").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1389                 execution.setVariable(Prefix + "activateSDNCResponse", assignSDNCResponseDecodeXml)
1390
1391                 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) {  // from sdnc util, Prefix+'sdncResponseSuccess'
1392                         execution.setVariable(Prefix + "isSdncActivateRollbackNeeded", true)
1393                         utils.log("DEBUG", "Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1394
1395                 } else {
1396                         utils.log("DEBUG", "Did NOT Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
1397                         throw new BpmnError("MSOWorkflowException")
1398                 }
1399                 
1400         }
1401
1402
1403         public void prepareSDNCRollbackRequest (DelegateExecution execution) {
1404                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1405                 execution.setVariable("prefix",Prefix)
1406
1407                 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1408
1409                 try {
1410                         // get variables
1411                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1412                         String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1413                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1414                         String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1415                         String networkId = execution.getVariable(Prefix + "networkId")
1416                         if (networkId == 'null') {networkId = ""}
1417                         String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1418                         
1419                         // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1420                         String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1421                         String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1422                         execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1423                         utils.log("DEBUG", " Preparing request for SDNC Topology 'rollback-NetworkActivateRequest' rollback . . . - " + "\n" +  sndcTopologyRollbackRequestAsString, isDebugEnabled)
1424
1425
1426                 } catch (Exception ex) {
1427                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1428                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1429                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1430
1431                 }
1432
1433         }
1434
1435         public void prepareRpcSDNCRollbackRequest (DelegateExecution execution) {
1436                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1437                 execution.setVariable("prefix",Prefix)
1438
1439                 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRollbackRequest() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1440
1441                 try {
1442                         // get variables
1443                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1444                         String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1445                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1446                         String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse")
1447                         String networkId = execution.getVariable(Prefix + "networkId")
1448                         if (networkId == 'null') {networkId = ""}
1449                         String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1450
1451                         // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1452                         String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "unassign", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1453                         String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1454                         execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1455                         utils.log("DEBUG", " Preparing request for SDNC Topology 'unassign-DeleteNetworkInstance' rollback . . . - " + "\n" +  sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1456
1457
1458                 } catch (Exception ex) {
1459                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCRollbackRequest() - " + ex.getMessage()
1460                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1461                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1462
1463                 }
1464
1465         }
1466         
1467         public void prepareRpcSDNCActivateRollback(DelegateExecution execution) {
1468                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1469                 execution.setVariable("prefix",Prefix)
1470
1471                 utils.log("DEBUG", " ***** Inside prepareRpcSDNCActivateRollback() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1472
1473                 try {
1474                 
1475                         // get variables
1476                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1477                         String createNetworkInput = execution.getVariable(Prefix + "networkRequest")
1478                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1479                         String activateSDNCResponse = execution.getVariable(Prefix + "activateSDNCResponse")
1480                         String networkId = execution.getVariable(Prefix + "networkId")
1481                         if (networkId == 'null') {networkId = ""}
1482                         String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
1483
1484                         // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1485                         String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "deactivate", "DeleteNetworkInstance", cloudRegionId, networkId, null)
1486                         String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
1487                         execution.setVariable(Prefix + "rollbackActivateSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
1488                         utils.log("DEBUG", " Preparing request for RPC SDNC Topology 'deactivate-DeleteNetworkInstance' rollback . . . - " + "\n" +  sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
1489
1490
1491                 } catch (Exception ex) {
1492                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRpcSDNCActivateRollback() - " + ex.getMessage()
1493                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1494                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1495
1496                 }
1497
1498         }
1499         
1500         public void prepareRollbackData(DelegateExecution execution) {
1501                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1502                 execution.setVariable("prefix",Prefix)
1503                 
1504                 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1505                 
1506                 try {
1507                         
1508                         Map<String, String> rollbackData = new HashMap<String, String>();
1509                         String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1510                         if (rollbackSDNCRequest != null) { 
1511                                 if (rollbackSDNCRequest != "") {
1512                                 rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1513                             }
1514                         }       
1515                         String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1516                         if (rollbackNetworkRequest != null) {
1517                                 if (rollbackNetworkRequest != "") {      
1518                                 rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1519                                 }       
1520                         }
1521                         String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1522                         if (rollbackActivateSDNCRequest != null) {
1523                                 if (rollbackActivateSDNCRequest != "") {         
1524                                 rollbackData.put("rollbackActivateSDNCRequest", execution.getVariable(Prefix + "rollbackActivateSDNCRequest"))
1525                                 }       
1526                         }
1527                         execution.setVariable("rollbackData", rollbackData)
1528                         utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
1529                         
1530                         execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1531                         utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
1532                         
1533                 } catch (Exception ex) {
1534                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1535                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1536                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1537                 
1538                 }
1539                 
1540         }
1541         
1542         public void postProcessResponse(DelegateExecution execution) {
1543                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1544                 execution.setVariable("prefix",Prefix)
1545                 
1546                 utils.log("DEBUG", " ***** Inside postProcessResponse() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1547                 
1548                 try {
1549                         
1550                         //Conditions:
1551                         // 1. Silent Success: execution.getVariable("CRENWKI_orchestrationStatus") == "ACTIVE"  
1552                         // 2. Success: execution.getVariable("WorkflowException") == null (NULL)
1553                         // 3. WorkflowException: execution.getVariable("WorkflowException") != null (NOT NULL) 
1554                         
1555                         utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
1556                         // successful flow
1557                         if (execution.getVariable(Prefix + "isException") == false) {  
1558                                 // set rollback data
1559                                 execution.setVariable("orchestrationStatus", "")
1560                                 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1561                                 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1562                                 prepareSuccessRollbackData(execution) // populate rollbackData  
1563                                 execution.setVariable("WorkflowException", null)
1564                                 execution.setVariable(Prefix + "Success", true)
1565                                 utils.log("DEBUG", " ***** postProcessResponse(), GOOD !!!", isDebugEnabled)
1566                         } else {
1567                            // inside sub-flow logic
1568                                 execution.setVariable(Prefix + "Success", false) 
1569                                 execution.setVariable("rollbackData", null)
1570                                 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1571                                 if (execution.getVariable("workflowException") != null) {  // Output of Rollback flow.
1572                                    utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
1573                                    WorkflowException wfex = execution.getVariable("workflowException")
1574                                    exceptionMessage = wfex.getErrorMessage()
1575                                 } else {
1576                                if (execution.getVariable(Prefix + "WorkflowException") != null) {
1577                                       WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1578                                       exceptionMessage = pwfex.getErrorMessage()
1579                                }   
1580                                 }
1581                             // going to the Main flow: a-la-carte or macro
1582                             utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
1583                             exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1584                                 throw new BpmnError("MSOWorkflowException")
1585                         }
1586                                                         
1587                 } catch(BpmnError b){
1588                      utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
1589                      throw b
1590                         
1591                 } catch (Exception ex) {
1592                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1593                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1594                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1595                         throw new BpmnError("MSOWorkflowException")
1596                 
1597                 }
1598                 
1599                 
1600                 
1601         }
1602         
1603         public void prepareSuccessRollbackData(DelegateExecution execution) {
1604                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1605                 execution.setVariable("prefix",Prefix)
1606                 
1607                 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1608                 
1609                 try {
1610                         
1611                         if (execution.getVariable("sdncVersion") != '1610') {
1612                             prepareRpcSDNCRollbackRequest(execution)
1613                                 prepareRpcSDNCActivateRollback(execution)
1614                         } else {
1615                             prepareSDNCRollbackRequest(execution)
1616                         }       
1617                         
1618                         Map<String, String> rollbackData = new HashMap<String, String>();
1619                         String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1620                         if (rollbackSDNCRequest != null) {
1621                                 if (rollbackSDNCRequest != "") {
1622                                         rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1623                                 }
1624                         }
1625                         String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1626                         if (rollbackNetworkRequest != null) {
1627                                 if (rollbackNetworkRequest != "") {
1628                                         rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1629                                 }
1630                         }
1631                         String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest")
1632                         if (rollbackActivateSDNCRequest != null) {
1633                                 if (rollbackActivateSDNCRequest != "") {
1634                                         rollbackData.put("rollbackActivateSDNCRequest", rollbackActivateSDNCRequest)
1635                                 }
1636                         }
1637                         execution.setVariable("rollbackData", rollbackData)
1638                         
1639                         utils.log("DEBUG", "** 'rollbackData' for Full Rollback : " + rollbackData, isDebugEnabled)
1640                         execution.setVariable("WorkflowException", null)
1641
1642                         
1643                 } catch (Exception ex) {
1644                         String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1645                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1646                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1647                 
1648                 }
1649                 
1650         }
1651
1652         public void setExceptionFlag(DelegateExecution execution){
1653                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1654                 execution.setVariable("prefix",Prefix)
1655                 
1656                 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoCreateNetworkInstance ***** ", isDebugEnabled)
1657                 
1658                 try {
1659                         
1660                         execution.setVariable(Prefix + "isException", true)
1661                         
1662                         if (execution.getVariable("SavedWorkflowException1") != null) {
1663                                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1664                         } else {
1665                                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1666                         }
1667                         utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1668                         
1669                 } catch(Exception ex){
1670                         String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1671                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1672                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1673                 }  
1674                 
1675         }
1676         
1677         
1678         // *******************************
1679         //     Build Error Section
1680         // *******************************
1681
1682
1683         
1684         public void processJavaException(DelegateExecution execution){
1685                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1686                 execution.setVariable("prefix",Prefix)
1687                 
1688                 try{
1689                         utils.log("DEBUG", "Caught a Java Exception in " + Prefix, isDebugEnabled)
1690                         utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1691                         utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1692                         execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix)  // Adding this line temporarily until this flows error handling gets updated
1693                         exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1694                         
1695                 }catch(Exception e){
1696                         utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1697                         execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix)  // Adding this line temporarily until this flows error handling gets updated
1698                         exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
1699                 }
1700                 utils.log("DEBUG", "Completed processJavaException Method in " + Prefix, isDebugEnabled)
1701         }
1702
1703 }