Search in sources :

Example 1 with DeleteTableRequest

use of com.amazonaws.services.dynamodbv2.model.DeleteTableRequest in project jcabi-dynamo by jcabi.

the class MadeTable method drop.

/**
 * Drop table.
 * @throws InterruptedException If something fails
 */
public void drop() throws InterruptedException {
    final AmazonDynamoDB aws = this.region.aws();
    final String name = this.request.getTableName();
    aws.deleteTable(new DeleteTableRequest().withTableName(name));
    Logger.info(this, "DynamoDB table '%s' deletion requested", name);
    while (this.exists()) {
        Logger.info(this, "DynamoDB table '%s' still exists", name);
        TimeUnit.SECONDS.sleep((long) Tv.TEN);
    }
    Logger.info(this, "DynamoDB table '%s' deleted", name);
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 2 with DeleteTableRequest

use of com.amazonaws.services.dynamodbv2.model.DeleteTableRequest in project camel by apache.

the class DeleteTableCommand method execute.

@Override
public void execute() {
    TableDescription tableDescription = ddbClient.deleteTable(new DeleteTableRequest(determineTableName())).getTableDescription();
    Map tmp = new HashMap<>();
    tmp.put(DdbConstants.PROVISIONED_THROUGHPUT, tableDescription.getProvisionedThroughput());
    tmp.put(DdbConstants.CREATION_DATE, tableDescription.getCreationDateTime());
    tmp.put(DdbConstants.ITEM_COUNT, tableDescription.getItemCount());
    tmp.put(DdbConstants.KEY_SCHEMA, tableDescription.getKeySchema());
    tmp.put(DdbConstants.TABLE_NAME, tableDescription.getTableName());
    tmp.put(DdbConstants.TABLE_SIZE, tableDescription.getTableSizeBytes());
    tmp.put(DdbConstants.TABLE_STATUS, tableDescription.getTableStatus());
    addToResults(tmp);
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) HashMap(java.util.HashMap) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with DeleteTableRequest

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

the class DynamoDbCloudConfigBootstrapConfiguration method createSettingsTable.

@SneakyThrows
private static void createSettingsTable(final AmazonDynamoDB amazonDynamoDBClient, final boolean deleteTables) {
    final String name = ColumnNames.ID.getColumnName();
    final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(name, ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(name, KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT)).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);
}
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) SneakyThrows(lombok.SneakyThrows)

Example 4 with DeleteTableRequest

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

the class DynamoDbServiceRegistryFacilitator method createServicesTable.

/**
 * Create tables.
 *
 * @param deleteTables the delete tables
 */
@SneakyThrows
public void createServicesTable(final boolean deleteTables) {
    LOGGER.debug("Attempting to create DynamoDb services table");
    final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getColumnName(), ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(ColumnNames.ID.getColumnName(), KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(), dynamoDbProperties.getWriteCapacity())).withTableName(dynamoDbProperties.getTableName());
    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);
}
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) SneakyThrows(lombok.SneakyThrows)

Example 5 with DeleteTableRequest

use of com.amazonaws.services.dynamodbv2.model.DeleteTableRequest in project amos-ss17-alexa by c-i-ber.

the class DynamoDbMapper method dropTable.

/**
 * drops table by a pojo class
 *
 * @param cl class which will be mapped to drop a table
 */
public void dropTable(Class cl) {
    DeleteTableRequest tableRequest = mapper.generateDeleteTableRequest(cl);
    Table table = dynamoDB.getTable(tableRequest.getTableName());
    try {
        dynamoDbClient.deleteTable(tableRequest);
        table.waitForDelete();
    } catch (ResourceNotFoundException e) {
    // Table does not exist
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) Table(com.amazonaws.services.dynamodbv2.document.Table) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Aggregations

DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)8 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)2 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)2 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)2 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)2 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)2 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)2 SneakyThrows (lombok.SneakyThrows)2 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)1 Table (com.amazonaws.services.dynamodbv2.document.Table)1 DeleteTableResult (com.amazonaws.services.dynamodbv2.model.DeleteTableResult)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GoraException (org.apache.gora.util.GoraException)1