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