Skip to content

Commit 210ffa8

Browse files
authored
Merge pull request #15 from Comcast/feature_java_upgrade
Java and AWS upgrades
2 parents 0157e84 + 361c6f7 commit 210ffa8

File tree

6 files changed

+66
-47
lines changed

6 files changed

+66
-47
lines changed

dynocon-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.comcast.dynocon</groupId>
88
<artifactId>dynocon-parent</artifactId>
9-
<version>1.1.0</version>
9+
<version>2.0.0</version>
1010
</parent>
1111

1212
<artifactId>dynocon-core</artifactId>

dynocon-dynamodb/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.comcast.dynocon</groupId>
88
<artifactId>dynocon-parent</artifactId>
9-
<version>1.1.0</version>
9+
<version>2.0.0</version>
1010
</parent>
1111

1212
<artifactId>dynocon-dynamodb</artifactId>
@@ -18,12 +18,12 @@
1818
<dependency>
1919
<groupId>com.comcast.dynocon</groupId>
2020
<artifactId>dynocon-core</artifactId>
21-
<version>1.1.0</version>
21+
<version>2.0.0</version>
2222
</dependency>
2323
<dependency>
24-
<groupId>com.amazonaws</groupId>
25-
<artifactId>aws-java-sdk-dynamodb</artifactId>
26-
<version>1.11.1008</version>
24+
<groupId>software.amazon.awssdk</groupId>
25+
<artifactId>dynamodb</artifactId>
26+
<version>2.40.5</version>
2727
</dependency>
2828

2929
<dependency>

dynocon-dynamodb/src/main/java/com/comcast/dynocon/dynamodb/DynamodbPropertiesSource.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212
*/
1313
package com.comcast.dynocon.dynamodb;
1414

15-
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
16-
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
17-
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
18-
import com.amazonaws.services.dynamodbv2.model.ScanRequest;
19-
import com.amazonaws.services.dynamodbv2.model.ScanResult;
2015
import com.comcast.dynocon.ConfigFactory;
2116
import com.comcast.dynocon.ConfigUtil;
2217
import com.comcast.dynocon.PropertiesSource;
2318
import org.slf4j.Logger;
2419
import org.slf4j.LoggerFactory;
20+
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
21+
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
22+
import software.amazon.awssdk.services.dynamodb.model.ScanRequest;
23+
import software.amazon.awssdk.services.dynamodb.model.ScanResponse;
2524

2625
import java.util.HashMap;
2726
import java.util.Map;
@@ -37,7 +36,7 @@ public class DynamodbPropertiesSource implements PropertiesSource {
3736

3837
private static final Logger LOGGER = LoggerFactory.getLogger(DynamodbPropertiesSource.class);
3938

40-
private static final AmazonDynamoDB CLIENT = AmazonDynamoDBClientBuilder.standard().build();
39+
private static final DynamoDbClient CLIENT = DynamoDbClient.create();
4140
private static final String DEFAULT_TABLE_NAME = "config";
4241
private static final int DEFAULT_POLLING_DELAY_SEC = 30;
4342

@@ -95,13 +94,20 @@ protected Map<String, String> getProperties() {
9594
try {
9695
Map<String, AttributeValue> lastKeyEvaluated = null;
9796
do {
98-
ScanResult scanResult = CLIENT.scan(new ScanRequest().withTableName(tableName).withExclusiveStartKey(lastKeyEvaluated));
99-
for (Map<String, AttributeValue> item : scanResult.getItems()) {
100-
LOGGER.trace("DynamoDB item: key=`{}` value=`{}`", item.get("key").getS(), item.get("value").getS());
101-
result.put(item.get("key").getS(), item.get("value").getS());
97+
ScanRequest.Builder scanRequestBuilder = ScanRequest.builder().tableName(tableName);
98+
if (lastKeyEvaluated != null && !lastKeyEvaluated.isEmpty()) {
99+
scanRequestBuilder.exclusiveStartKey(lastKeyEvaluated);
102100
}
103-
lastKeyEvaluated = scanResult.getLastEvaluatedKey();
104-
} while (lastKeyEvaluated != null);
101+
ScanRequest scanRequest = scanRequestBuilder.build();
102+
ScanResponse scanResponse = CLIENT.scan(scanRequest);
103+
for (Map<String, AttributeValue> item : scanResponse.items()) {
104+
String key = item.get("key").s();
105+
String value = item.get("value").s();
106+
LOGGER.trace("DynamoDB item: key=`{}` value=`{}`", key, value);
107+
result.put(key, value);
108+
}
109+
lastKeyEvaluated = scanResponse.lastEvaluatedKey();
110+
} while (lastKeyEvaluated != null && !lastKeyEvaluated.isEmpty());
105111
lastKnownGood = result;
106112
} catch (Throwable e) {
107113
result = lastKnownGood;

dynocon-s3/pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>dynocon-parent</artifactId>
77
<groupId>com.comcast.dynocon</groupId>
8-
<version>1.1.0</version>
8+
<version>2.0.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -14,20 +14,20 @@
1414
<description>AWS S3 Bucket source for JSON Dynamic Properties</description>
1515

1616
<properties>
17-
<maven.compiler.source>8</maven.compiler.source>
18-
<maven.compiler.target>8</maven.compiler.target>
17+
<maven.compiler.source>25</maven.compiler.source>
18+
<maven.compiler.target>25</maven.compiler.target>
1919
</properties>
2020

2121
<dependencies>
2222
<dependency>
2323
<groupId>com.comcast.dynocon</groupId>
2424
<artifactId>dynocon-core</artifactId>
25-
<version>1.1.0</version>
25+
<version>2.0.0</version>
2626
</dependency>
2727
<dependency>
28-
<groupId>com.amazonaws</groupId>
29-
<artifactId>aws-java-sdk-s3</artifactId>
30-
<version>1.11.1008</version>
28+
<groupId>software.amazon.awssdk</groupId>
29+
<artifactId>s3</artifactId>
30+
<version>2.40.5</version>
3131
</dependency>
3232

3333
<dependency>

dynocon-s3/src/main/java/com/comcast/dynocon/s3/S3PropertiesSource.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
package com.comcast.dynocon.s3;
22

3-
import com.amazonaws.services.s3.AmazonS3;
4-
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
5-
import com.amazonaws.services.s3.model.*;
6-
import com.amazonaws.util.IOUtils;
73
import com.comcast.dynocon.ConfigFactory;
84
import com.comcast.dynocon.ConfigUtil;
95
import com.comcast.dynocon.PropertiesSource;
106
import org.slf4j.Logger;
117
import org.slf4j.LoggerFactory;
12-
8+
import software.amazon.awssdk.services.s3.S3Client;
9+
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
10+
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
11+
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
12+
import software.amazon.awssdk.services.s3.model.S3Object;
13+
14+
import java.io.BufferedReader;
15+
import java.io.InputStream;
16+
import java.io.InputStreamReader;
17+
import java.nio.charset.StandardCharsets;
1318
import java.util.HashMap;
1419
import java.util.Map;
1520
import java.util.Optional;
1621
import java.util.concurrent.Executors;
1722
import java.util.concurrent.ScheduledExecutorService;
1823
import java.util.concurrent.TimeUnit;
24+
import java.util.stream.Collectors;
1925

2026
public class S3PropertiesSource implements PropertiesSource {
2127

@@ -24,7 +30,7 @@ public class S3PropertiesSource implements PropertiesSource {
2430

2531
private static final Logger LOGGER = LoggerFactory.getLogger(S3PropertiesSource.class);
2632

27-
private static final AmazonS3 CLIENT = AmazonS3ClientBuilder.standard().build();
33+
private static final S3Client CLIENT = S3Client.create();
2834
private static final String DEFAULT_BUCKET_NAME = "config";
2935
private static final int DEFAULT_POLLING_DELAY_SEC = 30;
3036

@@ -81,22 +87,29 @@ public S3PropertiesSource(String s3BucketName) {
8187
protected Map<String, String> getProperties() {
8288
Map<String, String> result = new HashMap<>();
8389
try {
84-
ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(bucketName).withMaxKeys(100);
85-
ListObjectsV2Result s3Result;
90+
String continuationToken = null;
8691
do {
87-
s3Result = CLIENT.listObjectsV2(req);
88-
for (S3ObjectSummary objectSummary : s3Result.getObjectSummaries()) {
89-
S3Object fullObject = CLIENT.getObject(new GetObjectRequest(bucketName, objectSummary.getKey()));
90-
String key = objectSummary.getKey();
91-
if (key.endsWith(".json")) {
92-
key = key.substring(0, key.length() - 5);
92+
ListObjectsV2Request.Builder reqBuilder = ListObjectsV2Request.builder().bucket(bucketName).maxKeys(100);
93+
if (continuationToken != null) {
94+
reqBuilder.continuationToken(continuationToken);
95+
}
96+
ListObjectsV2Request req = reqBuilder.build();
97+
ListObjectsV2Response s3Result = CLIENT.listObjectsV2(req);
98+
for (S3Object objectSummary : s3Result.contents()) {
99+
GetObjectRequest getObjectRequest = GetObjectRequest.builder().bucket(bucketName).key(objectSummary.key()).build();
100+
try (InputStream is = CLIENT.getObject(getObjectRequest);
101+
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
102+
String key = objectSummary.key();
103+
if (key.endsWith(".json")) {
104+
key = key.substring(0, key.length() - 5);
105+
}
106+
String value = reader.lines().collect(Collectors.joining("\n"));
107+
LOGGER.trace("S3 item: key=`{}` value=`{}`", key, value);
108+
result.put(key, value);
93109
}
94-
String value = IOUtils.toString(fullObject.getObjectContent());
95-
LOGGER.trace("S3 item: key=`{}` value=`{}`", key, value);
96-
result.put(key, value);
97110
}
98-
req.setContinuationToken(s3Result.getNextContinuationToken());
99-
} while (s3Result.isTruncated());
111+
continuationToken = s3Result.nextContinuationToken();
112+
} while (continuationToken != null && !continuationToken.isEmpty());
100113
lastKnownGood = result;
101114
} catch (Throwable e) {
102115
result = lastKnownGood;

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.comcast.dynocon</groupId>
66
<artifactId>dynocon-parent</artifactId>
7-
<version>1.1.0</version>
7+
<version>2.0.0</version>
88
<packaging>pom</packaging>
99
<name>Dynamic Configuration Parent</name>
1010
<description>JSON Dynamic Properties</description>
@@ -40,8 +40,8 @@
4040
</modules>
4141

4242
<properties>
43-
<maven.compiler.source>1.8</maven.compiler.source>
44-
<maven.compiler.target>1.8</maven.compiler.target>
43+
<maven.compiler.source>25</maven.compiler.source>
44+
<maven.compiler.target>25</maven.compiler.target>
4545
</properties>
4646

4747
<build>

0 commit comments

Comments
 (0)