29
29
*/
30
30
package com .jcabi .dynamodb .maven .plugin ;
31
31
32
+ import com .amazonaws .AmazonClientException ;
32
33
import com .amazonaws .auth .BasicAWSCredentials ;
33
34
import com .amazonaws .services .dynamodbv2 .AmazonDynamoDB ;
34
35
import com .amazonaws .services .dynamodbv2 .AmazonDynamoDBClient ;
39
40
import com .amazonaws .services .dynamodbv2 .model .LocalSecondaryIndex ;
40
41
import com .amazonaws .services .dynamodbv2 .model .Projection ;
41
42
import com .amazonaws .services .dynamodbv2 .model .ProvisionedThroughput ;
42
- import com .amazonaws .services .dynamodbv2 .util .Tables ;
43
+ import com .amazonaws .services .dynamodbv2 .util .TableUtils ;
44
+ import com .jcabi .aspects .Tv ;
43
45
import com .jcabi .log .Logger ;
44
46
import java .io .FileInputStream ;
45
47
import java .io .IOException ;
72
74
threadSafe = true , name = "create-tables" ,
73
75
defaultPhase = LifecyclePhase .PRE_INTEGRATION_TEST
74
76
)
75
- @ SuppressWarnings ("PMD.AvoidInstantiatingObjectsInLoops" )
77
+ @ SuppressWarnings
78
+ (
79
+ {
80
+ "PMD.NPathComplexity" ,
81
+ "PMD.CyclomaticComplexity" ,
82
+ "PMD.StdCyclomaticComplexity" ,
83
+ "PMD.ModifiedCyclomaticComplexity" ,
84
+ "PMD.AvoidInstantiatingObjectsInLoops"
85
+ }
86
+ )
76
87
public final class CreateTablesMojo extends AbstractDynamoMojo {
77
88
78
89
/**
@@ -109,7 +120,7 @@ public void run(final Instances instances) throws MojoFailureException {
109
120
final JsonObject json = this .readJson (table );
110
121
if (json .containsKey ("TableName" )) {
111
122
final String name = json .getString ("TableName" );
112
- if (Tables . doesTableExist (aws , name )) {
123
+ if (CreateTablesMojo . exists (aws , name )) {
113
124
Logger .info (
114
125
this , "Table '%s' already exists, skipping..." , name
115
126
);
@@ -126,12 +137,35 @@ public void run(final Instances instances) throws MojoFailureException {
126
137
}
127
138
}
128
139
140
+ /**
141
+ * Table exists?
142
+ * @param aws AWS
143
+ * @param name Table name
144
+ * @return TRUE if it exists
145
+ */
146
+ private static boolean exists (final AmazonDynamoDB aws , final String name ) {
147
+ boolean exists ;
148
+ try {
149
+ TableUtils .waitUntilExists (
150
+ aws , name , Tv .THOUSAND , Tv .HUNDRED
151
+ );
152
+ exists = true ;
153
+ } catch (final AmazonClientException ex ) {
154
+ exists = false ;
155
+ } catch (final InterruptedException ex ) {
156
+ Thread .currentThread ().interrupt ();
157
+ throw new IllegalStateException (ex );
158
+ }
159
+ return exists ;
160
+ }
161
+
129
162
/**
130
163
* Create DynamoDB table.
131
164
*
132
165
* @param aws DynamoDB client
133
166
* @param json JSON definition of table
134
167
* @checkstyle ExecutableStatementCount (50 lines)
168
+ * @checkstyle NPathComplexityCheck (100 lines)
135
169
*/
136
170
private void createTable (final AmazonDynamoDB aws , final JsonObject json ) {
137
171
final String name = json .getString ("TableName" );
@@ -204,7 +238,12 @@ private void createTable(final AmazonDynamoDB aws, final JsonObject json) {
204
238
}
205
239
aws .createTable (request );
206
240
Logger .info (this , "Waiting for table '%s' to become active" , name );
207
- Tables .waitForTableToBecomeActive (aws , name );
241
+ try {
242
+ TableUtils .waitUntilActive (aws , name );
243
+ } catch (final InterruptedException ex ) {
244
+ Thread .currentThread ().interrupt ();
245
+ throw new IllegalStateException (ex );
246
+ }
208
247
Logger .info (this , "Table '%s' is now ready for use" , name );
209
248
}
210
249
0 commit comments