36
36
import com .amazonaws .auth .AWSCredentialsProvider ;
37
37
import com .amazonaws .auth .AWSStaticCredentialsProvider ;
38
38
import com .google .common .annotations .VisibleForTesting ;
39
+ import com .google .common .base .Preconditions ;
39
40
import com .google .common .base .Strings ;
40
41
import com .google .common .util .concurrent .RateLimiter ;
41
42
import com .google .common .util .concurrent .RateLimiterCreator ;
@@ -68,24 +69,24 @@ public class Client {
68
69
private final String prefix ;
69
70
70
71
public Client (org .janusgraph .diskstorage .configuration .Configuration config ) {
71
- String credentialsClassName = config .get (Constants .DYNAMODB_CREDENTIALS_CLASS_NAME );
72
- Class <?> clazz ;
72
+ final String credentialsClassName = config .get (Constants .DYNAMODB_CREDENTIALS_CLASS_NAME );
73
+ final Class <?> clazz ;
73
74
try {
74
75
clazz = Class .forName (credentialsClassName );
75
76
} catch (ClassNotFoundException e ) {
76
77
throw new IllegalArgumentException (VALIDATE_CREDENTIALS_CLASS_NAME , e );
77
78
}
78
79
79
- String [] credentialsConstructorArgsValues = config .get (Constants .DYNAMODB_CREDENTIALS_CONSTRUCTOR_ARGS );
80
- final List <String > filteredArgList = new ArrayList <String >();
80
+ final String [] credentialsConstructorArgsValues = config .get (Constants .DYNAMODB_CREDENTIALS_CONSTRUCTOR_ARGS );
81
+ final List <String > filteredArgList = new ArrayList <>();
81
82
for (Object obj : credentialsConstructorArgsValues ) {
82
83
final String str = obj .toString ();
83
84
if (!str .isEmpty ()) {
84
85
filteredArgList .add (str );
85
86
}
86
87
}
87
88
88
- AWSCredentialsProvider credentialsProvider ;
89
+ final AWSCredentialsProvider credentialsProvider ;
89
90
if (AWSCredentials .class .isAssignableFrom (clazz )) {
90
91
AWSCredentials credentials = createCredentials (clazz , filteredArgList .toArray (new String [filteredArgList .size ()]));
91
92
credentialsProvider = new AWSStaticCredentialsProvider (credentials );
@@ -97,24 +98,23 @@ public Client(org.janusgraph.diskstorage.configuration.Configuration config) {
97
98
//begin adaptation of constructor at
98
99
//https://github.com/buka/titan/blob/master/src/main/java/com/thinkaurelius/titan/diskstorage/dynamodb/DynamoDBClient.java#L77
99
100
ClientConfiguration clientConfig = new ClientConfiguration ();
100
- clientConfig .withConnectionTimeout (config .get (Constants .DYNAMODB_CLIENT_CONN_TIMEOUT )) //
101
- .withConnectionTTL (config .get (Constants .DYNAMODB_CLIENT_CONN_TTL )) //
102
- .withMaxConnections (config .get (Constants .DYNAMODB_CLIENT_MAX_CONN )) //
103
- .withMaxErrorRetry (config .get (Constants .DYNAMODB_CLIENT_MAX_ERROR_RETRY )) //
104
- .withGzip (config .get (Constants .DYNAMODB_CLIENT_USE_GZIP )) //
105
- .withReaper (config .get (Constants .DYNAMODB_CLIENT_USE_REAPER )) //
106
- .withUserAgentSuffix (config .get (Constants .DYNAMODB_CLIENT_USER_AGENT )) //
107
- .withSocketTimeout (config .get (Constants .DYNAMODB_CLIENT_SOCKET_TIMEOUT )) //
108
- .withSocketBufferSizeHints ( //
109
- config .get (Constants .DYNAMODB_CLIENT_SOCKET_BUFFER_SEND_HINT ), //
110
- config .get (Constants .DYNAMODB_CLIENT_SOCKET_BUFFER_RECV_HINT )) //
111
- .withProxyDomain (config .get (Constants .DYNAMODB_CLIENT_PROXY_DOMAIN )) //
112
- .withProxyWorkstation (config .get (Constants .DYNAMODB_CLIENT_PROXY_WORKSTATION )) //
113
- .withProxyHost (config .get (Constants .DYNAMODB_CLIENT_PROXY_HOST )) //
114
- .withProxyPort (config .get (Constants .DYNAMODB_CLIENT_PROXY_PORT )) //
115
- .withProxyUsername (config .get (Constants .DYNAMODB_CLIENT_PROXY_USERNAME )) //
116
- .withProxyPassword (config .get (Constants .DYNAMODB_CLIENT_PROXY_PASSWORD )); //
117
-
101
+ clientConfig .withConnectionTimeout (config .get (Constants .DYNAMODB_CLIENT_CONN_TIMEOUT ))
102
+ .withConnectionTTL (config .get (Constants .DYNAMODB_CLIENT_CONN_TTL ))
103
+ .withMaxConnections (config .get (Constants .DYNAMODB_CLIENT_MAX_CONN ))
104
+ .withMaxErrorRetry (config .get (Constants .DYNAMODB_CLIENT_MAX_ERROR_RETRY ))
105
+ .withGzip (config .get (Constants .DYNAMODB_CLIENT_USE_GZIP ))
106
+ .withReaper (config .get (Constants .DYNAMODB_CLIENT_USE_REAPER ))
107
+ .withUserAgentSuffix (config .get (Constants .DYNAMODB_CLIENT_USER_AGENT ))
108
+ .withSocketTimeout (config .get (Constants .DYNAMODB_CLIENT_SOCKET_TIMEOUT ))
109
+ .withSocketBufferSizeHints (
110
+ config .get (Constants .DYNAMODB_CLIENT_SOCKET_BUFFER_SEND_HINT ),
111
+ config .get (Constants .DYNAMODB_CLIENT_SOCKET_BUFFER_RECV_HINT ))
112
+ .withProxyDomain (config .get (Constants .DYNAMODB_CLIENT_PROXY_DOMAIN ))
113
+ .withProxyWorkstation (config .get (Constants .DYNAMODB_CLIENT_PROXY_WORKSTATION ))
114
+ .withProxyHost (config .get (Constants .DYNAMODB_CLIENT_PROXY_HOST ))
115
+ .withProxyPort (config .get (Constants .DYNAMODB_CLIENT_PROXY_PORT ))
116
+ .withProxyUsername (config .get (Constants .DYNAMODB_CLIENT_PROXY_USERNAME ))
117
+ .withProxyPassword (config .get (Constants .DYNAMODB_CLIENT_PROXY_PASSWORD ));
118
118
forceConsistentRead = config .get (Constants .DYNAMODB_FORCE_CONSISTENT_READ );
119
119
//end adaptation of constructor at
120
120
//https://github.com/buka/titan/blob/master/src/main/java/com/thinkaurelius/titan/diskstorage/dynamodb/DynamoDBClient.java#L77
@@ -139,11 +139,9 @@ public Client(org.janusgraph.diskstorage.configuration.Configuration config) {
139
139
final Map <String , RateLimiter > readRateLimit = new HashMap <>();
140
140
final Map <String , RateLimiter > writeRateLimit = new HashMap <>();
141
141
142
- Set <String > storeNames = new HashSet <String >( Constants .REQUIRED_BACKEND_STORES );
142
+ final Set <String > storeNames = new HashSet <>( config . get ( Constants . DYNAMODB_USE_TITAN_ID_STORE ) ? Constants . ALTERNATE_BACKEND_STORES : Constants .REQUIRED_BACKEND_STORES );
143
143
storeNames .addAll (config .getContainedNamespaces (Constants .DYNAMODB_STORES_NAMESPACE ));
144
- for (String storeName : storeNames ) {
145
- setupStore (config , prefix , readRateLimit , writeRateLimit , storeName );
146
- }
144
+ storeNames .forEach (storeName -> setupStore (config , prefix , readRateLimit , writeRateLimit , storeName ));
147
145
148
146
endpoint = JanusGraphConfigUtil .getNullableConfigValue (config , Constants .DYNAMODB_CLIENT_ENDPOINT );
149
147
signingRegion = JanusGraphConfigUtil .getNullableConfigValue (config , Constants .DYNAMODB_CLIENT_SIGNING_REGION );
@@ -201,10 +199,12 @@ public boolean enableParallelScan() {
201
199
}
202
200
203
201
public long readCapacity (String tableName ) {
202
+ Preconditions .checkNotNull (tableName , "table name may not be null when looking up read capacity" );
204
203
return capacityRead .get (tableName );
205
204
}
206
205
207
206
public long writeCapacity (String tableName ) {
207
+ Preconditions .checkNotNull (tableName , "table name may not be null when looking up write capacity" );
208
208
return capacityWrite .get (tableName );
209
209
}
210
210
@@ -216,27 +216,6 @@ public int scanLimit(String tableName) {
216
216
return scanLimit .get (tableName );
217
217
}
218
218
219
- public static final AWSCredentialsProvider createAWSCredentialsProvider (String credentialsClassName ,
220
- String [] credentialsConstructorArgsValues ) {
221
- Class <?> clazz ;
222
- try {
223
- clazz = Class .forName (credentialsClassName );
224
- } catch (ClassNotFoundException e ) {
225
- throw new IllegalArgumentException (VALIDATE_CREDENTIALS_CLASS_NAME , e );
226
- }
227
- AWSCredentialsProvider credentialsProvider ;
228
- if (AWSCredentials .class .isAssignableFrom (clazz )) {
229
- AWSCredentials credentials = createCredentials (clazz , credentialsConstructorArgsValues );
230
- credentialsProvider = new AWSStaticCredentialsProvider (credentials );
231
- } else if (AWSCredentialsProvider .class .isAssignableFrom (clazz )) {
232
- credentialsProvider = createCredentialsProvider (clazz , credentialsConstructorArgsValues );
233
- } else {
234
- throw new IllegalArgumentException (VALIDATE_CREDENTIALS_CLASS_NAME );
235
- }
236
-
237
- return credentialsProvider ;
238
- }
239
-
240
219
private static final AWSCredentialsProvider createCredentialsProvider (Class <?> clazz , String [] credentialsProviderConstructorArgs ) {
241
220
return (AWSCredentialsProvider ) createInstance (clazz , credentialsProviderConstructorArgs );
242
221
}
0 commit comments