Example usage for com.amazonaws.services.dynamodbv2.model ResourceInUseException getMessage

List of usage examples for com.amazonaws.services.dynamodbv2.model ResourceInUseException getMessage

Introduction

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

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:com.exorath.service.lastserver.dynamodb.DynamoDBService.java

License:Apache License

public DynamoDBService(DynamoDBProvider provider) {
    try {//from   w  w  w. j a v a2  s  .co  m
        table = provider.getDB()
                .createTable(new CreateTableRequest().withTableName(TABLE_NAME)
                        .withKeySchema(new KeySchemaElement(PRIM_KEY, KeyType.HASH))
                        .withAttributeDefinitions(new AttributeDefinition(PRIM_KEY, ScalarAttributeType.S))
                        .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)));
        logger.info("Created DynamoDB table " + TABLE_NAME
                + " with 1r/1w provisioning. Waiting for it to activate.");
    } catch (ResourceInUseException ex) {
        table = provider.getDB().getTable(TABLE_NAME);
        logger.info("DynamoDB table " + TABLE_NAME + " already existed. Waiting for it to activate.");
    }

    try {
        table.waitForActive();
    } catch (InterruptedException ex) {
        logger.error("DynamoDB table " + TABLE_NAME + " could not activate!\n" + ex.getMessage());
        System.exit(1);
    }
    logger.info("DynamoDB table " + TABLE_NAME + " active.");
}

From source file:com.exorath.service.party.service.DynamoDatabaseProvider.java

License:Apache License

/**
 * @param primKey Primary partition key for the table
 * @param gsi     String array for global secondary index's, allow for searching on more than primary key
 * @return Table containing party information
 *//* w w  w .  j  a  va2  s. c  o m*/
private Table setupTable(String primKey, String... gsi) {
    Table table;
    try {
        ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(1L, 1L);
        ArrayList<GlobalSecondaryIndex> gsiArr = new ArrayList<>();
        ArrayList<AttributeDefinition> attDefs = new ArrayList<>();
        for (String g : gsi) {
            GlobalSecondaryIndex gsiIndex = new GlobalSecondaryIndex().withIndexName(g)
                    .withProvisionedThroughput(provisionedThroughput)
                    .withKeySchema(new KeySchemaElement().withAttributeName(g).withKeyType(KeyType.HASH))
                    .withProjection(new Projection().withProjectionType("ALL"));
            gsiArr.add(gsiIndex);
            attDefs.add(new AttributeDefinition(g, ScalarAttributeType.S));
        }
        attDefs.add(new AttributeDefinition(primKey, ScalarAttributeType.S));
        table = database.createTable(new CreateTableRequest().withTableName(tableName)
                .withKeySchema(new KeySchemaElement(primKey, KeyType.HASH)).withGlobalSecondaryIndexes(gsiArr)
                .withAttributeDefinitions(attDefs).withProvisionedThroughput(provisionedThroughput));
        logger.info("Created DynamoDB table " + tableName
                + " with 1r/1w provisioning. Waiting for it to activate.");
    } catch (ResourceInUseException ex) {
        table = database.getTable(tableName);
        logger.info("DynamoDB table " + tableName + " already existed. Waiting for it to activate.");
    }

    try {
        table.waitForActive();
    } catch (InterruptedException ex) {
        logger.error("DynamoDB table " + tableName + " could not activate!\n" + ex.getMessage());
        System.exit(1);
    }
    logger.info("DynamoDB table " + tableName + " active.");
    return table;
}