Search in sources :

Example 1 with KeySchemaElement

use of com.amazonaws.services.dynamodbv2.model.KeySchemaElement 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 2 with KeySchemaElement

use of com.amazonaws.services.dynamodbv2.model.KeySchemaElement in project camel by apache.

the class DeleteTableCommandTest method testExecute.

@Test
public void testExecute() {
    command.execute();
    assertEquals("DOMAIN1", ddbClient.deleteTableRequest.getTableName());
    assertEquals(new ProvisionedThroughputDescription(), exchange.getIn().getHeader(DdbConstants.PROVISIONED_THROUGHPUT));
    assertEquals(new Date(AmazonDDBClientMock.NOW), exchange.getIn().getHeader(DdbConstants.CREATION_DATE, Date.class));
    assertEquals(Long.valueOf(10L), exchange.getIn().getHeader(DdbConstants.ITEM_COUNT, Long.class));
    assertEquals(new ArrayList<KeySchemaElement>(), exchange.getIn().getHeader(DdbConstants.KEY_SCHEMA, ArrayList.class));
    assertEquals(Long.valueOf(20L), exchange.getIn().getHeader(DdbConstants.TABLE_SIZE, Long.class));
    assertEquals(TableStatus.ACTIVE, exchange.getIn().getHeader(DdbConstants.TABLE_STATUS, TableStatus.class));
}
Also used : ArrayList(java.util.ArrayList) TableStatus(com.amazonaws.services.dynamodbv2.model.TableStatus) ProvisionedThroughputDescription(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription) Date(java.util.Date) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) Test(org.junit.Test)

Example 3 with KeySchemaElement

use of com.amazonaws.services.dynamodbv2.model.KeySchemaElement 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 4 with KeySchemaElement

use of com.amazonaws.services.dynamodbv2.model.KeySchemaElement in project jcabi-dynamo by jcabi.

the class RegionMock method get.

/**
 * Get region with a table.
 * @param table Table name
 * @return Region
 * @throws Exception If fails
 */
public Region get(final String table) throws Exception {
    final Region region = new Region.Simple(new Credentials.Direct(Credentials.TEST, this.prt));
    final MadeTable mocker = new MadeTable(region, new CreateTableRequest().withTableName(table).withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)).withAttributeDefinitions(new AttributeDefinition().withAttributeName(this.ahash).withAttributeType(ScalarAttributeType.S), new AttributeDefinition().withAttributeName(this.arange).withAttributeType(ScalarAttributeType.N)).withKeySchema(new KeySchemaElement().withAttributeName(this.ahash).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(this.arange).withKeyType(KeyType.RANGE)));
    mocker.create();
    mocker.createIfAbsent();
    return new ReRegion(region);
}
Also used : MadeTable(com.jcabi.dynamo.mock.MadeTable) ReRegion(com.jcabi.dynamo.retry.ReRegion) ReRegion(com.jcabi.dynamo.retry.ReRegion) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 5 with KeySchemaElement

use of com.amazonaws.services.dynamodbv2.model.KeySchemaElement in project aws-doc-sdk-examples by awsdocs.

the class LowLevelParallelScan method createTable.

private static void createTable(String tableName, long readCapacityUnits, long writeCapacityUnits, String partitionKeyName, String partitionKeyType, String sortKeyName, String sortKeyType) {
    try {
        System.out.println("Creating table " + tableName);
        ArrayList<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
        ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
        // Partition
        ks.add(new KeySchemaElement().withAttributeName(partitionKeyName).withKeyType(KeyType.HASH));
        // key
        attributeDefinitions.add(new AttributeDefinition().withAttributeName(partitionKeyName).withAttributeType(partitionKeyType));
        if (sortKeyName != null) {
            // Sort
            ks.add(new KeySchemaElement().withAttributeName(sortKeyName).withKeyType(KeyType.RANGE));
            // key
            attributeDefinitions.add(new AttributeDefinition().withAttributeName(sortKeyName).withAttributeType(sortKeyType));
        }
        // Provide initial provisioned throughput values as Java long data
        // types
        ProvisionedThroughput provisionedthroughput = new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits).withWriteCapacityUnits(writeCapacityUnits);
        CreateTableRequest request = new CreateTableRequest().withTableName(tableName).withKeySchema(ks).withProvisionedThroughput(provisionedthroughput).withAttributeDefinitions(attributeDefinitions);
        client.createTable(request);
    } catch (AmazonServiceException ase) {
        System.err.println("Failed to create table " + tableName + " " + ase);
    }
}
Also used : ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Aggregations

KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)30 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)23 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)22 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)21 ArrayList (java.util.ArrayList)16 Table (com.amazonaws.services.dynamodbv2.document.Table)9 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)8 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)6 CreateTableResult (com.amazonaws.services.dynamodbv2.model.CreateTableResult)5 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)5 Projection (com.amazonaws.services.dynamodbv2.model.Projection)5 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4 Test (org.junit.Test)4 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)3 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)3 LocalSecondaryIndex (com.amazonaws.services.dynamodbv2.model.LocalSecondaryIndex)3 StreamSpecification (com.amazonaws.services.dynamodbv2.model.StreamSpecification)3 AmazonClientException (com.amazonaws.AmazonClientException)2 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)2