Search in sources :

Example 1 with DescribeTableResult

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());
}
Also used : Message(org.apache.camel.Message) DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)

Example 2 with DescribeTableResult

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");
}
Also used : DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult) ProvisionedThroughputDescription(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) Date(java.util.Date) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 3 with DescribeTableResult

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);
    }
}
Also used : AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult)

Example 4 with DescribeTableResult

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();
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ToString(lombok.ToString) IOException(java.io.IOException) LinkedList(java.util.LinkedList) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) Cacheable(com.jcabi.aspects.Cacheable)

Example 5 with DescribeTableResult

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)))))));
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) ConsumedCapacity(com.amazonaws.services.dynamodbv2.model.ConsumedCapacity) PutItemResult(com.amazonaws.services.dynamodbv2.model.PutItemResult) PutItemRequest(com.amazonaws.services.dynamodbv2.model.PutItemRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) Test(org.junit.Test)

Aggregations

DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)8 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)5 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)5 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)5 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)3 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)3 AmazonClientException (com.amazonaws.AmazonClientException)2 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)2 Test (org.junit.Test)2 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)1 AmazonDynamoDBStreams (com.amazonaws.services.dynamodbv2.AmazonDynamoDBStreams)1 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)1 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)1 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)1 DeleteItemRequest (com.amazonaws.services.dynamodbv2.model.DeleteItemRequest)1 DeleteItemResult (com.amazonaws.services.dynamodbv2.model.DeleteItemResult)1 DescribeStreamRequest (com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest)1 DescribeStreamResult (com.amazonaws.services.dynamodbv2.model.DescribeStreamResult)1 GetRecordsRequest (com.amazonaws.services.dynamodbv2.model.GetRecordsRequest)1 GetRecordsResult (com.amazonaws.services.dynamodbv2.model.GetRecordsResult)1