use of com.amazonaws.services.dynamodbv2.model.DescribeTableResult in project camel by apache.
the class DescribeTableCommand method execute.
@Override
public void execute() {
DescribeTableResult result = ddbClient.describeTable(new DescribeTableRequest().withTableName(determineTableName()));
Message msg = getMessageForResponse(exchange);
msg.setHeader(DdbConstants.TABLE_NAME, result.getTable().getTableName());
msg.setHeader(DdbConstants.TABLE_STATUS, result.getTable().getTableStatus());
msg.setHeader(DdbConstants.CREATION_DATE, result.getTable().getCreationDateTime());
msg.setHeader(DdbConstants.ITEM_COUNT, result.getTable().getItemCount());
msg.setHeader(DdbConstants.KEY_SCHEMA, result.getTable().getKeySchema());
msg.setHeader(DdbConstants.READ_CAPACITY, result.getTable().getProvisionedThroughput().getReadCapacityUnits());
msg.setHeader(DdbConstants.WRITE_CAPACITY, result.getTable().getProvisionedThroughput().getWriteCapacityUnits());
msg.setHeader(DdbConstants.TABLE_SIZE, result.getTable().getTableSizeBytes());
}
use of com.amazonaws.services.dynamodbv2.model.DescribeTableResult in project camel by apache.
the class AmazonDDBClientMock method describeTable.
@Override
public DescribeTableResult describeTable(DescribeTableRequest describeTableRequest) {
this.describeTableRequest = describeTableRequest;
String tableName = describeTableRequest.getTableName();
if ("activeTable".equals(tableName)) {
return tableWithStatus(TableStatus.ACTIVE);
} else if ("creatibleTable".equals(tableName) && createTableRequest != null) {
return tableWithStatus(TableStatus.ACTIVE);
} else if ("FULL_DESCRIBE_TABLE".equals(tableName)) {
return new DescribeTableResult().withTable(new TableDescription().withTableName(tableName).withTableStatus(TableStatus.ACTIVE).withCreationDateTime(new Date(NOW)).withItemCount(100L).withKeySchema(new KeySchemaElement().withAttributeName("name")).withProvisionedThroughput(new ProvisionedThroughputDescription().withReadCapacityUnits(20L).withWriteCapacityUnits(10L)).withTableSizeBytes(1000L));
}
throw new ResourceNotFoundException(tableName + " is missing");
}
use of com.amazonaws.services.dynamodbv2.model.DescribeTableResult in project jcabi-dynamo by jcabi.
the class MadeTable method create.
/**
* Create table.
* @throws InterruptedException If something fails
*/
public void create() throws InterruptedException {
final AmazonDynamoDB aws = this.region.aws();
final String name = this.request.getTableName();
aws.createTable(this.request);
Logger.info(this, "DynamoDB table '%s' creation requested...", name);
final DescribeTableRequest req = new DescribeTableRequest().withTableName(name);
while (true) {
final DescribeTableResult result = aws.describeTable(req);
if ("ACTIVE".equals(result.getTable().getTableStatus())) {
Logger.info(this, "DynamoDB table '%s' is %s", name, result.getTable().getTableStatus());
break;
}
Logger.info(this, "waiting for DynamoDB table '%s': %s", name, result.getTable().getTableStatus());
TimeUnit.SECONDS.sleep((long) Tv.TEN);
}
}
use of com.amazonaws.services.dynamodbv2.model.DescribeTableResult in project jcabi-dynamo by jcabi.
the class AwsTable method keys.
/**
* Get names of keys.
* @return Names of attributes, which are primary keys
* @throws IOException If DynamoDB fails
*/
@Cacheable(forever = true)
public Collection<String> keys() throws IOException {
final AmazonDynamoDB aws = this.credentials.aws();
try {
final long start = System.currentTimeMillis();
final DescribeTableResult result = aws.describeTable(new DescribeTableRequest().withTableName(this.self));
final Collection<String> keys = new LinkedList<String>();
for (final KeySchemaElement key : result.getTable().getKeySchema()) {
keys.add(key.getAttributeName());
}
Logger.info(this, "#keys(): table %s described, in %[ms]s", this.self, System.currentTimeMillis() - start);
return keys;
} catch (final AmazonClientException ex) {
throw new IOException(String.format("Failed to describe \"%s\"", this.self), ex);
} finally {
aws.shutdown();
}
}
use of com.amazonaws.services.dynamodbv2.model.DescribeTableResult in project jcabi-dynamo by jcabi.
the class AwsTableTest method savesItemToDynamo.
/**
* AwsTable can save an item.
* @throws Exception If some problem inside
*/
@Test
public void savesItemToDynamo() throws Exception {
final Credentials credentials = Mockito.mock(Credentials.class);
final AmazonDynamoDB aws = Mockito.mock(AmazonDynamoDB.class);
Mockito.doReturn(aws).when(credentials).aws();
Mockito.doReturn(new PutItemResult().withConsumedCapacity(new ConsumedCapacity().withCapacityUnits(1.0d))).when(aws).putItem(Mockito.any(PutItemRequest.class));
Mockito.doReturn(new DescribeTableResult().withTable(new TableDescription().withKeySchema(new KeySchemaElement().withAttributeName(AwsTableTest.KEY)))).when(aws).describeTable(Mockito.any(DescribeTableRequest.class));
final String attr = "attribute-1";
final AttributeValue value = new AttributeValue("value-1");
final String name = "table-name";
final Table table = new AwsTable(credentials, Mockito.mock(Region.class), name);
table.put(new Attributes().with(attr, value));
Mockito.verify(aws).putItem(PutItemRequest.class.cast(MockitoHamcrest.argThat(Matchers.allOf(Matchers.hasProperty(AwsTableTest.TABLE_NAME, Matchers.equalTo(name)), Matchers.hasProperty("item", Matchers.hasEntry(Matchers.equalTo(attr), Matchers.equalTo(value)))))));
}
Aggregations