use of software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndexDescription in project para by Erudika.
the class AWSDynamoUtils method queryGSI.
private static QueryResponse queryGSI(String appid, Pager p) {
Pager pager = (p != null) ? p : new Pager();
GlobalSecondaryIndexDescription index = getSharedGlobalIndex();
QueryRequest.Builder query = QueryRequest.builder().limit(pager.getLimit()).keyConditionExpression(Config._APPID + " = :aid").expressionAttributeValues(Collections.singletonMap(":aid", AttributeValue.builder().s(appid).build()));
if (!StringUtils.isBlank(pager.getLastKey())) {
// See https://stackoverflow.com/questions/40988397/42735813#42735813
Map<String, AttributeValue> startKey = new HashMap<>(3);
// HASH/PARTITION KEY
startKey.put(Config._APPID, AttributeValue.builder().s(appid).build());
// RANGE/SORT KEY
startKey.put(Config._ID, AttributeValue.builder().s(pager.getLastKey()).build());
// TABLE PRIMARY KEY
startKey.put(Config._KEY, AttributeValue.builder().s(getKeyForAppid(pager.getLastKey(), appid)).build());
query.exclusiveStartKey(startKey);
}
return index != null ? getClient().query(query.indexName(index.indexName()).tableName(getTableNameForAppid(SHARED_TABLE)).build()) : null;
}
use of software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndexDescription in project scalardb by scalar-labs.
the class DynamoAdminTest method createIndex_ShouldCreateIndexProperly.
@Test
public void createIndex_ShouldCreateIndexProperly() throws ExecutionException {
// Arrange
GetItemResponse getItemResponse = mock(GetItemResponse.class);
when(client.getItem(any(GetItemRequest.class))).thenReturn(getItemResponse);
when(getItemResponse.item()).thenReturn(ImmutableMap.<String, AttributeValue>builder().put(DynamoAdmin.METADATA_ATTR_TABLE, AttributeValue.builder().s(FULL_TABLE_NAME).build()).put(DynamoAdmin.METADATA_ATTR_COLUMNS, AttributeValue.builder().m(ImmutableMap.<String, AttributeValue>builder().put("c1", AttributeValue.builder().s("text").build()).put("c2", AttributeValue.builder().s("bigint").build()).put("c3", AttributeValue.builder().s("boolean").build()).put("c4", AttributeValue.builder().s("int").build()).build()).build()).put(DynamoAdmin.METADATA_ATTR_PARTITION_KEY, AttributeValue.builder().l(AttributeValue.builder().s("c1").build()).build()).put(DynamoAdmin.METADATA_ATTR_CLUSTERING_KEY, AttributeValue.builder().l(AttributeValue.builder().s("c2").build(), AttributeValue.builder().s("c3").build()).build()).put(DynamoAdmin.METADATA_ATTR_CLUSTERING_ORDERS, AttributeValue.builder().m(ImmutableMap.<String, AttributeValue>builder().put("c2", AttributeValue.builder().s("DESC").build()).put("c3", AttributeValue.builder().s("ASC").build()).build()).build()).build());
DescribeTableResponse describeTableResponse = mock(DescribeTableResponse.class);
when(client.describeTable(any(DescribeTableRequest.class))).thenReturn(describeTableResponse);
TableDescription tableDescription = mock(TableDescription.class);
when(describeTableResponse.table()).thenReturn(tableDescription);
GlobalSecondaryIndexDescription globalSecondaryIndexDescription = mock(GlobalSecondaryIndexDescription.class);
when(tableDescription.globalSecondaryIndexes()).thenReturn(Collections.singletonList(globalSecondaryIndexDescription));
String indexName = getFullTableName(NAMESPACE, TABLE) + ".global_index.c4";
when(globalSecondaryIndexDescription.indexName()).thenReturn(indexName);
when(globalSecondaryIndexDescription.indexStatus()).thenReturn(IndexStatus.ACTIVE);
// Act
admin.createIndex(NAMESPACE, TABLE, "c4", Collections.emptyMap());
// Assert
verify(client).updateTable(any(UpdateTableRequest.class));
verify(applicationAutoScalingClient, times(2)).putScalingPolicy(any(PutScalingPolicyRequest.class));
verify(applicationAutoScalingClient, times(2)).registerScalableTarget(any(RegisterScalableTargetRequest.class));
}
use of software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndexDescription in project scalardb by scalar-labs.
the class DynamoAdmin method waitForIndexDeletion.
private void waitForIndexDeletion(String namespace, String table, String columnName) throws ExecutionException {
try {
String indexName = getGlobalIndexName(namespace, table, columnName);
while (true) {
Uninterruptibles.sleepUninterruptibly(WAITING_DURATION_SECS, TimeUnit.SECONDS);
DescribeTableResponse response = client.describeTable(DescribeTableRequest.builder().tableName(getFullTableName(namespace, table)).build());
boolean deleted = true;
for (GlobalSecondaryIndexDescription globalSecondaryIndex : response.table().globalSecondaryIndexes()) {
if (globalSecondaryIndex.indexName().equals(indexName)) {
deleted = false;
break;
}
}
if (deleted) {
break;
}
}
} catch (Exception e) {
throw new ExecutionException("waiting for the secondary index deletion failed", e);
}
}
use of software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndexDescription in project scalardb by scalar-labs.
the class DynamoAdmin method waitForIndexCreation.
private void waitForIndexCreation(String namespace, String table, String columnName) throws ExecutionException {
try {
String indexName = getGlobalIndexName(namespace, table, columnName);
while (true) {
Uninterruptibles.sleepUninterruptibly(WAITING_DURATION_SECS, TimeUnit.SECONDS);
DescribeTableResponse response = client.describeTable(DescribeTableRequest.builder().tableName(getFullTableName(namespace, table)).build());
for (GlobalSecondaryIndexDescription globalSecondaryIndex : response.table().globalSecondaryIndexes()) {
if (globalSecondaryIndex.indexName().equals(indexName)) {
if (globalSecondaryIndex.indexStatus() == IndexStatus.ACTIVE) {
return;
}
}
}
}
} catch (Exception e) {
throw new ExecutionException("waiting for the secondary index creation failed", e);
}
}
Aggregations