aboutsummaryrefslogtreecommitdiffstats
path: root/aai-resources/src/main/java/org/onap/aai/dbgen/ForceDeleteTool.java
blob: 42d401b2faaacff14a994496aa80398203d8f0fe (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
/**
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright © 2017-2018 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 org.onap.aai.dbgen;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import java.util.Scanner;
import java.util.UUID;

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.onap.aai.dbmap.AAIGraphConfig;
import org.onap.aai.dbmap.AAIGraph;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.logging.LogFormatTools;
import org.onap.aai.logging.LoggingContext;
import org.onap.aai.logging.LoggingContext.StatusCode;
import org.onap.aai.serialization.db.AAIDirection;
import org.onap.aai.serialization.db.EdgeProperty;
import org.onap.aai.util.AAIConfig;
import org.onap.aai.util.AAIConstants;
import org.slf4j.MDC;

import com.att.eelf.configuration.Configuration;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.JanusGraph;



public class ForceDeleteTool {
	private static final String FROMAPPID = "AAI-DB";
	private static final String TRANSID   = UUID.randomUUID().toString();
	private static final String DELETE_NODE = "DELETE_NODE";
	private static final String DELETE_EDGE = "DELETE_EDGE";
	private static String graphType = "realdb";
	private static String FOUND_VERTEX_ID_ = ">>> Found Vertex with VertexId = ";
	private static String PROPERTIES_ = ", properties:    ";
	private static String INMEMORY = "inmemory";

	public static boolean SHOULD_EXIT_VM = true;

	public static int EXIT_VM_STATUS_CODE = -1;

	public static void exit(int statusCode){
		if(SHOULD_EXIT_VM){
			System.exit(1);
		}
		EXIT_VM_STATUS_CODE = statusCode;
	}

	/*
	 * The main method.
	 *
	 * @param args the arguments
	 */
	public static void main(String[] args) {
		
		//SWGK 01/21/2016 - To suppress the warning message when the tool is run from the Terminal.

		System.setProperty("aai.service.name", ForceDelete.class.getSimpleName());
		// Set the logging file properties to be used by EELFManager
		Properties props = System.getProperties();
		props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, "forceDelete-logback.xml");
		props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES);
		EELFLogger logger = EELFManager.getInstance().getLogger(ForceDeleteTool.class.getSimpleName());
		MDC.put("logFilenameAppender", ForceDeleteTool.class.getSimpleName());
		
		LoggingContext.init();
		LoggingContext.partnerName(FROMAPPID);
		LoggingContext.serviceName(AAIConstants.AAI_RESOURCES_MS);
		LoggingContext.component("forceDeleteTool");
		LoggingContext.targetEntity(AAIConstants.AAI_RESOURCES_MS);
		LoggingContext.targetServiceName("main");
		LoggingContext.requestId(TRANSID);
		LoggingContext.statusCode(StatusCode.COMPLETE);
		LoggingContext.responseCode(LoggingContext.SUCCESS);
		
		String actionVal = "";
	  	String userIdVal = "";
	  	String dataString = "";
	  	Boolean displayAllVidsFlag = false;  // Note - This should rarely be needed
	  	Boolean overRideProtection = false;  // This should rarely be used - it overrides all our new checking
	  	long vertexIdLong = 0;
	  	String edgeIdStr = "";
	  	String argStr4Msg = "";
	  	
	  	if (args != null && args.length > 0) {
			// They passed some arguments in that will affect processing
			for (int i = 0; i < args.length; i++) {
				String thisArg = args[i];
				argStr4Msg = argStr4Msg + " " + thisArg;
				
				if (thisArg.equals("-action")) {
					i++;
					if (i >= args.length) {
						LoggingContext.statusCode(StatusCode.ERROR);
						LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
						logger.error(" No value passed with -action option.  ");
						exit(0);
					}
					actionVal = args[i];
					argStr4Msg = argStr4Msg + " " + actionVal;
				}
				else if ("-userId".equals(thisArg)) {
					i++;
					if (i >= args.length) {
						LoggingContext.statusCode(StatusCode.ERROR);
						LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
						logger.error(" No value passed with -userId option.  ");
						exit(0);
					}
					userIdVal = args[i];
					argStr4Msg = argStr4Msg + " " + userIdVal;
				}
				else if ("-overRideProtection".equals(thisArg)) {
					overRideProtection = true;
				}
				else if ("-DISPLAY_ALL_VIDS".equals(thisArg)) {
					displayAllVidsFlag = true;
				}
				else if ("-vertexId".equals(thisArg)) {
					i++;
					if (i >= args.length) {
						LoggingContext.statusCode(StatusCode.ERROR);
						LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
						logger.error(" No value passed with -vertexId option.  ");
						exit(0);
					}
					String nextArg = args[i];
					argStr4Msg = argStr4Msg + " " + nextArg;
					try {
						vertexIdLong = Long.parseLong(nextArg);
					} catch (Exception e) {
						LoggingContext.statusCode(StatusCode.ERROR);
						LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
						logger.error("Bad value passed with -vertexId option: ["
										+ nextArg + "]");
						exit(0);
					}
				}
				else if ("-params4Collect".equals(thisArg)) {
					i++;
					if (i >= args.length) {
						LoggingContext.statusCode(StatusCode.ERROR);
						LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
						logger.error(" No value passed with -params4Collect option.  ");
						exit(0);
					}
					dataString = args[i];
					argStr4Msg = argStr4Msg + " " + dataString;
				}
				else if ("-edgeId".equals(thisArg)) {
					i++;
					if (i >= args.length) {
						LoggingContext.statusCode(StatusCode.ERROR);
						LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
						logger.error(" No value passed with -edgeId option.  ");
						exit(0);
					}
					String nextArg = args[i];
					argStr4Msg = argStr4Msg + " " + nextArg;
					edgeIdStr = nextArg;
				}
				else {
					LoggingContext.statusCode(StatusCode.ERROR);
					LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
					logger.error(" Unrecognized argument passed to ForceDeleteTool: ["
									+ thisArg + "]. ");
					logger.error(" Valid values are: -action -userId -vertexId -edgeId -overRideProtection -params4Collect -DISPLAY_ALL_VIDS");
					exit(0);
				}
			}
		}
		
	  	if( !"COLLECT_DATA".equals(actionVal) && !DELETE_NODE.equals(actionVal) && !DELETE_EDGE.equals(actionVal)){
	 		String emsg = "Bad action parameter [" + actionVal + "] passed to ForceDeleteTool().  Valid values = COLLECT_DATA or DELETE_NODE or DELETE_EDGE\n";
			System.out.println(emsg);
			LoggingContext.statusCode(StatusCode.ERROR);
			LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
			logger.error(emsg);
	 		exit(0);
	  	}
	  	
	  	if( DELETE_NODE.equals(actionVal) && vertexIdLong == 0 ){
	 		String emsg = "ERROR: No vertex ID passed on DELETE_NODE request. \n";
			System.out.println(emsg);
			LoggingContext.statusCode(StatusCode.ERROR);
			LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
			logger.error(emsg);
	 		exit(0);
	  	}
	  	else if( DELETE_EDGE.equals(actionVal) && edgeIdStr.isEmpty()){
	 		String emsg = "ERROR: No edge ID passed on DELETE_EDGE request. \n";
			System.out.println(emsg);
			LoggingContext.statusCode(StatusCode.ERROR);
			LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
			logger.error(emsg);
	 		exit(0);
	  	}
	  	
	  	
	  	userIdVal = userIdVal.trim();
	  	if( (userIdVal.length() < 6) || "AAIADMIN".equalsIgnoreCase(userIdVal) ){
	  		String emsg = "Bad userId parameter [" + userIdVal + "] passed to ForceDeleteTool(). must be not empty and not aaiadmin \n";
			System.out.println(emsg);
			LoggingContext.statusCode(StatusCode.ERROR);
			LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
			logger.error(emsg);
	 		exit(0);
	  	}
	  	
	  	String msg = "";
	  	JanusGraph graph = null;
		try {   
    		AAIConfig.init();
    		System.out.println("    ---- NOTE --- about to open graph (takes a little while)--------\n");
			graph = setupGraph(logger);
    		if( graph == null ){
    			String emsg = "could not get graph object in ForceDeleteTool() \n";
    			System.out.println(emsg);
    			LoggingContext.statusCode(StatusCode.ERROR);
    			LoggingContext.responseCode(LoggingContext.AVAILABILITY_TIMEOUT_ERROR);
    			logger.error(emsg);
    	 		exit(0);
    		}
    	}
	    catch (AAIException e1) {
			msg =  e1.getErrorObject().toString();
			System.out.println(msg);
			LoggingContext.statusCode(StatusCode.ERROR);
			LoggingContext.responseCode(LoggingContext.UNKNOWN_ERROR);
			logger.error(msg);
			exit(0);
	    }
        catch (Exception e2) {
	 		msg =  e2.toString();
	 		System.out.println(msg);
	 		LoggingContext.statusCode(StatusCode.ERROR);
	 		LoggingContext.responseCode(LoggingContext.UNKNOWN_ERROR);
	 		logger.error(msg);
	 		exit(0);
        }
	
		msg = "ForceDelete called by: userId [" + userIdVal + "] with these params: [" + argStr4Msg + "]";
		System.out.println(msg);
		logger.info(msg);
  	
		ForceDelete fd = new ForceDelete(graph);
    	if( "COLLECT_DATA".equals(actionVal) ){
	  		// When doing COLLECT_DATA, we expect the dataString string to be comma separated
    		// name value pairs like this:
	  		//    "propName1|propVal1,propName2|propVal2" etc.  We will look for a node or nodes
	  		//    that have properties that ALL match what was passed in.

	  	   	int resCount = 0;
        	int firstPipeLoc = dataString.indexOf("|");
	  		if( firstPipeLoc <= 0 ){
	  			msg =  "Must use the -params4Collect option when collecting data with data string in a format like: 'propName1|propVal1,propName2|propVal2'";
		 		System.out.println(msg);
		 		LoggingContext.statusCode(StatusCode.ERROR);
		 		LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
		 		logger.error(msg);
		 		exit(0);
	  		}
			GraphTraversal<Vertex, Vertex> g  = null;
			String qStringForMsg = null;
	  		if (graph != null) {
				g = graph.traversal().V();
				qStringForMsg = " graph.traversal().V()";
				// Note - if they're only passing on parameter, there won't be any commas
				String[] paramArr = dataString.split(",");
				for (int i = 0; i < paramArr.length; i++) {
					int pipeLoc = paramArr[i].indexOf("|");
					if (pipeLoc <= 0) {
						msg = "Must use the -params4Collect option when collecting data with data string in a format like: 'propName1|propVal1,propName2|propVal2'";
						System.out.println(msg);
						LoggingContext.statusCode(StatusCode.ERROR);
						LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
						logger.error(msg);
						exit(0);
					} else {
						String propName = paramArr[i].substring(0, pipeLoc);
						String propVal = paramArr[i].substring(pipeLoc + 1);
						g = g.has(propName, propVal);
						qStringForMsg = qStringForMsg + ".has(" + propName + "," + propVal + ")";
					}
				}
			}
	  	   	if( (g != null)){
	        	Iterator<Vertex> vertItor = g;
	           	while( vertItor.hasNext() ){
	        		resCount++;
	        		Vertex v = vertItor.next();
	        		fd.showNodeInfo( logger, v, displayAllVidsFlag );
	        		int descendantCount = fd.countDescendants( logger, v, 0 );
	        		String infMsg = " Found " + descendantCount + " descendant nodes \n";
	    	  		System.out.println( infMsg );
	    	  		logger.info( infMsg );
	        	}
	        }
	        else {
	           	msg =  "Bad JanusGraphQuery object.  ";
		 		System.out.println(msg);
		 		LoggingContext.statusCode(StatusCode.ERROR);
		 		LoggingContext.responseCode(LoggingContext.DATA_ERROR);
		 		logger.error(msg);
		 		exit(0);
	  		}
	  		
	  	   	String infMsg = "\n\n Found: " + resCount + " nodes for this query: [" + qStringForMsg + "]\n";
	  		System.out.println( infMsg );
	  		logger.info( infMsg );
	  	} 
	  	else if( DELETE_NODE.equals(actionVal) ){
	  		Iterator <Vertex> vtxItr = graph.vertices( vertexIdLong );
	  		if( vtxItr != null && vtxItr.hasNext() ) {
	  			Vertex vtx = vtxItr.next();
	  			fd.showNodeInfo( logger, vtx, displayAllVidsFlag );
        		int descendantCount = fd.countDescendants( logger, vtx, 0 );
        		String infMsg = " Found " + descendantCount + " descendant nodes.  Note - forceDelete does not cascade to " +
        				" child nodes, but they may become unreachable after the delete. \n";
    	  		System.out.println( infMsg );
    	  		logger.info( infMsg );
    	  		
    	  		int edgeCount = fd.countEdges( logger, vtx );
    			
    			infMsg = " Found total of " + edgeCount + " edges incident on this node.  \n";
    	  		System.out.println( infMsg );
    	  		logger.info( infMsg );
    			
    			if( fd.getNodeDelConfirmation(logger, userIdVal, vtx, descendantCount, edgeCount, overRideProtection) ){
			  		vtx.remove();
			  		graph.tx().commit();
			  		infMsg = ">>>>>>>>>> Removed node with vertexId = " + vertexIdLong;
			  		logger.info( infMsg );
			  		System.out.println(infMsg);
    	  		}
    	  		else {
    	  			infMsg = " Delete Cancelled. ";
    	  			System.out.println(infMsg);
    	  			logger.info( infMsg );
    	  		}
	  		}
	  		else {
	  			String infMsg = ">>>>>>>>>> Vertex with vertexId = " + vertexIdLong + " not found.";
	  			System.out.println( infMsg );
	  			logger.info( infMsg );
	  		}
	  	}
	  	else if( DELETE_EDGE.equals(actionVal) ){
	  		Edge thisEdge = null;
	  		Iterator <Edge> edItr = graph.edges( edgeIdStr );
	  		if( edItr != null && edItr.hasNext() ) {
		  		thisEdge = edItr.next();
	  		}
	  		
	  		if( thisEdge == null ){
	  			String infMsg = ">>>>>>>>>> Edge with edgeId = " + edgeIdStr + " not found.";
		  		logger.info( infMsg );
		  		System.out.println(infMsg);
		  		exit(0);
		  	}
	  		
	  		if( fd.getEdgeDelConfirmation(logger, userIdVal, thisEdge, overRideProtection) ){
	  			thisEdge.remove();
		  		graph.tx().commit();
		  		String infMsg = ">>>>>>>>>> Removed edge with edgeId = " + edgeIdStr;
		  		logger.info( infMsg );
		  		System.out.println(infMsg);
	  		} 
	  		else {	
	  			String infMsg = " Delete Cancelled. ";
	  			System.out.println(infMsg);
	  			logger.info( infMsg );
	  		}
	 		exit(0);
	  	}
	  	else {
			String emsg = "Unknown action parameter [" + actionVal + "] passed to ForceDeleteTool().  Valid values = COLLECT_DATA, DELETE_NODE or DELETE_EDGE \n";
			System.out.println(emsg);
			logger.info( emsg );
	 		exit(0);
	  	}

	  	closeGraph(graph, logger);
	  	exit(0);
    
	}// end of main()
	
	public static class ForceDelete {
		
		private final int MAXDESCENDENTDEPTH = 15;
		private final JanusGraph graph;
		public ForceDelete(JanusGraph graph) {
			this.graph = graph;
		}
		public void showNodeInfo(EELFLogger logger, Vertex tVert, Boolean displayAllVidsFlag ){ 
			
			try {
				Iterator<VertexProperty<Object>> pI = tVert.properties();
				String infStr = FOUND_VERTEX_ID_ + tVert.id() + PROPERTIES_;
				System.out.println( infStr );
				logger.info(infStr);
				while( pI.hasNext() ){
					VertexProperty<Object> tp = pI.next();
					infStr = " [" + tp.key() + "|" + tp.value() + "] ";
					System.out.println( infStr ); 
					logger.info(infStr);
				}
			
				ArrayList <String> retArr = collectEdgeInfoForNode( logger, tVert, displayAllVidsFlag );
				for( String infoStr : retArr ){ 
					System.out.println( infoStr ); 
					logger.info(infoStr);
				}
			}
			catch (Exception e){
				String warnMsg = " -- Error -- trying to display edge info. [" + e.getMessage() + "]";
				System.out.println( warnMsg );
				LoggingContext.statusCode(StatusCode.ERROR);
				LoggingContext.responseCode(LoggingContext.DATA_ERROR);
				logger.warn(warnMsg);
				LoggingContext.successStatusFields();
			}
			
		}// End of showNodeInfo()

		
		public void showPropertiesForEdge( EELFLogger logger, Edge tEd ){ 
			String infMsg = "";
			if( tEd == null ){
				infMsg = "null Edge object passed to showPropertiesForEdge()";
				System.out.print(infMsg);
				logger.info(infMsg);
				return;
			}
			
			// Try to show the edge properties
			try {
				infMsg =" Label for this Edge = [" + tEd.label() + "] ";
				System.out.print(infMsg);
				logger.info(infMsg);
				
				infMsg =" EDGE Properties for edgeId = " + tEd.id() + ": ";
				System.out.print(infMsg);
				logger.info(infMsg);
				Iterator <String> pI = tEd.keys().iterator();
				while( pI.hasNext() ){
					String propKey = pI.next();
					infMsg = "Prop: [" + propKey + "], val = [" 
							+ tEd.property(propKey) + "] ";
					System.out.print(infMsg);
					logger.info(infMsg);
				}
			}
			catch( Exception ex ){
				infMsg = " Could not retrieve properties for this edge. exMsg = [" 
						+ ex.getMessage() + "] ";
				System.out.println( infMsg ); 
				logger.info(infMsg);
			}
			
			// Try to show what's connected to the IN side of this Edge
			try {
				infMsg = " Looking for the Vertex on the IN side of the edge:  ";
				System.out.print(infMsg);
				logger.info(infMsg);
				Vertex inVtx = tEd.inVertex();
				Iterator<VertexProperty<Object>> pI = inVtx.properties();
				String infStr = FOUND_VERTEX_ID_ + inVtx.id()
					+ PROPERTIES_;
				System.out.println( infStr );
				logger.info(infStr);
				while( pI.hasNext() ){
					VertexProperty<Object> tp = pI.next();
					infStr = " [" + tp.key() + "|" + tp.value() + "] ";
					System.out.println( infStr ); 
					logger.info(infStr);
				}
			}
			catch( Exception ex ){
				infMsg = " Could not retrieve vertex data for the IN side of "
						+ "the edge. exMsg = [" + ex.getMessage() + "] ";
				System.out.println( infMsg ); 
				logger.info(infMsg);
			}
			
			// Try to show what's connected to the OUT side of this Edge
			try {
				infMsg = " Looking for the Vertex on the OUT side of the edge:  ";
				System.out.print(infMsg);
				logger.info(infMsg);
				Vertex outVtx = tEd.outVertex();
				Iterator<VertexProperty<Object>> pI = outVtx.properties();
				String infStr = FOUND_VERTEX_ID_ + outVtx.id()
					+ PROPERTIES_;
				System.out.println( infStr );
				logger.info(infStr);
				while( pI.hasNext() ){
					VertexProperty<Object> tp = pI.next();
					infStr = " [" + tp.key() + "|" + tp.value() + "] ";
					System.out.println( infStr ); 
					logger.info(infStr);
				}
			}
			catch( Exception ex ){
				infMsg = " Could not retrieve vertex data for the OUT side of "
						+ "the edge. exMsg = [" + ex.getMessage() + "] ";
				System.out.println( infMsg ); 
				logger.info(infMsg);
			}
			
		}// end showPropertiesForEdge()

		
		
		public ArrayList <String> collectEdgeInfoForNode( EELFLogger logger, Vertex tVert, boolean displayAllVidsFlag ){ 
			ArrayList <String> retArr = new ArrayList <String> ();
			Direction dir = Direction.OUT;
			for ( int i = 0; i <= 1; i++ ){
				if( i == 1 ){
					// Second time through we'll look at the IN edges.
					dir = Direction.IN;
				}
				Iterator <Edge> eI = tVert.edges(dir);
				if( ! eI.hasNext() ){
					retArr.add("No " + dir + " edges were found for this vertex. ");
				}
				while( eI.hasNext() ){
					Edge ed =  eI.next();
					String lab = ed.label();
					Vertex vtx = null;
					if( dir == Direction.OUT ){
						// get the vtx on the "other" side
						vtx = ed.inVertex();
					}
					else {
						// get the vtx on the "other" side
						vtx = ed.outVertex();
					}
					if( vtx == null ){
						retArr.add(" >>> COULD NOT FIND VERTEX on the other side of this edge edgeId = " + ed.id() + " <<< ");
						continue;
					}

					String nType = vtx.<String>property("aai-node-type").orElse(null);
					if( displayAllVidsFlag ){
						// This should rarely be needed
						String vid = vtx.id().toString();
						retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node with VtxId = " + vid );
					}
					else {
						// This is the normal case
						retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node. ");
					}
				}
			}
			return retArr;
			
		}// end of collectEdgeInfoForNode()

		
		public int countEdges( EELFLogger logger, Vertex vtx ){ 
			int edgeCount = 0;
			try {
				Iterator<Edge> edgesItr = vtx.edges(Direction.BOTH);
				while( edgesItr.hasNext() ){
					edgesItr.next();
					edgeCount++;
				}
			}
			catch (Exception e) {
				String wMsg = "-- ERROR -- Stopping the counting of edges because of Exception [" + e.getMessage() + "]";
				System.out.println( wMsg );
				LoggingContext.statusCode(StatusCode.ERROR);
				LoggingContext.responseCode(LoggingContext.DATA_ERROR);
				logger.warn( wMsg );
				LoggingContext.successStatusFields();
			}
			return edgeCount;
			
		}// end of countEdges()
		

		public int countDescendants(EELFLogger logger, Vertex vtx, int levelVal ){ 
			int totalCount = 0;
			int thisLevel = levelVal + 1;
			
			if( thisLevel > MAXDESCENDENTDEPTH ){
				String wMsg = "Warning -- Stopping the counting of descendents because we reached the max depth of " + MAXDESCENDENTDEPTH;
				System.out.println( wMsg );
				LoggingContext.statusCode(StatusCode.ERROR);
				LoggingContext.responseCode(LoggingContext.DATA_ERROR);
				logger.warn( wMsg );
				return totalCount;
			}
			
			try {
				Iterator <Vertex> vertI = graph.traversal().V(vtx).union(__.outE().has(EdgeProperty.CONTAINS.toString(), AAIDirection.OUT.toString()).inV(), __.inE().has(EdgeProperty.CONTAINS.toString(), AAIDirection.IN.toString()).outV());
				while( vertI != null && vertI.hasNext() ){
					totalCount++;
					Vertex childVtx = vertI.next();
					totalCount = totalCount + countDescendants( logger, childVtx, thisLevel );
				}
			}
			catch (Exception e) {
				String wMsg = "Error -- Stopping the counting of descendents because of Exception [" + e.getMessage() + "]";
				System.out.println( wMsg );
				LoggingContext.statusCode(StatusCode.ERROR);
				LoggingContext.responseCode(LoggingContext.DATA_ERROR);
				logger.warn( wMsg );
				LoggingContext.successStatusFields();
				
			}
			
			return totalCount;
		}// end of countDescendants()

		
		public boolean getEdgeDelConfirmation( EELFLogger logger, String uid, Edge ed, 
				Boolean overRideProtection ) {
			
			showPropertiesForEdge( logger, ed );
			System.out.print("\n Are you sure you want to delete this EDGE? (y/n): ");
			Scanner s = new Scanner(System.in);
			s.useDelimiter("");
			String confirm = s.next();
			s.close();
			
			if (!"y".equalsIgnoreCase(confirm)) {
				String infMsg = " User [" + uid + "] has chosen to abandon this delete request. ";
				System.out.println("\n" + infMsg);
				logger.info(infMsg);
				return false;
			}
			else {
				String infMsg = " User [" + uid + "] has confirmed this delete request. ";
				System.out.println("\n" + infMsg);
				logger.info(infMsg);
				return true;
			}
		
		} // End of getEdgeDelConfirmation()
			

		public boolean getNodeDelConfirmation( EELFLogger logger, String uid, Vertex vtx, int edgeCount, 
				int descendantCount, Boolean overRideProtection ) {
			String thisNodeType = "";
			try {
				thisNodeType = vtx.<String>property("aai-node-type").orElse(null);
			}
			catch ( Exception nfe ){
				// Let the user know something is going on - but they can confirm the delete if they want to. 
				String infMsg = " -- WARNING -- could not get an aai-node-type for this vertex. -- WARNING -- ";
				System.out.println( infMsg );
				LoggingContext.statusCode(StatusCode.ERROR);
				LoggingContext.responseCode(LoggingContext.DATA_ERROR);
				logger.warn( infMsg );
				LoggingContext.successStatusFields();
			}
			
			String ntListString = "";  
			String maxDescString = "";
			String maxEdgeString = "";
			
			int maxDescCount = 10; // default value
			int maxEdgeCount = 10; // default value
			ArrayList <String> protectedNTypes = new ArrayList <String> ();
			protectedNTypes.add("cloud-region");  // default value
			
			try {
				ntListString = AAIConfig.get("aai.forceDel.protected.nt.list");
				maxDescString = AAIConfig.get("aai.forceDel.protected.descendant.count");
				maxEdgeString = AAIConfig.get("aai.forceDel.protected.edge.count");
			}
			catch ( Exception nfe ){
				// Don't worry, we will use default values 
				String infMsg = "-- WARNING -- could not get aai.forceDel.protected values from aaiconfig.properties -- will use default values. ";
				System.out.println( infMsg );
				LoggingContext.statusCode(StatusCode.ERROR);
				LoggingContext.responseCode(LoggingContext.DATA_ERROR);
				logger.warn( infMsg );
				LoggingContext.successStatusFields();
			}
			
			if( maxDescString != null && !maxDescString.isEmpty() ){
				try {
					maxDescCount = Integer.parseInt(maxDescString);
				}
				catch ( Exception nfe ){
					// Don't worry, we will leave "maxDescCount" set to the default value 
				}
			}
			
			if( maxEdgeString != null &&  !maxEdgeString.isEmpty() ){
				try {
					maxEdgeCount = Integer.parseInt(maxEdgeString);
				}
				catch ( Exception nfe ){
					// Don't worry, we will leave "maxEdgeCount" set to the default value 
				}
			}
			
			if( ntListString != null && !ntListString.trim().isEmpty() ){
				String [] nodeTypes = ntListString.split("\\|");
				for( int i = 0; i < nodeTypes.length; i++ ){
					protectedNTypes.add(nodeTypes[i]);
				}
			}
			
			boolean giveProtOverRideMsg = false;
			boolean giveProtErrorMsg = false;
			if( descendantCount > maxDescCount ){
				// They are trying to delete a node with a lots of descendants
				String infMsg = " >> WARNING >> This node has more descendant edges than the max ProtectedDescendantCount: " + edgeCount + ".  Max = " + 
							maxEdgeCount + ".  It can be DANGEROUS to delete one of these. << WARNING << ";
				System.out.println(infMsg);
				logger.info(infMsg);
				if( ! overRideProtection ){
					// They cannot delete this kind of node without using the override option
					giveProtErrorMsg = true;
				}
				else {
					giveProtOverRideMsg = true;
				}
			}
			
			if( edgeCount > maxEdgeCount ){
				// They are trying to delete a node with a lot of edges
				String infMsg = " >> WARNING >> This node has more edges than the max ProtectedEdgeCount: " + edgeCount + ".  Max = " + 
							maxEdgeCount + ".  It can be DANGEROUS to delete one of these. << WARNING << ";
				System.out.println(infMsg);
				logger.info(infMsg);
				if( ! overRideProtection ){
					// They cannot delete this kind of node without using the override option
					giveProtErrorMsg = true;
				}
				else {
					giveProtOverRideMsg = true;
				}
			}
			
			if( thisNodeType != null && !thisNodeType.equals("") && protectedNTypes.contains(thisNodeType) ){
				// They are trying to delete a protected Node Type
				String infMsg = " >> WARNING >> This node is a PROTECTED NODE-TYPE (" + thisNodeType + "). " +
						" It can be DANGEROUS to delete one of these. << WARNING << ";
				System.out.println(infMsg);
				logger.info(infMsg);
				if( ! overRideProtection ){
					// They cannot delete this kind of node without using the override option
					giveProtErrorMsg = true;
				}
				else {
					giveProtOverRideMsg = true;
				}
			}
			
			if( giveProtOverRideMsg ){
				String infMsg = " !!>> WARNING >>!! you are using the overRideProtection parameter which will let you do this potentially dangerous delete.";
				System.out.println("\n" + infMsg);
				logger.info(infMsg);
			}
			else if( giveProtErrorMsg ) {
				String errMsg = " ERROR >> this kind of node can only be deleted if you pass the overRideProtection parameter.";
				System.out.println("\n" + errMsg);
				LoggingContext.statusCode(StatusCode.ERROR);
				LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
				logger.error(errMsg);
				LoggingContext.successStatusFields();
				return false;
			}
			
			System.out.print("\n Are you sure you want to do this delete? (y/n): ");
			Scanner s = new Scanner(System.in);
			s.useDelimiter("");
			String confirm = s.next();
			s.close();
			
			if (!"y".equalsIgnoreCase(confirm)) {
				String infMsg = " User [" + uid + "] has chosen to abandon this delete request. ";
				System.out.println("\n" + infMsg);
				logger.info(infMsg);
				return false;
			}
			else {
				String infMsg = " User [" + uid + "] has confirmed this delete request. ";
				System.out.println("\n" + infMsg);
				logger.info(infMsg);
				return true;
			}
		
		} // End of getNodeDelConfirmation()
	}

	public static JanusGraph setupGraph(EELFLogger logger){

		JanusGraph janusGraph = null;

		try (InputStream inputStream = new FileInputStream(AAIConstants.REALTIME_DB_CONFIG);){

			Properties properties = new Properties();
			properties.load(inputStream);

			if(INMEMORY.equals(properties.get("storage.backend"))){
				janusGraph = AAIGraph.getInstance().getGraph();
				graphType = INMEMORY;
			} else {
				janusGraph = JanusGraphFactory.open(
						new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG)
						.forService(ForceDeleteTool.class.getSimpleName())
						.withGraphType("realtime1")
						.buildConfiguration()
				);
			}
		} catch (Exception e) {
			logger.error("Unable to open the graph", LogFormatTools.getStackTop(e));
		}

		return janusGraph;
	}

	public static void closeGraph(JanusGraph graph, EELFLogger logger){

		try {
			if(INMEMORY.equals(graphType)) {
				return;
			}
			if( graph != null && graph.isOpen() ){
				graph.tx().close();
				graph.close();
			}
		} catch (Exception ex) {
			// Don't throw anything because JanusGraph sometimes is just saying that the graph is already closed{
			logger.warn("WARNING from final graph.shutdown()", ex);
		}
	}
}