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