Search in sources :

Example 1 with AttributeDefinition

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);
    }));
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) PutItemResult(com.amazonaws.services.dynamodbv2.model.PutItemResult) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) KeyType(com.amazonaws.services.dynamodbv2.model.KeyType) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) LoggerFactory(org.slf4j.LoggerFactory) SerializationUtils(org.apache.commons.lang3.SerializationUtils) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) DeleteItemResult(com.amazonaws.services.dynamodbv2.model.DeleteItemResult) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Map(java.util.Map) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TicketCatalog(org.apereo.cas.ticket.TicketCatalog) Unchecked(org.jooq.lambda.Unchecked) Logger(org.slf4j.Logger) GetItemRequest(com.amazonaws.services.dynamodbv2.model.GetItemRequest) ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) DeleteItemRequest(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest) TableUtils(com.amazonaws.services.dynamodbv2.util.TableUtils) PutItemRequest(com.amazonaws.services.dynamodbv2.model.PutItemRequest) ScalarAttributeType(com.amazonaws.services.dynamodbv2.model.ScalarAttributeType) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DynamoDbTicketRegistryProperties(org.apereo.cas.configuration.model.support.dynamodb.DynamoDbTicketRegistryProperties) Collections(java.util.Collections) Ticket(org.apereo.cas.ticket.Ticket) DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 2 with AttributeDefinition

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;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 3 with AttributeDefinition

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!");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) ProvisionedThroughputDescription(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Example 4 with AttributeDefinition

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!");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) CreateTableResult(com.amazonaws.services.dynamodbv2.model.CreateTableResult)

Example 5 with AttributeDefinition

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);
    }
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Aggregations

AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)6 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)5 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)5 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)3 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)3 CreateTableResult (com.amazonaws.services.dynamodbv2.model.CreateTableResult)2 DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)2 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)2 ArrayList (java.util.ArrayList)2 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 DeleteItemRequest (com.amazonaws.services.dynamodbv2.model.DeleteItemRequest)1 DeleteItemResult (com.amazonaws.services.dynamodbv2.model.DeleteItemResult)1 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)1 KeyType (com.amazonaws.services.dynamodbv2.model.KeyType)1 ProvisionedThroughputDescription (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription)1 PutItemRequest (com.amazonaws.services.dynamodbv2.model.PutItemRequest)1 PutItemResult (com.amazonaws.services.dynamodbv2.model.PutItemResult)1