use of com.amazonaws.services.dynamodbv2.model.AttributeDefinition 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);
}));
}
use of com.amazonaws.services.dynamodbv2.model.AttributeDefinition 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.AttributeDefinition in project aws-doc-sdk-examples by awsdocs.
the class DescribeTable method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " DescribeTable <table>\n\n" + "Where:\n" + " table - the table to get information about.\n\n" + "Example:\n" + " DescribeTable HelloTable\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String table_name = args[0];
System.out.format("Getting description for %s\n\n", table_name);
final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
try {
TableDescription table_info = ddb.describeTable(table_name).getTable();
if (table_info != null) {
System.out.format("Table name : %s\n", table_info.getTableName());
System.out.format("Table ARN : %s\n", table_info.getTableArn());
System.out.format("Status : %s\n", table_info.getTableStatus());
System.out.format("Item count : %d\n", table_info.getItemCount().longValue());
System.out.format("Size (bytes): %d\n", table_info.getTableSizeBytes().longValue());
ProvisionedThroughputDescription throughput_info = table_info.getProvisionedThroughput();
System.out.println("Throughput");
System.out.format(" Read Capacity : %d\n", throughput_info.getReadCapacityUnits().longValue());
System.out.format(" Write Capacity: %d\n", throughput_info.getWriteCapacityUnits().longValue());
List<AttributeDefinition> attributes = table_info.getAttributeDefinitions();
System.out.println("Attributes");
for (AttributeDefinition a : attributes) {
System.out.format(" %s (%s)\n", a.getAttributeName(), a.getAttributeType());
}
}
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("\nDone!");
}
use of com.amazonaws.services.dynamodbv2.model.AttributeDefinition 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.AttributeDefinition 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);
}
}
Aggregations