55
66import org .slf4j .Logger ;
77import org .slf4j .LoggerFactory ;
8+ import software .amazon .awssdk .services .neptunegraph .model .ResourceNotFoundException ;
9+ import software .amazon .awssdk .services .neptunegraph .model .ServiceQuotaExceededException ;
810
911import java .util .Scanner ;
12+ import java .util .concurrent .CompletionException ;
1013
1114// snippet-start:[neptune.java2.scenario.main]
1215public class NeptuneScenario {
@@ -26,33 +29,32 @@ public static void main(String[] args) {
2629 clusterName - The unique identifier for the Neptune DB cluster.
2730 dbInstanceId - The identifier for a specific Neptune DB instance within the cluster.
2831 """ ;
29- String subnetGroupName = "neptuneSubnetGroup56 " ;
30- String clusterName = "neptuneCluster56 " ;
31- String dbInstanceId = "neptuneDB56 " ;
32+ String subnetGroupName = "neptuneSubnetGroup58 " ;
33+ String clusterName = "neptuneCluster58 " ;
34+ String dbInstanceId = "neptuneDB58 " ;
3235
3336 logger .info ("""
34- Amazon Neptune is a fully managed graph
35- database service by AWS, designed specifically
36- for handling complex relationships and connected
37- datasets at scale. It supports two popular graph models:
38- property graphs (via openCypher and Gremlin) and RDF
39- graphs (via SPARQL). This makes Neptune ideal for
40- use cases such as knowledge graphs, fraud detection,
41- social networking, recommendation engines, and
42- network management, where relationships between
43- entities are central to the data.
37+ Amazon Neptune is a fully managed graph
38+ database service by AWS, designed specifically
39+ for handling complex relationships and connected
40+ datasets at scale. It supports two popular graph models:
41+ property graphs (via openCypher and Gremlin) and RDF
42+ graphs (via SPARQL). This makes Neptune ideal for
43+ use cases such as knowledge graphs, fraud detection,
44+ social networking, recommendation engines, and
45+ network management, where relationships between
46+ entities are central to the data.
4447
45- Being fully managed, Neptune handles database
46- provisioning, patching, backups, and replication,
47- while also offering high availability and durability
48- within AWS's infrastructure.
48+ Being fully managed, Neptune handles database
49+ provisioning, patching, backups, and replication,
50+ while also offering high availability and durability
51+ within AWS's infrastructure.
4952
50- For developers, programming with Neptune allows
51- for building intelligent, relationship-aware
52- applications that go beyond traditional tabular
53- databases. Developers can use the AWS SDK for Java
54- V2 to automate infrastructure operations
55- (via NeptuneClient).
53+ For developers, programming with Neptune allows
54+ for building intelligent, relationship-aware
55+ applications that go beyond traditional tabular
56+ databases. Developers can use the AWS SDK for Java
57+ to automate infrastructure operations (via NeptuneClient).
5658
5759 Let's get started...
5860 """ );
@@ -65,23 +67,56 @@ public static void runScenario(String subnetGroupName, String dbInstanceId, Stri
6567 logger .info ("1. Create a Neptune DB Subnet Group" );
6668 logger .info ("The Neptune DB subnet group is used when launching a Neptune cluster" );
6769 waitForInputToContinue (scanner );
68- neptuneActions .createSubnetGroupAsync (subnetGroupName ).join ();
70+ try {
71+ neptuneActions .createSubnetGroupAsync (subnetGroupName ).join ();
72+
73+ } catch (CompletionException ce ) {
74+ Throwable cause = ce .getCause ();
75+ if (cause instanceof ServiceQuotaExceededException ) {
76+ logger .error ("The request failed due to service quota exceeded: {}" , cause .getMessage ());
77+ } else {
78+ logger .error ("An unexpected error occurred." , cause );
79+ }
80+ return ;
81+ }
6982 waitForInputToContinue (scanner );
7083 logger .info (DASHES );
7184
7285 logger .info (DASHES );
7386 logger .info ("2. Create a Neptune Cluster" );
7487 logger .info ("A Neptune Cluster allows you to store and query highly connected datasets with low latency." );
7588 waitForInputToContinue (scanner );
76- String dbClusterId = neptuneActions .createDBClusterAsync (clusterName ).join ();
89+ String dbClusterId ;
90+ try {
91+ dbClusterId = neptuneActions .createDBClusterAsync (clusterName ).join ();
92+ } catch (CompletionException ce ) {
93+ Throwable cause = ce .getCause ();
94+ if (cause instanceof ServiceQuotaExceededException ) {
95+ logger .error ("The request failed due to service quota exceeded: {}" , cause .getMessage ());
96+ } else {
97+ logger .error ("An unexpected error occurred." , cause );
98+ }
99+ return ;
100+ }
101+
77102 waitForInputToContinue (scanner );
78103 logger .info (DASHES );
79104
80105 logger .info (DASHES );
81106 logger .info ("3. Create a Neptune DB Instance" );
82107 logger .info ("In this step, we add a new database instance to the Neptune cluster" );
83108 waitForInputToContinue (scanner );
109+ try {
84110 neptuneActions .createDBInstanceAsync (dbInstanceId , dbClusterId ).join ();
111+ } catch (CompletionException ce ) {
112+ Throwable cause = ce .getCause ();
113+ if (cause instanceof ServiceQuotaExceededException ) {
114+ logger .error ("The request failed due to service quota exceeded: {}" , cause .getMessage ());
115+ } else {
116+ logger .error ("An unexpected error occurred." , cause );
117+ }
118+ return ;
119+ }
85120 waitForInputToContinue (scanner );
86121 logger .info (DASHES );
87122
@@ -92,14 +127,30 @@ public static void runScenario(String subnetGroupName, String dbInstanceId, Stri
92127 becomes available. This may take around 10 minutes.
93128 """ );
94129 waitForInputToContinue (scanner );
95- neptuneActions .checkInstanceStatus (dbInstanceId , "available" ).join ();
130+ try {
131+ neptuneActions .checkInstanceStatus (dbInstanceId , "available" ).join ();
132+ } catch (CompletionException ce ) {
133+ Throwable cause = ce .getCause ();
134+ logger .error ("An unexpected error occurred." , cause );
135+ return ;
136+ }
96137 waitForInputToContinue (scanner );
97138 logger .info (DASHES );
98139
99140 logger .info (DASHES );
100141 logger .info ("5.Show Neptune Cluster details" );
101142 waitForInputToContinue (scanner );
102- neptuneActions .describeDBClustersAsync (clusterName ).join ();
143+ try {
144+ neptuneActions .describeDBClustersAsync (clusterName ).join ();
145+ } catch (CompletionException ce ) {
146+ Throwable cause = ce .getCause ();
147+ if (cause instanceof ResourceNotFoundException ) {
148+ logger .error ("The request failed due to the resource not found: {}" , cause .getMessage ());
149+ } else {
150+ logger .error ("An unexpected error occurred." , cause );
151+ }
152+ return ;
153+ }
103154 waitForInputToContinue (scanner );
104155 logger .info (DASHES );
105156
@@ -110,8 +161,18 @@ public static void runScenario(String subnetGroupName, String dbInstanceId, Stri
110161 until the cluster is in a stopped state.
111162 """ );
112163 waitForInputToContinue (scanner );
113- neptuneActions .stopDBCluster (dbClusterId );
114- neptuneActions .waitForClusterStatus (dbClusterId , "stopped" );
164+ try {
165+ neptuneActions .stopDBClusterAsync (dbClusterId );
166+ neptuneActions .waitForClusterStatus (dbClusterId , "stopped" );
167+ } catch (CompletionException ce ) {
168+ Throwable cause = ce .getCause ();
169+ if (cause instanceof ResourceNotFoundException ) {
170+ logger .error ("The request failed due to the resource not found: {}" , cause .getMessage ());
171+ } else {
172+ logger .error ("An unexpected error occurred." , cause );
173+ }
174+ return ;
175+ }
115176 waitForInputToContinue (scanner );
116177 logger .info (DASHES );
117178
@@ -123,18 +184,38 @@ public static void runScenario(String subnetGroupName, String dbInstanceId, Stri
123184 We will also poll the instance status.
124185 """ );
125186 waitForInputToContinue (scanner );
126- neptuneActions .startDBCluster (dbClusterId );
127- neptuneActions .waitForClusterStatus (dbClusterId , "available" );
128- neptuneActions .checkInstanceStatus (dbInstanceId , "available" ).join ();
187+ try {
188+ neptuneActions .startDBClusterAsync (dbClusterId );
189+ neptuneActions .waitForClusterStatus (dbClusterId , "available" );
190+ neptuneActions .checkInstanceStatus (dbInstanceId , "available" ).join ();
191+ } catch (CompletionException ce ) {
192+ Throwable cause = ce .getCause ();
193+ if (cause instanceof ResourceNotFoundException ) {
194+ logger .error ("The request failed due to the resource not found: {}" , cause .getMessage ());
195+ } else {
196+ logger .error ("An unexpected error occurred." , cause );
197+ }
198+ return ;
199+ }
129200 logger .info (DASHES );
201+
130202 logger .info (DASHES );
131203 logger .info ("8. Delete the Neptune Assets" );
132204 logger .info ("Would you like to delete the Neptune Assets? (y/n)" );
133205 String delAns = scanner .nextLine ().trim ();
134206 if (delAns .equalsIgnoreCase ("y" )) {
135207 logger .info ("You selected to delete the Neptune assets." );
136- neptuneActions .deleteNeptuneResourcesAsync (dbInstanceId , clusterName , subnetGroupName );
137-
208+ try {
209+ neptuneActions .deleteNeptuneResourcesAsync (dbInstanceId , clusterName , subnetGroupName );
210+ } catch (CompletionException ce ) {
211+ Throwable cause = ce .getCause ();
212+ if (cause instanceof ResourceNotFoundException ) {
213+ logger .error ("The request failed due to the resource not found: {}" , cause .getMessage ());
214+ } else {
215+ logger .error ("An unexpected error occurred." , cause );
216+ }
217+ return ;
218+ }
138219 } else {
139220 logger .info ("You selected not to delete Neptune assets." );
140221 }
0 commit comments