aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOGammaBPMN/src/main/groovy/com/att/bpm/scripts/DeleteNetworkInstanceInfra.groovy
blob: 9cc756294c43166455b541322f936ba91e98a77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
/*-
 * ============LICENSE_START=======================================================
 * OPENECOMP - MSO
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package com.att.bpm.scripts;

import org.openecomp.mso.bpmn.core.WorkflowException
import org.openecomp.mso.bpmn.core.json.JsonUtils;
import org.openecomp.mso.rest.APIResponse
import org.openecomp.mso.rest.RESTClient
import org.openecomp.mso.rest.RESTConfig

import java.util.UUID;

import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.runtime.Execution
import org.apache.commons.lang3.*
import org.apache.commons.codec.binary.Base64;
import org.springframework.web.util.UriUtils

import groovy.xml.XmlUtil
import groovy.json.*

public class DeleteNetworkInstanceInfra extends AbstractServiceTaskProcessor {
	String Prefix="DELNWKI_"
	ExceptionUtil exceptionUtil = new ExceptionUtil()
	JsonUtils jsonUtil = new JsonUtils()
	VidUtils vidUtils = new VidUtils(this)

	public InitializeProcessVariables(Execution execution){
		/* Initialize all the process variables in this block */

		execution.setVariable("DELNWKI_DeleteNetworkInstanceInfraJsonRequest", "")
		execution.setVariable("DELNWKI_networkRequest", "")
		execution.setVariable("DELNWKI_networkRESTRequest", "")
		execution.setVariable("DELNWKI_CompleteMsoProcessRequest", "")
		execution.setVariable("DELNWKI_FalloutHandlerRequest", "")
		execution.setVariable("DELNWKI_isSilentSuccess", false)
		execution.setVariable("DELNWKI_Success", false)
		execution.setVariable("DELNWKI_isPONR", false)    // Point-of-no-return, means, rollback is not needed

		execution.setVariable("DELNWKI_requestId", "")
		execution.setVariable("DELNWKI_source", "")
		execution.setVariable("DELNWKI_networkInputs", "")

		execution.setVariable("DELNWKI_queryAAIRequest","")
		execution.setVariable("DELNWKI_queryAAIResponse", "")
		execution.setVariable("DELNWKI_aaiReturnCode", "")
		execution.setVariable("DELNWKI_isAAIGood", false)
		execution.setVariable("DELNWKI_isVfRelationshipExist", false)

		// AAI query Cloud Region
		execution.setVariable("DELNWKI_queryCloudRegionRequest","")
		execution.setVariable("DELNWKI_queryCloudRegionReturnCode","")
		execution.setVariable("DELNWKI_queryCloudRegionResponse","")
		execution.setVariable("DELNWKI_cloudRegionPo","")
		execution.setVariable("DELNWKI_cloudRegionSdnc","")

		execution.setVariable("DELNWKI_deleteNetworkRequest", "")
		execution.setVariable("DELNWKI_deleteNetworkResponse", "")
		execution.setVariable("DELNWKI_networkReturnCode", "")

		execution.setVariable("DELNWKI_deleteSDNCRequest", "")
		execution.setVariable("DELNWKI_deleteSDNCResponse", "")
		execution.setVariable("DELNWKI_rollbackSDNCRequest", "")
		execution.setVariable("DELNWKI_rollbackSDNCResponse", "")
		execution.setVariable("DELNWKI_sdncReturnCode", "")
		execution.setVariable("DELNWKI_rollbackSDNCReturnCode", "")
		execution.setVariable("DELNWKI_isSdncRollbackNeeded", false)
		execution.setVariable("DELNWKI_sdncResponseSuccess", false)

	}

	// **************************************************
	//     Pre or Prepare Request Section
	// **************************************************

	public void preProcessRequest (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix",Prefix)

		utils.log("DEBUG", " ***** Inside preProcessRequest() DeleteNetworkV2 Request ***** ", isDebugEnabled)

		// initialize flow variables
		InitializeProcessVariables(execution)

		// get incoming message/input
		String deleteNetworkJsonIncoming = execution.getVariable("bpmnRequest")
		utils.logAudit(deleteNetworkJsonIncoming)

		try {
			def prettyJson = JsonOutput.prettyPrint(deleteNetworkJsonIncoming.toString())
			utils.log("DEBUG", " Incoming message formatted . . . : " + '\n' + prettyJson, isDebugEnabled)

		} catch (Exception ex) {
			String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
			utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
		}

		// prepare messageId
		String messageId = execution.getVariable("DELNWKI_messageId") // test scenario
		if (messageId == null || messageId == "") {
			messageId = UUID.randomUUID()
			utils.log("DEBUG", " DELNWKI_messageId, random generated: " + messageId, isDebugEnabled)
		} else {
			utils.log("DEBUG", " DELNWKI_messageId, pre-assigned: " + messageId, isDebugEnabled)
		}
		execution.setVariable("DELNWKI_messageId", messageId)

		// PO Authorization Info / headers Authorization=
		String basicAuthValuePO = execution.getVariable("URN_mso_adapters_po_auth")
		utils.log("DEBUG", " Obtained BasicAuth userid password for PO/SDNC adapter: " + basicAuthValuePO, isDebugEnabled)
		try {
			def encodedString = utils.getBasicAuth(basicAuthValuePO, execution.getVariable("URN_mso_msoKey"))
			execution.setVariable("BasicAuthHeaderValuePO",encodedString)
			execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)

		} catch (IOException ex) {
			String dataErrorMessage = " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
			utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
		}

		try {

			execution.setVariable("DELNWKI_DeleteNetworkInstanceInfraJsonRequest", deleteNetworkJsonIncoming)

			// recreate the xml network-request
			String networkRequest =  vidUtils.createXmlNetworkRequestInfra(execution, deleteNetworkJsonIncoming)
			execution.setVariable("DELNWKI_networkRequest", networkRequest)
			utils.log("DEBUG", " network-request - " + '\n' + networkRequest, isDebugEnabled)

			String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
			execution.setVariable("DELNWKI_networkInputs", networkInputs)

			String requestId = execution.getVariable("att-mso-request-id")
			if (requestId == null || requestId == "") {
				requestId = utils.getNodeText(networkRequest, "request-id")
			}
			execution.setVariable("DELNWKI_requestId", requestId)
			execution.setVariable("DELNWKI_source", utils.getNodeText(networkRequest, "source"))

			String networkId = ""
			if (utils.nodeExists(networkInputs, "network-id")) {
				networkId = utils.getNodeText1(networkInputs, "network-id")
				if (networkId == 'null' || networkId == "") {
					sendSyncError(execution)
					// missing value of network-name
					String dataErrorMessage = "network-request has missing 'network-id' element/value."
					utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
					exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
				}
			}

			String lcpCloudRegion = ""
			if (utils.nodeExists(networkInputs, "aic-cloud-region")) {
				lcpCloudRegion = utils.getNodeText1(networkInputs, "aic-cloud-region")
				if ((lcpCloudRegion == 'null') || (lcpCloudRegion == "")) {
					sendSyncError(execution)
					String dataErrorMessage = "network-request has missing 'aic-cloud-region' element/value."
					utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
					exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
				}
			}


		} catch (BpmnError e) {
			throw e;

		} catch (Exception ex){
			 // caught exception
			String exceptionMessage = "Exception Encountered in DeleteNetworkInstanceInfra, PreProcessRequest() - " + ex.getMessage()
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

		}

	}

	public void sendSyncResponse (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix",Prefix)

		utils.log("DEBUG", " ***** Inside sendSyncResponse() of DeleteNetworkV2 ***** ", isDebugEnabled)

		try {
			String requestId = execution.getVariable("att-mso-request-id")
			String serviceInstanceId = execution.getVariable("serviceInstanceId")

			// RESTResponse (for API Handler (APIH) Reply Task)
			String deleteNetworkRestRequest = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()

			utils.log("DEBUG", " sendSyncResponse to APIH - " + "\n" + deleteNetworkRestRequest, isDebugEnabled)

			sendWorkflowResponse(execution, 202, deleteNetworkRestRequest)

		} catch (Exception ex) {
			 // caught exception
			String exceptionMessage = "Exception Encountered in DeleteNetworkInstanceInfra, sendSyncResponse() - " + ex.getMessage()
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

		}

	}

	public void callRESTQueryAAI (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix",Prefix)

		utils.log("DEBUG", " ***** Inside callRESTQueryAAI() of DeleteNetworkV2 ***** " , isDebugEnabled)

		// get variables
		String networkInputs  = execution.getVariable("DELNWKI_networkInputs")
		String networkId   = utils.getNodeText(networkInputs, "network-id")
		networkId = UriUtils.encode(networkId,"UTF-8")
		String messageId = execution.getVariable("DELNWKI_messageId")

		// Prepare AA&I url
		String aai_endpoint = execution.getVariable("URN_aai_endpoint")
		AaiUtil aaiUriUtil = new AaiUtil(this)
		String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
		String queryAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId
		utils.logAudit(queryAAIRequest)
		execution.setVariable("DELNWKI_queryAAIRequest", queryAAIRequest)
		utils.log("DEBUG", " DELNWKI_AAIRequest - " + "\n" + queryAAIRequest, isDebugEnabled)

		String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))

		RESTConfig config = new RESTConfig(queryAAIRequest);

		ExceptionUtil exceptionUtil = new ExceptionUtil()
		Boolean isVfRelationshipExist = false
		try {
			RESTClient client = new RESTClient(config).addHeader("X-TransactionId", messageId)
													  .addHeader("X-FromAppId", "MSO")
													  .addHeader("Content-Type", "application/xml")
													  .addHeader("Accept","application/xml");
			if (basicAuthCred != null && !"".equals(basicAuthCred)) {
				client.addAuthorizationHeader(basicAuthCred)
			}
			APIResponse response = client.get()
			String returnCode = response.getStatusCode()
			execution.setVariable("DELNWKI_aaiReturnCode", returnCode)

			utils.log("DEBUG", " ***** AAI Response Code  : " + returnCode, isDebugEnabled)

			String aaiResponseAsString = response.getResponseBodyAsString()
			aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
			execution.setVariable("DELNWKI_queryAAIResponse", aaiResponseAsString)

			if (returnCode=='200' || returnCode=='204') {
				utils.logAudit(aaiResponseAsString)
				execution.setVariable("DELNWKI_isAAIGood", true)
				utils.log("DEBUG", " AAI Query Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
				// verify if vf or vnf relationship exist
				if (utils.nodeExists(aaiResponseAsString, "relationship")) {
					NetworkUtils networkUtils = new NetworkUtils()
			        isVfRelationshipExist = networkUtils.isVfRelationshipExist(aaiResponseAsString)
					execution.setVariable("DELNWKI_isVfRelationshipExist", isVfRelationshipExist)
					if (isVfRelationshipExist == true) {
						String relationshipMessage = "AAI Query Success Response but 'vf-module' relationship exist, not allowed to delete: network Id: " + networkId
						exceptionUtil.buildWorkflowException(execution, 2500, relationshipMessage)

					}
				}
				utils.log("DEBUG", " DELNWKI_isVfRelationshipExist - " + isVfRelationshipExist, isDebugEnabled)

			} else {
				execution.setVariable("DELNWKI_isAAIGood", false)
			    if (returnCode=='404' || aaiResponseAsString == "" || aaiResponseAsString == null) {
					// not found // empty aai response
					execution.setVariable("DELNWKI_isSilentSuccess", true)
					utils.log("DEBUG", " AAI Query is Silent Success", isDebugEnabled)

				} else {
				   if (aaiResponseAsString.contains("RESTFault")) {
					   WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
					   execution.setVariable("WorkflowException", exceptionObject)

				   } else {
 			       	  // aai all errors
						 String dataErrorMessage = "Unexpected Error Response from callRESTQueryAAI() - " + returnCode
						 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
						 exceptionUtil.buildWorkflowException(execution, 2500, dataErrorMessage)

			      }
				}
			}

			utils.log("DEBUG", " AAI Query call, isAAIGood? : " + execution.getVariable("DELNWKI_isAAIGood"), isDebugEnabled)

		} catch (Exception ex) {
		   // caught exception
		   String exceptionMessage = "Exception Encountered in DeleteNetworkInstanceInfra, callRESTQueryAAI() - " + ex.getMessage()
		   utils.log("DEBUG", exceptionMessage, isDebugEnabled)
		   exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

		}

	}

	public void callRESTQueryAAICloudRegion (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		utils.log("DEBUG", " ***** Inside callRESTQueryAAICloudRegion of DeleteNetworkV2 ***** " , isDebugEnabled)

		try {
			String networkInputs  = execution.getVariable("DELNWKI_networkInputs")
			String cloudRegion = utils.getNodeText(networkInputs, "aic-cloud-region")
			cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
			// Prepare AA&I url
			String aai_endpoint = execution.getVariable("URN_aai_endpoint")
			AaiUtil aaiUtil = new AaiUtil(this)
			String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
			String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
			utils.logAudit(queryCloudRegionRequest)
			execution.setVariable("DELNWKI_queryCloudRegionRequest", queryCloudRegionRequest)
			utils.log("DEBUG", " DELNWKI_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugEnabled)

			String cloudRegionPo = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "PO", cloudRegion)
			String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution,  queryCloudRegionRequest, "SDNC", cloudRegion)

			if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
				execution.setVariable("DELNWKI_cloudRegionPo", cloudRegionPo)
				execution.setVariable("DELNWKI_cloudRegionSdnc", cloudRegionSdnc)

			} else {
				String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable("DELNWKI_queryCloudRegionReturnCode")
				utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
				exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)

			}

		} catch (BpmnError e) {
		throw e;

		} catch (Exception ex) {
			// caught exception
			String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, callRESTQueryAAICloudRegion(). Unexpected Response from AAI - " + ex.getMessage()
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

		}

	}

	public void prepareNetworkRequest (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		utils.log("DEBUG", " ***** Inside prepareNetworkRequest of DeleteNetworkV2 ***** ", isDebugEnabled)
		ExceptionUtil exceptionUtil = new ExceptionUtil()
		try {
			// get variables
			String cloudSiteId = execution.getVariable("DELNWKI_cloudRegionPo")
			String networkInputs = execution.getVariable("DELNWKI_networkInputs")
			String tenantId = utils.getNodeText(networkInputs, "tenant-id")
			String networkType = utils.getNodeText(networkInputs, "network-type")
			String networkId = utils.getNodeText(networkInputs, "network-id")

			String networkStackId = ""
			networkStackId = utils.getNodeText1(execution.getVariable("DELNWKI_queryAAIResponse"), "heat-stack-id")
			if (networkStackId == 'null' || networkStackId == "") {
				networkStackId = "force_delete"
			}

			String requestId = execution.getVariable("DELNWKI_requestId")
			String serviceInstanceId = execution.getVariable("serviceInstanceId")

			// Added new Elements
			String messageId = execution.getVariable("DELNWKI_messageId")
			String notificationUrl = ""                                   //TODO - is this coming from URN? What variable/value to use?
			//String notificationUrl = execution.getVariable("URN_?????") //TODO - is this coming from URN? What variable/value to use?

			String deleteNetworkRequest = """
					  <deleteNetworkRequest>
					    <cloudSiteId>${cloudSiteId}</cloudSiteId>
					    <tenantId>${tenantId}</tenantId>
					    <networkId>${networkId}</networkId>
						<networkStackId>${networkStackId}</networkStackId>
					    <networkType>${networkType}</networkType>
						<skipAAI>true</skipAAI>
					    <msoRequest>
					       <requestId>${requestId}</requestId>
					       <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
					    </msoRequest>
						<messageId>${messageId}</messageId>
						<notificationUrl>${notificationUrl}</notificationUrl>
					  </deleteNetworkRequest>
						""".trim()

			utils.log("DEBUG", " DELNWKI_deleteNetworkRequest - " + "\n" +  deleteNetworkRequest, isDebugEnabled)
			// Format Response
			String buildDeleteNetworkRequestAsString = utils.formatXml(deleteNetworkRequest)
			utils.logAudit(buildDeleteNetworkRequestAsString)
			utils.log("DEBUG", " DELNWKI_deleteNetworkRequestAsString - " + "\n" +  buildDeleteNetworkRequestAsString, isDebugEnabled)

			String restURL = execution.getVariable("URN_mso_adapters_network_rest_endpoint")
			execution.setVariable("URN_mso_adapters_network_rest_endpoint", restURL + "/" + networkId)
			utils.log("DEBUG", "URN_mso_adapters_network_rest_endpoint - " + "\n" +  restURL + "/" + networkId, isDebugEnabled)

			execution.setVariable("DELNWKI_deleteNetworkRequest", buildDeleteNetworkRequestAsString)
			utils.log("DEBUG", " DELNWKI_deleteNetworkRequest - " + "\n" +  buildDeleteNetworkRequestAsString, isDebugEnabled)
		}
		catch (Exception ex) {
			// caught exception
			String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, prepareNetworkRequest(). Unexpected Response from AAI - " + ex.getMessage()
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

		}
	}

	/**
	 * This method is used instead of an HTTP Connector task because the
	 * connector does not allow DELETE with a body.
	 */
	public void sendRequestToVnfAdapter(Execution execution) {
		def method = getClass().getSimpleName() + '.sendRequestToVnfAdapter(' +
			'execution=' + execution.getId() +
			')'
		def isDebugEnabled = execution.getVariable('isDebugLogEnabled')
		logDebug('Entered ' + method, isDebugEnabled)

		try {

			String vnfAdapterUrl = execution.getVariable("URN_mso_adapters_network_rest_endpoint")
			String vnfAdapterRequest = execution.getVariable("DELNWKI_deleteNetworkRequest")

			RESTConfig config = new RESTConfig(vnfAdapterUrl)
			RESTClient client = new RESTClient(config).
				addHeader("Content-Type", "application/xml").
				addAuthorizationHeader(execution.getVariable("BasicAuthHeaderValuePO"));

			APIResponse response;

			response = client.httpDelete(vnfAdapterRequest)

			execution.setVariable("DELNWKI_networkReturnCode", response.getStatusCode())
			execution.setVariable("DELNWKI_deleteNetworkResponse", response.getResponseBodyAsString())

		} catch (Exception ex) {
			// caught exception
			String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, sendRequestToVnfAdapter() - " + ex.getMessage()
			logError(exceptionMessage)
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

		}
	}


	public void prepareSDNCRequest (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		utils.log("DEBUG", " ***** Inside prepareSDNCRequest of DeleteNetworkV2 ***** ", isDebugEnabled)

		try {
			// get variables
			String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
			String deleteNetworkInput = execution.getVariable("DELNWKI_networkRequest")

			String networkId = ""
			if (utils.nodeExists(deleteNetworkInput, "network-id")) {
				networkId = utils.getNodeText1(deleteNetworkInput, "network-id")
			}
			if (networkId == 'null') {networkId = ""}

			String serviceInstanceId = utils.getNodeText1(deleteNetworkInput, "service-instance-id")

			SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
			String cloudRegionId = execution.getVariable("DELNWKI_cloudRegionSdnc")
			// 1. prepare delete topology via SDNC Adapter SUBFLOW call
			String sndcTopologyDeleteRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, deleteNetworkInput, serviceInstanceId, sdncCallback, "delete", "DisconnectNetworkRequest", cloudRegionId, networkId, null)
		    String sndcTopologyDeleteRequesAsString = utils.formatXml(sndcTopologyDeleteRequest)
			utils.logAudit(sndcTopologyDeleteRequesAsString)
			execution.setVariable("DELNWKI_deleteSDNCRequest", sndcTopologyDeleteRequesAsString)
			utils.log("DEBUG", " DELNWKI_deleteSDNCRequest - " + "\n" +  sndcTopologyDeleteRequesAsString, isDebugEnabled)

			// 2. prepare rollback topology via SDNC Adapter SUBFLOW call
			String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, deleteNetworkInput, serviceInstanceId, sdncCallback, "rollback", "DisconnectNetworkRequest", cloudRegionId, networkId, null)
			String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
			execution.setVariable("DELNWKI_rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
			utils.log("DEBUG", " DELNWKI_rollbackSDNCRequest (prepared if NEEDED later for SDNC Topology delete's rollback/compensation . . . - " + "\n" +  sndcTopologyRollbackRequestAsString, isDebugEnabled)

		} catch (Exception ex) {
			// caught exception
			String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, prepareSDNCRequest() - " + ex.getMessage()
			logError(exceptionMessage)
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

		}

	}

	public void prepareDBRequest (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		try {
			utils.log("DEBUG", " ***** Inside prepareDBRequest of DeleteNetworkV2 ***** ", isDebugEnabled)

			String aaiReturnCode = execution.getVariable("DELNWKI_aaiReturnCode")
			String requestId = execution.getVariable("DELNWKI_requestId")

			String statusMessage = ""
			if (aaiReturnCode == '404' || execution.getVariable("DELNWKI_isSilentSuccess") == true) {
				// SILENT SUCCESS
				statusMessage = "Network Id to be deleted NOT found. Silent success."
			} else {
				statusMessage = "Network successfully deleted."
			}

			String dbRequest =
					"""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
						<soapenv:Header/>
						<soapenv:Body>
							<ns:updateInfraRequest xmlns:ns="http://com.att.mso/requestsdb">
								<requestId>${requestId}</requestId>
								<lastModifiedBy>BPMN</lastModifiedBy>
								<statusMessage>${statusMessage}</statusMessage>
								<responseBody></responseBody>
								<requestStatus>COMPLETED</requestStatus>
								<progress>100</progress>
								<vnfOutputs>&lt;network-outputs xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1" xmlns:aetgt="http://ecomp.att.com/mso/infra/vnf-request/v1" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"/&gt;</vnfOutputs>
							</ns:updateInfraRequest>
					   	</soapenv:Body>
					   </soapenv:Envelope>"""

		   String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
		   utils.logAudit(buildDeleteDBRequestAsString)
		   execution.setVariable("DELNWKI_deleteDBRequest", buildDeleteDBRequestAsString)
		   utils.log("DEBUG", " DB Adapter Request - " + "\n" + buildDeleteDBRequestAsString, isDebugEnabled)

		} catch (Exception ex) {
			// caught exception
			String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, prepareDBRequest() - " + ex.getMessage()
			logError(exceptionMessage)
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

		}

	 }

	public void prepareDBRequestError (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		try {
			utils.log("DEBUG", " ***** Inside prepareDBRequestError of DeleteNetworkV2 ***** ", isDebugEnabled)

			WorkflowException wfe = execution.getVariable("WorkflowException")
			String statusMessage = wfe.getErrorMessage()
			String requestId = execution.getVariable("DELNWKI_requestId")

			String dbRequest =
					"""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
						<soapenv:Header/>
						<soapenv:Body>
							<ns:updateInfraRequest xmlns:ns="http://com.att.mso/requestsdb">
								<requestId>${requestId}</requestId>
								<lastModifiedBy>BPMN</lastModifiedBy>
								<statusMessage>${statusMessage}</statusMessage>
								<responseBody></responseBody>
								<requestStatus>FAILED</requestStatus>
								<progress></progress>
								<vnfOutputs>&lt;network-outputs xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1" xmlns:aetgt="http://ecomp.att.com/mso/infra/vnf-request/v1" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"/&gt;</vnfOutputs>
							</ns:updateInfraRequest>
					   	</soapenv:Body>
					   </soapenv:Envelope>"""

		   execution.setVariable("DELNWKI_deleteDBRequest", dbRequest)
		   utils.log("DEBUG", " DB Adapter Request - " + "\n" + dbRequest, isDebugEnabled)

		} catch (Exception ex) {
			// caught exception
			String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, prepareDBRequestError() - " + ex.getMessage()
			logError(exceptionMessage)
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)

		}

	 }

	// **************************************************
	//     Post or Validate Response Section
	// **************************************************

	public void validateNetworkResponse (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		utils.log("DEBUG", " ***** Inside validateNetworkResponse of DeleteNetworkV2 *****", isDebugEnabled)

		try {
			String returnCode = execution.getVariable("DELNWKI_networkReturnCode")
			String networkResponse = execution.getVariable("DELNWKI_deleteNetworkResponse")

			utils.log("DEBUG", " Network Adapter responseCode: " + returnCode, isDebugEnabled)
			utils.log("DEBUG", "Network Adapter Error Response - " + "\n" + networkResponse, isDebugEnabled)

			String errorMessage = ""
			if (returnCode == "200") {
				utils.logAudit(networkResponse)
				execution.setVariable("DELNWKI_deleteNetworkResponse", networkResponse)
				utils.log("DEBUG", " Network Adapter Success Response - " + "\n" + networkResponse, isDebugEnabled)

			} else { // network error
			   if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) {   //4xx, 5xx
				   if (networkResponse.contains("deleteNetworkError")  ) {
					   networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
					   errorMessage  = utils.getNodeText1(networkResponse, "message")
					   errorMessage  = "Received error from Network Adapter: " + errorMessage
					   exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)

				   } else { // CatchAll exception
				   	   if (returnCode == "500") {
						   errorMessage = "JBWEB000065: HTTP Status 500."
				       } else {
					       errorMessage = "Return code is " + returnCode
				       }
					   errorMessage  = "Received error from Network Adapter: " + errorMessage
					   exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)

				   }

			   } else { // CatchAll exception
				   String dataErrorMessage  = "Received error from Network Adapter. Return code is: " + returnCode
				   exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)

			   }

			}

		} catch (BpmnError e) {
			throw e;

		} catch (Exception ex) {
			// caught exception
			String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, validateNetworkResponse() - " + ex.getMessage()
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

		}

	}

	public void validateSDNCResponse (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		utils.log("DEBUG", " ***** Inside validateSDNCResponse of DeleteNetworkV2 ***** ", isDebugEnabled)

		String response = execution.getVariable("DELNWKI_deleteSDNCResponse")
		WorkflowException workflowException = execution.getVariable("WorkflowException")

		boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")

		SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
		sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
		// reset variable
		String deleteSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable("DELNWKI_deleteSDNCResponse"))
		deleteSDNCResponseDecodeXml = deleteSDNCResponseDecodeXml.replace("&", "&amp;").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
		execution.setVariable("DELNWKI_deleteSDNCResponse", deleteSDNCResponseDecodeXml)

		if (execution.getVariable("DELNWKI_sdncResponseSuccess") == true) {  // from sdnc util, prefix+'sdncResponseSuccess'
			execution.setVariable("DELNWKI_isSdncRollbackNeeded", true)      //
			execution.setVariable("DELNWKI_isPONR", true)
			utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
		} else {
			utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
		 	throw new BpmnError("MSOWorkflowException")
		}

	}


	public void postProcessResponse (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		utils.log("DEBUG", " ***** Inside postProcessResponse of DeleteNetworkV2 ***** ", isDebugEnabled)

		try {
			// Display DB response: DELNWKI_deleteDBResponse / DELNWKI_dbReturnCode
			String dbReturnCode = execution.getVariable("DELNWKI_dbReturnCode")
			utils.log("DEBUG", " ***** DB Update Response Code  : " + dbReturnCode, isDebugEnabled)
			utils.log("DEBUG", " ***** DB Update Response String: " + '\n' + execution.getVariable("DELNWKI_deleteDBResponse"), isDebugEnabled)

			if (dbReturnCode == '200') {

				String source = execution.getVariable("DELNWKI_source")
				String requestId = execution.getVariable("DELNWKI_requestId")

				String msoCompletionRequest =
					"""<aetgt:MsoCompletionRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
									xmlns:ns="http://ecomp.att.com/mso/request/types/v1"
				    	    		xmlns:ns8="http://ecomp.att.com/mso/workflow/schema/v1">
							<request-info xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1">
								<request-id>${requestId}</request-id>
								<action>DELETE</action>
								<source>${source}</source>
				   			</request-info>
							<ns8:status-message>Network has been deleted successfully.</ns8:status-message>
				   			<ns8:mso-bpel-name>BPMN Network action: DELETE</ns8:mso-bpel-name>
						</aetgt:MsoCompletionRequest>"""

					// Format Response
					String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)

				utils.logAudit(xmlMsoCompletionRequest)
				execution.setVariable("DELNWKI_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
				execution.setVariable("DELNWKI_Success", true)
				if (execution.getVariable("DELNWKI_isSilentSuccess") == false) {
					utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
				} else {
					utils.log("DEBUG", " Silent SUCCESS going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
				}

			} else {
				// caught exception
				String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, DB Update Failed: " + dbReturnCode
				utils.log("DEBUG", exceptionMessage, isDebugEnabled)
				exceptionUtil.buildAndThrowWorkflowException(execution, 2500, exceptionMessage)

			}

		} catch (BpmnError e) {
			throw e;

		} catch (Exception ex) {
			// caught exception
			String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, postProcessResponse() - " + ex.getMessage()
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)

        }

	}


	// *******************************
	//     Build Error Section
	// *******************************

	// Prepare for FalloutHandler
	public void buildErrorResponse (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		utils.log("DEBUG", " ***** Prepare for FalloutHandler. FAILURE - prepare request for sub-process FalloutHandler. *****", isDebugEnabled)

		String dbReturnCode = execution.getVariable("DELNWKI_dbReturnCode")
		utils.log("DEBUG", " ***** DB Update Response Code  : " + dbReturnCode, isDebugEnabled)
		utils.log("DEBUG", " ***** DB Update Response String: " + '\n' + execution.getVariable("DELNWKI_deleteDBResponse"), isDebugEnabled)

		String falloutHandlerRequest = ""
		String workflowException = ""
		String requestId = execution.getVariable("DELNWKI_requestId")
		String source = execution.getVariable("DELNWKI_source")
		execution.setVariable("DELNWKI_Success", false)
		try {
			WorkflowException wfe = execution.getVariable("WorkflowException")
			String errorCode = String.valueOf(wfe.getErrorCode())
			String errorMessage = wfe.getErrorMessage()

			falloutHandlerRequest =
			    """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
					                             xmlns:ns="http://ecomp.att.com/mso/request/types/v1"
					                             xmlns:wfsch="http://ecomp.att.com/mso/workflow/schema/v1">
					   <request-info xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1">
					      <request-id>${requestId}</request-id>
					      <action>DELETE</action>
					      <source>${source}</source>
					   </request-info>
						<aetgt:WorkflowException xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1">
							<aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
							<aetgt:ErrorCode>${errorCode}</aetgt:ErrorCode>
						</aetgt:WorkflowException>
					</aetgt:FalloutHandlerRequest>"""

			utils.logAudit(falloutHandlerRequest)
			execution.setVariable("DELNWKI_FalloutHandlerRequest", falloutHandlerRequest)
			utils.log("ERROR", "  Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)

		} catch (Exception ex) {
			// caught exception
			String exceptionMessage = "Bpmn error encountered in DeleteNetworkInstanceInfra, buildErrorResponse() - " + ex.getMessage()
			utils.log("DEBUG", exceptionMessage, isDebugEnabled)
			falloutHandlerRequest =
			"""<aetgt:FalloutHandlerRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
					                             xmlns:ns="http://ecomp.att.com/mso/request/types/v1"
					                             xmlns:wfsch="http://ecomp.att.com/mso/workflow/schema/v1">
					   <request-info xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1">
					      <request-id>${requestId}</request-id>
					      <action>CREATE</action>
					      <source>${source}</source>
					   </request-info>
						<aetgt:WorkflowException xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1">
							<aetgt:ErrorMessage>${exceptionMessage}</aetgt:ErrorMessage>
							<aetgt:ErrorCode>9999</aetgt:ErrorCode>
						</aetgt:WorkflowException>
					</aetgt:FalloutHandlerRequest>"""
			execution.setVariable("DELNWKI_FalloutHandlerRequest", falloutHandlerRequest)
			utils.log("DEBUG", "  Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)
		}
	}


	public void sendSyncError (Execution execution) {
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix", Prefix)

		try {
			String requestId = execution.getVariable("att-mso-request-id")
			String serviceInstanceId = execution.getVariable("serviceInstanceId")

			// RESTResponse (for API Handler (APIH) Reply Task)
			String deleteNetworkRestError = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()

			utils.log("DEBUG", " sendSyncResponse to APIH - " + "\n" + deleteNetworkRestError, isDebugEnabled)

			sendWorkflowResponse(execution, 500, deleteNetworkRestError)

		} catch (Exception ex) {
			utils.log("DEBUG", " Sending Sync Error Activity Failed - DeleteNetworkInstanceInfra, sendSyncError(): " + "\n" + ex.getMessage(), isDebugEnabled)
		}
	}

	public void processJavaException(Execution execution){
		def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
		execution.setVariable("prefix",Prefix)
		try{
			utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
			utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
			utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
			execution.setVariable("UnexpectedError", "Caught a Java Lang Exception")  // Adding this line temporarily until this flows error handling gets updated
			exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
		}catch(BpmnError b){
			utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
			throw b
		}catch(Exception e){
			utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
			execution.setVariable("UnexpectedError", "Exception in processJavaException method")  // Adding this line temporarily until this flows error handling gets updated
			exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
		}
		utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
	}

}