dbe31528cfafc7fd6ce384a173aef84e2ad7295e
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
21
22 import org.openecomp.mso.bpmn.core.json.JsonUtils
23 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
24 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
25 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
26 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils
27 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
28 import org.openecomp.mso.bpmn.common.scripts.VidUtils
29 import org.openecomp.mso.bpmn.core.WorkflowException
30 import org.openecomp.mso.rest.APIResponse;
31 import org.openecomp.mso.rest.RESTClient
32 import org.openecomp.mso.rest.RESTConfig
33
34 import java.util.UUID;
35
36 import org.camunda.bpm.engine.delegate.BpmnError
37 import org.camunda.bpm.engine.runtime.Execution
38 import org.apache.commons.lang3.*
39 import org.apache.commons.codec.binary.Base64;
40 import org.springframework.web.util.UriUtils
41
42 import groovy.xml.XmlUtil
43 import groovy.json.*
44
45 public class DoDeleteNetworkInstance extends AbstractServiceTaskProcessor {
46         String Prefix= "DELNWKI_"
47         String groovyClassName = "DoDeleteNetworkInstance"
48         ExceptionUtil exceptionUtil = new ExceptionUtil()
49         JsonUtils jsonUtil = new JsonUtils()
50         VidUtils vidUtils = new VidUtils(this)
51         NetworkUtils networkUtils = new NetworkUtils()
52         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
53
54         public InitializeProcessVariables(Execution execution){
55                 /* Initialize all the process variables in this block */
56
57                 execution.setVariable(Prefix + "networkRequest", "")
58                 execution.setVariable(Prefix + "isSilentSuccess", false)
59                 execution.setVariable(Prefix + "Success", false)
60
61                 execution.setVariable(Prefix + "requestId", "")
62                 execution.setVariable(Prefix + "source", "")
63                 execution.setVariable(Prefix + "lcpCloudRegion", "")
64                 execution.setVariable(Prefix + "networkInputs", "")
65                 execution.setVariable(Prefix + "tenantId", "")
66
67                 execution.setVariable(Prefix + "queryAAIRequest","")
68                 execution.setVariable(Prefix + "queryAAIResponse", "")
69                 execution.setVariable(Prefix + "aaiReturnCode", "")
70                 execution.setVariable(Prefix + "isAAIGood", false)
71                 execution.setVariable(Prefix + "isVfRelationshipExist", false)
72
73                 // AAI query Cloud Region
74                 execution.setVariable(Prefix + "queryCloudRegionRequest","")
75                 execution.setVariable(Prefix + "queryCloudRegionReturnCode","")
76                 execution.setVariable(Prefix + "queryCloudRegionResponse","")
77                 execution.setVariable(Prefix + "cloudRegionPo","")
78                 execution.setVariable(Prefix + "cloudRegionSdnc","")
79
80                 execution.setVariable(Prefix + "deleteNetworkRequest", "")
81                 execution.setVariable(Prefix + "deleteNetworkResponse", "")
82                 execution.setVariable(Prefix + "networkReturnCode", "")
83                 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
84
85                 execution.setVariable(Prefix + "deleteSDNCRequest", "")
86                 execution.setVariable(Prefix + "deleteSDNCResponse", "")
87                 execution.setVariable(Prefix + "sdncReturnCode", "")
88                 execution.setVariable(Prefix + "sdncResponseSuccess", false)
89
90                 execution.setVariable(Prefix + "deactivateSDNCRequest", "")
91                 execution.setVariable(Prefix + "deactivateSDNCResponse", "")
92                 execution.setVariable(Prefix + "deactivateSdncReturnCode", "")
93                 execution.setVariable(Prefix + "isSdncDeactivateRollbackNeeded", "")
94                 
95                 execution.setVariable(Prefix + "rollbackDeactivateSDNCRequest", "")
96                 execution.setVariable(Prefix + "isException", false)
97                 
98
99         }
100         
101         // **************************************************
102         //     Pre or Prepare Request Section
103         // **************************************************
104
105         public void preProcessRequest (Execution execution) {
106                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
107                 execution.setVariable("prefix",Prefix)
108
109                 utils.log("DEBUG", " ***** Inside preProcessRequest() of " + groovyClassName + " Request ***** ", isDebugEnabled)
110
111                 // initialize flow variables
112                 InitializeProcessVariables(execution)
113                 
114                 try {
115                         // get incoming message/input
116                         execution.setVariable("action", "DELETE")
117                         String deleteNetwork = execution.getVariable("bpmnRequest")
118                         if (deleteNetwork != null) {
119                                 if (deleteNetwork.contains("requestDetails")) {
120                                         // JSON format request is sent, create xml 
121                                         try {
122                                                 def prettyJson = JsonOutput.prettyPrint(deleteNetwork.toString())
123                                                 utils.log("DEBUG", " Incoming message formatted . . . : " + '\n' + prettyJson, isDebugEnabled)
124                                                 deleteNetwork =  vidUtils.createXmlNetworkRequestInfra(execution, deleteNetwork)
125                 
126                                         } catch (Exception ex) {
127                                                 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
128                                                 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
129                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
130                                         }
131                                 } else {
132                                            // XML format request is sent
133                                            
134                                 }
135                         } else {
136                                         // vIPR format request is sent, create xml from individual variables
137                                 deleteNetwork = vidUtils.createXmlNetworkRequestInstance(execution)
138                         }
139                                 
140                         deleteNetwork = utils.formatXml(deleteNetwork)
141                         utils.logAudit(deleteNetwork)
142                         execution.setVariable(Prefix + "networkRequest", deleteNetwork)
143                         utils.log("DEBUG", Prefix + "networkRequest - " + '\n' + deleteNetwork, isDebugEnabled)
144                                 
145                         // validate 'backout-on-failure' to override 'URN_mso_rollback'
146                         boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, deleteNetwork)
147                         execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled)
148                         utils.log("DEBUG", Prefix + "rollbackEnabled - " + rollbackEnabled, isDebugEnabled)
149                         
150                         String networkInputs = utils.getNodeXml(deleteNetwork, "network-inputs", false).replace("tag0:","").replace(":tag0","")
151                         execution.setVariable(Prefix + "networkInputs", networkInputs)
152                         
153                         // prepare messageId
154                         String messageId = execution.getVariable("testMessageId")  // for testing
155                         if (messageId == null || messageId == "") {
156                                         messageId = UUID.randomUUID()
157                                         utils.log("DEBUG", Prefix + "messageId, random generated: " + messageId, isDebugEnabled)
158                         } else {
159                                         utils.log("DEBUG", Prefix + "messageId, pre-assigned: " + messageId, isDebugEnabled)
160                         }
161                         execution.setVariable(Prefix + "messageId", messageId)
162                                 
163                         String source = utils.getNodeText1(deleteNetwork, "source")
164                         execution.setVariable(Prefix + "source", source)
165                         utils.log("DEBUG", Prefix + "source - " + source, isDebugEnabled)
166                         
167                         String networkId = ""
168                         if (utils.nodeExists(networkInputs, "network-id")) {
169                                 networkId = utils.getNodeText1(networkInputs, "network-id")
170                                 if (networkId == null || networkId == "" || networkId == 'null' ) {
171                                         sendSyncError(execution)
172                                         // missing value of network-id
173                                         String dataErrorMessage = "network-request has missing 'network-id' element/value."
174                                         utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
175                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
176                                 }
177                         }
178
179                         // lcpCloudRegion or tenantId not sent, will be extracted from query AA&I
180                         def lcpCloudRegion = null
181                         if (utils.nodeExists(networkInputs, "aic-cloud-region")) {
182                                 lcpCloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
183                                 if (lcpCloudRegion == 'null') {
184                                         lcpCloudRegion = null
185                                 }
186                         }
187                         execution.setVariable(Prefix + "lcpCloudRegion", lcpCloudRegion)
188                         utils.log("DEBUG", "lcpCloudRegion : " + lcpCloudRegion, isDebugEnabled)
189                         
190                         String tenantId = null
191                         if (utils.nodeExists(networkInputs, "tenant-id")) {
192                                 tenantId = utils.getNodeText1(networkInputs, "tenant-id")
193                                 if (tenantId == 'null') {
194                                         tenantId = null
195                                 }
196
197                         }
198                         execution.setVariable(Prefix + "tenantId", tenantId)
199                         utils.log("DEBUG", "tenantId : " + tenantId, isDebugEnabled)
200                         
201                         String sdncVersion = execution.getVariable("sdncVersion")
202                         utils.log("DEBUG", "sdncVersion? : " + sdncVersion, isDebugEnabled)
203                         
204                         // PO Authorization Info / headers Authorization=
205                         String basicAuthValuePO = execution.getVariable("URN_mso_adapters_po_auth")
206                         utils.log("DEBUG", " Obtained BasicAuth userid password for PO/SDNC adapter: " + basicAuthValuePO, isDebugEnabled)
207                         try {
208                                 def encodedString = utils.getBasicAuth(basicAuthValuePO, execution.getVariable("URN_mso_msoKey"))
209                                 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
210                                 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
211         
212                         } catch (IOException ex) {
213                                 String dataErrorMessage = " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
214                                 utils.log("DEBUG", dataErrorMessage, , isDebugEnabled)
215                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
216                         }
217
218                 } catch (BpmnError e) {
219                         throw e;
220
221                 } catch (Exception ex){
222                          // caught exception
223                         String exceptionMessage = "Exception Encountered in DoDeleteNetworkInstance, PreProcessRequest() - " + ex.getMessage()
224                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
225                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
226
227                 }
228                 
229         }
230
231
232         public void callRESTQueryAAI (Execution execution) {
233                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
234                 execution.setVariable("prefix",Prefix)
235
236                 utils.log("DEBUG", " ***** Inside callRESTQueryAAI() of DoDoDeleteNetworkInstance ***** " , isDebugEnabled)
237
238                 // get variables
239                 String networkInputs  = execution.getVariable(Prefix + "networkInputs")
240                 String networkId   = utils.getNodeText(networkInputs, "network-id")
241                 networkId = UriUtils.encode(networkId,"UTF-8")
242                 String messageId = execution.getVariable(Prefix + "messageId")
243
244                 // Prepare AA&I url
245                 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
246                 AaiUtil aaiUriUtil = new AaiUtil(this)
247                 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
248                 String queryAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId
249                 utils.logAudit(queryAAIRequest)
250                 execution.setVariable(Prefix + "queryAAIRequest", queryAAIRequest)
251                 utils.log("DEBUG", Prefix + "AAIRequest - " + "\n" + queryAAIRequest, isDebugEnabled)
252
253                 RESTConfig config = new RESTConfig(queryAAIRequest);
254
255                 ExceptionUtil exceptionUtil = new ExceptionUtil()
256                 Boolean isVfRelationshipExist = false
257                 try {
258                         RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
259                                                                                                           .addHeader("X-FromAppId", "MSO")
260                                                                                                           .addHeader("Content-Type", "application/xml")
261                                                                                                           .addHeader("Accept","application/xml");
262                         APIResponse response = client.get()
263                         String returnCode = response.getStatusCode()
264                         execution.setVariable(Prefix + "aaiReturnCode", returnCode)
265
266                         utils.log("DEBUG", " ***** AAI Response Code  : " + returnCode, isDebugEnabled)
267
268                         String aaiResponseAsString = response.getResponseBodyAsString()
269                         aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
270                         execution.setVariable(Prefix + "queryAAIResponse", aaiResponseAsString)
271
272                         if (returnCode=='200' || returnCode=='204') {
273                                 utils.logAudit(aaiResponseAsString)
274                                 execution.setVariable(Prefix + "isAAIGood", true)
275                                 utils.log("DEBUG", " AAI Query Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
276                                 // verify if vf or vnf relationship exist
277                                 if (utils.nodeExists(aaiResponseAsString, "relationship")) {
278                                         NetworkUtils networkUtils = new NetworkUtils()
279                                 isVfRelationshipExist = networkUtils.isVfRelationshipExist(aaiResponseAsString)
280                                         execution.setVariable(Prefix + "isVfRelationshipExist", isVfRelationshipExist)
281                                         if (isVfRelationshipExist == true) {
282                                                 String relationshipMessage = "AAI Query Success Response but 'vf-module' relationship exist, not allowed to delete: network Id: " + networkId
283                                                 exceptionUtil.buildWorkflowException(execution, 2500, relationshipMessage)
284
285                                         } else {
286                                             // verify if lcpCloudRegion was sent as input, if not get value from AAI Response 
287                                             if (execution.getVariable(Prefix + "lcpCloudRegion") == null ) {
288                                                         String lcpCloudRegion = networkUtils.getCloudRegion(aaiResponseAsString)
289                                                         execution.setVariable(Prefix + "lcpCloudRegion", lcpCloudRegion)
290                                                         utils.log("DEBUG", " Get AAI getCloudRegion()  : " + lcpCloudRegion, isDebugEnabled)
291                                                 }
292                                                 if (execution.getVariable(Prefix + "tenantId") == null ) {
293                                                         String tenantId = networkUtils.getTenantId(aaiResponseAsString)
294                                                         execution.setVariable(Prefix + "tenantId", tenantId)
295                                                         utils.log("DEBUG", " Get AAI getTenantId()  : " + tenantId, isDebugEnabled)
296                                                 }
297                                         
298                                         }
299                                 }
300                                 utils.log("DEBUG", Prefix + "isVfRelationshipExist - " + isVfRelationshipExist, isDebugEnabled)
301
302                         } else {
303                                 execution.setVariable(Prefix + "isAAIGood", false)
304                             if (returnCode=='404' || aaiResponseAsString == "" || aaiResponseAsString == null) {
305                                         // not found // empty aai response
306                                         execution.setVariable(Prefix + "isSilentSuccess", true)
307                                         utils.log("DEBUG", " AAI Query is Silent Success", isDebugEnabled)
308
309                                 } else {
310                                    if (aaiResponseAsString.contains("RESTFault")) {
311                                            WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
312                                            execution.setVariable("WorkflowException", exceptionObject)
313
314                                    } else {
315                                   // aai all errors
316                                                  String dataErrorMessage = "Unexpected Error Response from callRESTQueryAAI() - " + returnCode
317                                                  utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
318                                                  exceptionUtil.buildWorkflowException(execution, 2500, dataErrorMessage)
319
320                               }
321                                 }
322                         }
323
324                         utils.log("DEBUG", " AAI Query call, isAAIGood? : " + execution.getVariable(Prefix + "isAAIGood"), isDebugEnabled)
325
326                 } catch (Exception ex) {
327                    // caught exception
328                    String exceptionMessage = "Exception Encountered in DoDeleteNetworkInstance, callRESTQueryAAI() - " + ex.getMessage()
329                    utils.log("DEBUG", exceptionMessage, isDebugEnabled)
330                    exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
331
332                 }
333
334         }
335
336         public void callRESTQueryAAICloudRegion (Execution execution) {
337                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
338                 execution.setVariable("prefix", Prefix)
339
340                 utils.log("DEBUG", " ***** Inside callRESTQueryAAICloudRegion of DoDeleteNetworkInstance ***** " , isDebugEnabled)
341
342                 try {
343                         String networkInputs  = execution.getVariable(Prefix + "networkInputs")
344                         // String cloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
345                         String cloudRegion = execution.getVariable(Prefix + "lcpCloudRegion")
346                         cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
347                         // Prepare AA&I url
348                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
349                         AaiUtil aaiUtil = new AaiUtil(this)
350                         String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
351                         String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
352                         utils.logAudit(queryCloudRegionRequest)
353                         execution.setVariable(Prefix + "queryCloudRegionRequest", queryCloudRegionRequest)
354                         utils.log("DEBUG", Prefix + "queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugEnabled)
355
356                         String cloudRegionPo = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
357                         String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "SDNC", cloudRegion)
358
359                         if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
360                                 execution.setVariable(Prefix + "cloudRegionPo", cloudRegionPo)
361                                 execution.setVariable(Prefix + "cloudRegionSdnc", cloudRegionSdnc)
362
363                         } else {
364                                 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable(Prefix + "queryCloudRegionReturnCode")
365                                 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
366                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
367
368                         }
369
370                 } catch (BpmnError e) {
371                 throw e;
372
373                 } catch (Exception ex) {
374                         // caught exception
375                         String exceptionMessage = "Bpmn error encountered in DoDeleteNetworkInstance, callRESTQueryAAICloudRegion(). Unexpected Response from AAI - " + ex.getMessage()
376                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
377                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
378
379                 }
380
381         }
382
383         public void prepareNetworkRequest (Execution execution) {
384                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
385                 execution.setVariable("prefix", Prefix)
386
387                 utils.log("DEBUG", " ***** Inside prepareNetworkRequest of DoDeleteNetworkInstance ***** ", isDebugEnabled)
388                 ExceptionUtil exceptionUtil = new ExceptionUtil()
389                 try {
390                         // get variables
391                         String networkInputs = execution.getVariable(Prefix + "networkInputs")
392                         String cloudSiteId = execution.getVariable(Prefix + "cloudRegionPo")
393                         String tenantId = execution.getVariable(Prefix + "tenantId")
394
395                         String queryAAIResponse = execution.getVariable(Prefix + "queryAAIResponse")
396                         String networkType = utils.getNodeText1(queryAAIResponse, "network-type")
397                         String networkId = utils.getNodeText1(queryAAIResponse, "network-id")
398                         String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled")
399                         
400                         String networkStackId = ""
401                         networkStackId = utils.getNodeText1(queryAAIResponse, "heat-stack-id")
402                         if (networkStackId == 'null' || networkStackId == "") {
403                                 networkStackId = "force_delete"
404                         }
405
406                         String requestId = execution.getVariable(Prefix + "requestId")
407                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
408
409                         // Added new Elements
410                         String messageId = execution.getVariable(Prefix + "messageId")
411                         String notificationUrl = ""                                   //TODO - is this coming from URN? What variable/value to use?
412                         //String notificationUrl = execution.getVariable("URN_?????") //TODO - is this coming from URN? What variable/value to use?
413
414                         String deleteNetworkRequest = """
415                                           <deleteNetworkRequest>
416                                             <cloudSiteId>${cloudSiteId}</cloudSiteId>
417                                             <tenantId>${tenantId}</tenantId>
418                                             <networkId>${networkId}</networkId>
419                                                 <networkStackId>${networkStackId}</networkStackId>
420                                             <networkType>${networkType}</networkType>
421                                                 <skipAAI>true</skipAAI>
422                                             <msoRequest>
423                                                <requestId>${requestId}</requestId>
424                                                <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
425                                             </msoRequest>
426                                                 <messageId>${messageId}</messageId>
427                                                 <notificationUrl>${notificationUrl}</notificationUrl>
428                                           </deleteNetworkRequest>
429                                                 """.trim()
430
431                         utils.log("DEBUG", Prefix + "deleteNetworkRequest - " + "\n" +  deleteNetworkRequest, isDebugEnabled)
432                         // Format Response
433                         String buildDeleteNetworkRequestAsString = utils.formatXml(deleteNetworkRequest)
434                         utils.logAudit(buildDeleteNetworkRequestAsString)
435                         utils.log("DEBUG", Prefix + "deleteNetworkRequestAsString - " + "\n" +  buildDeleteNetworkRequestAsString, isDebugEnabled)
436
437                         String restURL = execution.getVariable("URN_mso_adapters_network_rest_endpoint")
438                         execution.setVariable("URN_mso_adapters_network_rest_endpoint", restURL + "/" + networkId)
439                         utils.log("DEBUG", "URN_mso_adapters_network_rest_endpoint - " + "\n" +  restURL + "/" + networkId, isDebugEnabled)
440
441                         execution.setVariable(Prefix + "deleteNetworkRequest", buildDeleteNetworkRequestAsString)
442                         utils.log("DEBUG", Prefix + "deleteNetworkRequest - " + "\n" +  buildDeleteNetworkRequestAsString, isDebugEnabled)
443                 }
444                 catch (Exception ex) {
445                         // caught exception
446                         String exceptionMessage = "Bpmn error encountered in DoDeleteNetworkInstance, prepareNetworkRequest(). Unexpected Response from AAI - " + ex.getMessage()
447                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
448                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
449
450                 }
451         }
452
453         /**
454          * This method is used instead of an HTTP Connector task because the
455          * connector does not allow DELETE with a body.
456          */
457         public void sendRequestToVnfAdapter(Execution execution) {
458                 def method = getClass().getSimpleName() + '.sendRequestToVnfAdapter(' +
459                         'execution=' + execution.getId() +
460                         ')'
461                 def isDebugEnabled = execution.getVariable('isDebugLogEnabled')
462                 logDebug('Entered ' + method, isDebugEnabled)
463
464                 try {
465
466                         String vnfAdapterUrl = execution.getVariable("URN_mso_adapters_network_rest_endpoint")
467                         String vnfAdapterRequest = execution.getVariable(Prefix + "deleteNetworkRequest")
468
469                         RESTConfig config = new RESTConfig(vnfAdapterUrl)
470                         RESTClient client = new RESTClient(config).
471                                 addHeader("Content-Type", "application/xml").
472                                 addAuthorizationHeader(execution.getVariable("BasicAuthHeaderValuePO"));
473
474                         APIResponse response;
475
476                         response = client.httpDelete(vnfAdapterRequest)
477
478                         execution.setVariable(Prefix + "networkReturnCode", response.getStatusCode())
479                         execution.setVariable(Prefix + "deleteNetworkResponse", response.getResponseBodyAsString())
480
481                 } catch (Exception ex) {
482                         // caught exception
483                         String exceptionMessage = "Bpmn error encountered in DoDeleteNetworkInstance, sendRequestToVnfAdapter() - " + ex.getMessage()
484                         logError(exceptionMessage)
485                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
486                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
487
488                 }
489         }
490
491
492         public void prepareSDNCRequest (Execution execution) {
493                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
494                 execution.setVariable("prefix", Prefix)
495
496                 utils.log("DEBUG", " ***** Inside prepareSDNCRequest of DoDeleteNetworkInstance ***** ", isDebugEnabled)
497
498                 try {
499                         // get variables
500                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
501                         String deleteNetworkInput = execution.getVariable(Prefix + "networkRequest")
502
503                         String networkId = ""
504                         if (utils.nodeExists(deleteNetworkInput, "network-id")) {
505                                 networkId = utils.getNodeText1(deleteNetworkInput, "network-id")
506                         }
507                         if (networkId == 'null') {networkId = ""}
508                         
509                         String serviceInstanceId = utils.getNodeText1(deleteNetworkInput, "service-instance-id")
510
511                         // get/set 'msoRequestId' and 'mso-request-id'
512                         String requestId = execution.getVariable("msoRequestId")
513                         if (requestId != null) {
514                                 execution.setVariable("mso-request-id", requestId)
515                         } else {
516                             requestId = execution.getVariable("mso-request-id")
517                         }       
518                         execution.setVariable(Prefix + "requestId", requestId)
519                         
520                         String queryAAIResponse = execution.getVariable(Prefix + "queryAAIResponse")
521                         
522                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
523                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
524                         // 1. prepare delete topology via SDNC Adapter SUBFLOW call
525                         String sndcTopologyDeleteRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, deleteNetworkInput, serviceInstanceId, sdncCallback, "delete", "DisconnectNetworkRequest", cloudRegionId, networkId, queryAAIResponse, null)
526                     String sndcTopologyDeleteRequesAsString = utils.formatXml(sndcTopologyDeleteRequest)
527                         utils.logAudit(sndcTopologyDeleteRequesAsString)
528                         execution.setVariable(Prefix + "deleteSDNCRequest", sndcTopologyDeleteRequesAsString)
529                         utils.log("DEBUG", Prefix + "deleteSDNCRequest - " + "\n" +  sndcTopologyDeleteRequesAsString, isDebugEnabled)
530
531                 } catch (Exception ex) {
532                         // caught exception
533                         String exceptionMessage = "Bpmn error encountered in DoDeleteNetworkInstance, prepareSDNCRequest() - " + ex.getMessage()
534                         logError(exceptionMessage)
535                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
536                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
537
538                 }
539
540         }
541
542         public void prepareRpcSDNCRequest (Execution execution) {
543                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
544                 execution.setVariable("prefix", Prefix)
545
546                 utils.log("DEBUG", " ***** Inside prepareRpcSDNCRequest of DoDeleteNetworkInstance ***** ", isDebugEnabled)
547
548                 try {
549                         // get variables
550                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
551                         String deleteNetworkInput = execution.getVariable(Prefix + "networkRequest")
552
553                         String networkId = ""
554                         if (utils.nodeExists(deleteNetworkInput, "network-id")) {
555                                 networkId = utils.getNodeText1(deleteNetworkInput, "network-id")
556                         }
557                         if (networkId == 'null') {networkId = ""}
558
559                         String serviceInstanceId = utils.getNodeText1(deleteNetworkInput, "service-instance-id")
560                         
561                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
562                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
563                         // 1. prepare delete topology via SDNC Adapter SUBFLOW call
564                         String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, deleteNetworkInput, serviceInstanceId, sdncCallback, "unassign", "DeleteNetworkInstance", cloudRegionId, networkId, null)
565                         String sndcTopologyDeleteRequesAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
566                         utils.logAudit(sndcTopologyDeleteRequesAsString)
567                         execution.setVariable(Prefix + "deleteSDNCRequest", sndcTopologyDeleteRequesAsString)
568                         utils.log("DEBUG", Prefix + "deleteSDNCRequest - " + "\n" +  sndcTopologyDeleteRequesAsString, isDebugEnabled)
569
570                 } catch (Exception ex) {
571                         // caught exception
572                         String exceptionMessage = "Bpmn error encountered in DoDeleteNetworkInstance, prepareSDNCRequest() - " + ex.getMessage()
573                         logError(exceptionMessage)
574                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
575                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
576
577                 }
578
579         }
580         
581         
582         public void prepareRpcSDNCDeactivate(Execution execution) {
583                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
584                 execution.setVariable("prefix",Prefix)
585
586                 utils.log("DEBUG", " ***** Inside prepareRpcSDNCDeactivate() of DoDeleteNetworkInstance ***** ", isDebugEnabled)
587
588                 try {
589                 
590                         // get variables
591                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
592                         String deleteNetworkInput = execution.getVariable(Prefix + "networkRequest")
593                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
594                         String networkId = ""
595                         if (utils.nodeExists(deleteNetworkInput, "network-id")) {
596                                 networkId = utils.getNodeText1(deleteNetworkInput, "network-id")
597                         }
598                         if (networkId == 'null') {networkId = ""}
599                         String serviceInstanceId = utils.getNodeText1(deleteNetworkInput, "service-instance-id")
600                         
601                         String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, deleteNetworkInput, serviceInstanceId, sdncCallback, "deactivate", "DeleteNetworkInstance", cloudRegionId, networkId, null)
602                         String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
603                         execution.setVariable(Prefix + "deactivateSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
604                         utils.log("DEBUG", " Preparing request for RPC SDNC Topology deactivate - " + "\n" +  sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
605
606
607                 } catch (Exception ex) {
608                         String exceptionMessage = " Bpmn error encountered in DoDeleteNetworkInstance flow. prepareRpcSDNCActivateRollback() - " + ex.getMessage()
609                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
610                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
611
612                 }
613
614         }
615         
616         // **************************************************
617         //     Post or Validate Response Section
618         // **************************************************
619
620         public void validateNetworkResponse (Execution execution) {
621                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
622                 execution.setVariable("prefix", Prefix)
623
624                 utils.log("DEBUG", " ***** Inside validateNetworkResponse of DoDeleteNetworkInstance *****", isDebugEnabled)
625
626                 try {
627                         String returnCode = execution.getVariable(Prefix + "networkReturnCode")
628                         String networkResponse = execution.getVariable(Prefix + "deleteNetworkResponse")
629
630                         utils.log("DEBUG", " Network Adapter responseCode: " + returnCode, isDebugEnabled)
631                         utils.log("DEBUG", "Network Adapter Response - " + "\n" + networkResponse, isDebugEnabled)
632                         utils.logAudit(networkResponse)
633                         
634                         String errorMessage = ""
635                         if (returnCode == "200") {
636                                 utils.log("DEBUG", " Network Adapter Response is successful - " + "\n" + networkResponse, isDebugEnabled)
637
638                                 // prepare rollback data
639                                 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
640                                 if ((rollbackData == null) || (rollbackData.isEmpty())) {
641                                         utils.log("DEBUG", " Network Adapter 'rollback' data is not Sent: " + "\n" + networkResponse, isDebugEnabled)
642                                         execution.setVariable(Prefix + "rollbackNetworkRequest", "")
643                                 } else {
644                                     String rollbackNetwork =
645                                           """<NetworkAdapter:rollbackNetwork xmlns:NetworkAdapter="http://org.openecomp.mso/network">
646                                                         ${rollbackData}
647                                                  </NetworkAdapter:rollbackNetwork>"""
648                                     String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
649                                     execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkXml)
650                                     utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
651                                 }       
652                                 
653                                 
654                         } else { // network error
655                            if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) {   //4xx, 5xx
656                                    if (networkResponse.contains("deleteNetworkError")  ) {
657                                            networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
658                                            errorMessage  = utils.getNodeText1(networkResponse, "message")
659                                            errorMessage  = "Received error from Network Adapter: " + errorMessage
660                                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
661
662                                    } else { // CatchAll exception
663                                            if (returnCode == "500") {
664                                                    errorMessage = "JBWEB000065: HTTP Status 500."
665                                        } else {
666                                                errorMessage = "Return code is " + returnCode
667                                        }
668                                            errorMessage  = "Received error from Network Adapter: " + errorMessage
669                                            exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
670
671                                    }
672
673                            } else { // CatchAll exception
674                                    String dataErrorMessage  = "Received error from Network Adapter. Return code is: " + returnCode
675                                    exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
676
677                            }
678
679                         }
680
681                 } catch (BpmnError e) {
682                         throw e;
683
684                 } catch (Exception ex) {
685                         // caught exception
686                         String exceptionMessage = "Bpmn error encountered in DoDeleteNetworkInstance, validateNetworkResponse() - " + ex.getMessage()
687                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
688                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
689
690                 }
691
692         }
693
694         public void validateSDNCResponse (Execution execution) {
695                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
696                 execution.setVariable("prefix", Prefix)
697
698                 utils.log("DEBUG", " ***** Inside validateSDNCResponse of DoDeleteNetworkInstance ***** ", isDebugEnabled)
699
700                 String response = execution.getVariable(Prefix + "deleteSDNCResponse")
701                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
702                 WorkflowException workflowException = execution.getVariable("WorkflowException")
703
704                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
705                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
706                 // reset variable
707                 String deleteSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "deleteSDNCResponse"))
708                 deleteSDNCResponseDecodeXml = deleteSDNCResponseDecodeXml.replace("&", "&amp;").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
709                 execution.setVariable(Prefix + "deleteSDNCResponse", deleteSDNCResponseDecodeXml)
710
711                 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) {  // from sdnc util, prefix+'sdncResponseSuccess'
712                         execution.setVariable(Prefix + "isSdncRollbackNeeded", true)      //
713                         execution.setVariable(Prefix + "isPONR", true)
714                         utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
715                 } else {
716                         utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
717                         throw new BpmnError("MSOWorkflowException")
718                 }
719
720         }
721
722         public void validateRpcSDNCDeactivateResponse (Execution execution) {
723                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
724                 execution.setVariable("prefix",Prefix)
725
726                 utils.log("DEBUG", " ***** Inside validateRpcSDNCDeactivateResponse() of DoDeleteNetworkInstance ***** ", isDebugEnabled)
727
728                 String response = execution.getVariable(Prefix + "deactivateSDNCResponse")
729                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
730                 WorkflowException workflowException = execution.getVariable("WorkflowException")
731
732                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
733                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
734                 // reset variable
735                 String assignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable(Prefix + "deactivateSDNCResponse"))
736                 assignSDNCResponseDecodeXml = assignSDNCResponseDecodeXml.replace("&", "&amp;").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
737                 execution.setVariable(Prefix + "deactivateSDNCResponse", assignSDNCResponseDecodeXml)
738
739                 if (execution.getVariable(Prefix + "sdncResponseSuccess") == true) {  // from sdnc util, Prefix+'sdncResponseSuccess'
740                         execution.setVariable(Prefix + "isSdncDeactivateRollbackNeeded", true)
741                         utils.log("DEBUG", "Successfully Validated Rpc SDNC Activate Response", isDebugEnabled)
742
743                 } else {
744                         utils.log("DEBUG", "Did NOT Successfully Validated Rpc SDNC Deactivate Response", isDebugEnabled)
745                         throw new BpmnError("MSOWorkflowException")
746                 }
747
748         }
749         
750         public void prepareRpcSDNCDeactivateRollback(Execution execution) {
751                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
752                 execution.setVariable("prefix",Prefix)
753
754                 utils.log("DEBUG", " ***** Inside prepareRpcSDNCDeactivateRollback() of DoDeleteNetworkInstance ***** ", isDebugEnabled)
755
756                 try {
757                 
758                         // get variables
759                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
760                         String deleteNetworkInput = execution.getVariable(Prefix + "networkRequest")
761                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
762                         String deactivateSDNCResponse = execution.getVariable(Prefix + "deactivateSDNCResponse")
763                         String networkId = utils.getNodeText1(deactivateSDNCResponse, "network-id")
764                         if (networkId == 'null') {networkId = ""}
765                         String serviceInstanceId = utils.getNodeText1(deleteNetworkInput, "service-instance-id")
766
767                         // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
768                         String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, deleteNetworkInput, serviceInstanceId, sdncCallback, "activate", "ActivateNetworkInstance", cloudRegionId, networkId, null)
769                         String sndcTopologyRollbackRpcRequestAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
770                         execution.setVariable(Prefix + "rollbackDeactivateSDNCRequest", sndcTopologyRollbackRpcRequestAsString)
771                         utils.log("DEBUG", " Preparing request for RPC SDNC Topology 'activate-ActivateNetworkInstance' rollback . . . - " + "\n" +  sndcTopologyRollbackRpcRequestAsString, isDebugEnabled)
772
773
774                 } catch (Exception ex) {
775                         String exceptionMessage = " Bpmn error encountered in DoDeleteNetworkInstance flow. prepareRpcSDNCDeactivateRollback() - " + ex.getMessage()
776                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
777                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
778
779                 }
780
781         }
782         
783         public void prepareRollbackData(Execution execution) {
784                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
785                 execution.setVariable("prefix",Prefix)
786                 
787                 utils.log("DEBUG", " ***** Inside prepareRollbackData() of DoDeleteNetworkInstance ***** ", isDebugEnabled)
788                 
789                 try {
790                         
791                         Map<String, String> rollbackData = new HashMap<String, String>();
792                         String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
793                         if (rollbackNetworkRequest != null) {
794                                 if (rollbackNetworkRequest != "") {
795                                    rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
796                             }
797                         }       
798                         String rollbackDeactivateSDNCRequest = execution.getVariable(Prefix + "rollbackDeactivateSDNCRequest")
799                         if (rollbackDeactivateSDNCRequest != null) {
800                                 if (rollbackDeactivateSDNCRequest != "") {
801                                 rollbackData.put("rollbackDeactivateSDNCRequest", execution.getVariable(Prefix + "rollbackDeactivateSDNCRequest"))
802                             }
803                         }               
804                         execution.setVariable("rollbackData", rollbackData)
805                         utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
806                         
807                         execution.setVariable("WorkflowException", execution.getVariable("WorkflowException"))
808                         utils.log("DEBUG", "** WorkflowException : " + execution.getVariable("WorkflowException"), isDebugEnabled)
809                         
810                 } catch (Exception ex) {
811                         String exceptionMessage = " Bpmn error encountered in DoDeleteNetworkInstance flow. prepareRollbackData() - " + ex.getMessage()
812                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
813                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
814                 
815                 }
816                 
817         }
818         
819         public void postProcessResponse (Execution execution) {
820                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
821                 execution.setVariable("prefix", Prefix)
822
823                 utils.log("DEBUG", " ***** Inside postProcessResponse of DoDeleteNetworkInstance ***** ", isDebugEnabled)
824
825                 try {
826                         
827                         utils.log("DEBUG", " ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException"), isDebugEnabled)
828                         if (execution.getVariable(Prefix + "isException") == false) {
829                                 execution.setVariable(Prefix + "Success", true)
830                                 execution.setVariable("WorkflowException", null)
831                                 if (execution.getVariable(Prefix + "isSilentSuccess") == true) {
832                                         execution.setVariable("rolledBack", false)
833                                 } else {
834                                     execution.setVariable("rolledBack", true) 
835                                 }
836                                 prepareSuccessRollbackData(execution) // populate rollbackData
837                                 
838                         } else {
839                                 execution.setVariable(Prefix + "Success", false)
840                                 execution.setVariable("rollbackData", null)
841                                 String exceptionMessage = " Exception encountered in MSO Bpmn. "
842                                 if (execution.getVariable("workflowException") != null) {  // Output of Rollback flow.
843                                    utils.log("DEBUG", " ***** workflowException: " + execution.getVariable("workflowException"), isDebugEnabled)
844                                    WorkflowException wfex = execution.getVariable("workflowException")
845                                    exceptionMessage = wfex.getErrorMessage()
846                                 } else {
847                                if (execution.getVariable(Prefix + "WorkflowException") != null) {
848                                       WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException")
849                                       exceptionMessage = pwfex.getErrorMessage()
850                                }   
851                                 }
852                                 // going to the Main flow: a-la-carte or macro
853                                 utils.log("DEBUG", " ***** postProcessResponse(), BAD !!!", isDebugEnabled)
854                                 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
855                                 throw new BpmnError("MSOWorkflowException")
856                                  
857                         }       
858                         
859                 } catch(BpmnError b){
860                     utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
861                     throw b
862                         
863                 } catch (Exception ex) {
864                         // caught exception
865                         String exceptionMessage = "Bpmn error encountered in DoDeleteNetworkInstance, postProcessResponse() - " + ex.getMessage()
866                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
867                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
868                         throw new BpmnError("MSOWorkflowException")
869                         
870         }
871
872         }
873
874         public void prepareSuccessRollbackData(Execution execution) {
875                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
876                 execution.setVariable("prefix",Prefix)
877                 
878                 utils.log("DEBUG", " ***** Inside prepareSuccessRollbackData() of DoDeleteNetworkInstance ***** ", isDebugEnabled)
879                 
880                 try {
881                         
882                         if (execution.getVariable("sdncVersion") == '1702') {
883                                 prepareRpcSDNCDeactivateRollback(execution)
884                                 prepareRpcSDNCUnassignRollback(execution)
885                         } else {
886                             prepareSDNCRollback(execution)
887                         }       
888                         
889                         Map<String, String> rollbackData = new HashMap<String, String>();
890                         String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest")
891                         if (rollbackSDNCRequest != null) {
892                                 if (rollbackSDNCRequest != "") {
893                                    rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest"))
894                                 }
895                         }
896                         String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest")
897                         if (rollbackNetworkRequest != null) {
898                                 if (rollbackNetworkRequest != "") {
899                                    rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest"))
900                             }
901                         }       
902                         String rollbackDeactivateSDNCRequest = execution.getVariable(Prefix + "rollbackDeactivateSDNCRequest")
903                         if (rollbackDeactivateSDNCRequest != null) {
904                                 if (rollbackDeactivateSDNCRequest != "") {
905                                 rollbackData.put("rollbackDeactivateSDNCRequest", execution.getVariable(Prefix + "rollbackDeactivateSDNCRequest"))
906                             }
907                         }               
908                         execution.setVariable("rollbackData", rollbackData)
909                         
910                         utils.log("DEBUG", "** rollbackData : " + rollbackData, isDebugEnabled)
911                         execution.setVariable("WorkflowException", null)
912
913                         
914                 } catch (Exception ex) {
915                         String exceptionMessage = " Bpmn error encountered in DoDeleteNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage()
916                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
917                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
918                 
919                 }
920                 
921         }
922
923         public void prepareRpcSDNCUnassignRollback(Execution execution) {
924                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
925                 execution.setVariable("prefix",Prefix)
926
927                 utils.log("DEBUG", " ***** Inside prepareRpcSDNCUnassignRollbac() of DoDeleteNetworkInstance ***** ", isDebugEnabled)
928
929                 try {
930                 
931                         // get variables
932                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
933                         String deleteNetworkInput = execution.getVariable(Prefix + "networkRequest")
934
935                         String deleteSDNCResponse = execution.getVariable(Prefix + "deleteSDNCResponse")
936                         String networkId = utils.getNodeText1(deleteSDNCResponse, "network-id")
937                         if (networkId == 'null') {networkId = ""}
938                         String serviceInstanceId = utils.getNodeText1(deleteNetworkInput, "service-instance-id")
939                                 
940                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
941                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
942                         // 1. prepare delete topology via SDNC Adapter SUBFLOW call
943                         String sndcTopologyRollbackRpcRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, deleteNetworkInput, serviceInstanceId, sdncCallback, "assign", "CreateNetworkInstance", cloudRegionId, networkId, null)
944                         String sndcTopologyDeleteRequesAsString = utils.formatXml(sndcTopologyRollbackRpcRequest)
945                         utils.logAudit(sndcTopologyDeleteRequesAsString)
946                         execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyDeleteRequesAsString)
947                         utils.log("DEBUG", Prefix + "rollbackSDNCRequest" + "\n" +  sndcTopologyDeleteRequesAsString, isDebugEnabled)
948                         utils.log("DEBUG", " Preparing request for RPC SDNC Topology 'assign-CreateNetworkInstance' rollback . . . - " + "\n" +  sndcTopologyDeleteRequesAsString, isDebugEnabled)
949         
950
951                 } catch (Exception ex) {
952                         String exceptionMessage = " Bpmn error encountered in DoDeleteNetworkInstance flow. prepareRpcSDNCUnassignRollback() - " + ex.getMessage()
953                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
954                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
955
956                 }
957
958         }
959         
960         public void prepareSDNCRollback (Execution execution) {
961                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
962                 execution.setVariable("prefix", Prefix)
963
964                 utils.log("DEBUG", " ***** Inside prepareSDNCRollback of DoDeleteNetworkInstance ***** ", isDebugEnabled)
965
966                 try {
967                         
968                         // get variables
969                         String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
970                         String deleteNetworkInput = execution.getVariable(Prefix + "networkRequest")
971
972                         String networkId = ""
973                         if (utils.nodeExists(deleteNetworkInput, "network-id")) {
974                                 networkId = utils.getNodeText1(deleteNetworkInput, "network-id")
975                         }
976                         if (networkId == 'null') {networkId = ""}
977                         
978                         String serviceInstanceId = utils.getNodeText1(deleteNetworkInput, "service-instance-id")
979
980                         // get/set 'msoRequestId' and 'mso-request-id'
981                         String requestId = execution.getVariable("msoRequestId")
982                         if (requestId != null) {
983                                 execution.setVariable("mso-request-id", requestId)
984                         } else {
985                             requestId = execution.getVariable("mso-request-id")
986                         }       
987                         execution.setVariable(Prefix + "requestId", requestId)
988                         
989                         String queryAAIResponse = execution.getVariable(Prefix + "queryAAIResponse")
990                         
991                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
992                         String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc")
993                         // 1. prepare delete topology via SDNC Adapter SUBFLOW call
994                         String sndcTopologyDeleteRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, deleteNetworkInput, serviceInstanceId, sdncCallback, "rollback", "DisconnectNetworkRequest", cloudRegionId, networkId, queryAAIResponse, null)
995                     String sndcTopologyDeleteRequesAsString = utils.formatXml(sndcTopologyDeleteRequest)
996                         utils.logAudit(sndcTopologyDeleteRequesAsString)
997                         execution.setVariable(Prefix + "rollbackSDNCRequest", sndcTopologyDeleteRequesAsString)
998                         utils.log("DEBUG", Prefix + "rollbackSDNCRequest - " + "\n" +  sndcTopologyDeleteRequesAsString, isDebugEnabled)
999                         utils.log("DEBUG", " Preparing request for RPC SDNC Topology 'rollback-DisconnectNetworkRequest' rollback . . . - " + "\n" +  sndcTopologyDeleteRequesAsString, isDebugEnabled)
1000
1001
1002                 } catch (Exception ex) {
1003                         // caught exception
1004                         String exceptionMessage = "Bpmn error encountered in DoDeleteNetworkInstance, prepareSDNCRollback() - " + ex.getMessage()
1005                         logError(exceptionMessage)
1006                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1007                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1008
1009                 }
1010
1011         }
1012         
1013         public void setExceptionFlag(Execution execution){
1014                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1015                 execution.setVariable("prefix",Prefix)
1016                 
1017                 utils.log("DEBUG", " ***** Inside setExceptionFlag() of DoDeleteNetworkInstance ***** ", isDebugEnabled)
1018                 
1019                 try {
1020
1021                         execution.setVariable(Prefix + "isException", true)
1022                         
1023                         if (execution.getVariable("SavedWorkflowException1") != null) {
1024                                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
1025                         } else {
1026                                 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
1027                         }
1028                         utils.log("DEBUG", Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException"), isDebugEnabled)
1029                         
1030                 } catch(Exception ex){
1031                           String exceptionMessage = "Bpmn error encountered in DoDeleteNetworkInstance flow. setExceptionFlag(): " + ex.getMessage()
1032                         utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1033                         exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1034                 }
1035                 
1036         }
1037         
1038         
1039         // *******************************
1040         //     Build Error Section
1041         // *******************************
1042
1043         public void processJavaException(Execution execution){
1044                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1045                 execution.setVariable("prefix",Prefix)
1046                 try{
1047                         utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
1048                         utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1049                         utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1050                         execution.setVariable("UnexpectedError", "Caught a Java Lang Exception")  // Adding this line temporarily until this flows error handling gets updated
1051                         exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1052                         
1053                 }catch(Exception e){
1054                         utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1055                         execution.setVariable("UnexpectedError", "Exception in processJavaException method")  // Adding this line temporarily until this flows error handling gets updated
1056                         exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1057                 }
1058                 utils.log("DEBUG", "Completed processJavaException Method of " + Prefix, isDebugEnabled)
1059         }
1060
1061 }