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