Search in sources :

Example 6 with TableStatus

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

the class DynamoDBUtils method waitForTableToBecomeAvailable.

/**
 * Waits up to 6 minutes to confirm if a table has been created or not
 *
 * @param awsClient
 * @param tableName
 */
public static void waitForTableToBecomeAvailable(AmazonDynamoDB awsClient, String tableName) {
    LOG.debug("Waiting for {} to become available", tableName);
    long startTime = System.currentTimeMillis();
    long endTime = startTime + WAIT_TIME;
    while (System.currentTimeMillis() < endTime) {
        try {
            Thread.sleep(SLEEP_TIME);
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = awsClient.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            LOG.debug("{} - current state: {}", tableName, 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 became active");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) ResourceInUseException(com.amazonaws.services.dynamodbv2.model.ResourceInUseException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 7 with TableStatus

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

the class LowLevelGlobalSecondaryIndexExample 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) {
            e.printStackTrace();
        }
    }
    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 8 with TableStatus

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

the class LowLevelParallelScan 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) AmazonServiceException(com.amazonaws.AmazonServiceException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 9 with TableStatus

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

the class DynamoDBDynamicFaultInjection method waitForTableToBecomeAvailable.

/*
     * Waits for the table to become ACTIVE Times out after 10 minutes
     */
private static void waitForTableToBecomeAvailable(String tableName) {
    logger.info("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 = dynamoDBClient.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            logger.info("  - 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");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) ResourceInUseException(com.amazonaws.services.dynamodbv2.model.ResourceInUseException) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 10 with TableStatus

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

the class LowLevelTableExample 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)

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