Merge "Update .gitreview with onap URL"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoUpdateNetworkInstance.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
21
22 import groovy.xml.XmlUtil
23 import groovy.json.*
24 import org.openecomp.mso.bpmn.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.runtime.Execution
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(Execution 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 (Execution 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 (Execution 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(Execution 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                         String messageId = execution.getVariable(Prefix + "messageId")
369
370                         // Prepare AA&I url
371                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
372                         AaiUtil aaiUriUtil = new AaiUtil(this)
373                         String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
374                         String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
375                         utils.logAudit(queryIdAAIRequest)
376                         execution.setVariable(Prefix + "queryIdAAIRequest", queryIdAAIRequest)
377                         utils.log("DEBUG", Prefix + "queryIdAAIRequest - " + "\n" + queryIdAAIRequest, isDebugEnabled)
378
379                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
380                         String returnCode = response.getStatusCode()
381                         execution.setVariable(Prefix + "aaiIdReturnCode", returnCode)
382                         utils.log("DEBUG", " ***** AAI Response Code  : " + returnCode, isDebugEnabled)
383                         
384                         String aaiResponseAsString = response.getResponseBodyAsString()
385
386                         if (returnCode=='200') {
387                                 utils.logAudit(aaiResponseAsString)
388                                 execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString)
389                                 utils.log("DEBUG", " QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
390
391                         } else {
392                                 if (returnCode=='404') {
393                                         String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
394                                         utils.log("DEBUG", " AAI Query Failed. " + dataErrorMessage, isDebugEnabled)
395                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
396
397                                 } else {
398                                    if (aaiResponseAsString.contains("RESTFault")) {
399                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
400                                            execution.setVariable("WorkflowException", exceptionObject)
401                                            throw new BpmnError("MSOWorkflowException")
402
403                                    } else {
404                                                         // aai all errors
405                                                         String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
406                                                         utils.log("DEBUG", "Unexpected Response from QueryAAINetworkId - " + dataErrorMessage, isDebugEnabled)
407                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
408
409                                   }
410                                 }
411                         }
412
413                 } catch (BpmnError e) {
414                         throw e;
415
416                 } catch (Exception ex) {
417                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
418                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
419                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
420
421                 }
422
423         }
424
425         public void callRESTReQueryAAINetworkId(Execution execution) {
426                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
427                 execution.setVariable("prefix", Prefix)
428
429                 utils.log("DEBUG", " ***** Inside callRESTReQueryAAINetworkId of DoUpdateNetworkInstance ***** " , isDebugEnabled)
430
431                 try {
432                         // get variables
433                         String networkRequest = execution.getVariable(Prefix + "networkRequest")
434                         String networkId   = utils.getNodeText1(networkRequest, "network-id")
435                         networkId = UriUtils.encode(networkId,"UTF-8")
436                         String messageId = execution.getVariable(Prefix + "messageId")
437
438                         // Prepare AA&I url
439                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
440                         AaiUtil aaiUriUtil = new AaiUtil(this)
441                         String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
442                         String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
443                         utils.logAudit(requeryIdAAIRequest)
444                         execution.setVariable(Prefix + "requeryIdAAIRequest", requeryIdAAIRequest)
445                         utils.log("DEBUG", " UPDNETI_requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest, isDebugEnabled)
446
447                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
448                         String returnCode = response.getStatusCode()
449                         execution.setVariable(Prefix + "aaiRequeryIdReturnCode", returnCode)
450                         utils.log("DEBUG", " ***** AAI ReQuery Response Code  : " + returnCode, isDebugEnabled)
451
452                         String aaiResponseAsString = response.getResponseBodyAsString()
453
454                         if (returnCode=='200') {
455                                 utils.logAudit(aaiResponseAsString)
456                                 execution.setVariable(Prefix + "requeryIdAAIResponse", aaiResponseAsString)
457                                 utils.log("DEBUG", " ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
458
459                                 String netId = utils.getNodeText1(aaiResponseAsString, "network-id")
460                                 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
461                                 String networkOutputs =
462                                    """<network-outputs>
463                    <network-id>${netId}</network-id>                    
464                    <network-name>${netName}</network-name>
465                  </network-outputs>"""
466                                 execution.setVariable(Prefix + "networkOutputs", networkOutputs)
467                                 utils.log("DEBUG", " networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
468                                 
469                         } else {
470                                 if (returnCode=='404') {
471                                         String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
472                                         utils.log("DEBUG", " AAI ReQuery Failed. - " + dataErrorMessage, isDebugEnabled)
473                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
474
475                                 } else {
476                                    if (aaiResponseAsString.contains("RESTFault")) {
477                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
478                                            execution.setVariable("WorkflowException", exceptionObject)
479                                            throw new BpmnError("MSOWorkflowException")
480
481                                            } else {
482                                                         // aai all errors
483                                                         String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
484                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
485                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
486
487                                         }
488                                 }
489                         }
490
491                 } catch (BpmnError e) {
492                         throw e;
493
494                 } catch (Exception ex) {
495                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
496                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
497                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
498
499                 }
500
501         }
502
503         public void callRESTQueryAAINetworkVpnBinding(Execution execution) {
504                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
505                 execution.setVariable("prefix", Prefix)
506
507                 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkVpnBinding of DoUpdateNetworkInstance ***** " , isDebugEnabled)
508
509                 try {
510
511                         // get variables
512                         String messageId = execution.getVariable(Prefix + "messageId")
513                         String queryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
514                         String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
515                         utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
516
517                         // Check if Vnf Binding is present, then build a List of vnfBinding
518                         List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
519                         int vpnCount = vpnBindingUri.size()
520                         execution.setVariable(Prefix + "vpnCount", vpnCount)
521                         utils.log("DEBUG", " UPDNETI_vpnCount - " + vpnCount, isDebugEnabled)
522
523                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
524                         AaiUtil aaiUriUtil = new AaiUtil(this)
525
526                         if (vpnCount > 0) {
527                                 execution.setVariable(Prefix + "vpnBindings", vpnBindingUri)
528                                 utils.log("DEBUG", " vpnBindingUri List - " + vpnBindingUri, isDebugEnabled)
529
530                                 String routeTargets = ""
531                                 // AII loop call using list vpnBindings
532                                 for (i in 0..vpnBindingUri.size()-1) {
533
534                                         int counting = i+1
535
536                                         // prepare url using vpnBinding
537                                         String queryVpnBindingAAIRequest = ""
538                                         String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
539
540                                         // Note: By default, the vpnBinding url is found in 'related-link' of the response,
541                                         //       so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
542                                         if (aai_uri == null || aai_uri == "") {
543                                                 // using value of 'related-link' from response
544                                                 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
545                                                     queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1)
546                                                 } else {
547                                                     queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i]
548                                                 }
549
550                                         } else {
551                                             // using uri value in URN mapping
552                                                 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
553                                                 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
554                                                         vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
555                                                 }
556                                             queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId
557                                         }
558
559                                         utils.logAudit(queryVpnBindingAAIRequest)
560                                         execution.setVariable(Prefix + "queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
561                                         utils.log("DEBUG", " UPDNETI_queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest, isDebugEnabled)
562
563                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
564                                         String returnCode = response.getStatusCode()
565                                         execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", returnCode)
566                                         utils.log("DEBUG", " ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode, isDebugEnabled)
567
568                                         String aaiResponseAsString = response.getResponseBodyAsString()
569
570                                         if (returnCode=='200') {
571                                                 utils.logAudit(aaiResponseAsString)
572                                                 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiResponseAsString)
573                                                 utils.log("DEBUG", " AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
574
575                                                 String routeTarget = ""
576                                                 if (utils.nodeExists(aaiResponseAsString, "global-route-target")) {
577                                                         routeTarget  = utils.getNodeText1(aaiResponseAsString, "global-route-target")
578                                                         routeTargets += "<routeTargets>" + routeTarget + "</routeTargets>" + '\n'
579                                                 }
580
581                                         } else {
582                                                 if (returnCode=='404') {
583                                                         String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
584                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
585                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
586
587                                                 } else {
588                                                    if (aaiResponseAsString.contains("RESTFault")) {
589                                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
590                                                            execution.setVariable("WorkflowException", exceptionObject)
591                                                            throw new BpmnError("MSOWorkflowException")
592
593                                                            } else {
594                                                                         // aai all errors
595                                                                         String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
596                                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
597                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
598
599                                                           }
600                                                 }
601                                         }
602
603                                 } // end loop
604
605                                 execution.setVariable(Prefix + "routeCollection", routeTargets)
606                                 utils.log("DEBUG", " UPDNETI_routeCollection - " + '\n' + routeTargets, isDebugEnabled)
607
608                         } else {
609                                 // reset return code to success
610                                 execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
611                                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
612                                 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
613                             String aaiStubResponse =
614                                         """     <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
615                                                         <vpn-binding xmlns="${schemaVersion}">
616                                                       <global-route-target/>
617                                                         </vpn-binding>
618                                                 </rest:payload>"""
619                                 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
620                                 execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
621                                 execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
622                                 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
623
624                         }
625
626                 } catch (BpmnError e) {
627                         throw e;
628
629                 } catch (Exception ex) {
630                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
631                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
632                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
633
634                 }
635
636         }
637
638         public void callRESTQueryAAINetworkPolicy(Execution execution) {
639                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
640                 execution.setVariable("prefix", Prefix)
641
642                 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " , isDebugEnabled)
643
644                 try {
645                         // get variables
646                         String messageId = execution.getVariable(Prefix + "messageId")
647                         String queryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
648                         String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
649                         utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
650
651                         // Check if Network Policy is present, then build a List of network policy
652                         List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
653                         int networkPolicyCount = networkPolicyUriList.size()
654                         execution.setVariable(Prefix + "networkPolicyCount", networkPolicyCount)
655                         utils.log("DEBUG", " UPDNETI_networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
656
657                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
658                         AaiUtil aaiUriUtil = new AaiUtil(this)
659
660                         if (networkPolicyCount > 0) {
661                                 execution.setVariable(Prefix + "networkPolicyUriList", networkPolicyUriList)
662                                 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
663
664                                 String networkPolicies = ""
665                                 // AII loop call using list vpnBindings
666                                 for (i in 0..networkPolicyUriList.size()-1) {
667
668                                         int counting = i+1
669
670                                         // prepare url using vpnBinding
671                                         String queryNetworkPolicyAAIRequest = ""
672
673                                         String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
674
675                                         // Note: By default, the network policy url is found in 'related-link' of the response,
676                                         //       so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
677                                         if (aai_uri == null || aai_uri == "") {
678                                                 // using value of 'related-link' from response
679                                                 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
680                                                         queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1)
681                                                 } else {
682                                                         queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i]
683                                                 }
684                                         } else {
685                                                 // using uri value in URN mapping
686                                                 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
687                                                 println " networkPolicyId - " + networkPolicyId
688                                                 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
689                                                         networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
690                                                 }
691                                                 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId
692
693                                         }
694
695
696                                         utils.logAudit(queryNetworkPolicyAAIRequest)
697                                         execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
698                                         utils.log("DEBUG", " UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
699
700                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
701                                         String returnCode = response.getStatusCode()
702                                         execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", returnCode)
703                                         utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
704
705                                         String aaiResponseAsString = response.getResponseBodyAsString()
706
707                                         if (returnCode=='200') {
708                                                 utils.logAudit(aaiResponseAsString)
709                                                 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiResponseAsString)
710                                                 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
711
712                                                 String networkPolicy = ""
713                                                 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
714                                                         networkPolicy  = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
715                                                         networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
716                                                 }
717
718                                         } else {
719                                                 if (returnCode=='404') {
720                                                         String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
721                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
722                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
723
724                                                 } else {
725                                                    if (aaiResponseAsString.contains("RESTFault")) {
726                                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
727                                                            execution.setVariable("WorkflowException", exceptionObject)
728                                                            throw new BpmnError("MSOWorkflowException")
729
730                                                            } else {
731                                                                         // aai all errors
732                                                                         String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
733                                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
734                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
735
736                                                           }
737                                                 }
738                                         }
739
740                                 } // end loop
741
742                                 execution.setVariable(Prefix + "networkCollection", networkPolicies)
743                                 utils.log("DEBUG", " UPDNETI_networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
744
745                         } else {
746                                 // reset return code to success
747                                 execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
748                                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
749                                 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
750                                 String aaiStubResponse =
751                                         """     <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
752                                                         <network-policy xmlns="${schemaVersion}">
753                                                           <network-policy-fqdn/>
754                             </network-policy>
755                                                 </rest:payload>"""
756                                 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
757                                 execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
758                                 execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
759                                 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
760
761                         }
762
763                 } catch (BpmnError e) {
764                         throw e;
765
766                 } catch (Exception ex) {
767                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
768                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
769                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
770
771                 }
772
773         }
774
775         public void callRESTQueryAAINetworkTableRef(Execution execution) {
776                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
777                 execution.setVariable("prefix", Prefix)
778
779                 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " , isDebugEnabled)
780
781                 try {
782                         // get variables
783                         String messageId = execution.getVariable(Prefix + "messageId")
784                         String queryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
785                         String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
786                         utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
787
788                         // Check if Network TableREf is present, then build a List of network policy
789                         List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
790                         int networkTableRefCount = networkTableRefUriList.size()
791                         execution.setVariable(Prefix + "networkTableRefCount", networkTableRefCount)
792                         utils.log("DEBUG", " UPDNETI_networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
793
794                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
795                         AaiUtil aaiUriUtil = new AaiUtil(this)
796
797                         if (networkTableRefCount > 0) {
798                                 execution.setVariable(Prefix + "networkTableRefUriList", networkTableRefUriList)
799                                 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
800
801                                 // AII loop call using list vpnBindings
802                                 String networkTableRefs = ""
803                                 for (i in 0..networkTableRefUriList.size()-1) {
804
805                                         int counting = i+1
806
807                                         // prepare url using tableRef
808                                         String queryNetworkTableRefAAIRequest = ""
809
810                                         String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
811
812                                         // Note: By default, the network policy url is found in 'related-link' of the response,
813                                         //       so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
814                                         if (aai_uri == null || aai_uri == "") {
815                                                 // using value of 'related-link' from response
816                                                 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
817                                                         queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1)
818                                                 } else {
819                                                         queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i]
820                                                 }
821                                         } else {
822                                                 // using uri value in URN mapping
823                                                 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
824
825                                                 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
826                                                         networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
827                                                 }
828                                                 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId
829
830                                         }
831
832
833                                         utils.logAudit(queryNetworkTableRefAAIRequest)
834                                         execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
835                                         utils.log("DEBUG", " UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
836
837                                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
838                                         String returnCode = response.getStatusCode()
839                                         execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", returnCode)
840                                         utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
841
842                                         String aaiResponseAsString = response.getResponseBodyAsString()
843
844                                         if (returnCode=='200') {
845                                                 utils.logAudit(aaiResponseAsString)
846                                                 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiResponseAsString)
847                                                 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
848
849                                                 String networkTableRef = ""
850                                                 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
851                                                         networkTableRef  = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
852                                                         networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
853                                                 }
854
855                                         } else {
856                                                 if (returnCode=='404') {
857                                                         String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
858                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
859                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
860                                                         
861                                                 } else {
862                                                    if (aaiResponseAsString.contains("RESTFault")) {
863                                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
864                                                            execution.setVariable("WorkflowException", exceptionObject)
865                                                            throw new BpmnError("MSOWorkflowException")
866                 
867                                                            } else {
868                                                                         // aai all errors
869                                                                         String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
870                                                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
871                                                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
872
873                                                           }
874                                                 }
875                                         }
876
877                                 } // end loop
878
879                                 execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
880                                 utils.log("DEBUG", " UPDNETI_tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
881
882                         } else {
883                                 // reset return code to success
884                                 execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
885                                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
886                                 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
887                                 String aaiStubResponse =
888                                         """     <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
889                                                         <route-table-references xmlns="${schemaVersion}">
890                                                           <route-table-reference-fqdn/>
891                             </route-table-references>
892                                                 </rest:payload>"""
893                                 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
894                                 execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
895                                 execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
896                                 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
897
898                         }
899
900                 } catch (BpmnError e) {
901                         throw e;
902                         
903                 } catch (Exception ex) {
904                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
905                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
906                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
907
908                 }
909
910         }
911         
912         public void callRESTUpdateContrailAAINetwork(Execution execution) {
913                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
914                 execution.setVariable("prefix", Prefix)
915
916                 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " , isDebugEnabled)
917
918                 try {
919                         // get variables
920                         String networkRequest = execution.getVariable(Prefix + "networkRequest")
921                         String networkId   = utils.getNodeText1(networkRequest, "network-id")
922                         networkId = UriUtils.encode(networkId,"UTF-8")
923                         String requeryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse")
924                         String updateNetworkResponse   = execution.getVariable(Prefix + "updateNetworkResponse")
925                         String messageId = execution.getVariable(Prefix + "messageId")
926
927                         // Prepare url
928                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
929                         AaiUtil aaiUriUtil = new AaiUtil(this)
930                         String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
931                         String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId + "?depth=1"
932
933                         utils.logAudit(updateContrailAAIUrlRequest)
934                         execution.setVariable(Prefix + "updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
935                         utils.log("DEBUG", " UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
936
937                         //Prepare payload (PUT)
938                         String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
939                         String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
940                         String payloadXml = utils.formatXml(payload)
941                         utils.logAudit(payloadXml)
942                         execution.setVariable(Prefix + "updateContrailAAIPayloadRequest", payloadXml)
943                         utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
944
945                         APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
946                         String returnCode = response.getStatusCode()
947                         String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
948                         
949                         execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode)
950                         utils.log("DEBUG", " ***** AAI Update Contrail Response Code  : " + returnCode, isDebugEnabled)
951
952
953                         if (returnCode=='200') {
954                                 utils.logAudit(aaiUpdateContrailResponseAsString)
955                                 execution.setVariable(Prefix + "updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
956                                 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
957                                 // Point-of-no-return is set to false, rollback not needed.
958                                 execution.setVariable(Prefix + "isPONR", true)
959
960                         } else {
961                                 if (returnCode=='404') {
962                                         String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
963                                         utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
964                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
965
966                                 } else {
967                                    if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
968                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
969                                            execution.setVariable("WorkflowException", exceptionObject)
970                                            throw new BpmnError("MSOWorkflowException")
971
972                                            } else {
973                                                         // aai all errors
974                                                         String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
975                                                         utils.log("DEBUG", errorMessage, isDebugEnabled)
976                                                         exceptionUtil.buildAndThrowWorkflowException(execution, "2500", errorMessage)
977                                           }
978                                 }
979                         }
980
981                 } catch (BpmnError e) {
982                         throw e;
983
984                 } catch (Exception ex) {
985                         String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
986                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
987                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
988
989                 }
990
991         }
992
993         public void prepareUpdateNetworkRequest (Execution execution) {
994                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
995                 execution.setVariable("prefix", Prefix)
996
997                 utils.log("DEBUG", " ***** Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
998
999                 try {
1000
1001                         // get variables
1002                         String requestId = execution.getVariable(Prefix + "requestId")
1003                         String messageId = execution.getVariable(Prefix + "messageId")
1004                         String source    = execution.getVariable(Prefix + "source")
1005
1006                         String requestInput = execution.getVariable(Prefix + "networkRequest")
1007                         String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
1008                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
1009                         String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
1010                         
1011                         // Prepare Network request
1012                         String routeCollection = execution.getVariable(Prefix + "routeCollection")
1013                         String policyCollection = execution.getVariable(Prefix + "networkCollection")
1014                         String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
1015                         String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1016                         // Format Response
1017                         String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
1018                         buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1019                         utils.logAudit(buildUpdateNetworkRequestAsString)
1020
1021                         execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
1022                         utils.log("DEBUG", " UPDNETI_updateNetworkRequest - " + "\n" +  buildUpdateNetworkRequestAsString, isDebugEnabled)
1023
1024                 } catch (Exception ex) {
1025                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
1026                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1027                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1028
1029                 }
1030
1031         }
1032
1033         public void prepareSDNCRequest (Execution execution) {
1034                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1035                 execution.setVariable("prefix", Prefix)
1036
1037                 utils.log("DEBUG", " ***** Inside prepareSDNCRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1038
1039                 try {
1040                         // get variables
1041                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1042                         String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1043                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1044
1045                         String networkId = ""
1046                         if (utils.nodeExists(updateNetworkInput, "network-id")) {
1047                            networkId = utils.getNodeText1(updateNetworkInput, "network-id")
1048                         }
1049                         if (networkId == null) {networkId = ""}
1050
1051                         String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1052
1053                         // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1054                         String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1055
1056                         String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1057                         utils.logAudit(sndcTopologyUpdateRequesAsString)
1058                         execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1059                         utils.log("DEBUG", " UPDNETI_changeAssignSDNCRequest - " + "\n" +  sndcTopologyUpdateRequesAsString, isDebugEnabled)
1060
1061
1062                 } catch (Exception ex) {
1063                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
1064                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1065                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1066
1067                 }
1068
1069         }
1070
1071         
1072
1073
1074         // **************************************************
1075         //     Post or Validate Response Section
1076         // **************************************************
1077
1078         public void validateUpdateNetworkResponse (Execution execution) {
1079                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1080                 execution.setVariable("prefix", Prefix)
1081
1082                 utils.log("DEBUG", " ***** Inside validateUpdateNetworkResponse of DoUpdateNetworkInstance *****", isDebugEnabled)
1083
1084                 try {
1085                         String returnCode = execution.getVariable(Prefix + "networkReturnCode")
1086                         String networkResponse = execution.getVariable(Prefix + "updateNetworkResponse")
1087                         if (networkResponse==null)      {
1088                                 networkResponse="" // reset
1089                         }
1090
1091                         utils.log("DEBUG", " Network Adapter update responseCode: " + returnCode, isDebugEnabled)
1092
1093                         String errorMessage = ""
1094                         if (returnCode == "200") {
1095                                 execution.setVariable(Prefix + "isNetworkRollbackNeeded", true)
1096                                 utils.logAudit(networkResponse)
1097                                 execution.setVariable(Prefix + "updateNetworkResponse", networkResponse)
1098                                 utils.log("DEBUG", " Network Adapter update Success Response - " + "\n" + networkResponse, isDebugEnabled)
1099
1100                                 // prepare rollback data
1101                                 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1102                                 rollbackData = rollbackData.replace("rollback>", "networkRollback>")
1103                                 String rollbackNetwork =
1104                                         """<rollbackNetworkRequest>
1105                                                         ${rollbackData}
1106                                                 </rollbackNetworkRequest>"""
1107                                 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1108                                 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
1109                                 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1110
1111                         } else { // network error
1112                            if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) {   //4xx, 5xx
1113                                    if (networkResponse.contains("updateNetworkError")) {
1114                                            networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1115                                            errorMessage = utils.getNodeText1(networkResponse, "message")
1116                                            errorMessage  = "Received error from Network Adapter: " + errorMessage
1117                                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1118
1119                                    } else { // CatchAll exception
1120                                            if (returnCode == "500") {
1121                                                    errorMessage = "JBWEB000065: HTTP Status 500."
1122                                        } else {
1123                                                errorMessage = "Return code is " + returnCode
1124                                        }
1125                                            errorMessage  = "Received error from Network Adapter: " + errorMessage
1126                                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1127
1128                                    }
1129
1130                            } else { // CatchAll exception
1131                                    String dataErrorMessage  = "Received error from Network Adapter. Return code is: " + returnCode
1132                                    exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1133
1134                            }
1135
1136                         }
1137
1138                 } catch (BpmnError e) {
1139                         throw e;
1140
1141                 } catch (Exception ex) {
1142                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1143                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1144                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1145
1146                 }
1147
1148
1149         }
1150
1151         public void validateSDNCResponse (Execution execution) {
1152                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1153                 execution.setVariable("prefix", Prefix)
1154
1155                 utils.log("DEBUG", " ***** Inside validateSDNCResponse of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1156
1157                 String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1158                 WorkflowException workflowException = null
1159                 try {
1160                         workflowException = execution.getVariable(Prefix + "WorkflowException")
1161                         //execution.setVariable("WorkflowException", workflowException)
1162                 } catch (Exception ex) {
1163                         utils.log("DEBUG", " Sdnc 'WorkflowException' object is empty or null. ", isDebugEnabled)
1164                 }
1165
1166                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1167
1168                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1169                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1170                 // reset variable
1171                 String changeAssignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "changeAssignSDNCResponse"))
1172                 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace("&", "&amp;").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1173                 execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1174
1175                 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) {  // from sdnc util, prefix+'sdncResponseSuccess'
1176                         execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
1177                         utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1178
1179                 } else {
1180                         utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1181                         throw new BpmnError("MSOWorkflowException")
1182                 }
1183
1184         }
1185
1186
1187         public void postProcessResponse (Execution execution) {
1188                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1189                 execution.setVariable("prefix", Prefix)
1190
1191                 utils.log("DEBUG", " ***** Inside postProcessResponse of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1192
1193                 try {
1194                         utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
1195                         if (execution.getVariable(Prefix + "isException") == false) {
1196                                 // set rollback data
1197                                 execution.setVariable("orchestrationStatus", "")
1198                                 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
1199                                 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
1200                                 prepareSuccessRollbackData(execution) // populate rollbackData
1201                                 execution.setVariable("WorkflowException", null)
1202                                 execution.setVariable(Prefix + "Success", true)
1203                                 utils.log("DEBUG", " ***** postProcessResponse(), GOOD !!!", isDebugEnabled)
1204                         } else {
1205                                 execution.setVariable(Prefix + "Success", false) 
1206                                 execution.setVariable("rollbackData", null)
1207                                 String exceptionMessage = " Exception encountered in MSO Bpmn. "
1208                                 if (execution.getVariable("workflowException") != null) {  // Output of Rollback flow.
1209                                    utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
1210                                    WorkflowException wfex = execution.getVariable("workflowException")
1211                                    exceptionMessage = wfex.getErrorMessage()
1212                                 } else {
1213                                if (execution.getVariable(Prefix + "WorkflowException") != null) {
1214                                       WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
1215                                       exceptionMessage = pwfex.getErrorMessage()
1216                                }   
1217                                 }
1218                             // going to the Main flow: a-la-carte or macro
1219                             utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
1220                             exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1221                                 throw new BpmnError("MSOWorkflowException")
1222                         }
1223                                                         
1224                 } catch(BpmnError b){
1225                      utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
1226                      throw b
1227                         
1228
1229                 } catch (Exception ex) {
1230                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
1231                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1232                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1233
1234         }
1235
1236
1237         }
1238
1239         public void prepareSDNCRollbackRequest (Execution execution) {
1240                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1241                 execution.setVariable("prefix", Prefix)
1242
1243                 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1244
1245                 try {
1246                         // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException. 
1247                         execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1248                         // get variables
1249                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1250                         String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
1251                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
1252                         String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
1253                         String networkId = utils.getNodeText1(changeAssignSDNCResponse, "network-id")
1254
1255                         String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1256
1257                         // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1258                         String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1259                         String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1260                         execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1261                         utils.log("DEBUG", " Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" +  sndcTopologyRollbackRequestAsString, isDebugEnabled)
1262
1263
1264                 } catch (Exception ex) {
1265                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1266                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1267                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1268
1269                 }
1270
1271         }
1272
1273         public void prepareRollbackData(Execution execution) {
1274                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1275                 execution.setVariable("prefix",Prefix)
1276                 
1277                 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1278                 
1279                 try {
1280                         
1281                         Map<String, String> rollbackData = new HashMap<String, String>();
1282                         String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1283                         if (rollbackSDNCRequest != null) {
1284                                 if (rollbackSDNCRequest != "") {
1285                                         rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
1286                                 }
1287                         }
1288                         String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1289                         if (rollbackNetworkRequest != null) {
1290                                 if (rollbackNetworkRequest != "") {
1291                                         rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
1292                                 }
1293                         }
1294                         execution.setVariable("rollbackData", rollbackData)
1295                         utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
1296                         
1297                         execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
1298                         utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
1299                         
1300                 } catch (Exception ex) {
1301                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
1302                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1303                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1304                 
1305                 }
1306                 
1307         }
1308         
1309         public void prepareSuccessRollbackData(Execution execution) {
1310                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1311                 execution.setVariable("prefix",Prefix)
1312                 
1313                 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1314                 
1315                 try {
1316                         
1317                         if (execution.getVariable("sdncVersion") == '1702') {
1318                                 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1319                         } else {
1320                                 prepareSDNCRollbackRequest(execution)
1321                         }
1322                         
1323                         Map<String, String> rollbackData = new HashMap<String, String>();
1324                         String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1325                         if (rollbackSDNCRequest != null) {
1326                                 if (rollbackSDNCRequest != "") {
1327                                         rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1328                                 }
1329                         }
1330                         String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1331                         if (rollbackNetworkRequest != null) {
1332                                 if (rollbackNetworkRequest != "") {
1333                                         rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1334                                 }
1335                         }
1336                         execution.setVariable("rollbackData", rollbackData)
1337                         
1338                         utils.log("DEBUG", "** 'rollbackData' for Full Rollback : " + rollbackData, isDebugEnabled)
1339                         execution.setVariable("WorkflowException", null)
1340
1341                         
1342                 } catch (Exception ex) {
1343                         String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1344                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1345                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1346                 
1347                 }
1348                 
1349         }
1350         
1351         public void setExceptionFlag(Execution execution){
1352                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1353                 execution.setVariable("prefix",Prefix)
1354                 
1355                 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoUpdateNetworkInstance ***** ", isDebugEnabled)
1356                 
1357                 try {
1358                         
1359                         execution.setVariable(Prefix + "isException", true)
1360                         
1361                         if (execution.getVariable("SavedWorkflowException1") != null) {
1362                                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1363                         } else {
1364                                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1365                         }
1366                         utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1367                         
1368                 } catch(Exception ex){
1369                           String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1370                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1371                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1372                 }
1373                 
1374         }
1375
1376
1377         // *******************************
1378         //     Build Error Section
1379         // *******************************
1380
1381         public void processJavaException(Execution execution){
1382                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1383                 execution.setVariable("prefix",Prefix)
1384                 try{
1385                         utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
1386                         utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1387                         utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1388                         execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - "  + Prefix)  // Adding this line temporarily until this flows error handling gets updated
1389                         exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1390                         
1391                 }catch(Exception e){
1392                         utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1393                         execution.setVariable("UnexpectedError", "Exception in processJavaException method")  // Adding this line temporarily until this flows error handling gets updated
1394                         exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1395                 }
1396                 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
1397         }
1398
1399 }