Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

Commit 0dee9eb

Browse files
author
Alexander Patrikalakis
committed
Add PMD to build and fix violations
1 parent 32bb819 commit 0dee9eb

File tree

12 files changed

+80
-81
lines changed

12 files changed

+80
-81
lines changed

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@
198198
</dependencies>
199199
<build>
200200
<plugins>
201+
<plugin>
202+
<groupId>org.apache.maven.plugins</groupId>
203+
<artifactId>maven-pmd-plugin</artifactId>
204+
<version>3.8</version>
205+
<executions>
206+
<execution>
207+
<goals>
208+
<goal>check</goal>
209+
<goal>cpd-check</goal>
210+
</goals>
211+
</execution>
212+
</executions>
213+
</plugin>
201214
<plugin>
202215
<groupId>org.apache.maven.plugins</groupId>
203216
<artifactId>maven-dependency-plugin</artifactId>

src/main/java/com/amazon/janusgraph/diskstorage/dynamodb/AbstractDynamoDBStore.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public AbstractDynamoDBStore(final DynamoDBStoreManager manager, final String pr
7373
this.client = this.manager.client();
7474
this.storeName = storeName;
7575
this.tableName = prefix + "_" + storeName;
76-
this.forceConsistentRead = client.forceConsistentRead();
76+
this.forceConsistentRead = client.isForceConsistentRead();
7777

78-
final CacheBuilder<Pair<StaticBuffer, StaticBuffer>, DynamoDBStoreTransaction> builder = CacheBuilder.newBuilder().concurrencyLevel(client.delegate().getMaxConcurrentUsers())
78+
final CacheBuilder<Pair<StaticBuffer, StaticBuffer>, DynamoDBStoreTransaction> builder = CacheBuilder.newBuilder().concurrencyLevel(client.getDelegate().getMaxConcurrentUsers())
7979
.expireAfterWrite(manager.getLockExpiresDuration().toMillis(), TimeUnit.MILLISECONDS)
8080
.removalListener(ReportingRemovalListener.theInstance());
8181
this.keyColumnLocalLocks = builder.build();
@@ -89,15 +89,15 @@ public AbstractDynamoDBStore(final DynamoDBStoreManager manager, final String pr
8989
@Override
9090
public final void ensureStore() throws BackendException {
9191
LOG.debug("Entering ensureStore table:{}", tableName);
92-
client.delegate().createTableAndWaitForActive(getTableSchema());
92+
client.getDelegate().createTableAndWaitForActive(getTableSchema());
9393
}
9494

9595
@Override
9696
public final void deleteStore() throws BackendException {
9797
LOG.debug("Entering deleteStore name:{}", storeName);
98-
client.delegate().deleteTable(getTableSchema().getTableName());
98+
client.getDelegate().deleteTable(getTableSchema().getTableName());
9999
//block until the tables are actually deleted
100-
client.delegate().ensureTableDeleted(getTableSchema().getTableName());
100+
client.getDelegate().ensureTableDeleted(getTableSchema().getTableName());
101101
}
102102

103103
private class SetStoreIfTxMappingDoesntExist implements Callable<DynamoDBStoreTransaction> {

src/main/java/com/amazon/janusgraph/diskstorage/dynamodb/Client.java

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import java.util.concurrent.ThreadPoolExecutor;
2929
import java.util.concurrent.TimeUnit;
3030

31+
import lombok.AccessLevel;
32+
import lombok.Getter;
33+
import lombok.NonNull;
3134
import org.janusgraph.diskstorage.configuration.Configuration;
3235
import org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration;
3336
import org.janusgraph.util.stats.MetricManager;
@@ -36,8 +39,6 @@
3639
import com.amazonaws.auth.AWSCredentials;
3740
import com.amazonaws.auth.AWSCredentialsProvider;
3841
import com.amazonaws.auth.AWSStaticCredentialsProvider;
39-
import com.google.common.annotations.VisibleForTesting;
40-
import com.google.common.base.Preconditions;
4142
import com.google.common.base.Strings;
4243
import com.google.common.util.concurrent.RateLimiter;
4344
import com.google.common.util.concurrent.RateLimiterCreator;
@@ -59,17 +60,17 @@ public class Client {
5960
private final Map<String, Long> capacityRead = new HashMap<>();
6061
private final Map<String, Long> capacityWrite = new HashMap<>();
6162
private final Map<String, BackendDataModel> dataModel = new HashMap<>();
63+
@Getter(AccessLevel.PACKAGE)
6264
private final boolean forceConsistentRead;
65+
@Getter(AccessLevel.PACKAGE)
6366
private final boolean enableParallelScan;
6467
private final Map<String, Integer> scanLimit = new HashMap<>();
68+
@Getter
6569
private final DynamoDBDelegate delegate;
66-
@VisibleForTesting
67-
final String endpoint;
68-
final String signingRegion;
6970

7071
private final String prefix;
7172

72-
public Client(org.janusgraph.diskstorage.configuration.Configuration config) {
73+
public Client(final Configuration config) {
7374
final String credentialsClassName = config.get(Constants.DYNAMODB_CREDENTIALS_CLASS_NAME);
7475
final Class<?> clazz;
7576
try {
@@ -145,15 +146,15 @@ public Client(org.janusgraph.diskstorage.configuration.Configuration config) {
145146
storeNames.addAll(config.getContainedNamespaces(Constants.DYNAMODB_STORES_NAMESPACE));
146147
storeNames.forEach(storeName -> setupStore(config, prefix, readRateLimit, writeRateLimit, storeName));
147148

148-
endpoint = JanusGraphConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_ENDPOINT);
149-
signingRegion = JanusGraphConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_SIGNING_REGION);
150-
delegate = new DynamoDBDelegate(endpoint, signingRegion, credentialsProvider,
149+
delegate = new DynamoDBDelegate(JanusGraphConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_ENDPOINT),
150+
JanusGraphConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_SIGNING_REGION),
151+
credentialsProvider,
151152
clientConfig, config, readRateLimit, writeRateLimit, maxRetries, retryMillis, prefix, metricsPrefix, controlPlaneRateLimiter);
152153
}
153154

154-
public static final ThreadPoolExecutor getPoolFromNs(Configuration ns) {
155+
public static final ThreadPoolExecutor getPoolFromNs(final Configuration ns) {
155156
final int maxQueueSize = ns.get(Constants.DYNAMODB_CLIENT_EXECUTOR_QUEUE_MAX_LENGTH);
156-
final ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("delegate-%d").build();
157+
final ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("getDelegate-%d").build();
157158
//begin adaptation of constructor at
158159
//https://github.com/buka/titan/blob/master/src/main/java/com/thinkaurelius/titan/diskstorage/dynamodb/DynamoDBClient.java#L104
159160
final int maxPoolSize = ns.get(Constants.DYNAMODB_CLIENT_EXECUTOR_MAX_POOL_SIZE);
@@ -168,8 +169,8 @@ public static final ThreadPoolExecutor getPoolFromNs(Configuration ns) {
168169
return executor;
169170
}
170171

171-
private void setupStore(org.janusgraph.diskstorage.configuration.Configuration config, String prefix,
172-
final Map<String, RateLimiter> readRateLimit, final Map<String, RateLimiter> writeRateLimit, String store) {
172+
private void setupStore(final Configuration config, final String prefix,
173+
final Map<String, RateLimiter> readRateLimit, final Map<String, RateLimiter> writeRateLimit, final String store) {
173174

174175
final String dataModel = config.get(Constants.STORES_DATA_MODEL, store);
175176
final int scanLimit = config.get(Constants.STORES_SCAN_LIMIT, store);
@@ -188,25 +189,11 @@ private void setupStore(org.janusgraph.diskstorage.configuration.Configuration c
188189
this.scanLimit.put(actualTableName, scanLimit);
189190
}
190191

191-
public DynamoDBDelegate delegate() {
192-
return delegate;
193-
}
194-
195-
public boolean forceConsistentRead() {
196-
return forceConsistentRead;
197-
}
198-
199-
public boolean enableParallelScan() {
200-
return enableParallelScan;
201-
}
202-
203-
public long readCapacity(String tableName) {
204-
Preconditions.checkNotNull(tableName, "table name may not be null when looking up read capacity");
192+
long readCapacity(final @NonNull String tableName) {
205193
return capacityRead.get(tableName);
206194
}
207195

208-
public long writeCapacity(String tableName) {
209-
Preconditions.checkNotNull(tableName, "table name may not be null when looking up write capacity");
196+
long writeCapacity(final @NonNull String tableName) {
210197
return capacityWrite.get(tableName);
211198
}
212199

@@ -218,15 +205,15 @@ public int scanLimit(String tableName) {
218205
return scanLimit.get(tableName);
219206
}
220207

221-
private static final AWSCredentialsProvider createCredentialsProvider(Class<?> clazz, String[] credentialsProviderConstructorArgs) {
208+
private static AWSCredentialsProvider createCredentialsProvider(Class<?> clazz, String[] credentialsProviderConstructorArgs) {
222209
return (AWSCredentialsProvider) createInstance(clazz, credentialsProviderConstructorArgs);
223210
}
224211

225-
private static final AWSCredentials createCredentials(Class<?> clazz, String[] credentialsConstructorArgs) {
212+
private static AWSCredentials createCredentials(Class<?> clazz, String[] credentialsConstructorArgs) {
226213
return (AWSCredentials) createInstance(clazz, credentialsConstructorArgs);
227214
}
228215

229-
private static final Object createInstance(Class<?> clazz, String[] constructorArgs) {
216+
private static Object createInstance(Class<?> clazz, String[] constructorArgs) {
230217
Class<?>[] constructorTypes;
231218
String[] actualArgs = constructorArgs;
232219
if (null == constructorArgs) {

src/main/java/com/amazon/janusgraph/diskstorage/dynamodb/DynamoDBDelegate.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.concurrent.Future;
3535
import java.util.concurrent.ThreadPoolExecutor;
3636

37+
import lombok.extern.slf4j.Slf4j;
3738
import org.apache.commons.lang3.builder.EqualsBuilder;
3839
import org.janusgraph.diskstorage.BackendException;
3940
import org.janusgraph.diskstorage.PermanentBackendException;
@@ -111,6 +112,7 @@
111112
* @author Alexander Patrikalakis
112113
*
113114
*/
115+
@Slf4j
114116
public class DynamoDBDelegate
115117
{
116118
public static final String PAGES = "Pages";
@@ -193,7 +195,7 @@ static AwsClientBuilder.EndpointConfiguration getEndpointConfiguration(Optional<
193195
final String expectedServiceEndpoint = "https://" + Region.getRegion(Regions.fromName(signingRegion)).getServiceEndpoint(AmazonDynamoDB.ENDPOINT_PREFIX);
194196
if(endpoint.isPresent() && !Strings.isNullOrEmpty(endpoint.get())) {
195197
final String regionParsedFromEndpoint = AwsHostNameUtils.parseRegion(endpoint.get(), AmazonDynamoDB.ENDPOINT_PREFIX);
196-
Preconditions.checkArgument(regionParsedFromEndpoint == null || (regionParsedFromEndpoint != null && signingRegion.equals(regionParsedFromEndpoint)));
198+
Preconditions.checkArgument(regionParsedFromEndpoint == null || signingRegion.equals(regionParsedFromEndpoint));
197199
return new AwsClientBuilder.EndpointConfiguration(endpoint.get(), signingRegion);
198200
} else {
199201
//Regions.fromName will throw IllegalArgumentException if signingRegion is not valid.
@@ -427,15 +429,15 @@ public GetItemResult getItem(GetItemRequest request) throws BackendException {
427429

428430
public BatchWriteItemResult batchWriteItem(BatchWriteItemRequest batchRequest) throws BackendException {
429431
int count = 0;
430-
for(Entry<String,java.util.List<WriteRequest>> entry : batchRequest.getRequestItems().entrySet()) {
432+
for(Entry<String, List<WriteRequest>> entry : batchRequest.getRequestItems().entrySet()) {
431433
final String tableName = entry.getKey();
432434
final List<WriteRequest> requests = entry.getValue();
433435
count += requests.size();
434436
if(count > 25) {
435437
throw new IllegalArgumentException("cant have more than 25 requests in a batchwrite");
436438
}
437439
for(WriteRequest request : requests) {
438-
if(!(request.getPutRequest() != null ^ request.getDeleteRequest() != null)) {
440+
if((request.getPutRequest() != null) == (request.getDeleteRequest() != null)) {
439441
throw new IllegalArgumentException("Exactly one of PutRequest or DeleteRequest must be set in each WriteRequest in a batch write operation");
440442
}
441443
final int wcu;
@@ -572,10 +574,8 @@ public int estimateCapacityUnits(String apiName, String tableName) {
572574
final Meter apiCcuMeter = getConsumedCapacityMeter(apiName, tableName);
573575
final Timer apiTimer = getTimer(apiName, tableName);
574576

575-
if(apiCcuMeter != null && apiTimer != null) {
576-
if(apiTimer.getCount() > 0) {
577-
cu = (int) Math.round(Math.max(1.0, (double) apiCcuMeter.getCount() / (double) apiTimer.getCount()));
578-
}
577+
if (apiCcuMeter != null && apiTimer != null && apiTimer.getCount() > 0) {
578+
cu = (int) Math.round(Math.max(1.0, (double) apiCcuMeter.getCount() / (double) apiTimer.getCount()));
579579
}
580580
return cu;
581581
}
@@ -740,7 +740,7 @@ public void waitForTableCreation(String tableName, boolean verifyIndexesList,
740740
actualLSIs.addAll(td.getLocalSecondaryIndexes());
741741
}
742742
// the lsi list should be there even if the table is in creating state
743-
if(!((expectedLsiList == null && td.getLocalSecondaryIndexes() == null) || expectedLSIs.equals(actualLSIs))) {
743+
if(!(expectedLsiList == null && td.getLocalSecondaryIndexes() == null || expectedLSIs.equals(actualLSIs))) {
744744
throw new PermanentBackendException("LSI list is not as expected during table creation. expectedLsiList=" +
745745
expectedLsiList.toString() + "; table description=" + td.toString());
746746
}
@@ -834,12 +834,11 @@ public void createTableAndWaitForActive(CreateTableRequest request) throws Backe
834834
TableDescription desc;
835835
try {
836836
desc = this.describeTable(tableName);
837-
if (null != desc) {
838-
if (isTableAcceptingWrites(desc.getTableStatus())) {
839-
return; //store existed
840-
}
837+
if (null != desc && isTableAcceptingWrites(desc.getTableStatus())) {
838+
return; //store existed
841839
}
842-
} catch (BackendNotFoundException e) {
840+
} catch (BackendNotFoundException ignore) {
841+
log.debug(tableName + " did not exist yet, creating it");
843842
//Swallow, table doesnt exist yet
844843
}
845844

src/main/java/com/amazon/janusgraph/diskstorage/dynamodb/DynamoDBSingleRowStore.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private GetItemWorker createGetItemWorker(StaticBuffer hashKey) {
120120
.withTableName(tableName)
121121
.withConsistentRead(forceConsistentRead)
122122
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
123-
return new GetItemWorker(hashKey, request, client.delegate());
123+
return new GetItemWorker(hashKey, request, client.getDelegate());
124124
}
125125

126126
private EntryList extractEntriesFromGetItemResult(GetItemResult result, StaticBuffer sliceStart, StaticBuffer sliceEnd, int limit) {
@@ -145,10 +145,10 @@ public KeyIterator getKeys(SliceQuery query, StoreTransaction txh) throws Backen
145145
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
146146

147147
final Scanner scanner;
148-
if (client.enableParallelScan()) {
149-
scanner = client.delegate().getParallelScanCompletionService(scanRequest);
148+
if (client.isEnableParallelScan()) {
149+
scanner = client.getDelegate().getParallelScanCompletionService(scanRequest);
150150
} else {
151-
scanner = new SequentialScanner(client.delegate(), scanRequest);
151+
scanner = new SequentialScanner(client.getDelegate(), scanRequest);
152152
}
153153
// Because SINGLE records cannot be split across scan results, we can use the same interpreter for both
154154
// sequential and parallel scans.
@@ -173,7 +173,7 @@ public EntryList getSlice(KeySliceQuery query, StoreTransaction txh) throws Back
173173
.withTableName(tableName)
174174
.withConsistentRead(forceConsistentRead)
175175
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
176-
final GetItemResult result = new ExponentialBackoff.GetItem(request, client.delegate()).runWithBackoff();
176+
final GetItemResult result = new ExponentialBackoff.GetItem(request, client.getDelegate()).runWithBackoff();
177177

178178
final List<Entry> filteredEntries = extractEntriesFromGetItemResult(result, query.getSliceStart(), query.getSliceEnd(), query.getLimit());
179179
log.debug("Exiting getSliceKeySliceQuery table:{} query:{} txh:{} returning:{}", getTableName(), encodeForLog(query), txh,
@@ -193,7 +193,7 @@ public Map<StaticBuffer, EntryList> getSlice(List<StaticBuffer> keys, SliceQuery
193193
getItemWorkers.add(worker);
194194
}
195195

196-
final Map<StaticBuffer, GetItemResult> resultMap = client.delegate().parallelGetItem(getItemWorkers);
196+
final Map<StaticBuffer, GetItemResult> resultMap = client.getDelegate().parallelGetItem(getItemWorkers);
197197
for (Map.Entry<StaticBuffer, GetItemResult> resultEntry : resultMap.entrySet()) {
198198
EntryList entryList = extractEntriesFromGetItemResult(resultEntry.getValue(), query.getSliceStart(),
199199
query.getSliceEnd(), query.getLimit());
@@ -287,9 +287,9 @@ public Collection<MutateWorker> createMutationWorkers(Map<StaticBuffer, KCVMutat
287287

288288
MutateWorker worker;
289289
if (mutation.hasDeletions() && !mutation.hasAdditions()) {
290-
worker = new SingleUpdateWithCleanupWorker(request, client.delegate());
290+
worker = new SingleUpdateWithCleanupWorker(request, client.getDelegate());
291291
} else {
292-
worker = new UpdateItemWorker(request, client.delegate());
292+
worker = new UpdateItemWorker(request, client.getDelegate());
293293
}
294294
workers.add(worker);
295295
}

0 commit comments

Comments
 (0)