Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoUpdateNetworkInstance.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts;
22
23 import org.apache.commons.lang3.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.so.bpmn.common.scripts.AaiUtil
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.NetworkUtils
31 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
32 import org.onap.so.bpmn.common.scripts.VidUtils
33 import org.onap.so.bpmn.core.UrnPropertiesReader
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.onap.so.logger.MsoLogger
37 import org.onap.so.rest.APIResponse
38 import org.springframework.web.util.UriUtils
39
40 import groovy.json.*
41 import groovy.xml.XmlUtil
42
43 /**
44  * This groovy class supports the <class>DoUpdateNetworkInstance.bpmn</class> process.
45  *
46  */
47 public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor {
48         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoUpdateNetworkInstance.class);
49         
50         String Prefix="UPDNETI_"
51         ExceptionUtil exceptionUtil = new ExceptionUtil()
52         JsonUtils jsonUtil = new JsonUtils()
53         VidUtils vidUtils = new VidUtils(this)
54         NetworkUtils networkUtils = new NetworkUtils()
55         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
56
57         /**
58          * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
59          * @param execution
60          */
61         public InitializeProcessVariables(DelegateExecution execution){
62                 /* Initialize all the process variables in this block */
63
64                 execution.setVariable(Prefix + "messageId", "")
65                 execution.setVariable("BasicAuthHeaderValuePO", "")
66                 execution.setVariable("BasicAuthHeaderValueSDNC", "")
67                 execution.setVariable(Prefix + "networkRequest", "")
68                 execution.setVariable(Prefix + "networkInputs", "")
69                 execution.setVariable(Prefix + "networkOutputs", "")
70                 execution.setVariable(Prefix + "requestId", "")
71                 execution.setVariable(Prefix + "source", "")
72                 execution.setVariable(Prefix + "networkId", "")
73
74                 execution.setVariable(Prefix + "isPONR", false)    // Point-of-no-return, means, rollback is not needed
75
76                 // AAI query Cloud Region
77                 execution.setVariable(Prefix + "queryCloudRegionRequest","")
78                 execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
79                 execution.setVariable(Prefix + "queryCloudRegionResponse","")
80                 execution.setVariable(Prefix + "cloudRegionPo","")
81                 execution.setVariable(Prefix + "cloudRegionSdnc","")
82                 execution.setVariable(Prefix + "isCloudRegionGood", false)
83
84                 // AAI query Id
85                 execution.setVariable(Prefix + "queryIdAAIRequest","")
86                 execution.setVariable(Prefix + "queryIdAAIResponse", "")
87                 execution.setVariable(Prefix + "aaiIdReturnCode", "")
88
89                 // AAI query vpn binding
90                 execution.setVariable(Prefix + "queryVpnBindingAAIRequest","")
91                 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", "")
92                 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "")
93                 execution.setVariable(Prefix + "vpnBindings", null)
94                 execution.setVariable(Prefix + "vpnCount", 0)
95                 execution.setVariable(Prefix + "routeCollection", "")
96
97                 // AAI query network policy
98                 execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest","")
99                 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", "")
100                 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "")
101                 execution.setVariable(Prefix + "networkPolicyUriList", null)
102                 execution.setVariable(Prefix + "networkPolicyCount", 0)
103                 execution.setVariable(Prefix + "networkCollection", "")
104
105                 // AAI query route table reference
106                 execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest","")
107                 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", "")
108                 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "")
109                 execution.setVariable(Prefix + "networkTableRefUriList", null)
110                 execution.setVariable(Prefix + "networkTableRefCount", 0)
111                 execution.setVariable(Prefix + "tableRefCollection", "")
112                 
113                 // AAI requery Id
114                 execution.setVariable(Prefix + "requeryIdAAIRequest","")
115                 execution.setVariable(Prefix + "requeryIdAAIResponse", "")
116                 execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
117
118                 // AAI update contrail
119                 execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
120                 execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
121                 execution.setVariable(Prefix + "updateContrailAAIResponse", "")
122                 execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
123
124                 execution.setVariable(Prefix + "updateNetworkRequest", "")
125                 execution.setVariable(Prefix + "updateNetworkResponse", "")
126                 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
127                 execution.setVariable(Prefix + "networkReturnCode", "")
128                 execution.setVariable(Prefix + "isNetworkRollbackNeeded", false)
129
130                 execution.setVariable(Prefix + "changeAssignSDNCRequest", "")
131                 execution.setVariable(Prefix + "changeAssignSDNCResponse", "")
132                 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
133                 execution.setVariable(Prefix + "sdncReturnCode", "")
134                 execution.setVariable(Prefix + "isSdncRollbackNeeded", false)
135                 execution.setVariable(Prefix + "sdncResponseSuccess", false)
136
137                 execution.setVariable(Prefix + "isVnfBindingPresent", false)
138                 execution.setVariable(Prefix + "Success", false)
139                 execution.setVariable(Prefix + "serviceInstanceId", "")
140                 
141                 execution.setVariable(Prefix + "isException", false)
142                 
143         }
144
145         // **************************************************
146         //     Pre or Prepare Request Section
147         // **************************************************
148         /**
149          * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
150          * @param execution
151          */
152         public void preProcessRequest (DelegateExecution execution) {
153
154                 execution.setVariable("prefix",Prefix)
155
156                 msoLogger.trace("Inside preProcessRequest DoUpdateNetworkInstance Request ")
157
158                 try {
159                         // initialize flow variables
160                         InitializeProcessVariables(execution)
161         
162                         // GET Incoming request & validate 3 kinds of format.
163                         execution.setVariable("action", "UPDATE")
164                         String networkRequest = execution.getVariable("bpmnRequest")
165                         if (networkRequest != null) {
166                                 if (networkRequest.contains("requestDetails")) {
167                                         // JSON format request is sent, create xml
168                                         try {
169                                                 def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
170                                                 msoLogger.debug(" Incoming message formatted . . . : " + '\n' + prettyJson)
171                                                 networkRequest =  vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
172                 
173                                         } catch (Exception ex) {
174                                                 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
175                                                 msoLogger.debug(dataErrorMessage)
176                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
177                                         }
178                                 } else {
179                                          // XML format request is sent
180                                    
181                                 }
182                         } else {
183                                 // vIPR format request is sent, create xml from individual variables
184                                 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
185                         }
186                         
187                         networkRequest = utils.formatXml(networkRequest)
188                         msoLogger.debug(networkRequest)
189                         execution.setVariable(Prefix + "networkRequest", networkRequest)
190                         msoLogger.debug(" network-request - " + '\n' + networkRequest)
191                 
192                         // validate 'disableRollback'  (aka, 'suppressRollback')
193                         boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
194                         execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
195                         msoLogger.debug(Prefix + "rollbackEnabled - " + rollbackEnabled)
196                                                                                 
197                         String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
198                         execution.setVariable(Prefix + "networkInputs", networkInputs)
199                         msoLogger.debug(Prefix + "networkInputs - " + '\n' + networkInputs)
200                         
201                         // prepare messageId
202                         String messageId = execution.getVariable(Prefix + "messageId")  // for testing
203                         if (messageId == null || messageId == "") {
204                                 messageId = UUID.randomUUID()
205                                 msoLogger.debug(" UPDNETI_messageId, random generated: " + messageId)
206                         } else {
207                                 msoLogger.debug(" UPDNETI_messageId, pre-assigned: " + messageId)
208                         }
209                         execution.setVariable(Prefix + "messageId", messageId)
210                         
211                         String source = utils.getNodeText(networkRequest, "source")
212                         execution.setVariable(Prefix + "source", source)
213                         msoLogger.debug(Prefix + "source - " + source)
214                         
215                         String networkId = ""
216                         if (utils.nodeExists(networkRequest, "network-id")) {
217                                 networkId = utils.getNodeText(networkRequest, "network-id")
218                                 if (networkId == 'null' || networkId == "") {
219                                         sendSyncError(execution)
220                                         // missing value of networkId
221                                         String dataErrorMessage = "Variable 'network-id' value/element is missing."
222                                         msoLogger.debug(" Invalid Request - " + dataErrorMessage)
223                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
224         
225                                 }
226                         }
227         
228                         String lcpCloudRegion = ""
229                         if (utils.nodeExists(networkRequest, "aic-cloud-region")) {
230                                 lcpCloudRegion = utils.getNodeText(networkRequest, "aic-cloud-region")
231                                 if ((lcpCloudRegion == 'null') || (lcpCloudRegion == "")) {
232                                         sendSyncError(execution)
233                                         String dataErrorMessage = "requestDetails has missing 'aic-cloud-region' value/element."
234                                         msoLogger.debug(" Invalid Request - " + dataErrorMessage)
235                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
236                                 }
237                         }
238         
239                         String serviceInstanceId = ""
240                         if (utils.nodeExists(networkRequest, "service-instance-id")) {
241                                 serviceInstanceId = utils.getNodeText(networkRequest, "service-instance-id")
242                                 if ((serviceInstanceId == 'null') || (lcpCloudRegion == "")) {
243                                         sendSyncError(execution)
244                                         String dataErrorMessage = "Variable 'serviceInstanceId' value/element is missing."
245                                         msoLogger.debug(" Invalid Request - " + dataErrorMessage)
246                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
247                                 }
248                         }
249                         
250                         // PO Authorization Info / headers Authorization=
251                         String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution)
252                         
253
254                         try {
255                                 def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey", execution))
256                                 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
257                                 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
258         
259                         } catch (IOException ex) {
260                                 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - "
261                                 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
262                                 msoLogger.debug(dataErrorMessage)
263                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
264                         }
265                         
266                         // Set variables for Generic Get Sub Flow use
267                         execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
268                         msoLogger.debug(Prefix + "serviceInstanceId - " + serviceInstanceId)
269         
270                         execution.setVariable("GENGS_type", "service-instance")
271                         msoLogger.debug("GENGS_type - " + "service-instance")
272                         msoLogger.debug(" Url for SDNC adapter: " + UrnPropertiesReader.getVariable("mso.adapters.sdnc.endpoint",execution))
273                         
274                         String sdncVersion = execution.getVariable("sdncVersion")
275                         msoLogger.debug("sdncVersion? : " + sdncVersion)
276                         
277                         // build 'networkOutputs'                       
278                         networkId = utils.getNodeText(networkRequest, "network-id")
279                         if ((networkId == null) || (networkId == "null")) {
280                                 networkId = ""
281                         }
282                         String networkName = utils.getNodeText(networkRequest, "network-name")
283                         if ((networkName == null) || (networkName == "null")) {
284                                 networkName = ""
285                         }
286                         String networkOutputs =
287                            """<network-outputs>
288                            <network-id>${MsoUtils.xmlEscape(networkId)}</network-id>
289                            <network-name>${MsoUtils.xmlEscape(networkName)}</network-name>
290                          </network-outputs>"""
291                         execution.setVariable(Prefix + "networkOutputs", networkOutputs)
292                         msoLogger.debug(Prefix + "networkOutputs - " + '\n' + networkOutputs)
293                         execution.setVariable(Prefix + "networkId", networkId)
294                         execution.setVariable(Prefix + "networkName", networkName)
295                 
296
297                 } catch (BpmnError e) {
298                         throw e;
299
300                 } catch (Exception ex){
301                         sendSyncError(execution)
302                          // caught exception
303                         String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - " + ex.getMessage()
304                         msoLogger.debug(exceptionMessage)
305                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
306
307                 }
308         }
309
310         public void callRESTQueryAAICloudRegion (DelegateExecution execution) {
311
312                 execution.setVariable("prefix", Prefix)
313
314                 msoLogger.debug(" ***** Inside callRESTQueryAAICloudRegion of DoUpdateNetworkInstance ***** " )
315
316                 try {
317                         String networkInputs  = execution.getVariable(Prefix + "networkInputs")
318                         String cloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
319                         cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
320
321                         // Prepare AA&I url
322                         String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
323                         AaiUtil aaiUtil = new AaiUtil(this)
324                         String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
325                         String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
326                         msoLogger.debug(queryCloudRegionRequest)
327                         execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
328                         msoLogger.debug(" UPDNETI_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest)
329
330                         String cloudRegionPo = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
331                         String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "SDNC", cloudRegion)
332
333                         if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
334                                 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
335                                 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
336                                 execution.setVariable(Prefix + "isCloudRegionGood", true)
337
338                         } else {
339                             String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
340                             msoLogger.debug(dataErrorMessage)
341                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
342
343                         }
344
345                         msoLogger.debug(" is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"))
346
347                 } catch (BpmnError e) {
348                         throw e;
349
350                 } catch (Exception ex) {
351                         // try error
352                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
353                         msoLogger.debug(exceptionMessage)
354                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
355
356                 }
357
358         }
359
360         public void callRESTQueryAAINetworkId(DelegateExecution execution) {
361
362                 execution.setVariable("prefix", Prefix)
363
364                 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
365
366                 try {
367                         // get variables
368                         String networkRequest = execution.getVariable(Prefix + "networkRequest")
369                         String networkId   = utils.getNodeText(networkRequest, "network-id")
370                         networkId = UriUtils.encode(networkId,"UTF-8")
371                         execution.setVariable(Prefix + "networkId", networkId)
372
373                         // Prepare AA&I url
374                         String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
375                         AaiUtil aaiUriUtil = new AaiUtil(this)
376                         String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
377                         String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
378                         msoLogger.debug(queryIdAAIRequest)
379                         execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
380                         msoLogger.debug(Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest)
381
382                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
383                         String returnCode = response.getStatusCode()
384                         execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
385                         msoLogger.debug(" ***** AAI Response Code  : " + returnCode)
386                         
387                         String aaiResponseAsString = response.getResponseBodyAsString()
388
389                         if (returnCode=='200') {
390                                 msoLogger.debug(aaiResponseAsString)
391                                 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
392                                 msoLogger.debug(" QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
393
394                         } else {
395                                 if (returnCode=='404') {
396                                         String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
397                                         msoLogger.debug(" AAI Query Failed. " + dataErrorMessage)
398                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
399
400                                 } else {
401                                    if (aaiResponseAsString.contains("RESTFault")) {
402                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
403                                            execution.setVariable("WorkflowException", exceptionObject)
404                                            throw new BpmnError("MSOWorkflowException")
405
406                                    } else {
407                                                         // aai all errors
408                                                         String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
409                                                         msoLogger.debug("Unexpected Response from QueryAAINetworkId - " + dataErrorMessage)
410                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
411
412                                   }
413                                 }
414                         }
415
416                 } catch (BpmnError e) {
417                         throw e;
418
419                 } catch (Exception ex) {
420                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
421                         msoLogger.debug(exceptionMessage)
422                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
423
424                 }
425
426         }
427
428         public void callRESTReQueryAAINetworkId(DelegateExecution execution) {
429
430                 execution.setVariable("prefix", Prefix)
431
432                 msoLogger.debug(" ***** Inside callRESTReQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
433
434                 try {
435                         // get variables
436                         String networkRequest = execution.getVariable(Prefix + "networkRequest")
437                         String networkId   = utils.getNodeText(networkRequest, "network-id")
438                         networkId = UriUtils.encode(networkId,"UTF-8")
439
440                         // Prepare AA&I url
441                         String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
442                         AaiUtil aaiUriUtil = new AaiUtil(this)
443                         String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
444                         String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
445                         msoLogger.debug(requeryIdAAIRequest)
446                         execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
447                         msoLogger.debug(" UPDNETI_requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest)
448
449                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
450                         String returnCode = response.getStatusCode()
451                         execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
452                         msoLogger.debug(" ***** AAI ReQuery Response Code  : " + returnCode)
453
454                         String aaiResponseAsString = response.getResponseBodyAsString()
455
456                         if (returnCode=='200') {
457                                 msoLogger.debug(aaiResponseAsString)
458                                 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
459                                 msoLogger.debug(" ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString)
460
461                                 String netId = utils.getNodeText(aaiResponseAsString, "network-id")
462                                 String netName = utils.getNodeText(aaiResponseAsString, "network-name")
463                                 String networkOutputs =
464                                    """<network-outputs>
465                    <network-id>${MsoUtils.xmlEscape(netId)}</network-id>                        
466                    <network-name>${MsoUtils.xmlEscape(netName)}</network-name>
467                  </network-outputs>"""
468                                 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
469                                 msoLogger.debug(" networkOutputs - " + '\n' + networkOutputs)
470                                 
471                         } else {
472                                 if (returnCode=='404') {
473                                         String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
474                                         msoLogger.debug(" AAI ReQuery Failed. - " + dataErrorMessage)
475                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
476
477                                 } else {
478                                    if (aaiResponseAsString.contains("RESTFault")) {
479                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
480                                            execution.setVariable("WorkflowException", exceptionObject)
481                                            throw new BpmnError("MSOWorkflowException")
482
483                                            } else {
484                                                         // aai all errors
485                                                         String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
486                                                         msoLogger.debug(dataErrorMessage)
487                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
488
489                                         }
490                                 }
491                         }
492
493                 } catch (BpmnError e) {
494                         throw e;
495
496                 } catch (Exception ex) {
497                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
498                         msoLogger.debug(exceptionMessage)
499                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
500
501                 }
502
503         }
504
505         public void callRESTQueryAAINetworkVpnBinding(DelegateExecution execution) {
506
507                 execution.setVariable("prefix", Prefix)
508
509                 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkVpnBinding of DoUpdateNetworkInstance ***** " )
510
511                 try {
512
513                         // get variables
514                         String queryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
515                         String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
516                         msoLogger.debug(" relationship - " + relationship)
517
518                         // Check if Vnf Binding is present, then build a List of vnfBinding
519                         List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
520                         int vpnCount = vpnBindingUri.size()
521                         execution.setVariable(Prefix + "vpnCount", vpnCount)
522                         msoLogger.debug(" UPDNETI_vpnCount - " + vpnCount)
523
524                         String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
525                         AaiUtil aaiUriUtil = new AaiUtil(this)
526
527                         if (vpnCount > 0) {
528                                 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
529                                 msoLogger.debug(" vpnBindingUri List - " + vpnBindingUri)
530
531                                 String routeTargets = ""
532                                 // AII loop call using list vpnBindings
533                                 for (i in 0..vpnBindingUri.size()-1) {
534
535                                         int counting = i+1
536
537                                         // prepare url using vpnBinding
538                                         String queryVpnBindingAAIRequest = ""
539                                         String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
540
541                                         // Note: By default, the vpnBinding url is found in 'related-link' of the response,
542                                         //       so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
543                                         if (aai_uri == null || aai_uri == "") {
544                                                 // using value of 'related-link' from response
545                                                 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
546                                                     queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1) + "?depth=all"
547                                                 } else {
548                                                     queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i] + "?depth=all"
549                                                 }
550
551                                         } else {
552                                             // using uri value in URN mapping
553                                                 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
554                                                 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
555                                                         vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
556                                                 }
557                                             queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId + "?depth=all"
558                                         }
559
560                                         msoLogger.debug(queryVpnBindingAAIRequest)
561                                         execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
562                                         msoLogger.debug(" UPDNETI_queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest)
563
564                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
565                                         String returnCode = response.getStatusCode()
566                                         execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
567                                         msoLogger.debug(" ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode)
568
569                                         String aaiResponseAsString = response.getResponseBodyAsString()
570
571                                         if (returnCode=='200') {
572                                                 msoLogger.debug(aaiResponseAsString)
573                                                 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
574                                                 msoLogger.debug(" AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString)
575
576                                                 String routeTarget = ""
577                                                 String routeRole = ""
578                                                 if (utils.nodeExists(aaiResponseAsString, "route-targets")) {
579                                                         String aaiRouteTargets = utils.getNodeXml(aaiResponseAsString, "route-targets", false)
580                                                         def aaiRouteTargetsXml = new XmlSlurper().parseText(aaiRouteTargets)
581                                                         def aaiRouteTarget = aaiRouteTargetsXml.'**'.findAll {it.name() == "route-target"}
582                                                         for (j in 0..aaiRouteTarget.size()-1) {
583                                                                 routeTarget  = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "global-route-target")
584                                                                 routeRole  = utils.getNodeText(XmlUtil.serialize(aaiRouteTarget[j]), "route-target-role")
585                                                                 routeTargets += "<routeTargets>" + '\n' +
586                                                                                 " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
587                                                                                                 " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
588                                                                                                 "</routeTargets>" + '\n'
589                                                         }
590                                                 }
591
592                                         } else {
593                                                 if (returnCode=='404') {
594                                                         String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
595                                                         msoLogger.debug(dataErrorMessage)
596                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
597
598                                                 } else {
599                                                    if (aaiResponseAsString.contains("RESTFault")) {
600                                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
601                                                            execution.setVariable("WorkflowException", exceptionObject)
602                                                            throw new BpmnError("MSOWorkflowException")
603
604                                                            } else {
605                                                                         // aai all errors
606                                                                         String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
607                                                                         msoLogger.debug(dataErrorMessage)
608                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
609
610                                                           }
611                                                 }
612                                         }
613
614                                 } // end loop
615
616                                 execution.setVariable(Prefix + "routeCollection", routeTargets)
617                                 msoLogger.debug(" UPDNETI_routeCollection - " + '\n' + routeTargets)
618
619                         } else {
620                                 // reset return code to success
621                                 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
622                                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
623                                 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
624                             String aaiStubResponse =
625                                         """     <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
626                                                         <vpn-binding xmlns="${schemaVersion}">
627                                                       <global-route-target/>
628                                                         </vpn-binding>
629                                                 </rest:payload>"""
630                                 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
631                                 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
632                                 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
633                                 msoLogger.debug(" No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml)
634
635                         }
636
637                 } catch (BpmnError e) {
638                         throw e;
639
640                 } catch (Exception ex) {
641                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
642                         msoLogger.debug(exceptionMessage)
643                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
644
645                 }
646
647         }
648
649         public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
650
651                 execution.setVariable("prefix", Prefix)
652
653                 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " )
654
655                 try {
656                         // get variables
657                         String queryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
658                         String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
659                         msoLogger.debug(" relationship - " + relationship)
660
661                         // Check if Network Policy is present, then build a List of network policy
662                         List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
663                         int networkPolicyCount = networkPolicyUriList.size()
664                         execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
665                         msoLogger.debug(" UPDNETI_networkPolicyCount - " + networkPolicyCount)
666
667                         String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
668                         AaiUtil aaiUriUtil = new AaiUtil(this)
669
670                         if (networkPolicyCount > 0) {
671                                 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
672                                 msoLogger.debug(" networkPolicyUri List - " + networkPolicyUriList)
673
674                                 String networkPolicies = ""
675                                 // AII loop call using list vpnBindings
676                                 for (i in 0..networkPolicyUriList.size()-1) {
677
678                                         int counting = i+1
679
680                                         // prepare url using vpnBinding
681                                         String queryNetworkPolicyAAIRequest = ""
682
683                                         String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
684
685                                         // Note: By default, the network policy url is found in 'related-link' of the response,
686                                         //       so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
687                                         if (aai_uri == null || aai_uri == "") {
688                                                 // using value of 'related-link' from response
689                                                 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
690                                                         queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1) + "?depth=all"
691                                                 } else {
692                                                         queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i] + "?depth=all"
693                                                 }
694                                         } else {
695                                                 // using uri value in URN mapping
696                                                 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
697                                                 println " networkPolicyId - " + networkPolicyId
698                                                 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
699                                                         networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
700                                                 }
701                                                 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId + "?depth=all"
702
703                                         }
704
705
706                                         msoLogger.debug(queryNetworkPolicyAAIRequest)
707                                         execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
708                                         msoLogger.debug(" UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest)
709
710                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
711                                         String returnCode = response.getStatusCode()
712                                         execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
713                                         msoLogger.debug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode)
714
715                                         String aaiResponseAsString = response.getResponseBodyAsString()
716
717                                         if (returnCode=='200') {
718                                                 msoLogger.debug(aaiResponseAsString)
719                                                 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
720                                                 msoLogger.debug(" QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString)
721
722                                                 String networkPolicy = ""
723                                                 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
724                                                         networkPolicy  = utils.getNodeText(aaiResponseAsString, "network-policy-fqdn")
725                                                         networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
726                                                 }
727
728                                         } else {
729                                                 if (returnCode=='404') {
730                                                         String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
731                                                         msoLogger.debug(dataErrorMessage)
732                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
733
734                                                 } else {
735                                                    if (aaiResponseAsString.contains("RESTFault")) {
736                                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
737                                                            execution.setVariable("WorkflowException", exceptionObject)
738                                                            throw new BpmnError("MSOWorkflowException")
739
740                                                            } else {
741                                                                         // aai all errors
742                                                                         String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
743                                                                         msoLogger.debug(dataErrorMessage)
744                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
745
746                                                           }
747                                                 }
748                                         }
749
750                                 } // end loop
751
752                                 execution.setVariable(Prefix + "networkCollection", networkPolicies)
753                                 msoLogger.debug(" UPDNETI_networkCollection - " + '\n' + networkPolicies)
754
755                         } else {
756                                 // reset return code to success
757                                 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
758                                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
759                                 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
760                                 String aaiStubResponse =
761                                         """     <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
762                                                         <network-policy xmlns="${schemaVersion}">
763                                                           <network-policy-fqdn/>
764                             </network-policy>
765                                                 </rest:payload>"""
766                                 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
767                                 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
768                                 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
769                                 msoLogger.debug(" No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml)
770
771                         }
772
773                 } catch (BpmnError e) {
774                         throw e;
775
776                 } catch (Exception ex) {
777                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
778                         msoLogger.debug(exceptionMessage)
779                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
780
781                 }
782
783         }
784
785         public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
786
787                 execution.setVariable("prefix", Prefix)
788
789                 msoLogger.debug(" ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " )
790
791                 try {
792                         // get variables
793                         String queryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
794                         String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
795                         msoLogger.debug(" relationship - " + relationship)
796
797                         // Check if Network TableREf is present, then build a List of network policy
798                         List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
799                         int networkTableRefCount = networkTableRefUriList.size()
800                         execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
801                         msoLogger.debug(" UPDNETI_networkTableRefCount - " + networkTableRefCount)
802
803                         String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
804                         AaiUtil aaiUriUtil = new AaiUtil(this)
805
806                         if (networkTableRefCount > 0) {
807                                 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
808                                 msoLogger.debug(" networkTableRefUri List - " + networkTableRefUriList)
809
810                                 // AII loop call using list vpnBindings
811                                 String networkTableRefs = ""
812                                 for (i in 0..networkTableRefUriList.size()-1) {
813
814                                         int counting = i+1
815
816                                         // prepare url using tableRef
817                                         String queryNetworkTableRefAAIRequest = ""
818
819                                         String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
820
821                                         // Note: By default, the network policy url is found in 'related-link' of the response,
822                                         //       so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
823                                         if (aai_uri == null || aai_uri == "") {
824                                                 // using value of 'related-link' from response
825                                                 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
826                                                         queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1) + "?depth=all"
827                                                 } else {
828                                                         queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i] + "?depth=all"
829                                                 }
830                                         } else {
831                                                 // using uri value in URN mapping
832                                                 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
833
834                                                 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
835                                                         networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
836                                                 }
837                                                 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId + "?depth=all"
838
839                                         }
840
841
842                                         msoLogger.debug(queryNetworkTableRefAAIRequest)
843                                         execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
844                                         msoLogger.debug(" UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest)
845
846                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
847                                         String returnCode = response.getStatusCode()
848                                         execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
849                                         msoLogger.debug(" ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode)
850
851                                         String aaiResponseAsString = response.getResponseBodyAsString()
852
853                                         if (returnCode=='200') {
854                                                 msoLogger.debug(aaiResponseAsString)
855                                                 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
856                                                 msoLogger.debug(" QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString)
857
858                                                 String networkTableRef = ""
859                                                 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
860                                                         networkTableRef  = utils.getNodeText(aaiResponseAsString, "route-table-reference-fqdn")
861                                                         networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
862                                                 }
863
864                                         } else {
865                                                 if (returnCode=='404') {
866                                                         String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
867                                                         msoLogger.debug(dataErrorMessage)
868                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
869                                                         
870                                                 } else {
871                                                    if (aaiResponseAsString.contains("RESTFault")) {
872                                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
873                                                            execution.setVariable("WorkflowException", exceptionObject)
874                                                            throw new BpmnError("MSOWorkflowException")
875                 
876                                                            } else {
877                                                                         // aai all errors
878                                                                         String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
879                                                                         msoLogger.debug(dataErrorMessage)
880                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
881
882                                                           }
883                                                 }
884                                         }
885
886                                 } // end loop
887
888                                 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
889                                 msoLogger.debug(" UPDNETI_tableRefCollection - " + '\n' + networkTableRefs)
890
891                         } else {
892                                 // reset return code to success
893                                 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
894                                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
895                                 String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
896                                 String aaiStubResponse =
897                                         """     <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
898                                                         <route-table-references xmlns="${schemaVersion}">
899                                                           <route-table-reference-fqdn/>
900                             </route-table-references>
901                                                 </rest:payload>"""
902                                 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
903                                 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
904                                 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
905                                 msoLogger.debug(" No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml)
906
907                         }
908
909                 } catch (BpmnError e) {
910                         throw e;
911                         
912                 } catch (Exception ex) {
913                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
914                         msoLogger.debug(exceptionMessage)
915                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
916
917                 }
918
919         }
920         
921         public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
922
923                 execution.setVariable("prefix", Prefix)
924
925                 msoLogger.debug(" ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " )
926
927                 try {
928                         // get variables
929                         String networkRequest = execution.getVariable(Prefix + "networkRequest")
930                         String networkId   = utils.getNodeText(networkRequest, "network-id")
931                         networkId = UriUtils.encode(networkId,"UTF-8")
932                         String requeryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse")
933                         String updateNetworkResponse   = execution.getVariable(Prefix + "updateNetworkResponse")
934
935                         // Prepare url
936                         String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
937                         AaiUtil aaiUriUtil = new AaiUtil(this)
938                         String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
939                         String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=all"
940
941                         msoLogger.debug(updateContrailAAIUrlRequest)
942                         execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
943                         msoLogger.debug(" UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest)
944
945                         //Prepare payload (PUT)
946                         String schemaVersion = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
947                         String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
948                         String payloadXml = utils.formatXml(payload)
949                         msoLogger.debug(payloadXml)
950                         execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
951                         msoLogger.debug(" 'payload' to Update Contrail - " + "\n" + payloadXml)
952
953                         APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
954                         String returnCode = response.getStatusCode()
955                         String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
956                         
957                         execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
958                         msoLogger.debug(" ***** AAI Update Contrail Response Code  : " + returnCode)
959
960
961                         if (returnCode=='200') {
962                                 msoLogger.debug(aaiUpdateContrailResponseAsString)
963                                 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
964                                 msoLogger.debug(" AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString)
965                                 // Point-of-no-return is set to false, rollback not needed.
966                                 execution.setVariable(Prefix + "isPONR", true)
967
968                         } else {
969                                 if (returnCode=='404') {
970                                         String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
971                                         msoLogger.debug(dataErrorMessage)
972                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
973
974                                 } else {
975                                    if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
976                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
977                                            execution.setVariable("WorkflowException", exceptionObject)
978                                            throw new BpmnError("MSOWorkflowException")
979
980                                            } else {
981                                                         // aai all errors
982                                                         String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
983                                                         msoLogger.debug(errorMessage)
984                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
985                                           }
986                                 }
987                         }
988
989                 } catch (BpmnError e) {
990                         throw e;
991
992                 } catch (Exception ex) {
993                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
994                         msoLogger.debug(exceptionMessage)
995                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
996
997                 }
998
999         }
1000
1001         public void prepareUpdateNetworkRequest (DelegateExecution execution) {
1002
1003                 execution.setVariable("prefix", Prefix)
1004
1005                 msoLogger.trace("Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ")
1006
1007                 try {
1008
1009                         // get variables
1010                         String requestId = execution.getVariable(Prefix + "requestId")
1011                         String messageId = execution.getVariable(Prefix + "messageId")
1012                         String source    = execution.getVariable(Prefix + "source")
1013
1014                         String requestInput = execution.getVariable(Prefix + "networkRequest")
1015                         String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1016                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1017                         String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1018                         
1019                         // Prepare Network request
1020                         String routeCollection = execution.getVariable(Prefix + "routeCollection")
1021                         String policyCollection = execution.getVariable(Prefix + "networkCollection")
1022                         String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1023                         String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1024                         // Format Response
1025                         String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
1026                         buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1027                         msoLogger.debug(buildUpdateNetworkRequestAsString)
1028
1029                         execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
1030                         msoLogger.debug(" UPDNETI_updateNetworkRequest - " + "\n" +  buildUpdateNetworkRequestAsString)
1031
1032                 } catch (Exception ex) {
1033                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
1034                         msoLogger.debug(exceptionMessage)
1035                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1036
1037                 }
1038
1039         }
1040
1041         public void prepareSDNCRequest (DelegateExecution execution) {
1042
1043                 execution.setVariable("prefix", Prefix)
1044
1045                 msoLogger.trace("Inside prepareSDNCRequest of DoUpdateNetworkInstance ")
1046
1047                 try {
1048                         // get variables
1049                         String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1050                         String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1051                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1052
1053                         String networkId = ""
1054                         if (utils.nodeExists(updateNetworkInput, "network-id")) {
1055                            networkId = utils.getNodeText(updateNetworkInput, "network-id")
1056                         }
1057                         if (networkId == null) {networkId = ""}
1058
1059                         String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1060                         
1061                         String queryAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse")
1062
1063                         // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1064                         String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, queryAAIResponse, null)
1065
1066                         String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1067                         msoLogger.debug(sndcTopologyUpdateRequesAsString)
1068                         execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1069                         msoLogger.debug(" UPDNETI_changeAssignSDNCRequest - " + "\n" +  sndcTopologyUpdateRequesAsString)
1070
1071
1072                 } catch (Exception ex) {
1073                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1074                         msoLogger.debug(exceptionMessage)
1075                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1076
1077                 }
1078
1079         }
1080
1081         
1082
1083
1084         // **************************************************
1085         //     Post or Validate Response Section
1086         // **************************************************
1087
1088         public void validateUpdateNetworkResponse (DelegateExecution execution) {
1089
1090                 execution.setVariable("prefix", Prefix)
1091
1092                 msoLogger.trace("Inside validateUpdateNetworkResponse of DoUpdateNetworkInstance ")
1093
1094                 try {
1095                         String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1096                         String networkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
1097                         if (networkResponse==null)      {
1098                                 networkResponse="" // reset
1099                         }
1100
1101                         msoLogger.debug(" Network Adapter update responseCode: " + returnCode)
1102
1103                         String errorMessage = ""
1104                         if (returnCode == "200") {
1105                                 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1106                                 msoLogger.debug(networkResponse)
1107                                 execution.setVariable(Prefix + "updateNetworkResponse", networkResponse)
1108                                 msoLogger.debug(" Network Adapter update Success Response - " + "\n" + networkResponse)
1109
1110                                 // prepare rollback data
1111                                 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1112                                 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1113                                 String rollbackNetwork =
1114                                         """<rollbackNetworkRequest>
1115                                                         ${rollbackData}
1116                                                 </rollbackNetworkRequest>"""
1117                                 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1118                                 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1119                                 msoLogger.debug(" Network Adapter rollback data - " + "\n" + rollbackNetworkXml)
1120
1121                         } else { // network error
1122                            if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) {   //4xx, 5xx
1123                                    if (networkResponse.contains("updateNetworkError")) {
1124                                            networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1125                                            errorMessage = utils.getNodeText(networkResponse, "message")
1126                                            errorMessage  = "Received error from Network Adapter: " + errorMessage
1127                                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1128
1129                                    } else { // CatchAll exception
1130                                            if (returnCode == "500") {
1131                                                    errorMessage = "JBWEB000065: HTTP Status 500."
1132                                        } else {
1133                                                errorMessage = "Return code is " + returnCode
1134                                        }
1135                                            errorMessage  = "Received error from Network Adapter: " + errorMessage
1136                                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1137
1138                                    }
1139
1140                            } else { // CatchAll exception
1141                                    String dataErrorMessage  = "Received error from Network Adapter. Return code is: " + returnCode
1142                                    exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1143
1144                            }
1145
1146                         }
1147
1148                 } catch (BpmnError e) {
1149                         throw e;
1150
1151                 } catch (Exception ex) {
1152                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1153                         msoLogger.debug(exceptionMessage)
1154                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1155
1156                 }
1157
1158
1159         }
1160
1161         public void validateSDNCResponse (DelegateExecution execution) {
1162
1163                 execution.setVariable("prefix", Prefix)
1164
1165                 msoLogger.trace("Inside validateSDNCResponse of DoUpdateNetworkInstance ")
1166
1167                 String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1168                 WorkflowException workflowException = null
1169                 try {
1170                         workflowException = execution.getVariable(Prefix + "WorkflowException")
1171                         //execution.setVariable("WorkflowException", workflowException)
1172                 } catch (Exception ex) {
1173                         msoLogger.debug(" Sdnc 'WorkflowException' object is empty or null. ")
1174                 }
1175
1176                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1177
1178                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1179                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1180                 // reset variable
1181                 String changeAssignSDNCResponseDecodeXml = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1182                 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1183                 execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1184
1185                 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) {  // from sdnc util, prefix+'sdncResponseSuccess'
1186                         execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1187                         msoLogger.debug("Successfully Validated SDNC Response")
1188
1189                 } else {
1190                         msoLogger.debug("Did NOT Successfully Validated SDNC Response")
1191                         throw new BpmnError("MSOWorkflowException")
1192                 }
1193
1194         }
1195
1196
1197         public void postProcessResponse (DelegateExecution execution) {
1198
1199                 execution.setVariable("prefix", Prefix)
1200
1201                 msoLogger.trace("Inside postProcessResponse of DoUpdateNetworkInstance ")
1202
1203                 try {
1204                         msoLogger.debug(" ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"))
1205                         if (execution.getVariable(Prefix + "isException") == false) {
1206                                 // set rollback data
1207                                 execution.setVariable("orchestrationStatus", "")
1208                                 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1209                                 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1210                                 prepareSuccessRollbackData(execution) // populate rollbackData
1211                                 execution.setVariable("WorkflowException", null)
1212                                 execution.setVariable(Prefix + "Success", true)
1213                                 msoLogger.debug(" ***** postProcessResponse(), GOOD !!!")
1214                         } else {
1215                                 execution.setVariable(Prefix + "Success", false) 
1216                                 execution.setVariable("rollbackData", null)
1217                                 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1218                                 if (execution.getVariable("workflowException") != null) {  // Output of Rollback flow.
1219                                    msoLogger.debug(" ***** workflowException: " + execution.getVariable("workflowException"))
1220                                    WorkflowException wfex = execution.getVariable("workflowException")
1221                                    exceptionMessage = wfex.getErrorMessage()
1222                                 } else {
1223                                if (execution.getVariable(Prefix + "WorkflowException") != null) {
1224                                       WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1225                                       exceptionMessage = pwfex.getErrorMessage()
1226                                }   
1227                                 }
1228                             // going to the Main flow: a-la-carte or macro
1229                             msoLogger.debug(" ***** postProcessResponse(), BAD !!!")
1230                             exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1231                                 throw new BpmnError("MSOWorkflowException")
1232                         }
1233                                                         
1234                 } catch(BpmnError b){
1235                      msoLogger.debug("Rethrowing MSOWorkflowException")
1236                      throw b
1237                         
1238
1239                 } catch (Exception ex) {
1240                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1241                         msoLogger.debug(exceptionMessage)
1242                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1243
1244         }
1245
1246
1247         }
1248
1249         public void prepareSDNCRollbackRequest (DelegateExecution execution) {
1250
1251                 execution.setVariable("prefix", Prefix)
1252
1253                 msoLogger.trace("Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ")
1254
1255                 try {
1256                         // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException. 
1257                         execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1258                         // get variables
1259                         String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
1260                         String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1261                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1262                         String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1263                         String networkId = utils.getNodeText(changeAssignSDNCResponse, "network-id")
1264
1265                         String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
1266
1267                         // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1268                         String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1269                         String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1270                         execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1271                         msoLogger.debug(" Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" +  sndcTopologyRollbackRequestAsString)
1272
1273                 } catch (Exception ex) {
1274                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1275                         msoLogger.debug(exceptionMessage)
1276                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1277
1278                 }
1279
1280         }
1281
1282         public void prepareRollbackData(DelegateExecution execution) {
1283
1284                 execution.setVariable("prefix",Prefix)
1285                 
1286                 msoLogger.trace("Inside prepareRollbackData() of DoUpdateNetworkInstance ")
1287                 
1288                 try {
1289                         
1290                         Map<String, String> rollbackData = new HashMap<String, String>();
1291                         String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1292                         if (rollbackSDNCRequest != null) {
1293                                 if (rollbackSDNCRequest != "") {
1294                                         rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1295                                 }
1296                         }
1297                         String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1298                         if (rollbackNetworkRequest != null) {
1299                                 if (rollbackNetworkRequest != "") {
1300                                         rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1301                                 }
1302                         }
1303                         execution.setVariable("rollbackData", rollbackData)
1304                         msoLogger.debug("** rollbackData : " + rollbackData)
1305                         
1306                         execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1307                         msoLogger.debug("** WorkflowException : " + execution.getVariable("WorkflowException"))
1308                         
1309                 } catch (Exception ex) {
1310                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1311                         msoLogger.debug(exceptionMessage)
1312                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1313                 
1314                 }
1315                 
1316         }
1317         
1318         public void prepareSuccessRollbackData(DelegateExecution execution) {
1319
1320                 execution.setVariable("prefix",Prefix)
1321                 
1322                 msoLogger.trace("Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ")
1323                 
1324                 try {
1325                         
1326                         if (execution.getVariable("sdncVersion") != '1610') {
1327                                 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1328                         } else {
1329                                 prepareSDNCRollbackRequest(execution)
1330                         }
1331                         
1332                         Map<String, String> rollbackData = new HashMap<String, String>();
1333                         String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1334                         if (rollbackSDNCRequest != null) {
1335                                 if (rollbackSDNCRequest != "") {
1336                                         rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1337                                 }
1338                         }
1339                         String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1340                         if (rollbackNetworkRequest != null) {
1341                                 if (rollbackNetworkRequest != "") {
1342                                         rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1343                                 }
1344                         }
1345                         execution.setVariable("rollbackData", rollbackData)
1346                         
1347                         msoLogger.debug("** 'rollbackData' for Full Rollback : " + rollbackData)
1348                         execution.setVariable("WorkflowException", null)
1349
1350                         
1351                 } catch (Exception ex) {
1352                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1353                         msoLogger.debug(exceptionMessage)
1354                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1355                 
1356                 }
1357                 
1358         }
1359         
1360         public void setExceptionFlag(DelegateExecution execution){
1361
1362                 execution.setVariable("prefix",Prefix)
1363                 
1364                 msoLogger.trace("Inside setExceptionFlag() of DoUpdateNetworkInstance ")
1365                 
1366                 try {
1367                         
1368                         execution.setVariable(Prefix + "isException", true)
1369                         
1370                         if (execution.getVariable("SavedWorkflowException1") != null) {
1371                                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1372                         } else {
1373                                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1374                         }
1375                         msoLogger.debug(Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"))
1376                         
1377                 } catch(Exception ex){
1378                           String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1379                         msoLogger.debug(exceptionMessage)
1380                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1381                 }
1382                 
1383         }
1384
1385
1386         // *******************************
1387         //     Build Error Section
1388         // *******************************
1389
1390         public void processJavaException(DelegateExecution execution){
1391
1392                 execution.setVariable("prefix",Prefix)
1393                 try{
1394                         msoLogger.debug("Caught a Java Exception")
1395                         msoLogger.debug("Started processJavaException Method")
1396                         msoLogger.debug("Variables List: " + execution.getVariables())
1397                         execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - "  + Prefix)  // Adding this line temporarily until this flows error handling gets updated
1398                         exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1399                         
1400                 }catch(Exception e){
1401                         msoLogger.debug("Caught Exception during processJavaException Method: " + e)
1402                         execution.setVariable("UnexpectedError", "Exception in processJavaException method")  // Adding this line temporarily until this flows error handling gets updated
1403                         exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1404                 }
1405                 msoLogger.debug("Completed processJavaException Method")
1406         }
1407
1408 }