Search in sources :

Example 6 with TableDescription

use of com.amazonaws.services.dynamodbv2.model.TableDescription 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)

Example 7 with TableDescription

use of com.amazonaws.services.dynamodbv2.model.TableDescription 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 8 with TableDescription

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

the class DescribeTable method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    DescribeTable <table>\n\n" + "Where:\n" + "    table - the table to get information about.\n\n" + "Example:\n" + "    DescribeTable HelloTable\n";
    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String table_name = args[0];
    System.out.format("Getting description for %s\n\n", table_name);
    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
    try {
        TableDescription table_info = ddb.describeTable(table_name).getTable();
        if (table_info != null) {
            System.out.format("Table name  : %s\n", table_info.getTableName());
            System.out.format("Table ARN   : %s\n", table_info.getTableArn());
            System.out.format("Status      : %s\n", table_info.getTableStatus());
            System.out.format("Item count  : %d\n", table_info.getItemCount().longValue());
            System.out.format("Size (bytes): %d\n", table_info.getTableSizeBytes().longValue());
            ProvisionedThroughputDescription throughput_info = table_info.getProvisionedThroughput();
            System.out.println("Throughput");
            System.out.format("  Read Capacity : %d\n", throughput_info.getReadCapacityUnits().longValue());
            System.out.format("  Write Capacity: %d\n", throughput_info.getWriteCapacityUnits().longValue());
            List<AttributeDefinition> attributes = table_info.getAttributeDefinitions();
            System.out.println("Attributes");
            for (AttributeDefinition a : attributes) {
                System.out.format("  %s (%s)\n", a.getAttributeName(), a.getAttributeType());
            }
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("\nDone!");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) ProvisionedThroughputDescription(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Example 9 with TableDescription

use of com.amazonaws.services.dynamodbv2.model.TableDescription in project cas by apereo.

the class DynamoDbServiceRegistryFacilitator method createServicesTable.

/**
     * Create tables.
     *
     * @param deleteTables the delete tables
     */
public void createServicesTable(final boolean deleteTables) {
    try {
        final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(), dynamoDbProperties.getWriteCapacity())).withTableName(TABLE_NAME);
        if (deleteTables) {
            final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
            LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
            TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
        }
        LOGGER.debug("Sending delete request [{}] to create table", request);
        TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);
        LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
        TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());
        final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
        LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);
        final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
        LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 10 with TableDescription

use of com.amazonaws.services.dynamodbv2.model.TableDescription in project openhab1-addons by openhab.

the class DynamoDBPersistenceService method waitForTableToBecomeActive.

private boolean waitForTableToBecomeActive(String tableName) {
    try {
        logger.debug("Checking if table '{}' is created...", tableName);
        TableDescription tableDescription = db.getDynamoDB().getTable(tableName).waitForActiveOrDelete();
        if (tableDescription == null) {
            // table has been deleted
            logger.warn("Table '{}' deleted unexpectedly", tableName);
            return false;
        }
        boolean success = TableStatus.ACTIVE.equals(TableStatus.fromValue(tableDescription.getTableStatus()));
        if (success) {
            logger.debug("Creation of table '{}' successful, table status is now {}", tableName, tableDescription.getTableStatus());
        } else {
            logger.warn("Creation of table '{}' unsuccessful, table status is now {}", tableName, tableDescription.getTableStatus());
        }
        return success;
    } catch (AmazonClientException e) {
        logger.error("Exception when checking table status (describe): {}", e.getMessage());
        return false;
    } catch (InterruptedException e) {
        logger.error("Interrupted while trying to check table status: {}", e.getMessage());
        return false;
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Aggregations

TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)13 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)8 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)6 AmazonServiceException (com.amazonaws.AmazonServiceException)4 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)3 DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)3 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)3 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)2 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)2 ProvisionedThroughputDescription (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)1 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 DeleteItemRequest (com.amazonaws.services.dynamodbv2.model.DeleteItemRequest)1 DeleteItemResult (com.amazonaws.services.dynamodbv2.model.DeleteItemResult)1 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)1