use of com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException 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.ResourceNotFoundException 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.ResourceNotFoundException 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.ResourceNotFoundException in project openhab1-addons by openhab.
the class DynamoDBPersistenceService method createTable.
/**
* Create table (if not present) and wait for table to become active.
*
* Synchronized in order to ensure that at most single thread is creating the table at a time
*
* @param mapper
* @param dtoClass
* @return whether table creation succeeded.
*/
private synchronized boolean createTable(DynamoDBMapper mapper, Class<?> dtoClass) {
if (db == null) {
return false;
}
String tableName;
try {
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(dbConfig.getReadCapacityUnits(), dbConfig.getWriteCapacityUnits());
CreateTableRequest request = mapper.generateCreateTableRequest(dtoClass);
request.setProvisionedThroughput(provisionedThroughput);
if (request.getGlobalSecondaryIndexes() != null) {
for (GlobalSecondaryIndex index : request.getGlobalSecondaryIndexes()) {
index.setProvisionedThroughput(provisionedThroughput);
}
}
tableName = request.getTableName();
try {
db.getDynamoClient().describeTable(tableName);
} catch (ResourceNotFoundException e) {
// No table present, continue with creation
db.getDynamoClient().createTable(request);
} catch (AmazonClientException e) {
logger.error("Table creation failed due to error in describeTable operation", e);
return false;
}
// table found or just created, wait
return waitForTableToBecomeActive(tableName);
} catch (AmazonClientException e) {
logger.error("Exception when creating table", e);
return false;
}
}
use of com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException 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.");
}
Aggregations