use of com.amazonaws.services.dynamodbv2.model.DescribeTableRequest 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");
}
use of com.amazonaws.services.dynamodbv2.model.DescribeTableRequest 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);
}
}
use of com.amazonaws.services.dynamodbv2.model.DescribeTableRequest in project camel by apache.
the class DescribeTableCommand method execute.
@Override
public void execute() {
DescribeTableResult result = ddbClient.describeTable(new DescribeTableRequest().withTableName(determineTableName()));
Message msg = getMessageForResponse(exchange);
msg.setHeader(DdbConstants.TABLE_NAME, result.getTable().getTableName());
msg.setHeader(DdbConstants.TABLE_STATUS, result.getTable().getTableStatus());
msg.setHeader(DdbConstants.CREATION_DATE, result.getTable().getCreationDateTime());
msg.setHeader(DdbConstants.ITEM_COUNT, result.getTable().getItemCount());
msg.setHeader(DdbConstants.KEY_SCHEMA, result.getTable().getKeySchema());
msg.setHeader(DdbConstants.READ_CAPACITY, result.getTable().getProvisionedThroughput().getReadCapacityUnits());
msg.setHeader(DdbConstants.WRITE_CAPACITY, result.getTable().getProvisionedThroughput().getWriteCapacityUnits());
msg.setHeader(DdbConstants.TABLE_SIZE, result.getTable().getTableSizeBytes());
}
use of com.amazonaws.services.dynamodbv2.model.DescribeTableRequest 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");
}
use of com.amazonaws.services.dynamodbv2.model.DescribeTableRequest 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);
}));
}
Aggregations