cf7bb22442546200a1a1a51344d5584ddff26c34
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.scripts;
24
25 import javax.ws.rs.NotFoundException
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.aai.domain.yang.L3Network
29 import org.onap.aai.domain.yang.NetworkPolicy
30 import org.onap.aai.domain.yang.RouteTableReference
31 import org.onap.aai.domain.yang.RouteTarget
32 import org.onap.aai.domain.yang.Subnet
33 import org.onap.aai.domain.yang.VpnBinding
34 import org.onap.aaiclient.client.aai.AAIObjectType
35 import org.onap.aaiclient.client.aai.AAIResourcesClient
36 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
37 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
38 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
39 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
40 import org.onap.aaiclient.client.graphinventory.entities.uri.Depth
41 import org.onap.so.bpmn.common.scripts.AaiUtil
42 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
43 import org.onap.so.bpmn.common.scripts.ExceptionUtil
44 import org.onap.so.bpmn.common.scripts.MsoUtils
45 import org.onap.so.bpmn.common.scripts.NetworkUtils
46 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
47 import org.onap.so.bpmn.common.scripts.VidUtils
48 import org.onap.so.bpmn.core.UrnPropertiesReader
49 import org.onap.so.bpmn.core.WorkflowException
50 import org.onap.so.bpmn.core.json.JsonUtils
51 import org.onap.so.constants.Defaults
52 import org.slf4j.Logger
53 import org.slf4j.LoggerFactory
54 import groovy.json.*
55
56 /**
57  * This groovy class supports the <class>DoUpdateNetworkInstance.bpmn</class> process.
58  *
59  */
60 public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor {
61     private static final Logger logger = LoggerFactory.getLogger( DoUpdateNetworkInstance.class);
62
63     String Prefix="UPDNETI_"
64     ExceptionUtil exceptionUtil = new ExceptionUtil()
65     JsonUtils jsonUtil = new JsonUtils()
66     VidUtils vidUtils = new VidUtils(this)
67     NetworkUtils networkUtils = new NetworkUtils()
68     SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
69
70     /**
71      * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
72      * @param execution
73      */
74     public InitializeProcessVariables(DelegateExecution execution){
75         /* Initialize all the process variables in this block */
76
77         execution.setVariable(Prefix + "messageId", "")
78         execution.setVariable("BasicAuthHeaderValuePO", "")
79         execution.setVariable("BasicAuthHeaderValueSDNC", "")
80         execution.setVariable(Prefix + "networkRequest", "")
81         execution.setVariable(Prefix + "networkInputs", "")
82         execution.setVariable(Prefix + "networkOutputs", "")
83         execution.setVariable(Prefix + "requestId", "")
84         execution.setVariable(Prefix + "source", "")
85         execution.setVariable(Prefix + "networkId", "")
86
87         execution.setVariable(Prefix + "isPONR", false)    // Point-of-no-return, means, rollback is not needed
88
89         // AAI query Cloud Region
90         execution.setVariable(Prefix + "queryCloudRegionRequest","")
91         execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
92         execution.setVariable(Prefix + "queryCloudRegionResponse","")
93         execution.setVariable(Prefix + "cloudRegionPo","")
94         execution.setVariable(Prefix + "cloudRegionSdnc","")
95         execution.setVariable(Prefix + "isCloudRegionGood", false)
96
97         // AAI query Id
98         execution.setVariable(Prefix + "queryIdAAIRequest","")
99         execution.setVariable(Prefix + "queryIdAAIResponse", "")
100         execution.setVariable(Prefix + "aaiIdReturnCode", "")
101
102         // AAI query vpn binding
103         execution.setVariable(Prefix + "queryVpnBindingAAIRequest","")
104         execution.setVariable(Prefix + "queryVpnBindingAAIResponse", "")
105         execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "")
106         execution.setVariable(Prefix + "vpnBindings", null)
107         execution.setVariable(Prefix + "vpnCount", 0)
108         execution.setVariable(Prefix + "routeCollection", "")
109
110         // AAI query network policy
111         execution.setVariable(Prefix + "queryNetworkPolicyAAIRequest","")
112         execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", "")
113         execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "")
114         execution.setVariable(Prefix + "networkPolicyUriList", null)
115         execution.setVariable(Prefix + "networkPolicyCount", 0)
116         execution.setVariable(Prefix + "networkCollection", "")
117
118         // AAI query route table reference
119         execution.setVariable(Prefix + "queryNetworkTableRefAAIRequest","")
120         execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", "")
121         execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "")
122         execution.setVariable(Prefix + "networkTableRefUriList", null)
123         execution.setVariable(Prefix + "networkTableRefCount", 0)
124         execution.setVariable(Prefix + "tableRefCollection", "")
125
126         // AAI requery Id
127         execution.setVariable(Prefix + "requeryIdAAIRequest","")
128         execution.setVariable(Prefix + "requeryIdAAIResponse", "")
129         execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "")
130
131         // AAI update contrail
132         execution.setVariable(Prefix + "updateContrailAAIUrlRequest","")
133         execution.setVariable(Prefix + "updateContrailAAIPayloadRequest","")
134         execution.setVariable(Prefix + "updateContrailAAIResponse", "")
135         execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", "")
136
137         execution.setVariable(Prefix + "updateNetworkRequest", "")
138         execution.setVariable(Prefix + "updateNetworkResponse", "")
139         execution.setVariable(Prefix + "rollbackNetworkRequest", "")
140         execution.setVariable(Prefix + "networkReturnCode", "")
141         execution.setVariable(Prefix + "isNetworkRollbackNeeded", false)
142
143         execution.setVariable(Prefix + "changeAssignSDNCRequest", "")
144         execution.setVariable(Prefix + "changeAssignSDNCResponse", "")
145         execution.setVariable(Prefix + "rollbackSDNCRequest", "")
146         execution.setVariable(Prefix + "sdncReturnCode", "")
147         execution.setVariable(Prefix + "isSdncRollbackNeeded", false)
148         execution.setVariable(Prefix + "sdncResponseSuccess", false)
149
150         execution.setVariable(Prefix + "isVnfBindingPresent", false)
151         execution.setVariable(Prefix + "Success", false)
152         execution.setVariable(Prefix + "serviceInstanceId", "")
153
154         execution.setVariable(Prefix + "isException", false)
155
156     }
157
158     // **************************************************
159     //     Pre or Prepare Request Section
160     // **************************************************
161     /**
162      * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstance.bpmn</class> process.
163      * @param execution
164      */
165     public void preProcessRequest (DelegateExecution execution) {
166
167         execution.setVariable("prefix",Prefix)
168
169         logger.trace("Inside preProcessRequest DoUpdateNetworkInstance Request ")
170
171         try {
172             // initialize flow variables
173             InitializeProcessVariables(execution)
174
175             // GET Incoming request & validate 3 kinds of format.
176             execution.setVariable("action", "UPDATE")
177             String networkRequest = execution.getVariable("bpmnRequest")
178             if (networkRequest != null) {
179                 if (networkRequest.contains("requestDetails")) {
180                     // JSON format request is sent, create xml
181                     try {
182                         def prettyJson = JsonOutput.prettyPrint(networkRequest.toString())
183                         logger.debug(" Incoming message formatted . . . : " + '\n' + prettyJson)
184                         networkRequest =  vidUtils.createXmlNetworkRequestInfra(execution, networkRequest)
185
186                     } catch (Exception ex) {
187                         String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
188                         logger.debug(dataErrorMessage)
189                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
190                     }
191                 } else {
192                     // XML format request is sent
193
194                 }
195             } else {
196                 // vIPR format request is sent, create xml from individual variables
197                 networkRequest = vidUtils.createXmlNetworkRequestInstance(execution)
198             }
199
200             networkRequest = utils.formatXml(networkRequest)
201             logger.debug(networkRequest)
202             execution.setVariable(Prefix + "networkRequest", networkRequest)
203             logger.debug(" network-request - " + '\n' + networkRequest)
204
205             // validate 'disableRollback'  (aka, 'suppressRollback')
206             boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
207             execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
208             logger.debug(Prefix + "rollbackEnabled - " + rollbackEnabled)
209
210             String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
211             execution.setVariable(Prefix + "networkInputs", networkInputs)
212             logger.debug(Prefix + "networkInputs - " + '\n' + networkInputs)
213
214             // prepare messageId
215             String messageId = execution.getVariable(Prefix + "messageId")  // for testing
216             if (messageId == null || messageId == "") {
217                 messageId = UUID.randomUUID()
218                 logger.debug(" UPDNETI_messageId, random generated: " + messageId)
219             } else {
220                 logger.debug(" UPDNETI_messageId, pre-assigned: " + messageId)
221             }
222             execution.setVariable(Prefix + "messageId", messageId)
223
224             String source = utils.getNodeText(networkRequest, "source")
225             execution.setVariable(Prefix + "source", source)
226             logger.debug(Prefix + "source - " + source)
227
228             String networkId = ""
229             if (utils.nodeExists(networkRequest, "network-id")) {
230                 networkId = utils.getNodeText(networkRequest, "network-id")
231                 if (networkId == 'null' || networkId == "") {
232                     sendSyncError(execution)
233                     // missing value of networkId
234                     String dataErrorMessage = "Variable 'network-id' value/element is missing."
235                     logger.debug(" Invalid Request - " + dataErrorMessage)
236                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
237
238                 }
239             }
240
241             String lcpCloudRegion = ""
242             if (utils.nodeExists(networkRequest, "aic-cloud-region")) {
243                 lcpCloudRegion = utils.getNodeText(networkRequest, "aic-cloud-region")
244                 if ((lcpCloudRegion == 'null') || (lcpCloudRegion == "")) {
245                     sendSyncError(execution)
246                     String dataErrorMessage = "requestDetails has missing 'aic-cloud-region' value/element."
247                     logger.debug(" Invalid Request - " + dataErrorMessage)
248                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
249                 }
250             }
251
252             String serviceInstanceId = ""
253             if (utils.nodeExists(networkRequest, "service-instance-id")) {
254                 serviceInstanceId = utils.getNodeText(networkRequest, "service-instance-id")
255                 if ((serviceInstanceId == 'null') || (lcpCloudRegion == "")) {
256                     sendSyncError(execution)
257                     String dataErrorMessage = "Variable 'serviceInstanceId' value/element is missing."
258                     logger.debug(" Invalid Request - " + dataErrorMessage)
259                     exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
260                 }
261             }
262
263             // PO Authorization Info / headers Authorization=
264             String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution)
265
266
267             try {
268                 def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey", execution))
269                 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
270                 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
271
272             } catch (IOException ex) {
273                 String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - "
274                 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
275                 logger.debug(dataErrorMessage)
276                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
277             }
278
279             // Set variables for Generic Get Sub Flow use
280             execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId)
281             logger.debug(Prefix + "serviceInstanceId - " + serviceInstanceId)
282
283             logger.debug(" Url for SDNC adapter: " + UrnPropertiesReader.getVariable("mso.adapters.sdnc.endpoint",execution))
284
285             String sdncVersion = execution.getVariable("sdncVersion")
286             logger.debug("sdncVersion? : " + sdncVersion)
287
288             // build 'networkOutputs'
289             networkId = utils.getNodeText(networkRequest, "network-id")
290             if ((networkId == null) || (networkId == "null")) {
291                 networkId = ""
292             }
293             String networkName = utils.getNodeText(networkRequest, "network-name")
294             if ((networkName == null) || (networkName == "null")) {
295                 networkName = ""
296             }
297             String networkOutputs =
298                     """<network-outputs>
299                            <network-id>${MsoUtils.xmlEscape(networkId)}</network-id>
300                            <network-name>${MsoUtils.xmlEscape(networkName)}</network-name>
301                          </network-outputs>"""
302             execution.setVariable(Prefix + "networkOutputs", networkOutputs)
303             logger.debug(Prefix + "networkOutputs - " + '\n' + networkOutputs)
304             execution.setVariable(Prefix + "networkId", networkId)
305             execution.setVariable(Prefix + "networkName", networkName)
306
307
308         } catch (BpmnError e) {
309             throw e;
310
311         } catch (Exception ex){
312             sendSyncError(execution)
313             // caught exception
314             String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - " + ex.getMessage()
315             logger.debug(exceptionMessage)
316             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
317
318         }
319     }
320
321     /**
322      * Gets the service instance uri from aai
323      *
324      */
325     public void getServiceInstance(DelegateExecution execution) {
326         logger.trace("getServiceInstance ")
327         try {
328             String serviceInstanceId = execution.getVariable('serviceInstanceId')
329
330             AAIResourcesClient resourceClient = new AAIResourcesClient()
331             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
332
333             if(!resourceClient.exists(uri)){
334                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Service Instance not found in aai")
335             }else{
336                 Map<String, String> keys = uri.getURIKeys()
337                 execution.setVariable("serviceType", keys.get(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType))
338                 execution.setVariable("subscriberName", keys.get(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId))
339             }
340
341         }catch(BpmnError e) {
342             throw e;
343         }catch (Exception ex){
344             String msg = "Exception in getServiceInstance. " + ex.getMessage()
345             logger.debug(msg)
346             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
347         }
348     }
349
350     public void callRESTQueryAAICloudRegion (DelegateExecution execution) {
351
352         execution.setVariable("prefix", Prefix)
353
354         logger.debug(" ***** Inside callRESTQueryAAICloudRegion of DoUpdateNetworkInstance ***** " )
355
356         try {
357             String networkInputs  = execution.getVariable(Prefix + "networkInputs")
358             String cloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
359
360             // Prepare AA&I url
361             String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
362             AaiUtil aaiUtil = new AaiUtil(this)
363
364             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, Defaults.CLOUD_OWNER.toString(), cloudRegion)
365             def queryCloudRegionRequest = aaiUtil.createAaiUri(uri)
366
367             execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
368
369             String cloudRegionPo = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
370             String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "SDNC", cloudRegion)
371
372             if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
373                 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
374                 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
375                 execution.setVariable(Prefix + "isCloudRegionGood", true)
376
377             } else {
378                 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
379                 logger.debug(dataErrorMessage)
380                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
381
382             }
383
384             logger.debug(" is Cloud Region Good: " + execution.getVariable(Prefix + "isCloudRegionGood"))
385
386         } catch (BpmnError e) {
387             throw e;
388
389         } catch (Exception ex) {
390             // try error
391             String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
392             logger.debug(exceptionMessage)
393             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
394
395         }
396
397     }
398
399     public void callRESTQueryAAINetworkId(DelegateExecution execution) {
400
401         execution.setVariable("prefix", Prefix)
402
403         logger.debug(" ***** Inside callRESTQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
404
405         try {
406             // get variables
407             String networkRequest = execution.getVariable(Prefix + "networkRequest")
408             String networkId   = utils.getNodeText(networkRequest, "network-id")
409             execution.setVariable(Prefix + "networkId", networkId)
410
411             AAIResourcesClient client = new AAIResourcesClient()
412             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId).depth(Depth.ONE)
413             AAIResultWrapper network = client.get(uri, NotFoundException.class)
414
415             execution.setVariable(Prefix + "aaiIdReturnCode", "200")
416
417             execution.setVariable(Prefix + "queryIdAAIResponse", network)
418
419
420         } catch (NotFoundException e) {
421             String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
422             logger.debug(" AAI Query Failed. " + dataErrorMessage)
423             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
424         } catch (Exception ex) {
425             String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
426             logger.debug(exceptionMessage)
427             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
428
429         }
430
431     }
432
433     public void callRESTReQueryAAINetworkId(DelegateExecution execution) {
434
435         execution.setVariable("prefix", Prefix)
436
437         logger.debug(" ***** Inside callRESTReQueryAAINetworkId of DoUpdateNetworkInstance ***** " )
438
439         try {
440             // get variables
441             String networkRequest = execution.getVariable(Prefix + "networkRequest")
442             String networkId   = utils.getNodeText(networkRequest, "network-id")
443
444             AAIResourcesClient client = new AAIResourcesClient()
445             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId).depth(Depth.ONE)
446             AAIResultWrapper network = client.get(uri, NotFoundException.class)
447
448             execution.setVariable(Prefix + "aaiRequeryIdReturnCode", "200")
449             execution.setVariable(Prefix + "requeryIdAAIResponse", network)
450
451             L3Network net = network.asBean(L3Network.class).get()
452             String netId = net.getNetworkId()
453             String netName = net.getNetworkName()
454             String networkOutputs =
455                     """<network-outputs>
456                    <network-id>${MsoUtils.xmlEscape(netId)}</network-id>
457                    <network-name>${MsoUtils.xmlEscape(netName)}</network-name>
458                  </network-outputs>"""
459             execution.setVariable(Prefix + "networkOutputs", networkOutputs)
460             logger.debug(" networkOutputs - " + '\n' + networkOutputs)
461
462         } catch (NotFoundException e) {
463             String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
464             logger.debug(" AAI ReQuery Failed. - " + dataErrorMessage)
465             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
466         } catch (Exception ex) {
467             String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
468             logger.debug(exceptionMessage)
469             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
470
471         }
472
473     }
474
475     public void callRESTQueryAAINetworkVpnBinding(DelegateExecution execution) {
476
477         execution.setVariable("prefix", Prefix)
478
479         logger.debug(" ***** Inside callRESTQueryAAINetworkVpnBinding of DoUpdateNetworkInstance ***** " )
480
481         try {
482
483             // get variables
484             AAIResultWrapper queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
485             if(queryIdAAIResponse.getRelationships().isPresent()){
486                 List<AAIResourceUri> uris = queryIdAAIResponse.getRelationships().get().getRelatedAAIUris(AAIObjectType.VPN_BINDING)
487
488                 logger.debug(Prefix + "vpnCount - " + uris.size())
489
490                 if (uris.size() > 0) {
491                     String routeTargets = ""
492                     for(AAIResourceUri u : uris) {
493
494                         AAIResourcesClient client = new AAIResourcesClient()
495                         AAIResultWrapper wrapper = client.get(u.depth(Depth.TWO), NotFoundException.class)
496                         Optional<VpnBinding> binding = wrapper.asBean(VpnBinding.class)
497
498                         String routeTarget = ""
499                         String routeRole = ""
500                         if(binding.get().getRouteTargets() != null) {
501                             List<RouteTarget> targets = binding.get().getRouteTargets().getRouteTarget()
502                             for(RouteTarget target : targets) {
503                                 routeTarget  = target.getGlobalRouteTarget()
504                                 routeRole  = target.getRouteTargetRole()
505                                 routeTargets += "<routeTargets>" + '\n' +
506                                         " <routeTarget>" + routeTarget + "</routeTarget>" + '\n' +
507                                         " <routeTargetRole>" + routeRole + "</routeTargetRole>" + '\n' +
508                                         "</routeTargets>" + '\n'
509                             }
510                         }
511
512                     } // end loop
513
514                     execution.setVariable(Prefix + "routeCollection", routeTargets)
515                     logger.debug(" UPDNETI_routeCollection - " + '\n' + routeTargets)
516
517                 } else {
518                     // reset return code to success
519                     execution.setVariable(Prefix + "aaiQqueryVpnBindingReturnCode", "200")
520                     AaiUtil aaiUriUtil = new AaiUtil(this)
521                     String schemaVersion = aaiUriUtil.getNamespace()
522                     String aaiStubResponse =
523                             """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
524                                                         <vpn-binding xmlns="${schemaVersion}">
525                                                       <global-route-target/>
526                                                         </vpn-binding>
527                                                 </rest:payload>"""
528                     String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
529                     execution.setVariable(Prefix + "queryVpnBindingAAIResponse", aaiStubResponseAsXml)
530                     execution.setVariable(Prefix + "routeCollection", "<routeTargets/>")
531                     logger.debug(" No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml)
532
533                 }
534             }
535
536         } catch (NotFoundException e) {
537             logger.debug("Response Error from AAINetworkVpnBinding is 404 (Not Found).")
538             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Response Error from AAINetworkVpnBinding is 404 (Not Found).")
539         } catch (Exception ex) {
540             String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
541             logger.debug(exceptionMessage)
542             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
543
544         }
545
546     }
547
548     public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) {
549
550         execution.setVariable("prefix", Prefix)
551
552         logger.debug(" ***** Inside callRESTQueryAAINetworkPolicy of DoUpdateNetworkInstance ***** " )
553
554         try {
555             // get variables
556             AAIResultWrapper queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
557             if(queryIdAAIResponse.getRelationships().isPresent()){
558                 List<AAIResourceUri> uris = queryIdAAIResponse.getRelationships().get().getRelatedAAIUris(AAIObjectType.NETWORK_POLICY)
559
560                 execution.setVariable(Prefix + "networkPolicyCount", uris.size())
561                 logger.debug(Prefix + "networkPolicyCount - " + uris.size())
562
563                 if (uris.size() > 0) {
564
565                     String networkPolicies = ""
566                     // AII loop call using list vpnBindings
567                     for(AAIResourceUri u : uris) {
568
569                         AAIResourcesClient client = new AAIResourcesClient()
570                         NetworkPolicy p = client.get(u, NotFoundException.class).asBean(NetworkPolicy.class).get()
571
572                         execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
573
574                         String networkPolicy  = p.getNetworkPolicyFqdn()
575                         networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
576
577                     } // end loop
578
579                     execution.setVariable(Prefix + "networkCollection", networkPolicies)
580                     logger.debug(" UPDNETI_networkCollection - " + '\n' + networkPolicies)
581
582                 } else {
583                     // reset return code to success
584                     execution.setVariable(Prefix + "aaiQqueryNetworkPolicyReturnCode", "200")
585                     AaiUtil aaiUriUtil = new AaiUtil(this)
586                     String schemaVersion = aaiUriUtil.getNamespace()
587                     String aaiStubResponse =
588                             """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
589                                                         <network-policy xmlns="${schemaVersion}">
590                                                           <network-policy-fqdn/>
591                             </network-policy>
592                                                 </rest:payload>"""
593                     String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
594                     execution.setVariable(Prefix + "queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
595                     execution.setVariable(Prefix + "networkCollection", "<policyFqdns/>")
596                     logger.debug(" No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml)
597
598                 }
599             }
600
601         } catch (NotFoundException e) {
602             String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
603             logger.debug(dataErrorMessage)
604             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
605         } catch (Exception ex) {
606             String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
607             logger.debug(exceptionMessage)
608             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
609
610         }
611
612     }
613
614     public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) {
615
616         execution.setVariable("prefix", Prefix)
617
618         logger.debug(" ***** Inside callRESTQueryAAINetworkTableRef of DoUpdateNetworkInstance ***** " )
619
620         try {
621             AAIResultWrapper queryIdAAIResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
622             if(queryIdAAIResponse.getRelationships().isPresent()){
623                 List<AAIResourceUri> uris = queryIdAAIResponse.getRelationships().get().getRelatedAAIUris(AAIObjectType.ROUTE_TABLE_REFERENCE)
624
625                 execution.setVariable(Prefix + "networkTableRefCount", uris.size())
626                 logger.debug(Prefix + "networkTableRefCount - " + uris.size())
627
628                 logger.debug(" UPDNETI_networkTableRefCount - " + uris.size())
629                 if (uris.size() > 0) {
630
631                     execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
632
633                     // AII loop call using list vpnBindings
634                     String networkTableRefs = ""
635                     for(AAIResourceUri u : uris) {
636
637                         AAIResourcesClient client = new AAIResourcesClient()
638                         RouteTableReference rt = client.get(u, NotFoundException.class).asBean(RouteTableReference.class).get()
639
640                         String networkTableRef  = rt.getRouteTableReferenceFqdn()
641                         networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
642
643                     } // end loop
644
645                     execution.setVariable(Prefix + "tableRefCollection", networkTableRefs)
646                     logger.debug(" UPDNETI_tableRefCollection - " + '\n' + networkTableRefs)
647
648                 } else {
649                     // reset return code to success
650                     execution.setVariable(Prefix + "aaiQqueryNetworkTableRefReturnCode", "200")
651                     AaiUtil aaiUriUtil = new AaiUtil(this)
652                     String schemaVersion = aaiUriUtil.getNamespace()
653                     String aaiStubResponse =
654                             """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
655                                                         <route-table-references xmlns="${schemaVersion}">
656                                                           <route-table-reference-fqdn/>
657                             </route-table-references>
658                                                 </rest:payload>"""
659                     String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
660                     execution.setVariable(Prefix + "queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
661                     execution.setVariable(Prefix + "tableRefCollection", "<routeTableFqdns/>")
662                     logger.debug(" No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml)
663
664                 }
665             }
666
667         } catch (NotFoundException e) {
668             String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
669             logger.debug(dataErrorMessage)
670             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
671
672         } catch (Exception ex) {
673             String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
674             logger.debug(exceptionMessage)
675             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
676
677         }
678
679     }
680
681     public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) {
682         execution.setVariable("prefix", Prefix)
683         logger.debug(" ***** Inside callRESTUpdateContrailAAINetwork of DoUpdateNetworkInstance ***** " )
684         try {
685             // get variables
686             String networkRequest = execution.getVariable(Prefix + "networkRequest")
687             String networkId   = utils.getNodeText(networkRequest, "network-id")
688             AAIResultWrapper requeryIdAAIResponse   = execution.getVariable(Prefix + "requeryIdAAIResponse")
689             String updateNetworkResponse   = execution.getVariable(Prefix + "updateNetworkResponse")
690
691             L3Network oldL3Network = requeryIdAAIResponse.asBean(L3Network.class).get()
692             L3Network l3Network = new L3Network()
693             if (oldL3Network.getHeatStackId() != null) {
694             } else {
695                 if (utils.nodeExists(updateNetworkResponse, 'networkStackId')) {
696                     l3Network.setHeatStackId(utils.getNodeText(updateNetworkResponse, 'networkStackId'))
697                 }
698             }
699             if (oldL3Network.getNeutronNetworkId() != null) {
700             } else {
701                 if (utils.nodeExists(updateNetworkResponse, 'neutronNetworkId')) {
702                     l3Network.setNeutronNetworkId(utils.getNodeText(updateNetworkResponse, 'neutronNetworkId'))
703                 }
704             }
705             if (oldL3Network.getContrailNetworkFqdn() != null) {
706             } else {
707                 if (utils.nodeExists(updateNetworkResponse, 'networkFqdn')) {
708                     l3Network.setContrailNetworkFqdn(utils.getNodeText(updateNetworkResponse, 'networkFqdn'))
709                 }
710             }
711
712             String status = utils.getNodeText(updateNetworkResponse, 'orchestration-status')
713             if(status.equals("pending-create") || status.equals("PendingCreate")){
714                 l3Network.setOrchestrationStatus("Created")
715             }else{
716                 l3Network.setOrchestrationStatus("Active")
717             }
718
719             AAIResourcesClient client = new AAIResourcesClient()
720             AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId)
721             client.update(uri, l3Network)
722
723             List<Subnet> subnets = oldL3Network.getSubnets().getSubnet()
724             for(Subnet s:subnets){
725                 String subnetOrchStatus = s.getOrchestrationStatus()
726                 String subnetId = s.getSubnetId()
727
728                 Subnet subnet = new Subnet()
729                 String neutronSubnetId = networkUtils.extractNeutSubId(updateNetworkResponse, subnetId)
730                 subnet.setNeutronSubnetId(neutronSubnetId)
731                 if(subnetOrchStatus.equals("pending-create") || subnetOrchStatus.equals("PendingCreate") ){
732                     subnet.setOrchestrationStatus("Created")
733                 }else{
734                     subnet.setOrchestrationStatus("Active")
735                 }
736
737                 AAIResourceUri subUri = AAIUriFactory.createResourceUri(AAIObjectType.SUBNET, networkId, subnetId)
738                 client.update(subUri, subnet)
739             }
740
741             execution.setVariable(Prefix + "isPONR", true)
742
743         } catch (BpmnError e) {
744             throw e;
745         } catch (NotFoundException e) {
746             String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
747             logger.debug(dataErrorMessage)
748             exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
749         } catch (Exception ex) {
750             String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
751             logger.debug(exceptionMessage)
752             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
753
754         }
755
756     }
757
758     public void prepareUpdateNetworkRequest (DelegateExecution execution) {
759
760         execution.setVariable("prefix", Prefix)
761
762         logger.trace("Inside prepareUpdateNetworkRequest of DoUpdateNetworkInstance ")
763
764         try {
765
766             // get variables
767             String requestId = execution.getVariable(Prefix + "requestId")
768             String messageId = execution.getVariable(Prefix + "messageId")
769             String source    = execution.getVariable(Prefix + "source")
770
771             String requestInput = execution.getVariable(Prefix + "networkRequest")
772             L3Network queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse")
773             String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo")
774             String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
775
776             // Prepare Network request
777             String routeCollection = execution.getVariable(Prefix + "routeCollection")
778             String policyCollection = execution.getVariable(Prefix + "networkCollection")
779             String tableCollection = execution.getVariable(Prefix + "tableRefCollection")
780             String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
781             // Format Response
782             String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
783             buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
784             logger.debug(buildUpdateNetworkRequestAsString)
785
786             execution.setVariable(Prefix + "updateNetworkRequest", buildUpdateNetworkRequestAsString)
787             logger.debug(" UPDNETI_updateNetworkRequest - " + "\n" +  buildUpdateNetworkRequestAsString)
788
789         } catch (Exception ex) {
790             String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
791             logger.debug(exceptionMessage)
792             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
793
794         }
795
796     }
797
798     public void prepareSDNCRequest (DelegateExecution execution) {
799
800         execution.setVariable("prefix", Prefix)
801
802         logger.trace("Inside prepareSDNCRequest of DoUpdateNetworkInstance ")
803
804         try {
805             // get variables
806             String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
807             String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
808             String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
809
810             String networkId = ""
811             if (utils.nodeExists(updateNetworkInput, "network-id")) {
812                 networkId = utils.getNodeText(updateNetworkInput, "network-id")
813             }
814             if (networkId == null) {networkId = ""}
815
816             String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
817
818             AAIResultWrapper wrapper = execution.getVariable(Prefix + "queryIdAAIResponse")
819             L3Network queryAAIResponse = wrapper.asBean(L3Network.class).get()
820
821             // 1. prepare assign topology via SDNC Adapter SUBFLOW call
822             String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, queryAAIResponse, null)
823
824             String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
825             logger.debug(sndcTopologyUpdateRequesAsString)
826             execution.setVariable(Prefix + "changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
827             logger.debug(" UPDNETI_changeAssignSDNCRequest - " + "\n" +  sndcTopologyUpdateRequesAsString)
828
829
830         } catch (Exception ex) {
831             String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRequest() - " + ex.getMessage()
832             logger.debug(exceptionMessage)
833             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
834
835         }
836
837     }
838
839     public void validateSDNCResponse (DelegateExecution execution) {
840
841         execution.setVariable("prefix", Prefix)
842
843         logger.trace("Inside validateSDNCResponse of DoUpdateNetworkInstance ")
844
845         String response = execution.getVariable(Prefix + "changeAssignSDNCResponse")
846         WorkflowException workflowException = null
847         try {
848             workflowException = execution.getVariable(Prefix + "WorkflowException")
849             //execution.setVariable("WorkflowException", workflowException)
850         } catch (Exception ex) {
851             logger.debug(" Sdnc 'WorkflowException' object is empty or null. ")
852         }
853
854         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
855
856         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
857         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
858         // reset variable
859         String changeAssignSDNCResponseDecodeXml = execution.getVariable(Prefix + "changeAssignSDNCResponse")
860         changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace('<?xml version="1.0" encoding="UTF-8"?>', "")
861         execution.setVariable(Prefix + "changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
862
863         if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) {  // from sdnc util, prefix+'sdncResponseSuccess'
864             execution.setVariable(Prefix + "isSdncRollbackNeeded", true)
865             logger.debug("Successfully Validated SDNC Response")
866
867         } else {
868             logger.debug("Did NOT Successfully Validated SDNC Response")
869             throw new BpmnError("MSOWorkflowException")
870         }
871
872     }
873
874
875     public void postProcessResponse (DelegateExecution execution) {
876
877         execution.setVariable("prefix", Prefix)
878
879         logger.trace("Inside postProcessResponse of DoUpdateNetworkInstance ")
880
881         try {
882             logger.debug(" ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"))
883             if (execution.getVariable(Prefix + "isException") == false) {
884                 // set rollback data
885                 execution.setVariable("orchestrationStatus", "")
886                 execution.setVariable("networkId", execution.getVariable(Prefix + "networkId"))
887                 execution.setVariable("networkName", execution.getVariable(Prefix + "networkName"))
888                 prepareSuccessRollbackData(execution) // populate rollbackData
889                 execution.setVariable("WorkflowException", null)
890                 execution.setVariable(Prefix + "Success", true)
891                 logger.debug(" ***** postProcessResponse(), GOOD !!!")
892             } else {
893                 execution.setVariable(Prefix + "Success", false)
894                 execution.setVariable("rollbackData", null)
895                 String exceptionMessage = " Exception encountered in MSO Bpmn. "
896                 if (execution.getVariable("workflowException") != null) {  // Output of Rollback flow.
897                     logger.debug(" ***** workflowException: " + execution.getVariable("workflowException"))
898                     WorkflowException wfex = execution.getVariable("workflowException")
899                     exceptionMessage = wfex.getErrorMessage()
900                 } else {
901                     if (execution.getVariable(Prefix + "WorkflowException") != null) {
902                         WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
903                         exceptionMessage = pwfex.getErrorMessage()
904                     }
905                 }
906                 // going to the Main flow: a-la-carte or macro
907                 logger.debug(" ***** postProcessResponse(), BAD !!!")
908                 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
909                 throw new BpmnError("MSOWorkflowException")
910             }
911
912         } catch(BpmnError b){
913             logger.debug("Rethrowing MSOWorkflowException")
914             throw b
915
916
917         } catch (Exception ex) {
918             String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage()
919             logger.debug(exceptionMessage)
920             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
921
922         }
923
924
925     }
926
927     public void prepareSDNCRollbackRequest (DelegateExecution execution) {
928
929         execution.setVariable("prefix", Prefix)
930
931         logger.trace("Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ")
932
933         try {
934             // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException.
935             execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
936             // get variables
937             String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
938             String updateNetworkInput = execution.getVariable(Prefix + "networkRequest")
939             String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
940             String changeAssignSDNCResponse = execution.getVariable(Prefix + "changeAssignSDNCResponse")
941             String networkId = utils.getNodeText(changeAssignSDNCResponse, "network-id")
942
943             String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id")
944
945             // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
946             String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
947             String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
948             execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
949             logger.debug(" Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" +  sndcTopologyRollbackRequestAsString)
950
951         } catch (Exception ex) {
952             String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
953             logger.debug(exceptionMessage)
954             exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
955
956         }
957
958     }
959
960     public void prepareRollbackData(DelegateExecution execution) {
961
962         execution.setVariable("prefix",Prefix)
963
964         logger.trace("Inside prepareRollbackData() of DoUpdateNetworkInstance ")
965
966         try {
967
968             Map<String, String> rollbackData = new HashMap<String, String>();
969             String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
970             if (rollbackSDNCRequest != null) {
971                 if (rollbackSDNCRequest != "") {
972                     rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
973                 }
974             }
975             String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
976             if (rollbackNetworkRequest != null) {
977                 if (rollbackNetworkRequest != "") {
978                     rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
979                 }
980             }
981             execution.setVariable("rollbackData", rollbackData)
982             logger.debug("** rollbackData : " + rollbackData)
983
984             execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException"))
985             logger.debug("** WorkflowException : " + execution.getVariable("WorkflowException"))
986
987         } catch (Exception ex) {
988             String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
989             logger.debug(exceptionMessage)
990             exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
991
992         }
993
994     }
995
996     public void prepareSuccessRollbackData(DelegateExecution execution) {
997
998         execution.setVariable("prefix",Prefix)
999
1000         logger.trace("Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ")
1001
1002         try {
1003
1004             if (execution.getVariable("sdncVersion") != '1610') {
1005                 // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback.
1006             } else {
1007                 prepareSDNCRollbackRequest(execution)
1008             }
1009
1010             Map<String, String> rollbackData = new HashMap<String, String>();
1011             String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
1012             if (rollbackSDNCRequest != null) {
1013                 if (rollbackSDNCRequest != "") {
1014                     rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
1015                 }
1016             }
1017             String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
1018             if (rollbackNetworkRequest != null) {
1019                 if (rollbackNetworkRequest != "") {
1020                     rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
1021                 }
1022             }
1023             execution.setVariable("rollbackData", rollbackData)
1024
1025             logger.debug("** 'rollbackData' for Full Rollback : " + rollbackData)
1026             execution.setVariable("WorkflowException", null)
1027
1028
1029         } catch (Exception ex) {
1030             String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
1031             logger.debug(exceptionMessage)
1032             exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1033
1034         }
1035
1036     }
1037
1038     public void setExceptionFlag(DelegateExecution execution){
1039
1040         execution.setVariable("prefix",Prefix)
1041
1042         logger.trace("Inside setExceptionFlag() of DoUpdateNetworkInstance ")
1043
1044         try {
1045
1046             execution.setVariable(Prefix + "isException", true)
1047
1048             if (execution.getVariable("SavedWorkflowException1") != null) {
1049                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1050             } else {
1051                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1052             }
1053             logger.debug(Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"))
1054
1055         } catch(Exception ex){
1056             String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1057             logger.debug(exceptionMessage)
1058             exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1059         }
1060
1061     }
1062
1063
1064     // *******************************
1065     //     Build Error Section
1066     // *******************************
1067
1068     public void processJavaException(DelegateExecution execution){
1069
1070         execution.setVariable("prefix",Prefix)
1071         try{
1072             logger.debug("Caught a Java Exception")
1073             logger.debug("Started processJavaException Method")
1074             logger.debug("Variables List: " + execution.getVariables())
1075             execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - "  + Prefix)  // Adding this line temporarily until this flows error handling gets updated
1076             exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1077
1078         }catch(Exception e){
1079             logger.debug("Caught Exception during processJavaException Method: " + e)
1080             execution.setVariable("UnexpectedError", "Exception in processJavaException method")  // Adding this line temporarily until this flows error handling gets updated
1081             exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1082         }
1083         logger.debug("Completed processJavaException Method")
1084     }
1085
1086 }