Search in sources :

Example 11 with KeySchemaElement

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

the class DynamoDBUtils method buildCreateTableRequest.

/**
 * Builds the necessary requests to create tables
 *
 * @param tableName
 * @param keySchema
 * @param proThrou
 * @param attrs
 * @return
 */
public static CreateTableRequest buildCreateTableRequest(String tableName, ArrayList<KeySchemaElement> keySchema, ProvisionedThroughput proThrou, Map<String, String> attrs) {
    CreateTableRequest createTableRequest = new CreateTableRequest();
    createTableRequest.setTableName(tableName);
    createTableRequest.setKeySchema(keySchema);
    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    for (KeySchemaElement kEle : keySchema) {
        AttributeDefinition attrDef = new AttributeDefinition();
        attrDef.setAttributeName(kEle.getAttributeName());
        attrDef.setAttributeType(attrs.get(kEle.getAttributeName()));
        attributeDefinitions.add(attrDef);
    }
    createTableRequest.setAttributeDefinitions(attributeDefinitions);
    createTableRequest.setProvisionedThroughput(proThrou);
    return createTableRequest;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 12 with KeySchemaElement

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

the class DynamoDBUtils method executeCreateTableRequest.

/**
 * Executes a create table request using the DynamoDB client and waits the
 * default time until it's been created.
 *
 * @param awsClient
 * @param keySchema
 * @param tableName
 * @param proThrou
 */
public static void executeCreateTableRequest(AmazonDynamoDB awsClient, String tableName, ArrayList<KeySchemaElement> keySchema, Map<String, String> attrs, ProvisionedThroughput proThrou) {
    CreateTableRequest createTableRequest = buildCreateTableRequest(tableName, keySchema, proThrou, attrs);
    // use the client to perform the request
    try {
        awsClient.createTable(createTableRequest).getTableDescription();
        // wait for table to become active
        waitForTableToBecomeAvailable(awsClient, tableName);
    } catch (ResourceInUseException ex) {
        LOG.warn("Table '{}' already exists.", tableName);
    } finally {
        LOG.info("Table '{}' is available.", tableName);
    }
}
Also used : ResourceInUseException(com.amazonaws.services.dynamodbv2.model.ResourceInUseException) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest)

Example 13 with KeySchemaElement

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

the class DescribeTableCommandTest method testExecute.

@Test
public void testExecute() {
    command.execute();
    List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("name"));
    assertEquals("FULL_DESCRIBE_TABLE", ddbClient.describeTableRequest.getTableName());
    assertEquals("FULL_DESCRIBE_TABLE", exchange.getIn().getHeader(DdbConstants.TABLE_NAME));
    assertEquals("ACTIVE", exchange.getIn().getHeader(DdbConstants.TABLE_STATUS));
    assertEquals(new Date(AmazonDDBClientMock.NOW), exchange.getIn().getHeader(DdbConstants.CREATION_DATE));
    assertEquals(100L, exchange.getIn().getHeader(DdbConstants.ITEM_COUNT));
    assertEquals(keySchema, exchange.getIn().getHeader(DdbConstants.KEY_SCHEMA));
    assertEquals(20L, exchange.getIn().getHeader(DdbConstants.READ_CAPACITY));
    assertEquals(10L, exchange.getIn().getHeader(DdbConstants.WRITE_CAPACITY));
    assertEquals(1000L, exchange.getIn().getHeader(DdbConstants.TABLE_SIZE));
}
Also used : ArrayList(java.util.ArrayList) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) Date(java.util.Date) Test(org.junit.Test)

Example 14 with KeySchemaElement

use of com.amazonaws.services.dynamodbv2.model.KeySchemaElement in project cas by apereo.

the class DynamoDbCloudConfigBootstrapConfiguration method createSettingsTable.

@SneakyThrows
private static void createSettingsTable(final AmazonDynamoDB amazonDynamoDBClient, final boolean deleteTables) {
    final String name = ColumnNames.ID.getColumnName();
    final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(name, ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(name, KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT)).withTableName(TABLE_NAME);
    if (deleteTables) {
        final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
        LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
        TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
    }
    LOGGER.debug("Sending delete request [{}] to create table", request);
    TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);
    LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
    TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());
    final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
    LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);
    final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
    LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) SneakyThrows(lombok.SneakyThrows)

Example 15 with KeySchemaElement

use of com.amazonaws.services.dynamodbv2.model.KeySchemaElement in project cas by apereo.

the class DynamoDbServiceRegistryFacilitator method createServicesTable.

/**
 * Create tables.
 *
 * @param deleteTables the delete tables
 */
@SneakyThrows
public void createServicesTable(final boolean deleteTables) {
    LOGGER.debug("Attempting to create DynamoDb services table");
    final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getColumnName(), ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(ColumnNames.ID.getColumnName(), KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(), dynamoDbProperties.getWriteCapacity())).withTableName(dynamoDbProperties.getTableName());
    if (deleteTables) {
        final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
        LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
        TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
    }
    LOGGER.debug("Sending delete request [{}] to create table", request);
    TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);
    LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
    TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());
    final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
    LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);
    final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
    LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) SneakyThrows(lombok.SneakyThrows)

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