use of com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput in project aws-doc-sdk-examples by awsdocs.
the class CreateTable method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " CreateTable <table>\n\n" + "Where:\n" + " table - the table to create.\n\n" + "Example:\n" + " CreateTable HelloTable\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
/* Read the name from command args */
String table_name = args[0];
System.out.format("Creating table \"%s\" with a simple primary key: \"Name\".\n", table_name);
CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition("Name", ScalarAttributeType.S)).withKeySchema(new KeySchemaElement("Name", KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(new Long(10), new Long(10))).withTableName(table_name);
final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
try {
CreateTableResult result = ddb.createTable(request);
System.out.println(result.getTableDescription().getTableName());
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Done!");
}
use of com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput in project gora by apache.
the class DynamoDBUtils method buildCreateTableRequest.
/**
* Builds the necessary requests to create tables
*
* @param tableName
* @param keySchema
* @param proThrou
* @param attrs
* @return
*/
public static CreateTableRequest buildCreateTableRequest(String tableName, ArrayList<KeySchemaElement> keySchema, ProvisionedThroughput proThrou, Map<String, String> attrs) {
CreateTableRequest createTableRequest = new CreateTableRequest();
createTableRequest.setTableName(tableName);
createTableRequest.setKeySchema(keySchema);
ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
for (KeySchemaElement kEle : keySchema) {
AttributeDefinition attrDef = new AttributeDefinition();
attrDef.setAttributeName(kEle.getAttributeName());
attrDef.setAttributeType(attrs.get(kEle.getAttributeName()));
attributeDefinitions.add(attrDef);
}
createTableRequest.setAttributeDefinitions(attributeDefinitions);
createTableRequest.setProvisionedThroughput(proThrou);
return createTableRequest;
}
use of com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput 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.ProvisionedThroughput in project cas by apereo.
the class DynamoDbCloudConfigBootstrapConfiguration method createSettingsTable.
@SneakyThrows
private static void createSettingsTable(final AmazonDynamoDB amazonDynamoDBClient, final boolean deleteTables) {
final String name = ColumnNames.ID.getColumnName();
final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(name, ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(name, KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT)).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);
}
use of com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput in project cas by apereo.
the class DynamoDbServiceRegistryFacilitator method createServicesTable.
/**
* Create tables.
*
* @param deleteTables the delete tables
*/
@SneakyThrows
public void createServicesTable(final boolean deleteTables) {
LOGGER.debug("Attempting to create DynamoDb services table");
final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getColumnName(), ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(ColumnNames.ID.getColumnName(), KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(), dynamoDbProperties.getWriteCapacity())).withTableName(dynamoDbProperties.getTableName());
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);
}
Aggregations