Skip to content

Commit 68eef7a

Browse files
author
Yegor Bugayenko
committed
#47 versions up
1 parent eb8d1ef commit 68eef7a

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![We recommend IntelliJ IDEA](http://img.teamed.io/intellij-idea-recommend.svg)](https://www.jetbrains.com/idea/)
66

77
[![Build Status](https://travis-ci.org/jcabi/jcabi-dynamodb-maven-plugin.svg?branch=master)](https://travis-ci.org/jcabi/jcabi-dynamodb-maven-plugin)
8+
[![Build status](https://ci.appveyor.com/api/projects/status/4ads96yp0axlg9wv?svg=true)](https://ci.appveyor.com/project/yegor256/jcabi-dynamodb-maven-plugin)
89
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.jcabi/jcabi-dynamodb-maven-plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.jcabi/jcabi-dynamodb-maven-plugin)
910

1011
More details are here: [dynamodb.jcabi.com](http://dynamodb.jcabi.com/index.html).

pom.xml

+9-4
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@
9292
</dependency>
9393
<dependency>
9494
<groupId>com.amazonaws</groupId>
95-
<artifactId>aws-java-sdk</artifactId>
96-
<version>1.7.7</version>
95+
<artifactId>aws-java-sdk-core</artifactId>
96+
<version>1.10.47</version>
97+
</dependency>
98+
<dependency>
99+
<groupId>com.amazonaws</groupId>
100+
<artifactId>aws-java-sdk-dynamodb</artifactId>
101+
<version>1.10.47</version>
97102
</dependency>
98103
<dependency>
99104
<groupId>org.aspectj</groupId>
@@ -132,7 +137,7 @@
132137
<dependency>
133138
<groupId>org.codehaus.plexus</groupId>
134139
<artifactId>plexus-utils</artifactId>
135-
<version>2.0.6</version>
140+
<version>3.0.22</version>
136141
<scope>provided</scope>
137142
</dependency>
138143
<dependency>
@@ -154,7 +159,7 @@
154159
<dependency>
155160
<groupId>org.apache.maven.plugin-tools</groupId>
156161
<artifactId>maven-plugin-annotations</artifactId>
157-
<version>3.2</version>
162+
<version>3.4</version>
158163
<scope>provided</scope>
159164
</dependency>
160165
<dependency>

src/main/java/com/jcabi/dynamodb/maven/plugin/CreateTablesMojo.java

+43-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
package com.jcabi.dynamodb.maven.plugin;
3131

32+
import com.amazonaws.AmazonClientException;
3233
import com.amazonaws.auth.BasicAWSCredentials;
3334
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
3435
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
@@ -39,7 +40,8 @@
3940
import com.amazonaws.services.dynamodbv2.model.LocalSecondaryIndex;
4041
import com.amazonaws.services.dynamodbv2.model.Projection;
4142
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;
4345
import com.jcabi.log.Logger;
4446
import java.io.FileInputStream;
4547
import java.io.IOException;
@@ -72,7 +74,16 @@
7274
threadSafe = true, name = "create-tables",
7375
defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST
7476
)
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+
)
7687
public final class CreateTablesMojo extends AbstractDynamoMojo {
7788

7889
/**
@@ -109,7 +120,7 @@ public void run(final Instances instances) throws MojoFailureException {
109120
final JsonObject json = this.readJson(table);
110121
if (json.containsKey("TableName")) {
111122
final String name = json.getString("TableName");
112-
if (Tables.doesTableExist(aws, name)) {
123+
if (CreateTablesMojo.exists(aws, name)) {
113124
Logger.info(
114125
this, "Table '%s' already exists, skipping...", name
115126
);
@@ -126,12 +137,35 @@ public void run(final Instances instances) throws MojoFailureException {
126137
}
127138
}
128139

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+
129162
/**
130163
* Create DynamoDB table.
131164
*
132165
* @param aws DynamoDB client
133166
* @param json JSON definition of table
134167
* @checkstyle ExecutableStatementCount (50 lines)
168+
* @checkstyle NPathComplexityCheck (100 lines)
135169
*/
136170
private void createTable(final AmazonDynamoDB aws, final JsonObject json) {
137171
final String name = json.getString("TableName");
@@ -204,7 +238,12 @@ private void createTable(final AmazonDynamoDB aws, final JsonObject json) {
204238
}
205239
aws.createTable(request);
206240
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+
}
208247
Logger.info(this, "Table '%s' is now ready for use", name);
209248
}
210249

0 commit comments

Comments
 (0)