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