Skip to content

Commit 4e5332a

Browse files
authored
Merge pull request #105 from brenopessoa/dynamodb
Dynamodb
2 parents e6cef2c + 76df001 commit 4e5332a

21 files changed

+1256
-0
lines changed

docker.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ docker run --name elasticsearch-instance -p 9300:9300 -p 9200:9200 -d elasticsea
44
docker run -d --name orientdb -p 2424:2424 -p 2480:2480 -e ORIENTDB_ROOT_PASSWORD=rootpwd orientdb
55
docker run --name redis-instance -p 6379:6379 -d redis
66
docker run --name riak-instance -d -p 8087:8087 -p 8098:8098 basho/riak-ts
7+
./dynamodb-driver/dynamoDockerRun.sh

dynamodb-driver/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM amazon/dynamodb-local

dynamodb-driver/dynamoDockerRun.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
AWS_ACCESS_KEY_ID=$(aws --profile default configure get aws_access_key_id)
2+
AWS_SECRET_ACCESS_KEY=$(aws --profile default configure get aws_secret_access_key)
3+
4+
docker build -t my_app .
5+
docker run -it --rm -p 8000:8000 \
6+
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
7+
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
8+
my_app

dynamodb-driver/pom.xml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- ~ Copyright (c) 2017 Otávio Santana and others ~ All rights reserved.
3+
This program and the accompanying materials ~ are made available under the
4+
terms of the Eclipse Public License v1.0 ~ and Apache License v2.0 which
5+
accompanies this distribution. ~ The Eclipse Public License is available
6+
at http://www.eclipse.org/legal/epl-v10.html ~ and the Apache License v2.0
7+
is available at http://www.opensource.org/licenses/apache2.0.php. ~ ~ You
8+
may elect to redistribute this code under either of these licenses. ~ ~ Contributors:
9+
~ ~ Otavio Santana -->
10+
11+
<project xmlns="http://maven.apache.org/POM/4.0.0"
12+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
14+
<modelVersion>4.0.0</modelVersion>
15+
<parent>
16+
<groupId>org.jnosql.diana</groupId>
17+
<artifactId>diana-driver</artifactId>
18+
<version>0.0.7-SNAPSHOT</version>
19+
</parent>
20+
21+
22+
<artifactId>dynamodb-driver</artifactId>
23+
<name>${project.groupId}:${project.artifactId}</name>
24+
<description>The Eclipse JNoSQL communication layer, Diana, implementation Redis</description>
25+
<url>http://jnosql.org/</url>
26+
27+
<licenses>
28+
<license>
29+
<name>The Apache Software License, Version 2.0</name>
30+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
31+
</license>
32+
<license>
33+
<name>The Eclipse Public License v1.0</name>
34+
<url>http://www.eclipse.org/legal/epl-v10.html</url>
35+
</license>
36+
</licenses>
37+
38+
39+
<scm>
40+
<connection>scm:git:git://github.com/eclipse/jnosql-diana-driver.git</connection>
41+
<developerConnection>scm:git:ssh://github.com:eclipse/jnosql-diana-driver.git</developerConnection>
42+
<url>https://github.com/eclipse/jnosql-diana-driver</url>
43+
</scm>
44+
45+
<developers>
46+
<developer>
47+
<name>Otavio Santana</name>
48+
<email>[email protected]</email>
49+
<organization>SouJava</organization>
50+
<organizationUrl>https://about.me/otaviojava</organizationUrl>
51+
</developer>
52+
<developer>
53+
<name>JNoSQL Developers</name>
54+
<email>[email protected]</email>
55+
<organization>Eclipse JNoSQL</organization>
56+
<organizationUrl>https://dev.eclipse.org/mailman/listinfo/jnosql-dev</organizationUrl>
57+
</developer>
58+
</developers>
59+
60+
<properties>
61+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
62+
</properties>
63+
<dependencies>
64+
<dependency>
65+
<groupId>org.jnosql.diana</groupId>
66+
<artifactId>diana-key-value</artifactId>
67+
<version>${project.version}</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.jnosql.diana</groupId>
71+
<artifactId>diana-driver-commons</artifactId>
72+
<version>${project.version}</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>software.amazon.awssdk</groupId>
76+
<artifactId>dynamodb</artifactId>
77+
<version>2.0.0-preview-12</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>software.amazon.awssdk</groupId>
81+
<artifactId>apache-client</artifactId>
82+
<version>2.0.0-preview-12</version>
83+
</dependency>
84+
<dependency>
85+
<groupId>software.amazon.awssdk</groupId>
86+
<artifactId>aws-http-client-apache</artifactId>
87+
<version>2.0.0-preview-1</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>software.amazon.awssdk</groupId>
91+
<artifactId>aws-http-nio-client-netty</artifactId>
92+
<version>2.0.0-preview-1</version>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.testcontainers</groupId>
96+
<artifactId>testcontainers</artifactId>
97+
<version>${testcontainers.version}</version>
98+
<scope>test</scope>
99+
</dependency>
100+
</dependencies>
101+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2018 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.jnosql.diana.dynamodb;
16+
17+
public interface DynamoDBBuilder {
18+
19+
void endpoint(String endpoint);
20+
void region(String region);
21+
void profile(String profile);
22+
void awsAccessKey(String awsAccessKey);
23+
void awsSecretAccess(String awsSecretAccess);
24+
void maxConnections(int maxConnections);
25+
void timeout(int timeout);
26+
27+
28+
29+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2018 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.jnosql.diana.dynamodb;
16+
17+
import java.net.URI;
18+
import java.time.Duration;
19+
20+
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
21+
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
22+
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
23+
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
24+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
25+
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
26+
import software.amazon.awssdk.regions.Region;
27+
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
28+
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClientBuilder;
29+
30+
public class DynamoDBBuilderASync implements DynamoDBBuilder{
31+
32+
33+
private final DynamoDbAsyncClientBuilder dynamoDB = DynamoDbAsyncClient.builder();
34+
private final NettyNioAsyncHttpClient.Builder httpClient = NettyNioAsyncHttpClient.builder();
35+
36+
private String awsAccessKey;
37+
private String awsSecretAccess;
38+
39+
@Override
40+
public void endpoint(String endpoint) {
41+
dynamoDB.endpointOverride(URI.create(endpoint));
42+
43+
}
44+
45+
@Override
46+
public void region(String region) {
47+
dynamoDB.region(Region.of(region));
48+
}
49+
50+
@Override
51+
public void profile(String profile) {
52+
dynamoDB.credentialsProvider(ProfileCredentialsProvider.builder()
53+
.profileName(profile)
54+
.build());
55+
56+
}
57+
58+
public DynamoDbAsyncClient build() {
59+
60+
SdkAsyncHttpClient asyncHttpClient = httpClient.build();
61+
dynamoDB.httpClient(asyncHttpClient);
62+
63+
boolean accessKey = awsAccessKey != null && !awsAccessKey.equals("");
64+
boolean secretAccess = awsSecretAccess != null && !awsSecretAccess.equals("");
65+
66+
if(accessKey && secretAccess){
67+
68+
AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(awsAccessKey,awsSecretAccess);
69+
AwsCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider.create(awsBasicCredentials);
70+
dynamoDB.credentialsProvider(staticCredentialsProvider);
71+
}
72+
73+
return dynamoDB.build();
74+
}
75+
76+
@Override
77+
public void maxConnections(int maxConnections) {
78+
}
79+
80+
@Override
81+
public void timeout(int timeout) {
82+
httpClient.connectionTimeout(Duration.ofMillis(timeout));
83+
}
84+
85+
@Override
86+
public void awsAccessKey(String awsAccessKey) {
87+
this.awsAccessKey = awsAccessKey;
88+
}
89+
90+
@Override
91+
public void awsSecretAccess(String awsSecretAccess) {
92+
this.awsSecretAccess = awsSecretAccess;
93+
}
94+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2018 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.jnosql.diana.dynamodb;
16+
17+
import java.net.URI;
18+
import java.time.Duration;
19+
20+
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
21+
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
22+
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
23+
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
24+
import software.amazon.awssdk.http.SdkHttpClient;
25+
import software.amazon.awssdk.http.apache.ApacheSdkHttpClientFactory;
26+
import software.amazon.awssdk.regions.Region;
27+
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
28+
import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder;
29+
30+
public class DynamoDBBuilderSync implements DynamoDBBuilder{
31+
32+
33+
private final DynamoDbClientBuilder dynamoDB = DynamoDbClient.builder();
34+
private final ApacheSdkHttpClientFactory.Builder apacheClientFactory = ApacheSdkHttpClientFactory.builder();
35+
36+
private String awsAccessKey;
37+
private String awsSecretAccess;
38+
39+
40+
@Override
41+
public void endpoint(String endpoint) {
42+
dynamoDB.endpointOverride(URI.create(endpoint));
43+
}
44+
45+
@Override
46+
public void region(String region) {
47+
dynamoDB.region(Region.of(region));
48+
}
49+
50+
@Override
51+
public void profile(String profile) {
52+
dynamoDB.credentialsProvider(ProfileCredentialsProvider.builder()
53+
.profileName(profile)
54+
.build());
55+
56+
}
57+
58+
public DynamoDbClient build() {
59+
60+
SdkHttpClient createHttpClient = apacheClientFactory.build().createHttpClient();
61+
dynamoDB.httpClient(createHttpClient);
62+
63+
boolean accessKey = awsAccessKey != null && !awsAccessKey.equals("");
64+
boolean secretAccess = awsSecretAccess != null && !awsSecretAccess.equals("");
65+
66+
67+
if(accessKey && secretAccess){
68+
69+
AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(awsAccessKey,awsSecretAccess);
70+
AwsCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider.create(awsBasicCredentials);
71+
dynamoDB.credentialsProvider(staticCredentialsProvider);
72+
}
73+
74+
return dynamoDB.build();
75+
}
76+
77+
@Override
78+
public void maxConnections(int maxConnections) {
79+
apacheClientFactory.maxConnections(maxConnections);
80+
81+
}
82+
83+
@Override
84+
public void timeout(int timeout) {
85+
apacheClientFactory.connectionTimeout(Duration.ofMillis(timeout));
86+
}
87+
88+
@Override
89+
public void awsAccessKey(String awsAccessKey) {
90+
this.awsAccessKey = awsAccessKey;
91+
}
92+
93+
@Override
94+
public void awsSecretAccess(String awsSecretAccess) {
95+
this.awsSecretAccess = awsSecretAccess;
96+
}
97+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2018 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
16+
package org.jnosql.diana.dynamodb;
17+
18+
import static java.util.Optional.ofNullable;
19+
20+
import org.jnosql.diana.api.Settings;
21+
22+
final class DynamoDBBuilders {
23+
24+
25+
private static final String ENDPOINT = "dynamodb.endpoint";
26+
private static final String REGION = "dynamodb.region";
27+
private static final String PROFILE = "dynamodb.profile";
28+
private static final String TIMEOUT = "dynamodb.timeout";
29+
private static final String MAXCONNECTIONS = "dynamodb.maxconnections";
30+
private static final String AWS_ACCESSKEY = "dynamodb.awsaccesskey";
31+
private static final String AWS_SECRETACCESS = "dynamodb.secretaccess";
32+
33+
private DynamoDBBuilders() {
34+
}
35+
36+
static void load(Settings settings , DynamoDBBuilder dynamoDB) {
37+
ofNullable(settings.get(ENDPOINT)).map(Object::toString).ifPresent(dynamoDB::endpoint);
38+
ofNullable(settings.get(REGION)).map(Object::toString).ifPresent(dynamoDB::region);
39+
ofNullable(settings.get(PROFILE)).map(Object::toString).ifPresent(dynamoDB::profile);
40+
ofNullable(settings.get(TIMEOUT)).map(Object::toString).map(Integer::valueOf).ifPresent(dynamoDB::maxConnections);
41+
ofNullable(settings.get(MAXCONNECTIONS)).map(Object::toString).map(Integer::valueOf).ifPresent(dynamoDB::maxConnections);
42+
ofNullable(settings.get(AWS_ACCESSKEY)).map(Object::toString).ifPresent(dynamoDB::awsAccessKey);
43+
ofNullable(settings.get(AWS_SECRETACCESS)).map(Object::toString).ifPresent(dynamoDB::awsSecretAccess);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)