Example usage for com.amazonaws.services.dynamodbv2.model CreateTableRequest CreateTableRequest

List of usage examples for com.amazonaws.services.dynamodbv2.model CreateTableRequest CreateTableRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model CreateTableRequest CreateTableRequest.

Prototype

public CreateTableRequest(java.util.List<AttributeDefinition> attributeDefinitions, String tableName,
        java.util.List<KeySchemaElement> keySchema, ProvisionedThroughput provisionedThroughput) 

Source Link

Document

Constructs a new CreateTableRequest object.

Usage

From source file:io.helixservice.feature.configuration.dynamo.DynamoConfigResourceLocator.java

License:Open Source License

private void createTable() {
    try {/*from   w  ww .  j  av a  2 s. co  m*/
        client.describeTable(tableName);
    } catch (ResourceNotFoundException e) {
        ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
        attributeDefinitions.add(new AttributeDefinition().withAttributeName("environment")
                .withAttributeType(ScalarAttributeType.S));
        attributeDefinitions.add(new AttributeDefinition().withAttributeName("service")
                .withAttributeType(ScalarAttributeType.S));

        List<KeySchemaElement> keySchema = new ArrayList<>();
        keySchema.add(new KeySchemaElement().withAttributeName("environment").withKeyType(KeyType.HASH));
        keySchema.add(new KeySchemaElement().withAttributeName("service").withKeyType(KeyType.RANGE));

        ProvisionedThroughput provisioning = new ProvisionedThroughput(8L, 4L);
        CreateTableRequest createTableRequest = new CreateTableRequest(attributeDefinitions, tableName,
                keySchema, provisioning);
        client.createTable(createTableRequest);
    }
}

From source file:io.ignitr.dispatchr.manager.core.data.ClientRepository.java

License:Apache License

/**
 * Creates the DynamoDB tables that are used by this repository.
 *
 * @throws Exception/*from   w w  w .  j a va2 s.c o m*/
 */
@PostConstruct
private void initialize() throws Exception {
    LOG.info("Initializing DynamoDB tables for TopicRepository...");

    CreateTableRequest clientRequest = new CreateTableRequest(
            Arrays.asList(new AttributeDefinition("clientId", ScalarAttributeType.S)), CLIENT_TABLE_NAME,
            Arrays.asList(new KeySchemaElement("clientId", KeyType.HASH)), new ProvisionedThroughput(4L, 1L));

    if (TableUtils.createTableIfNotExists(dynamoDBClient, clientRequest)) {
        LOG.info("Creating DynamoDB table '{}'...", CLIENT_TABLE_NAME);
    } else {
        LOG.debug("DynamoDB table '{}' already exists!  Skipping table creation.", CLIENT_TABLE_NAME);
    }

    LOG.info("Waiting for DynamoDB table '{}' to become active...", CLIENT_TABLE_NAME);
    TableUtils.waitUntilActive(dynamoDBClient, CLIENT_TABLE_NAME);
    LOG.info("DynamoDB table '{}' is active", CLIENT_TABLE_NAME);
}

From source file:io.ignitr.dispatchr.manager.core.data.SubscriptionRepository.java

License:Apache License

@PostConstruct
private void initialize() throws Exception {
    LOG.info("Initializing DynamoDB tables for SubscriptionRepository...");

    // Dispatchr_Subscription
    CreateTableRequest subscriptionRequest = new CreateTableRequest(
            Arrays.asList(new AttributeDefinition("id", ScalarAttributeType.S)), SUBSCRIPTION_TABLE_NAME,
            Arrays.asList(new KeySchemaElement("id", KeyType.HASH)), new ProvisionedThroughput(4L, 1L));

    // Dispatchr_TopicSubscriptions
    CreateTableRequest topicSubscriptionsRequest = new CreateTableRequest(
            Arrays.asList(new AttributeDefinition("topic", ScalarAttributeType.S),
                    new AttributeDefinition("subscriptionId", ScalarAttributeType.S)

            ), TOPIC_SUBSCRIPTIONS_TABLE_NAME, Arrays.asList(new KeySchemaElement("topic", KeyType.HASH),
                    new KeySchemaElement("subscriptionId", KeyType.RANGE)),
            new ProvisionedThroughput(4L, 1L));

    if (TableUtils.createTableIfNotExists(dynamoDBClient, subscriptionRequest)) {
        LOG.info("Creating DynamoDB table '{}'...", SUBSCRIPTION_TABLE_NAME);
    } else {// w w w . j av  a 2  s  . c  o m
        LOG.debug("DynamoDB table '{}' already exists!  Skipping table creation.", SUBSCRIPTION_TABLE_NAME);
    }

    if (TableUtils.createTableIfNotExists(dynamoDBClient, topicSubscriptionsRequest)) {
        LOG.info("Creating DynamoDB table '{}'...", TOPIC_SUBSCRIPTIONS_TABLE_NAME);
    } else {
        LOG.debug("DynamoDB table '{}' already exists!  Skipping table creation.",
                TOPIC_SUBSCRIPTIONS_TABLE_NAME);
    }

    LOG.info("Waiting for DynamoDB table '{}' to become active...", SUBSCRIPTION_TABLE_NAME);
    TableUtils.waitUntilActive(dynamoDBClient, SUBSCRIPTION_TABLE_NAME);
    LOG.info("DynamoDB table '{}' is active", SUBSCRIPTION_TABLE_NAME);

    LOG.info("Waiting for DynamoDB table '{}' to become active...", TOPIC_SUBSCRIPTIONS_TABLE_NAME);
    TableUtils.waitUntilActive(dynamoDBClient, TOPIC_SUBSCRIPTIONS_TABLE_NAME);
    LOG.info("DynamoDB table '{}' is active", TOPIC_SUBSCRIPTIONS_TABLE_NAME);
}

From source file:io.ignitr.dispatchr.manager.core.data.TopicRepository.java

License:Apache License

@PostConstruct
private void initialize() throws Exception {
    LOG.info("Initializing DynamoDB tables for TopicRepository...");

    CreateTableRequest request = new CreateTableRequest(
            Arrays.asList(new AttributeDefinition("name", ScalarAttributeType.S)), TOPIC_TABLE_NAME,
            Arrays.asList(new KeySchemaElement("name", KeyType.HASH)), new ProvisionedThroughput(4L, 1L));

    if (TableUtils.createTableIfNotExists(dynamoDBClient, request)) {
        LOG.info("Creating DynamoDB table '{}'...", TOPIC_TABLE_NAME);
    } else {/*from w  w  w. j av  a2s. c o  m*/
        LOG.debug("DynamoDB table '{}' already exists!  Skipping table creation.", TOPIC_TABLE_NAME);
    }

    LOG.info("Waiting for DynamoDB table '{}' to become active...", TOPIC_TABLE_NAME);
    TableUtils.waitUntilActive(dynamoDBClient, TOPIC_TABLE_NAME);
    LOG.info("DynamoDB table '{}' is active", TOPIC_TABLE_NAME);
}