Search in sources :

Example 1 with TableStatus

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

the class LowLevelParallelScan method waitForTableToBecomeAvailable.

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) {
        DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = client.describeTable(request).getTable();
        String tableStatus = tableDescription.getTableStatus();
        System.out.println("  - current state: " + tableStatus);
        if (tableStatus.equals(TableStatus.ACTIVE.toString()))
            return;
        try {
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
        }
    }
    throw new RuntimeException("Table " + tableName + " never went active");
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) AmazonServiceException(com.amazonaws.AmazonServiceException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 2 with TableStatus

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

the class LowLevelGlobalSecondaryIndexExample method waitForTableToBecomeAvailable.

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) {
        DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = client.describeTable(request).getTable();
        String tableStatus = tableDescription.getTableStatus();
        System.out.println("  - current state: " + tableStatus);
        if (tableStatus.equals(TableStatus.ACTIVE.toString()))
            return;
        try {
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    throw new RuntimeException("Table " + tableName + " never went active");
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 3 with TableStatus

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

the class LowLevelLocalSecondaryIndexExample method waitForTableToBeDeleted.

private static void waitForTableToBeDeleted(String tableName) {
    System.out.println("Waiting for " + tableName + " while status DELETING...");
    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = client.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            System.out.println("  - current state: " + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString()))
                return;
        } catch (ResourceNotFoundException e) {
            System.out.println("Table " + tableName + " is not found. It was deleted.");
            return;
        }
        try {
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
        }
    }
    throw new RuntimeException("Table " + tableName + " was never deleted");
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 4 with TableStatus

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

the class LowLevelLocalSecondaryIndexExample method waitForTableToBecomeAvailable.

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) {
        DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = client.describeTable(request).getTable();
        String tableStatus = tableDescription.getTableStatus();
        System.out.println("  - current state: " + tableStatus);
        if (tableStatus.equals(TableStatus.ACTIVE.toString()))
            return;
        try {
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
        }
    }
    throw new RuntimeException("Table " + tableName + " never went active");
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 5 with TableStatus

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

the class DynamoDBStore method waitForTableToBeDeleted.

/**
 * Waits up to 6 minutes to confirm if a table has been deleted or not
 *
 * @param pTableName
 */
private void waitForTableToBeDeleted(String pTableName) {
    LOG.debug("Waiting for " + pTableName + " to be deleted.");
    long startTime = System.currentTimeMillis();
    long endTime = startTime + WAIT_TIME;
    while (System.currentTimeMillis() < endTime) {
        try {
            Thread.sleep(SLEEP_DELETE_TIME);
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(pTableName);
            TableDescription tableDescription = getDynamoDBClient().describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            LOG.debug(pTableName + " - current state: " + tableStatus);
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == true)
                return;
            LOG.error(ase.getMessage());
        }
    }
    LOG.debug(pTableName + " deleted.");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) GoraException(org.apache.gora.util.GoraException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Aggregations

DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)11 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)11 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)9 AmazonServiceException (com.amazonaws.AmazonServiceException)5 ResourceInUseException (com.amazonaws.services.dynamodbv2.model.ResourceInUseException)2 IOException (java.io.IOException)2 AmazonClientException (com.amazonaws.AmazonClientException)1 FileNotFoundException (java.io.FileNotFoundException)1 GoraException (org.apache.gora.util.GoraException)1