|
3 | 3 |
|
4 | 4 | package com.example.neptune.scenerio;
|
5 | 5 |
|
| 6 | +import org.slf4j.Logger; |
| 7 | +import org.slf4j.LoggerFactory; |
| 8 | + |
6 | 9 | import java.util.Scanner;
|
7 | 10 |
|
8 | 11 | //TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
9 | 12 | // click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
10 | 13 | public class NeptuneScenario {
|
11 | 14 | public static final String DASHES = new String(new char[80]).replace("\0", "-");
|
12 |
| - |
| 15 | + private static final Logger logger = LoggerFactory.getLogger(NeptuneScenario.class); |
13 | 16 | static Scanner scanner = new Scanner(System.in);
|
14 | 17 | static NeptuneActions neptuneActions = new NeptuneActions();
|
15 | 18 |
|
16 | 19 | public static void main(String[] args) {
|
17 |
| - String subnetGroupName = "neptuneSubnetGroup28" ; |
| 20 | + String subnetGroupName = "neptuneSubnetGroup56" ; |
18 | 21 | String vpcId = "vpc-e97a4393" ;
|
19 |
| - String clusterName = "neptuneCluster28" ; |
20 |
| - String dbInstanceId = "neptuneDB28" ; |
| 22 | + String clusterName = "neptuneCluster56" ; |
| 23 | + String dbInstanceId = "neptuneDB56" ; |
21 | 24 |
|
22 |
| - System.out.println(""" |
| 25 | + logger.info(""" |
23 | 26 | Amazon Neptune is a fully managed graph
|
24 | 27 | database service by AWS, designed specifically
|
25 | 28 | for handling complex relationships and connected
|
@@ -50,98 +53,109 @@ property graphs (via openCypher and Gremlin) and RDF
|
50 | 53 | }
|
51 | 54 |
|
52 | 55 | public static void runScenario(String subnetGroupName, String vpcId, String dbInstanceId, String clusterName) {
|
53 |
| - System.out.println(DASHES); |
54 |
| - System.out.println("1. Create a Neptune DB Subnet Group"); |
55 |
| - System.out.println("The Neptune DB subnet group is used when launching a Neptune cluster"); |
| 56 | + logger.info(DASHES); |
| 57 | + logger.info("1. Create a Neptune DB Subnet Group"); |
| 58 | + logger.info("The Neptune DB subnet group is used when launching a Neptune cluster"); |
56 | 59 | waitForInputToContinue(scanner);
|
57 |
| - String groupARN = neptuneActions.createSubnetGroup(vpcId, subnetGroupName); |
| 60 | + neptuneActions.createSubnetGroupAsync(vpcId, subnetGroupName).join(); |
58 | 61 | waitForInputToContinue(scanner);
|
59 |
| - System.out.println(DASHES); |
| 62 | + logger.info(DASHES); |
60 | 63 |
|
61 |
| - System.out.println(DASHES); |
62 |
| - System.out.println("2. Create a Neptune Cluster"); |
63 |
| - System.out.println("A Neptune Cluster allows you to store and query highly connected datasets with low latency."); |
| 64 | + logger.info(DASHES); |
| 65 | + logger.info("2. Create a Neptune Cluster"); |
| 66 | + logger.info("A Neptune Cluster allows you to store and query highly connected datasets with low latency."); |
64 | 67 | waitForInputToContinue(scanner);
|
65 |
| - String dbClusterId = neptuneActions.createDBCluster(clusterName); |
| 68 | + String dbClusterId = neptuneActions.createDBClusterAsync(clusterName).join(); |
66 | 69 | waitForInputToContinue(scanner);
|
67 |
| - System.out.println(DASHES); |
| 70 | + logger.info(DASHES); |
68 | 71 |
|
69 |
| - System.out.println(DASHES); |
70 |
| - System.out.println("3. Create a Neptune DB Instance"); |
71 |
| - System.out.println("In this step, we add a new database instance to the Neptune cluster"); |
| 72 | + logger.info(DASHES); |
| 73 | + logger.info("3. Create a Neptune DB Instance"); |
| 74 | + logger.info("In this step, we add a new database instance to the Neptune cluster"); |
72 | 75 | waitForInputToContinue(scanner);
|
73 |
| - neptuneActions.createDBInstance(dbInstanceId, dbClusterId); |
| 76 | + neptuneActions.createDBInstanceAsync(dbInstanceId, dbClusterId).join(); |
74 | 77 | waitForInputToContinue(scanner);
|
75 |
| - System.out.println(DASHES); |
| 78 | + logger.info(DASHES); |
76 | 79 |
|
77 |
| - System.out.println(DASHES); |
78 |
| - System.out.println("4. Check the status of the Neptune DB Instance"); |
79 |
| - System.out.println(""" |
| 80 | + logger.info(DASHES); |
| 81 | + logger.info("4. Check the status of the Neptune DB Instance"); |
| 82 | + logger.info(""" |
80 | 83 | In this step, we will wait until the DB instance
|
81 | 84 | becomes available. This may take around 10 minutes.
|
82 | 85 | """);
|
83 | 86 | waitForInputToContinue(scanner);
|
84 |
| - neptuneActions.isNeptuneInstanceReady(dbInstanceId); |
| 87 | + neptuneActions.checkInstanceStatus(dbInstanceId, "available").join(); |
85 | 88 | waitForInputToContinue(scanner);
|
86 |
| - System.out.println(DASHES); |
| 89 | + logger.info(DASHES); |
87 | 90 |
|
88 |
| - System.out.println(DASHES); |
89 |
| - System.out.println("5. Tag the Amazon Neptune Resource"); |
| 91 | + logger.info(DASHES); |
| 92 | + logger.info("5.Show Neptune Cluster details"); |
90 | 93 | waitForInputToContinue(scanner);
|
91 |
| - System.out.println(DASHES); |
92 |
| - |
93 |
| - System.out.println(DASHES); |
94 |
| - System.out.println("6.Show Neptune Cluster details"); |
| 94 | + neptuneActions.describeDBClustersAsync(clusterName).join(); |
95 | 95 | waitForInputToContinue(scanner);
|
96 |
| - neptuneActions.describeDBClusters(clusterName); |
| 96 | + logger.info(DASHES); |
| 97 | + |
| 98 | + logger.info(DASHES); |
| 99 | + logger.info("6. Stop the Amazon Neptune cluster"); |
| 100 | + logger.info(""" |
| 101 | + Once stopped, this step polls the status |
| 102 | + until the cluster is in a stopped state. |
| 103 | + """); |
97 | 104 | waitForInputToContinue(scanner);
|
98 |
| - System.out.println(DASHES); |
99 |
| - |
100 |
| - System.out.println(DASHES); |
101 |
| - System.out.println("7.Show Neptune Instance details"); |
| 105 | + neptuneActions.stopDBCluster(dbClusterId); |
| 106 | + neptuneActions.waitForClusterStatus(dbClusterId,"stopped"); |
102 | 107 | waitForInputToContinue(scanner);
|
103 |
| - neptuneActions.describeDBInstances(dbInstanceId); |
| 108 | + logger.info(DASHES); |
| 109 | + |
| 110 | + logger.info(DASHES); |
| 111 | + logger.info("7. Start the Amazon Neptune cluster"); |
| 112 | + logger.info(""" |
| 113 | + Once started, this step polls the clusters |
| 114 | + status until it's in an available state. |
| 115 | + We will also poll the instance status. |
| 116 | + """); |
104 | 117 | waitForInputToContinue(scanner);
|
105 |
| - System.out.println(DASHES); |
106 |
| - |
107 |
| - System.out.println(DASHES); |
108 |
| - System.out.println("8. Delete the Neptune Assets"); |
109 |
| - System.out.println("Would you like to delete the Neptune Assets? (y/n)"); |
| 118 | + neptuneActions.startDBCluster(dbClusterId); |
| 119 | + neptuneActions.waitForClusterStatus(dbClusterId,"available"); |
| 120 | + neptuneActions.checkInstanceStatus(dbInstanceId, "available").join(); |
| 121 | + logger.info(DASHES); |
| 122 | + logger.info(DASHES); |
| 123 | + logger.info("8. Delete the Neptune Assets"); |
| 124 | + logger.info("Would you like to delete the Neptune Assets? (y/n)"); |
110 | 125 | String delAns = scanner.nextLine().trim();
|
111 | 126 | if (delAns.equalsIgnoreCase("y")) {
|
112 |
| - System.out.println("You selected to delete the Neptune assets."); |
113 |
| - neptuneActions.deleteDBInstance(dbInstanceId); |
114 |
| - neptuneActions.deleteDBCluster(dbClusterId); |
115 |
| - neptuneActions.deleteDBSubnetGroup(subnetGroupName); |
| 127 | + logger.info("You selected to delete the Neptune assets."); |
| 128 | + neptuneActions.deleteNeptuneResourcesAsync(dbInstanceId, clusterName, subnetGroupName); |
| 129 | + |
116 | 130 | } else {
|
117 |
| - System.out.println("You selected not to delete Neptune assets."); |
| 131 | + logger.info("You selected not to delete Neptune assets."); |
118 | 132 | }
|
119 | 133 | waitForInputToContinue(scanner);
|
120 |
| - System.out.println(DASHES); |
| 134 | + logger.info(DASHES); |
121 | 135 |
|
122 |
| - System.out.println(DASHES); |
123 |
| - System.out.println( |
| 136 | + logger.info(DASHES); |
| 137 | + logger.info( |
124 | 138 | """
|
125 | 139 | Thank you for checking out the Amazon Neptune Service Use demo. We hope you
|
126 | 140 | learned something new, or got some inspiration for your own apps today.
|
127 | 141 | For more AWS code examples, have a look at:
|
128 | 142 | https://docs.aws.amazon.com/code-library/latest/ug/what-is-code-library.html
|
129 | 143 | """);
|
130 |
| - System.out.println(DASHES); |
| 144 | + logger.info(DASHES); |
131 | 145 | }
|
132 | 146 |
|
133 | 147 | private static void waitForInputToContinue(Scanner scanner) {
|
134 | 148 | while (true) {
|
135 |
| - System.out.println(""); |
136 |
| - System.out.println("Enter 'c' followed by <ENTER> to continue:"); |
| 149 | + logger.info(""); |
| 150 | + logger.info("Enter 'c' followed by <ENTER> to continue:"); |
137 | 151 | String input = scanner.nextLine();
|
138 | 152 |
|
139 | 153 | if (input.trim().equalsIgnoreCase("c")) {
|
140 |
| - System.out.println("Continuing with the program..."); |
141 |
| - System.out.println(""); |
| 154 | + logger.info("Continuing with the program..."); |
| 155 | + logger.info(""); |
142 | 156 | break;
|
143 | 157 | } else {
|
144 |
| - System.out.println("Invalid input. Please try again."); |
| 158 | + logger.info("Invalid input. Please try again."); |
145 | 159 | }
|
146 | 160 | }
|
147 | 161 | }
|
|
0 commit comments