Search in sources :

Example 6 with DescribeTableRequest

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

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

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

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

the class DynamoDBStore method getTableSchema.

/**
   * Retrieves the table description for the specific resource name
   * 
   * @param tableName
   * @return
   */
private TableDescription getTableSchema(String tableName) {
    TableDescription tableDescription = null;
    try {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        tableDescription = getDynamoDBClient().describeTable(describeTableRequest).getTable();
    } catch (ResourceNotFoundException e) {
        LOG.error("Error while getting table schema: " + tableName);
        return tableDescription;
    }
    return tableDescription;
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Example 10 with DescribeTableRequest

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

the class GoraDynamoDBTestDriver method checkResource.

/**
   * Checks if a resource exists or not
   * 
   * @param tableName
   *          Table name to be checked
   * @return
   */
public TableDescription checkResource(String tableName) {
    TableDescription tableDescription = null;
    try {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        tableDescription = dynamoDBClient.describeTable(describeTableRequest).getTable();
    } catch (ResourceNotFoundException e) {
        tableDescription = null;
    }
    return tableDescription;
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Aggregations

DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)9 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)9 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)6 AmazonServiceException (com.amazonaws.AmazonServiceException)3 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)3 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)2 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)2 DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)2 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)2 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)2 IOException (java.io.IOException)2 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 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)1 KeyType (com.amazonaws.services.dynamodbv2.model.KeyType)1 ProvisionedThroughputDescription (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription)1 PutItemRequest (com.amazonaws.services.dynamodbv2.model.PutItemRequest)1 PutItemResult (com.amazonaws.services.dynamodbv2.model.PutItemResult)1