Search in sources :

Example 11 with ProvisionedThroughput

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

the class CreateTable method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    CreateTable <table>\n\n" + "Where:\n" + "    table - the table to create.\n\n" + "Example:\n" + "    CreateTable HelloTable\n";
    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    /* Read the name from command args */
    String table_name = args[0];
    System.out.format("Creating table \"%s\" with a simple primary key: \"Name\".\n", table_name);
    CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition("Name", ScalarAttributeType.S)).withKeySchema(new KeySchemaElement("Name", KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(new Long(10), new Long(10))).withTableName(table_name);
    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
    try {
        CreateTableResult result = ddb.createTable(request);
        System.out.println(result.getTableDescription().getTableName());
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) CreateTableResult(com.amazonaws.services.dynamodbv2.model.CreateTableResult)

Example 12 with ProvisionedThroughput

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

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

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

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

ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)30 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)25 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)23 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)23 ArrayList (java.util.ArrayList)14 Table (com.amazonaws.services.dynamodbv2.document.Table)11 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)7 AmazonServiceException (com.amazonaws.AmazonServiceException)5 CreateTableResult (com.amazonaws.services.dynamodbv2.model.CreateTableResult)5 Projection (com.amazonaws.services.dynamodbv2.model.Projection)5 ResourceInUseException (com.amazonaws.services.dynamodbv2.model.ResourceInUseException)5 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)3 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)3 GlobalSecondaryIndex (com.amazonaws.services.dynamodbv2.model.GlobalSecondaryIndex)3 LocalSecondaryIndex (com.amazonaws.services.dynamodbv2.model.LocalSecondaryIndex)3 StreamSpecification (com.amazonaws.services.dynamodbv2.model.StreamSpecification)3 AmazonClientException (com.amazonaws.AmazonClientException)2 DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)2 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)2 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)2