Search in sources :

Example 1 with TableDescription

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

the class DdbEndpoint method waitForTableToBecomeAvailable.

private void waitForTableToBecomeAvailable(String tableName) {
    LOG.trace("Waiting for [{}] to become ACTIVE...", tableName);
    long waitTime = 5 * 60 * 1000;
    while (waitTime > 0) {
        try {
            Thread.sleep(1000 * 5);
            waitTime -= 5000;
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = getDdbClient().describeTable(request).getTable();
            if (isTableActive(tableDescription)) {
                LOG.trace("Table [{}] became active", tableName);
                return;
            }
            LOG.trace("Table [{}] not active yet", tableName);
        } catch (AmazonServiceException ase) {
            if (!ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException")) {
                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) AmazonServiceException(com.amazonaws.AmazonServiceException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 2 with TableDescription

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

the class DdbEndpoint method doStart.

@Override
public void doStart() throws Exception {
    super.doStart();
    ddbClient = configuration.getAmazonDDBClient() != null ? configuration.getAmazonDDBClient() : createDdbClient();
    if (ObjectHelper.isNotEmpty(configuration.getAmazonDdbEndpoint())) {
        ddbClient.setEndpoint(configuration.getAmazonDdbEndpoint());
    }
    String tableName = getConfiguration().getTableName();
    LOG.trace("Querying whether table [{}] already exists...", tableName);
    try {
        DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = ddbClient.describeTable(request).getTable();
        if (!isTableActive(tableDescription)) {
            waitForTableToBecomeAvailable(tableName);
        }
        LOG.trace("Table [{}] already exists", tableName);
        return;
    } catch (ResourceNotFoundException e) {
        LOG.trace("Table [{}] doesn't exist yet", tableName);
        LOG.trace("Creating table [{}]...", tableName);
        TableDescription tableDescription = createTable(tableName);
        if (!isTableActive(tableDescription)) {
            waitForTableToBecomeAvailable(tableName);
        }
        LOG.trace("Table [{}] created", tableName);
    }
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Example 3 with TableDescription

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

the class AmazonDDBClientMock method describeTable.

@Override
public DescribeTableResult describeTable(DescribeTableRequest describeTableRequest) {
    this.describeTableRequest = describeTableRequest;
    String tableName = describeTableRequest.getTableName();
    if ("activeTable".equals(tableName)) {
        return tableWithStatus(TableStatus.ACTIVE);
    } else if ("creatibleTable".equals(tableName) && createTableRequest != null) {
        return tableWithStatus(TableStatus.ACTIVE);
    } else if ("FULL_DESCRIBE_TABLE".equals(tableName)) {
        return new DescribeTableResult().withTable(new TableDescription().withTableName(tableName).withTableStatus(TableStatus.ACTIVE).withCreationDateTime(new Date(NOW)).withItemCount(100L).withKeySchema(new KeySchemaElement().withAttributeName("name")).withProvisionedThroughput(new ProvisionedThroughputDescription().withReadCapacityUnits(20L).withWriteCapacityUnits(10L)).withTableSizeBytes(1000L));
    }
    throw new ResourceNotFoundException(tableName + " is missing");
}
Also used : DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult) ProvisionedThroughputDescription(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) Date(java.util.Date) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 4 with TableDescription

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

the class DynamoDbTicketRegistryFacilitator method createTicketTables.

/**
     * Create ticket tables.
     *
     * @param deleteTables the delete tables
     */
public void createTicketTables(final boolean deleteTables) {
    final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll();
    metadata.forEach(Unchecked.consumer(r -> {
        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(r.getProperties().getStorageName());
        if (deleteTables) {
            final DeleteTableRequest delete = new DeleteTableRequest(r.getProperties().getStorageName());
            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) PutItemResult(com.amazonaws.services.dynamodbv2.model.PutItemResult) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) KeyType(com.amazonaws.services.dynamodbv2.model.KeyType) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) LoggerFactory(org.slf4j.LoggerFactory) SerializationUtils(org.apache.commons.lang3.SerializationUtils) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) DeleteItemResult(com.amazonaws.services.dynamodbv2.model.DeleteItemResult) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Map(java.util.Map) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TicketCatalog(org.apereo.cas.ticket.TicketCatalog) Unchecked(org.jooq.lambda.Unchecked) Logger(org.slf4j.Logger) GetItemRequest(com.amazonaws.services.dynamodbv2.model.GetItemRequest) ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) DeleteItemRequest(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest) TableUtils(com.amazonaws.services.dynamodbv2.util.TableUtils) PutItemRequest(com.amazonaws.services.dynamodbv2.model.PutItemRequest) ScalarAttributeType(com.amazonaws.services.dynamodbv2.model.ScalarAttributeType) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DynamoDbTicketRegistryProperties(org.apereo.cas.configuration.model.support.dynamodb.DynamoDbTicketRegistryProperties) Collections(java.util.Collections) Ticket(org.apereo.cas.ticket.Ticket) DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) 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 5 with TableDescription

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

the class DynamoDBStore method schemaExists.

/**
   * Verifies if the specified schemas exist
   *
   * @return
   */
@Override
public boolean schemaExists() {
    LOG.info("Verifying schemas.");
    TableDescription success = null;
    if (getDynamoDbMapping().getTables().isEmpty())
        throw new IllegalStateException("There are not tables defined.");
    if (getPreferredSchema() == null) {
        LOG.debug("Verifying schemas");
        if (getDynamoDbMapping().getTables().isEmpty())
            throw new IllegalStateException("There are not tables defined.");
        // read the mapping object
        for (String tableName : getDynamoDbMapping().getTables().keySet()) {
            success = getTableSchema(tableName);
            if (success == null)
                return false;
        }
    } else {
        LOG.info("Verifying schema " + preferredSchema);
        success = getTableSchema(preferredSchema);
    }
    LOG.info("Finished verifying schemas.");
    return (success != null) ? true : false;
}
Also used : 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