Java 类com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput 实例源码

项目:strongbox    文件:GenericDynamoDB.java   
public CreateTableRequest constructCreateTableRequest() {
    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(partitionKeyName.toString()).withAttributeType("S"));
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(sortKeyName.toString()).withAttributeType("N"));

    ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
    keySchema.add(new KeySchemaElement().withAttributeName(partitionKeyName.toString()).withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName(sortKeyName.toString()).withKeyType(KeyType.RANGE));

    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(1L)
            .withWriteCapacityUnits(1L);
    CreateTableRequest request = new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(keySchema)
            .withAttributeDefinitions(attributeDefinitions)
            .withProvisionedThroughput(provisionedThroughput);
    return request;
}
项目:Java-9-Programming-Blueprints    文件:CloudNoticeDAO.java   
private void createRecipientTable() {
    CreateTableRequest request
            = new CreateTableRequest()
                    .withTableName(TABLE_NAME)
                    .withAttributeDefinitions(
                            new AttributeDefinition("_id", ScalarAttributeType.S)
                    )
                    .withKeySchema(
                            new KeySchemaElement("_id", KeyType.HASH)
                    )
                    .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L));

    ddb.createTable(request);
    try {
        TableUtils.waitUntilActive(ddb, TABLE_NAME);
    } catch (InterruptedException  e) {
        throw new RuntimeException(e);
    }
}
项目:orbit-dynamodb    文件:DynamoDBPersistenceTest.java   
@Override
public void closeStorage()
{
    try
    {
        dynamoDBConnection.getDynamoClient().describeTable(getTableName());
        dynamoDBConnection.getDynamoClient().deleteTable(getTableName());
    }
    catch(ResourceNotFoundException e)
    {

    }

    dynamoDBConnection.getDynamoDB().createTable(getTableName(),
            Collections.singletonList(
                    new KeySchemaElement("_id", KeyType.HASH)),
            Collections.singletonList(
                   new AttributeDefinition("_id", ScalarAttributeType.S)),
            new ProvisionedThroughput(1L, 1L));
}
项目:drill-dynamo-adapter    文件:BaseDynamoTest.java   
protected Table createTable(CreateTableRequest request) throws InterruptedException {
  DynamoDB dynamoDB = new DynamoDB(tables.getAsyncClient());
  request.withProvisionedThroughput(new ProvisionedThroughput()
    .withReadCapacityUnits(5L)
    .withWriteCapacityUnits(6L));

  if (request.getTableName() == null) {
    String tableName = tables.getTestTableName();
    tableName = tableName.replace('-', '_');
    request.setTableName(tableName);
  }

  Table table = dynamoDB.createTable(request);
  table.waitForActive();
  return table;
}
项目:java-translatebot    文件:DatabaseDeployer.java   
public void deploy() {

        final AttributeDefinition idAttr = new AttributeDefinition().withAttributeName("id")
                .withAttributeType(ScalarAttributeType.S);
        final ProvisionedThroughput throughput = new ProvisionedThroughput().withReadCapacityUnits(5L)
                .withWriteCapacityUnits(5L);

        final KeySchemaElement idKey = new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH);

        final CreateTableRequest createTableRequest = new CreateTableRequest().withTableName("TranslateSlack")
                .withAttributeDefinitions(idAttr)
                .withKeySchema(idKey)
                .withProvisionedThroughput(throughput);
        ;
        ;

        ddb.createTable(createTableRequest);

    }
项目:fleet-cron    文件:DynamoDbLockerTest.java   
@Before
public void setUp() {
    // Unique table for each run
    tableName = "table" + String.valueOf(tableCount++);
    dynamoDB.getDynamoDbClient().createTable(
        new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(new KeySchemaElement("id", "HASH"))
            .withAttributeDefinitions(
                new AttributeDefinition("id", "S")
            )
            .withProvisionedThroughput(
                new ProvisionedThroughput(1L, 1L)
            )
    );

    locker = new DynamoDbLocker(
        new DynamoDB(dynamoDB.getDynamoDbClient()),
        tableName,
        Clock.systemUTC()
    );
}
项目:lambdaDynamodbScaler    文件:Scaler.java   
private String scaleTable(String tableName, Long readCapacity, Long writeCapacity)
{
    Table table = dynamoDB.getTable(tableName);
    ProvisionedThroughput tp = new ProvisionedThroughput();
    tp.setReadCapacityUnits(readCapacity);
    tp.setWriteCapacityUnits(writeCapacity);
    TableDescription d = table.describe();
    if (!Objects.equals(d.getProvisionedThroughput().getReadCapacityUnits(), readCapacity)
        || !Objects.equals(d.getProvisionedThroughput().getWriteCapacityUnits(), writeCapacity))
    {
        d = table.updateTable(tp);
        return tableName + "\nRequested read/write : " + readCapacity + "/" + writeCapacity
               + "\nCurrent read/write :" + d.getProvisionedThroughput().getReadCapacityUnits() + "/" + d.getProvisionedThroughput().getWriteCapacityUnits()
               + "\nStatus : " + d.getTableStatus() + "\n";
    }
    else
    {
        return tableName + "\n Requested throughput equals current throughput\n";
    }
}
项目:amazon-cognito-developer-authentication-sample    文件:UserAuthentication.java   
/**
 * Used to create the Identity Table. This function only needs to be called
 * once.
 */
protected void createIdentityTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions
            .add(new AttributeDefinition().withAttributeName(ATTRIBUTE_USERNAME).withAttributeType("S"));

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_USERNAME).withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(USER_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + USER_TABLE, e);
    }
}
项目:amazon-cognito-developer-authentication-sample    文件:DeviceAuthentication.java   
/**
 * Used to create the device table. This function only needs to be called
 * once.
 */
protected void createDeviceTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(
            ATTRIBUTE_UID).withAttributeType("S"));

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
            .withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(DEVICE_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
    }
}
项目:nfscan    文件:BaseDatabaseControllerTest.java   
public void createTable(Class<? extends IDomain> domain){
    CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(domain);
    tableRequest = tableRequest.withProvisionedThroughput(new ProvisionedThroughput(5L,5L));

    //check whether or not we need to add a provisioning throughput value for GSI
    for (Method method : domain.getMethods()) {
        if(method.isAnnotationPresent(DynamoDBIndexHashKey.class)){
            String tempGSI = method.getAnnotation(DynamoDBIndexHashKey.class).globalSecondaryIndexName();
            for (GlobalSecondaryIndex globalSecondaryIndex : tableRequest.getGlobalSecondaryIndexes()) {
                if(globalSecondaryIndex.getIndexName().equals(tempGSI)){
                    globalSecondaryIndex.setProvisionedThroughput(new ProvisionedThroughput(5L,5L));
                }
            }
        }
    }

    amazonDynamoDBClient.createTable(tableRequest);
}
项目:AssortmentOfJUnitRules    文件:DynamoExample.java   
public void createTable() {
  List<KeySchemaElement> keySchema = new ArrayList<>();

  keySchema.add(
      new KeySchemaElement()
          .withAttributeName(sequenceNumber.getAttributeName())
          .withKeyType(KeyType.HASH)
  );

  ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput();
  provisionedThroughput.setReadCapacityUnits(10L);
  provisionedThroughput.setWriteCapacityUnits(10L);

  CreateTableRequest request = new CreateTableRequest()
      .withTableName("example_table")
      .withKeySchema(keySchema)
      .withAttributeDefinitions(singleton(sequenceNumber))
      .withProvisionedThroughput(provisionedThroughput);

  client.createTable(request);
}
项目:aws-java-sdk-stubs    文件:AmazonDynamoDBStubTest.java   
private CreateTableResult createTable() throws Exception {
  List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
  AttributeDefinition attributeDefinition = new AttributeDefinition()
    .withAttributeName(TEST_ATTRIBUTE)
    .withAttributeType(ScalarAttributeType.S);
  attributeDefinitions.add(attributeDefinition);

  String tableName = TEST_TABLE_NAME;

  List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
  KeySchemaElement keySchemaElement = new KeySchemaElement()
    .withAttributeName(TEST_ATTRIBUTE)
    .withKeyType(KeyType.HASH);

  ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
    .withReadCapacityUnits(UNITS)
    .withWriteCapacityUnits(UNITS);

  CreateTableResult result = dynamoDb.createTable(attributeDefinitions, tableName, keySchema, provisionedThroughput);

  return result;
}
项目:aws-java-sdk-stubs    文件:AmazonDynamoDBStubTest.java   
@Test
public void test_updateTable() throws Exception {
  createTable();

  DescribeTableResult describeResult = dynamoDb.describeTable(TEST_TABLE_NAME);
  Long readUnits = describeResult.getTable().getProvisionedThroughput().getReadCapacityUnits();

  assertThat(readUnits, equalTo(UNITS));

  UpdateTableResult updateResult = dynamoDb.updateTable(TEST_TABLE_NAME, new ProvisionedThroughput()
    .withReadCapacityUnits(new Long(200))
    .withWriteCapacityUnits(new Long(200)));
  String tableName = updateResult.getTableDescription().getTableName();

  assertThat(tableName, equalTo(TEST_TABLE_NAME));

  ListTablesResult listResult = listTables();

  describeResult = dynamoDb.describeTable(TEST_TABLE_NAME);
  readUnits = describeResult.getTable().getProvisionedThroughput().getReadCapacityUnits();

  assertThat(readUnits, equalTo(new Long(200)));
}
项目:para    文件:AWSDynamoUtils.java   
/**
 * Creates a table in AWS DynamoDB.
 * @param appid name of the {@link com.erudika.para.core.App}
 * @param readCapacity read capacity
 * @param writeCapacity write capacity
 * @return true if created
 */
public static boolean createTable(String appid, long readCapacity, long writeCapacity) {
    if (StringUtils.isBlank(appid)) {
        return false;
    } else if (StringUtils.containsWhitespace(appid)) {
        logger.warn("DynamoDB table name contains whitespace. The name '{}' is invalid.", appid);
        return false;
    } else if (existsTable(appid)) {
        logger.warn("DynamoDB table '{}' already exists.", appid);
        return false;
    }
    try {
        String table = getTableNameForAppid(appid);
        getClient().createTable(new CreateTableRequest().withTableName(table).
                withKeySchema(new KeySchemaElement(Config._KEY, KeyType.HASH)).
                withAttributeDefinitions(new AttributeDefinition(Config._KEY, ScalarAttributeType.S)).
                withProvisionedThroughput(new ProvisionedThroughput(readCapacity, writeCapacity)));
        logger.info("Created DynamoDB table '{}'.", table);
    } catch (Exception e) {
        logger.error(null, e);
        return false;
    }
    return true;
}
项目:para    文件:AWSDynamoUtils.java   
/**
 * Updates the table settings (read and write capacities).
 * @param appid name of the {@link com.erudika.para.core.App}
 * @param readCapacity read capacity
 * @param writeCapacity write capacity
 * @return true if updated
 */
public static boolean updateTable(String appid, long readCapacity, long writeCapacity) {
    if (StringUtils.isBlank(appid) || StringUtils.containsWhitespace(appid)) {
        return false;
    }
    String table = getTableNameForAppid(appid);
    try {
        // AWS throws an exception if the new read/write capacity values are the same as the current ones
        getClient().updateTable(new UpdateTableRequest().withTableName(table).
                withProvisionedThroughput(new ProvisionedThroughput(readCapacity, writeCapacity)));
        return true;
    } catch (Exception e) {
        logger.error("Could not update table '{}' - table is not active or no change to capacity: {}",
                table, e.getMessage());
    }
    return false;
}
项目:gora    文件:DynamoDBUtils.java   
/**
 * 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);
  }
}
项目:gora    文件:DynamoDBUtils.java   
/**
 * 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;
}
项目:Doradus    文件:DynamoDBService.java   
@Override
public void createStoreIfAbsent(String storeName, boolean bBinaryValues) {
    String tableName = storeToTableName(storeName);
    if (!Tables.doesTableExist(m_ddbClient, tableName)) {
        // Create a table with a primary hash key named '_key', which holds a string
        m_logger.info("Creating table: {}", tableName);
        CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
            .withKeySchema(new KeySchemaElement()
                .withAttributeName(ROW_KEY_ATTR_NAME)
                .withKeyType(KeyType.HASH))
            .withAttributeDefinitions(new AttributeDefinition()
                .withAttributeName(ROW_KEY_ATTR_NAME)
                .withAttributeType(ScalarAttributeType.S))
            .withProvisionedThroughput(new ProvisionedThroughput()
                .withReadCapacityUnits(READ_CAPACITY_UNITS)
                .withWriteCapacityUnits(WRITE_CAPACITY_UNITS));
        m_ddbClient.createTable(createTableRequest).getTableDescription();
        try {
            Tables.awaitTableToBecomeActive(m_ddbClient, tableName);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);  
        }
    }
}
项目:aws-dynamodb-examples    文件:LowLevelTableExample.java   
static void createExampleTable() {


    // Provide the initial provisioned throughput values as Java long data types
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
        .withReadCapacityUnits(5L)
        .withWriteCapacityUnits(6L);
    CreateTableRequest request = new CreateTableRequest()
        .withTableName(tableName)
        .withProvisionedThroughput(provisionedThroughput);

    ArrayList<AttributeDefinition> attributeDefinitions= new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N"));
    request.setAttributeDefinitions(attributeDefinitions);

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH));
    request.setKeySchema(tableKeySchema);

    client.createTable(request);

    waitForTableToBecomeAvailable(tableName); 

    getTableInformation();

}
项目:aws-dynamodb-examples    文件:MoviesCreateTable.java   
public static void main(String[] args) throws Exception {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();

        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);

        String tableName = "Movies";
        Table table = dynamoDB.createTable(tableName,
                Arrays.asList(
                        new KeySchemaElement("year", KeyType.HASH),
                        new KeySchemaElement("title", KeyType.RANGE)), 
                Arrays.asList(
                        new AttributeDefinition("year", ScalarAttributeType.N),
                        new AttributeDefinition("title", ScalarAttributeType.S)), 
                new ProvisionedThroughput(10L, 10L));

        try {
            TableUtils.waitUntilActive(client, tableName);
            System.out.println("Table status: " + table.getDescription().getTableStatus());
        } catch (AmazonClientException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
项目:aws-dynamodb-examples    文件:DynamoDBEmbeddedTest.java   
private static CreateTableResult createTable(AmazonDynamoDB ddb, String tableName, String hashKeyName) {
    List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition(hashKeyName, ScalarAttributeType.S));

    List<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
    ks.add(new KeySchemaElement(hashKeyName, KeyType.HASH));

    ProvisionedThroughput provisionedthroughput = new ProvisionedThroughput(1000L, 1000L);

    CreateTableRequest request =
        new CreateTableRequest()
            .withTableName(tableName)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(ks)
            .withProvisionedThroughput(provisionedthroughput);

    return ddb.createTable(request);
}
项目:reinvent2013-mobile-photo-share    文件:DeviceAuthentication.java   
/**
 * Used to create the device table. This function only needs to be called
 * once.
 */
protected void createDeviceTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(
            ATTRIBUTE_UID).withAttributeType("S"));

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
            .withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(DEVICE_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
    }
}
项目:reinvent2013-mobile-photo-share    文件:UserAuthentication.java   
/**
 * Used to create the Identity Table. This function only needs to be called
 * once.
 */
protected void createIdentityTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions
            .add(new AttributeDefinition().withAttributeName(ATTRIBUTE_USERNAME).withAttributeType("S"));

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_USERNAME).withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(USER_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + USER_TABLE, e);
    }
}
项目:reinvent2013-mobile-photo-share    文件:DeviceAuthentication.java   
/**
 * Used to create the device table. This function only needs to be called
 * once.
 */
protected void createDeviceTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(
            ATTRIBUTE_UID).withAttributeType("S"));

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
            .withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(DEVICE_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
    }
}
项目:quartz-dynamodb    文件:DynamoDbJobStore.java   
private void initializeHashAndRangeTable(String name, String hashName, String rangeName) {
    String tableName = quartzPrefix + name;

    if (!tableExists(tableName)) {
        log.info(String.format("Creating table '%s' with hash and range index.", tableName));
        CreateTableRequest request = new CreateTableRequest()
                .withTableName(tableName)
                .withKeySchema(
                        new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName(hashName),
                        new KeySchemaElement().withKeyType(KeyType.RANGE).withAttributeName(rangeName))
                .withAttributeDefinitions(
                        new AttributeDefinition(hashName, ScalarAttributeType.S),
                        new AttributeDefinition(rangeName, ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));

        client.createTable(request);

        waitForTable(tableName);
    } else {
        log.info(String.format("Table '%s' already exists.", tableName));
    }
}
项目:quartz-dynamodb    文件:DynamoDbJobStore.java   
private void initializeHashTable(String name, String hashName) {
    String tableName = quartzPrefix + name;

    if (!tableExists(tableName)) {
        log.info(String.format("Creating table '%s' with hash index.", tableName));
        CreateTableRequest request = new CreateTableRequest()
                .withTableName(tableName)
                .withKeySchema(
                        new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName(hashName))
                .withAttributeDefinitions(
                        new AttributeDefinition(hashName, ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));

        client.createTable(request);

        waitForTable(tableName);
    } else {
        log.info(String.format("Table '%s' already exists.", tableName));
    }
}
项目:aws-dynamodb-session-tomcat    文件:DynamoUtils.java   
public static void createSessionTable(AmazonDynamoDBClient dynamo,
                                      String tableName,
                                      long readCapacityUnits,
                                      long writeCapacityUnits) {
    CreateTableRequest request = new CreateTableRequest().withTableName(tableName);

    request.withKeySchema(new KeySchemaElement().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME)
            .withKeyType(KeyType.HASH));

    request.withAttributeDefinitions(
            new AttributeDefinition().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME)
                    .withAttributeType(ScalarAttributeType.S));

    request.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits)
            .withWriteCapacityUnits(writeCapacityUnits));

    dynamo.createTable(request);
}
项目:jcabi-dynamo    文件:ThroughputTest.java   
/**
 * Throughput can change throughput of a table.
 * @throws Exception If something went wrong
 */
@Test
public final void adjustsThroughput() throws Exception {
    final Table table = Mockito.mock(Table.class);
    final Region region = Mockito.mock(Region.class);
    final AmazonDynamoDB aws = Mockito.mock(AmazonDynamoDB.class);
    Mockito.when(table.region()).thenReturn(region);
    final String name = "Customers";
    Mockito.when(table.name()).thenReturn(name);
    Mockito.when(region.aws()).thenReturn(aws);
    new Throughput(table).adjust();
    Mockito.verify(aws, Mockito.times(1))
        .updateTable(
            Mockito.eq(name),
            Mockito.<ProvisionedThroughput>any()
        );
}
项目:lambdora    文件:IntegrationTestBase.java   
private CreateTableResult createTable() {
    final List<AttributeDefinition> attributeDefinitions = new ArrayList<>();
    attributeDefinitions.add(new AttributeDefinition(RESOURCE_NAME_ATT, ScalarAttributeType.S));
    attributeDefinitions.add(new AttributeDefinition(RDF_TRIPLE_ATT, ScalarAttributeType.S));
    attributeDefinitions.add(new AttributeDefinition(RDF_PREDICATE_ATT, ScalarAttributeType.S));
    attributeDefinitions.add(new AttributeDefinition(RDF_OBJECT_ATT, ScalarAttributeType.S));

    final List<KeySchemaElement> keySchema = new ArrayList<>();
    keySchema.add(new KeySchemaElement(RESOURCE_NAME_ATT, KeyType.HASH));
    keySchema.add(new KeySchemaElement(RDF_TRIPLE_ATT, KeyType.RANGE));

    final ProvisionedThroughput provisionedthroughput =
        new ProvisionedThroughput(10L, 10L);

    final LocalSecondaryIndex predicateIndex = new LocalSecondaryIndex()
        .withIndexName(PREDICATE_INDEX_NAME)
        .withKeySchema(new KeySchemaElement(RESOURCE_NAME_ATT, KeyType.HASH))
        .withKeySchema(new KeySchemaElement(RDF_PREDICATE_ATT, KeyType.RANGE))
        .withProjection(new Projection().withNonKeyAttributes(RDF_SUBJECT_ATT, RDF_OBJECT_ATT)
                                        .withProjectionType(ProjectionType.INCLUDE));

    final GlobalSecondaryIndex objectIndex = new GlobalSecondaryIndex()
        .withIndexName(OBJECT_INDEX_NAME)
        .withKeySchema(new KeySchemaElement(RDF_OBJECT_ATT, KeyType.HASH))
        .withKeySchema(new KeySchemaElement(RDF_PREDICATE_ATT, KeyType.RANGE))
        .withProjection(new Projection().withNonKeyAttributes(RDF_SUBJECT_ATT)
                                        .withProjectionType(ProjectionType.INCLUDE))
        .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L));

    final CreateTableRequest request =
        new CreateTableRequest()
            .withTableName(TABLE_NAME)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(keySchema)
            .withProvisionedThroughput(provisionedthroughput)
            .withLocalSecondaryIndexes(predicateIndex)
            .withGlobalSecondaryIndexes(objectIndex);

    return dynamodbClient.createTable(request);
}
项目:cas-5.1.0    文件:DynamoDbTicketRegistryFacilitator.java   
/**
 * 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);
    }));
}
项目:cas-5.1.0    文件:DynamoDbServiceRegistryFacilitator.java   
/**
 * 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);
    }
}
项目:cas-5.1.0    文件:DynamoDbCloudConfigBootstrapConfiguration.java   
private static void createSettingsTable(final AmazonDynamoDBClient amazonDynamoDBClient, 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(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);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:outland    文件:DynamoCreateGroupsTableTask.java   
private void createAppsTable(String tableName) {
  final AttributeDefinition appKey =
      new AttributeDefinition().withAttributeName(HASH_KEY).withAttributeType(
          ScalarAttributeType.S);

  final ArrayList<AttributeDefinition>
      tableAttributeDefinitions = Lists.newArrayList(appKey);

  final ArrayList<KeySchemaElement> tableKeySchema = Lists.newArrayList();
  tableKeySchema.add(
      new KeySchemaElement().withAttributeName(HASH_KEY).withKeyType(KeyType.HASH));

  final ProvisionedThroughput tableProvisionedThroughput =
      new ProvisionedThroughput()
          .withReadCapacityUnits(10L)
          .withWriteCapacityUnits(10L);

  final CreateTableRequest createTableRequest =
      new CreateTableRequest()
          .withTableName(tableName)
          .withKeySchema(tableKeySchema)
          .withAttributeDefinitions(tableAttributeDefinitions)
          .withProvisionedThroughput(tableProvisionedThroughput);

  final TableDescription tableDescription =
      amazonDynamoDB.createTable(createTableRequest).getTableDescription();

  logger.info("created_table {}", tableDescription);

  final DescribeTableRequest describeTableRequest =
      new DescribeTableRequest().withTableName(tableName);

  final TableDescription description =
      amazonDynamoDB.describeTable(describeTableRequest).getTable();

  logger.info("table_description: " + description);
}
项目:elo-api    文件:GenericDynamoDbDao.java   
public GenericDynamoDbDao(DynamoDbClientFactory clientFactory, Class<T> clazz) {
    DynamoDBTableMapper<T, K, ?> tableMapper = new DynamoDBMapper(clientFactory.client()).newTableMapper(clazz);
    log.info("Building table for " + clazz.getName());
    boolean tableIfNotExists = tableMapper.createTableIfNotExists(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
    log.info("table created?: "+tableIfNotExists);
    this.tableMapper = tableMapper;
}
项目:elo-api    文件:GenericDynamoDbRangeDao.java   
public GenericDynamoDbRangeDao(DynamoDbClientFactory clientFactory, Class<T> clazz) {
    DynamoDBTableMapper<T, K, R> tableMapper = new DynamoDBMapper(clientFactory.client()).newTableMapper(clazz);
    log.info("Building table for " + clazz.getName());
    tableMapper.deleteTableIfExists();
    tableMapper.createTableIfNotExists(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
    this.tableMapper = tableMapper;
}
项目:orbit-dynamodb    文件:DynamoDBUtils.java   
private static CreateTableRequest createCreateTableRequest(final String tableName)
{
    final List<KeySchemaElement> keySchema = new ArrayList<>();
    final List<AttributeDefinition> tableAttributes = new ArrayList<>();

    keySchema.add(new KeySchemaElement(FIELD_NAME_PRIMARY_ID, KeyType.HASH));
    tableAttributes.add(new AttributeDefinition(FIELD_NAME_PRIMARY_ID, ScalarAttributeType.S));


    return new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(keySchema)
            .withAttributeDefinitions(tableAttributes)
            .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
}
项目:plano    文件:PlanoApplicationDynamoDBTests.java   
private CreateTableResult createPlanoRequestsTable() {
    CreateTableRequest request = mapper.generateCreateTableRequest(DynamoDBPlanoRequest.class)
            .withProvisionedThroughput(new ProvisionedThroughput()
                    .withReadCapacityUnits(5L)
                    .withWriteCapacityUnits(6L));

    CreateTableResult createTableResult = dynamoDB.createTable(request);

    return createTableResult;
}
项目:plano    文件:DynamoDBRepositoryTests.java   
private CreateTableResult createPlanoRequestsTable() {
    CreateTableRequest request = sDynamoDBMapper.generateCreateTableRequest(DynamoDBPlanoRequest.class)
            .withProvisionedThroughput(new ProvisionedThroughput()
                    .withReadCapacityUnits(5L)
                    .withWriteCapacityUnits(6L));

    CreateTableResult createTableResult = sDynamoDB.createTable(request);

    return createTableResult;
}
项目:java-persistence    文件:DdbSchema.java   
@Override
protected void createIndex(String tableName, IndexDescription index) {
    // We ALWAYS create these as GSI's, since you can't add a LSI:
    CreateGlobalSecondaryIndexAction createAction = new CreateGlobalSecondaryIndexAction()
        .withIndexName(index.getIndexName())
        .withKeySchema(toKeySchema(tableName, index))
        .withProvisionedThroughput(
            new ProvisionedThroughput()
            .withReadCapacityUnits(index.getReadCapacity())
            .withWriteCapacityUnits(index.getWriteCapacity()))
        .withProjection(new Projection().withProjectionType(ProjectionType.ALL));

    AttributeDefinition hashKey = new AttributeDefinition()
        .withAttributeName(index.getHashKey().getAttrName())
        .withAttributeType(toScalarAttributeType(index.getHashKey().getAttrType()));

    if ( null == index.getRangeKey() ) {
        _dynamodb.getTable(getTableName(tableName))
            .createGSI(createAction, hashKey);
    } else {
        AttributeDefinition rangeKey = new AttributeDefinition()
            .withAttributeName(index.getRangeKey().getAttrName())
            .withAttributeType(toScalarAttributeType(index.getRangeKey().getAttrType()));

        _dynamodb.getTable(getTableName(tableName))
            .createGSI(createAction, hashKey, rangeKey);
    }
}
项目:aws-doc-sdk-examples    文件:UpdateTable.java   
public static void main(String[] args)
{
    final String USAGE = "\n" +
        "Usage:\n" +
        "    UpdateTable <table> <read> <write>\n\n" +
        "Where:\n" +
        "    table - the table to put the item in.\n" +
        "    read  - the new read capacity of the table.\n" +
        "    write - the new write capacity of the table.\n\n" +
        "Example:\n" +
        "    UpdateTable HelloTable 16 10\n";

    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String table_name = args[0];
    Long read_capacity = Long.parseLong(args[1]);
    Long write_capacity = Long.parseLong(args[2]);

    System.out.format(
            "Updating %s with new provisioned throughput values\n",
            table_name);
    System.out.format("Read capacity : %d\n", read_capacity);
    System.out.format("Write capacity : %d\n", write_capacity);

    ProvisionedThroughput table_throughput = new ProvisionedThroughput(
          read_capacity, write_capacity);

    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();

    try {
        ddb.updateTable(table_name, table_throughput);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}