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