use of com.amazonaws.services.dynamodbv2.model.ResourceInUseException in project tutorials by eugenp.
the class ProductInfoRepositoryIntegrationTest method setup.
@Before
public void setup() throws Exception {
try {
dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB);
CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class);
tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
amazonDynamoDB.createTable(tableRequest);
} catch (ResourceInUseException e) {
// Do nothing, table already created
}
// TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table
dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll());
}
use of com.amazonaws.services.dynamodbv2.model.ResourceInUseException in project gora by apache.
the class DynamoDBUtils method executeCreateTableRequest.
/**
* Executes a create table request using the DynamoDB client and waits the
* default time until it's been created.
*
* @param awsClient
* @param keySchema
* @param tableName
* @param proThrou
*/
public static void executeCreateTableRequest(AmazonDynamoDB awsClient, String tableName, ArrayList<KeySchemaElement> keySchema, Map<String, String> attrs, ProvisionedThroughput proThrou) {
CreateTableRequest createTableRequest = buildCreateTableRequest(tableName, keySchema, proThrou, attrs);
// use the client to perform the request
try {
awsClient.createTable(createTableRequest).getTableDescription();
// wait for table to become active
waitForTableToBecomeAvailable(awsClient, tableName);
} catch (ResourceInUseException ex) {
LOG.warn("Table '{}' already exists.", tableName);
} finally {
LOG.info("Table '{}' is available.", tableName);
}
}
use of com.amazonaws.services.dynamodbv2.model.ResourceInUseException in project aws-doc-sdk-examples by awsdocs.
the class StreamsAdapterDemoHelper method createTable.
/**
* @return StreamArn
*/
public static String createTable(AmazonDynamoDB client, String tableName) {
java.util.List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N"));
java.util.List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
// Partition
keySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH));
// key
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(2L).withWriteCapacityUnits(2L);
StreamSpecification streamSpecification = new StreamSpecification();
streamSpecification.setStreamEnabled(true);
streamSpecification.setStreamViewType(StreamViewType.NEW_IMAGE);
CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName).withAttributeDefinitions(attributeDefinitions).withKeySchema(keySchema).withProvisionedThroughput(provisionedThroughput).withStreamSpecification(streamSpecification);
try {
System.out.println("Creating table " + tableName);
CreateTableResult result = client.createTable(createTableRequest);
return result.getTableDescription().getLatestStreamArn();
} catch (ResourceInUseException e) {
System.out.println("Table already exists.");
return describeTable(client, tableName).getTable().getLatestStreamArn();
}
}
use of com.amazonaws.services.dynamodbv2.model.ResourceInUseException in project tutorials by eugenp.
the class ProductInfoRepositoryIntegrationTest method setup.
@Before
public void setup() {
try {
repository = new ProductInfoRepository();
repository.setMapper(dynamoDBMapper);
CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class);
tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
amazonDynamoDB.createTable(tableRequest);
} catch (ResourceInUseException e) {
// Do nothing, table already created
}
// TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table
dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll());
}
use of com.amazonaws.services.dynamodbv2.model.ResourceInUseException in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBDynamicFaultInjection method createTable.
/*
* Create the table if it already does not exist
*/
private static void createTable() {
List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
attributeDefinitions.add(new AttributeDefinition().withAttributeName("name").withAttributeType("S"));
List<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
// Partition
ks.add(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH));
// key
ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(10L);
CreateTableRequest request = new CreateTableRequest().withTableName(TABLENAME).withAttributeDefinitions(attributeDefinitions).withKeySchema(ks).withProvisionedThroughput(provisionedThroughput);
try {
CreateTableResult createdTableDescription = dynamoDBClient.createTable(request);
logger.info("Created Table: " + createdTableDescription);
// Wait for it to become active
waitForTableToBecomeAvailable(TABLENAME);
} catch (ResourceInUseException e) {
logger.warn("Table already existed", e);
}
}
Aggregations