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.");
}
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");
}
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);
}
}
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;
}
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;
}
Aggregations