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