Example usage for com.amazonaws.services.dynamodbv2.model TableStatus ACTIVE

List of usage examples for com.amazonaws.services.dynamodbv2.model TableStatus ACTIVE

Introduction

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

Prototype

TableStatus ACTIVE

To view the source code for com.amazonaws.services.dynamodbv2.model TableStatus ACTIVE.

Click Source Link

Usage

From source file:DynamoDBUtils.java

License:Open Source License

/**
 * Helper method to wait until Amazon DynamoDB table becomes active.
 *
 * @param client//from  ww w  .  j  ava  2s .c  o  m
 *        The {@link AmazonDynamoDBClient} with Amazon DynamoDB read privileges
 * @param tableName
 *        The Amazon DynamoDB table to check the state of
 * @throws IllegalStateException
 *         Table is in the deleting state
 * @throws IllegalStateException
 *         Table did not become active before timeout
 */
private static void waitForActive(AmazonDynamoDBClient client, String tableName) {
    switch (getTableStatus(client, tableName)) {
    case DELETING:
        throw new IllegalStateException("Table " + tableName + " is in the DELETING state");
    case ACTIVE:
        LOG.info("Table " + tableName + " is ACTIVE");
        return;
    default:
        long startTime = System.currentTimeMillis();
        long endTime = startTime + (10 * 60 * 1000);
        while (System.currentTimeMillis() < endTime) {
            try {
                Thread.sleep(10 * 1000);
            } catch (InterruptedException e) {
            }
            try {
                if (getTableStatus(client, tableName) == TableStatus.ACTIVE) {
                    LOG.info("Table " + tableName + " is ACTIVE");
                    return;
                }
            } catch (ResourceNotFoundException e) {
                throw new IllegalStateException("Table " + tableName + " never went active");
            }
        }
    }
}

From source file:TableCreator.java

License:Open Source License

private static void waitForTableToBecomeAvailable(String tableName) {
    System.out.println("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        try {/*from w  ww . j  av  a2s  .co m*/
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = dynamoDB.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            System.out.println("  - current state: " + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString()))
                return;
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
                throw ase;
        }
    }

    throw new RuntimeException("Table " + tableName + " never went active");
}

From source file:TableCreator.java

License:Open Source License

private static void waitForTableToDelete(String tableName) {
    System.out.println("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        try {//from   www  .  ja va  2 s .c  om
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = dynamoDB.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            System.out.println("  - current state: " + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString()))
                return;
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
                throw ase;
        }
    }

    throw new RuntimeException("Table " + tableName + " never went active");
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java

License:Open Source License

private static boolean isTableAcceptingWrites(final String status) {
    return isTableStatus(TableStatus.ACTIVE, status) || isTableStatus(TableStatus.UPDATING, status);
}

From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.manager.DynamoDbTemplateInfrastructureManager.java

License:Apache License

private boolean isTableCreated(final String tableName) {
    try {//w  ww . java 2  s .  c  o m
        final DescribeTableResult result = amazonDynamoDbClient
                .describeTable(new DescribeTableRequest(tableName));
        final TableDescription tableDescription = result.getTable();
        final String tableStatus = tableDescription.getTableStatus();
        final String returnedTableName = tableDescription.getTableName();
        return tableName.equals(returnedTableName) && TableStatus.ACTIVE.toString().equals(tableStatus);
    } catch (final ResourceNotFoundException e) {
        return false;
    }
}

From source file:com.github.sdmcraft.slingdynamo.demo.App.java

License:Open Source License

/**
 * Wait for table to become available.//from   w  w  w  . java  2 s. c  om
 *
 * @param tableName the table name
 */
private static void waitForTableToBecomeAvailable(String tableName) {
    System.out.println("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);

    while (System.currentTimeMillis() < endTime) {
        try {
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
            ;
        }

        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = dynamoDB.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            System.out.println("  - current state: " + tableStatus);

            if (tableStatus.equals(TableStatus.ACTIVE.toString())) {
                return;
            }
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false) {
                throw ase;
            }
        }
    }

    throw new RuntimeException("Table " + tableName + " never went active");
}

From source file:com.github.sporcina.mule.modules.DynamoDBConnector.java

License:Open Source License

/**
 * Wait for the table to become active/*from w  w w  . j a  v a2s  .  c o  m*/
 * <p/>
 * DynamoDB takes some time to create a new table, depending on the complexity of the table and the requested
 * read/write capacity.  Performing any actions against the table before it is active will result in a failure. This
 * method periodically checks to see if the table is active for the requested wait period.
 *
 * @param tableName
 *         the name of the table to create
 * @param waitFor
 *         number of minutes to wait for the table
 *
 * @throws TableNeverWentActiveException
 *         the table never became ACTIVE within the time allotted
 */
private void waitForTableToBecomeAvailable(final String tableName, final Integer waitFor)
        throws TableNeverWentActiveException {

    LOG.info("Waiting for table " + tableName + " to become ACTIVE...");

    final long millisecondsToWaitFor = (waitFor * 60 * 1000);
    final long startTime = System.currentTimeMillis();
    final long endTime = startTime + millisecondsToWaitFor;

    while (System.currentTimeMillis() < endTime) {

        try {
            Thread.sleep(TWENTY_SECONDS);
        } catch (Exception e) {
            /*ignore sleep exceptions*/ }

        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = getDynamoDBClient().describeTable(request).getTable();

            String tableStatus = tableDescription.getTableStatus();
            LOG.info("  - current state: " + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString())) {
                return;
            }

        } catch (AmazonServiceException ase) {
            if (!ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException")) {
                throw ase;
            }
        }
    }

    throw new TableNeverWentActiveException("Table " + tableName + " never went active");
}

From source file:com.intuit.tank.persistence.databases.AmazonDynamoDatabaseDocApi.java

License:Open Source License

/**
 * /* w w w  . java 2  s .c o  m*/
 * @{inheritDoc
 */
@Override
public void createTable(String tableName) {
    try {
        if (!hasTable(tableName)) {
            logger.info("Creating table: " + tableName);
            HierarchicalConfiguration resultsProviderConfig = config.getVmManagerConfig()
                    .getResultsProviderConfig();
            long readCapacity = getCapacity(resultsProviderConfig, "read-capacity", 10L);
            long writeCapacity = getCapacity(resultsProviderConfig, "write-capacity", 50L);
            ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
            attributeDefinitions
                    .add(new AttributeDefinition().withAttributeName(DatabaseKeys.JOB_ID_KEY.getShortKey())
                            .withAttributeType(ScalarAttributeType.S));
            attributeDefinitions.add(
                    new AttributeDefinition().withAttributeName(DatabaseKeys.REQUEST_NAME_KEY.getShortKey())
                            .withAttributeType(ScalarAttributeType.S));
            ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
                    .withReadCapacityUnits(readCapacity).withWriteCapacityUnits(writeCapacity);
            KeySchemaElement hashKeyElement = new KeySchemaElement()
                    .withAttributeName(DatabaseKeys.JOB_ID_KEY.getShortKey()).withKeyType(KeyType.HASH);
            KeySchemaElement rangeKeyElement = new KeySchemaElement()
                    .withAttributeName(DatabaseKeys.REQUEST_NAME_KEY.getShortKey()).withKeyType(KeyType.RANGE);
            CreateTableRequest request = new CreateTableRequest().withTableName(tableName)
                    .withKeySchema(hashKeyElement, rangeKeyElement)
                    .withAttributeDefinitions(attributeDefinitions)
                    .withProvisionedThroughput(provisionedThroughput);

            CreateTableResult result = dynamoDb.createTable(request);
            waitForStatus(tableName, TableStatus.ACTIVE);
            logger.info("Created table: " + result.getTableDescription().getTableName());
        }
    } catch (Exception t) {
        logger.error(t, t);
        throw new RuntimeException(t);
    }
}

From source file:com.mycompany.rproject.runnableClass.java

private static void waitForTableToBecomeAvailable(String tableName) {

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        try {// w  ww  .j  a  v a2  s. c  om
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = dynamoDBClient.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();

            System.out.println("tableStatus" + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString()))
                return;
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
                throw ase;
        }
    }

    throw new RuntimeException("Table " + tableName + " never went active");
}

From source file:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java

License:Open Source License

private static boolean isTableActive(String status) {
    return isTableStatus(TableStatus.ACTIVE, status);
}