com.amazonaws.services.dynamodbv2.model.CreateTableRequest Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.model.CreateTableRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProductInfoRepositoryIntegrationTest.java    From tutorials with MIT License 7 votes vote down vote up
@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());
}
 
Example #2
Source File: ScanITCase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpTestData() throws Exception {
    String keyName = "id";
    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(TABLE_NAME)
            .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH))
            .withAttributeDefinitions(
                    new AttributeDefinition().withAttributeName(keyName).withAttributeType(
                            ScalarAttributeType.S));
    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L));

    TableUtils.createTableIfNotExists(dynamo, createTableRequest);
    TableUtils.waitUntilActive(dynamo, TABLE_NAME);

    createTestData();
}
 
Example #3
Source File: DeviceAuthentication.java    From reinvent2013-mobile-photo-share with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #4
Source File: GenericDynamoDB.java    From strongbox with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: GenericDynamoDBTest.java    From strongbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithWait() throws Exception {
    // Create fake responses from AWS. First response is still creating the table, second response the table
    // has become active.
    TableDescription creatingDescription = constructTableDescription(TableStatus.CREATING);
    TableDescription createdDescription = constructTableDescription(TableStatus.ACTIVE);
    CreateTableResult mockCreateResult = new CreateTableResult().withTableDescription(creatingDescription);
    DescribeTableResult mockDescribeResultCreating = new DescribeTableResult().withTable(creatingDescription);
    DescribeTableResult mockDescribeResultCreated = new DescribeTableResult().withTable(createdDescription);

    // Create the table.
    CreateTableRequest expectedRequest = dynamoDB.constructCreateTableRequest();
    when(mockDynamoDBClient.createTable(expectedRequest)).thenReturn(mockCreateResult);
    when(mockDynamoDBClient.describeTable(tableName)).thenReturn(mockDescribeResultCreating, mockDescribeResultCreated);
    assertEquals(dynamoDB.create(), TEST_ARN);

    verify(mockDynamoDBClient, times(1)).createTable(expectedRequest);
    verify(mockDynamoDBClient, times(2)).describeTable(tableName);
}
 
Example #6
Source File: ProductInfoRepositoryIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@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());
}
 
Example #7
Source File: UserAuthentication.java    From reinvent2013-mobile-photo-share with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #8
Source File: Application.java    From spring-data-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
@Bean
public CommandLineRunner multirepo(ConfigurableApplicationContext ctx, CustomerRepository jpaRepository,
		DeviceRepository dynamoDBRepository, AmazonDynamoDB amazonDynamoDB, DynamoDBMapper dynamoDBMapper,
		DynamoDBMapperConfig config) {
	return (args) -> {
		demoJPA(jpaRepository);

		CreateTableRequest ctr = dynamoDBMapper.generateCreateTableRequest(Device.class)
				.withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
		TableUtils.createTableIfNotExists(amazonDynamoDB, ctr);
		TableUtils.waitUntilActive(amazonDynamoDB, ctr.getTableName());


		demoDynamoDB(dynamoDBRepository);

		ctx.close();
	};
}
 
Example #9
Source File: LowLevelTableExample.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
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();
    
}
 
Example #10
Source File: AwsTest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static Future<CreateTableResult> createTableAsync(final AmazonDynamoDBAsync dbClient, final String tableName) {
  final String partitionKeyName = tableName + "Id";
  final CreateTableRequest createTableRequest = new CreateTableRequest()
    .withTableName(tableName).withKeySchema(new KeySchemaElement().withAttributeName(partitionKeyName).withKeyType(KeyType.HASH))
    .withAttributeDefinitions(new AttributeDefinition().withAttributeName(partitionKeyName).withAttributeType("S"))
    .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L));

  return dbClient.createTableAsync(createTableRequest, new AsyncHandler<CreateTableRequest,CreateTableResult>() {
    @Override
    public void onError(final Exception exception) {
    }

    @Override
    public void onSuccess(final CreateTableRequest request, final CreateTableResult createTableResult) {
    }
  });
}
 
Example #11
Source File: DynamoDBServiceImpl2.java    From Serverless-Programming-Cookbook with MIT License 6 votes vote down vote up
@Override
public final Response createTable(final Request request) {

    final CreateTableRequest createTableRequest = new CreateTableRequest(
            Arrays.asList(
                    new AttributeDefinition(request.getPartitionKey(), ScalarAttributeType.S),
                    new AttributeDefinition(request.getSortKey(), ScalarAttributeType.N)),
            request.getTableName(),
            Arrays.asList(
                    new KeySchemaElement(request.getPartitionKey(), KeyType.HASH),
                    new KeySchemaElement(request.getSortKey(), KeyType.RANGE)),
            new ProvisionedThroughput(request.getReadCapacityUnits(), request.getWriteCapacityUnits()));

    TableUtils.createTableIfNotExists(this.dynamoDBClient, createTableRequest);

    try {
        TableUtils.waitUntilActive(this.dynamoDBClient, request.getTableName());
    } catch (final AmazonClientException | InterruptedException e) {
        return new Response(null, "Failed in table active check in API version V2: " + e.getMessage());
    }

    return new Response(request.getTableName() + " created with API version V2.", null);
}
 
Example #12
Source File: CRUDTest.java    From dynamo-cassandra-proxy with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreate() {
    AmazonDynamoDB proxyClient = getProxyClient();
    AmazonDynamoDB awsClient = getAwsClient();

    CreateTableRequest req = new CreateTableRequest()
            .withTableName("foo")
            .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(100L).withWriteCapacityUnits(100L))
            .withKeySchema(new KeySchemaElement("Name", KeyType.HASH))
            .withAttributeDefinitions(new AttributeDefinition("Name", ScalarAttributeType.S));

    proxyClient.createTable(req);
    awsClient.createTable(req);

    DescribeTableResult r = proxyClient.describeTable("foo");
    DescribeTableResult r2 = proxyClient.describeTable("foo");

    Date now = new Date();
    r.getTable().withCreationDateTime(now);
    r2.getTable().withCreationDateTime(now);

    Assert.assertEquals(r, r2);
}
 
Example #13
Source File: Application.java    From spring-data-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
@Bean
public CommandLineRunner rest(ConfigurableApplicationContext ctx, UserRepository dynamoDBRepository,
		AmazonDynamoDB amazonDynamoDB, DynamoDBMapper dynamoDBMapper, DynamoDBMapperConfig config) {
	return (args) -> {

		CreateTableRequest ctr = dynamoDBMapper.generateCreateTableRequest(User.class)
				.withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
		TableUtils.createTableIfNotExists(amazonDynamoDB, ctr);
		TableUtils.waitUntilActive(amazonDynamoDB, ctr.getTableName());

		createEntities(dynamoDBRepository);

		log.info("");
		log.info("Run curl -v http://localhost:8080/users and follow the HATEOS links");
		log.info("");
		log.info("Press <enter> to shutdown");
		System.in.read();
		ctx.close();
	};
}
 
Example #14
Source File: LowLevelTableExample.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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)); // Partition
                                                                                                      // key
        request.setKeySchema(tableKeySchema);

        client.createTable(request);

        waitForTableToBecomeAvailable(tableName);

        getTableInformation();

    }
 
Example #15
Source File: DeviceAuthentication.java    From reinvent2013-mobile-photo-share with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #16
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 6 votes vote down vote up
private boolean createTable(final String qName, final Supplier<CreateTableRequest> tableRequest) {
  synchronized (tableExistsCache) {
    final Boolean tableExists = tableExistsCache.get(qName);
    if ((tableExists == null) || !tableExists) {
      final boolean tableCreated =
          TableUtils.createTableIfNotExists(
              client,
              tableRequest.get().withProvisionedThroughput(
                  new ProvisionedThroughput(
                      Long.valueOf(options.getReadCapacity()),
                      Long.valueOf(options.getWriteCapacity()))));
      if (tableCreated) {
        try {
          TableUtils.waitUntilActive(client, qName);
        } catch (TableNeverTransitionedToStateException | InterruptedException e) {
          LOGGER.error("Unable to wait for active table '" + qName + "'", e);
        }
      }
      tableExistsCache.put(qName, true);
      return true;
    }
  }
  return false;
}
 
Example #17
Source File: MarsDynamoDBManagerTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateResourceTable() {
    final AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class);
    PowerMock.mockStatic(DynamoDBManager.class);
    final CreateTableRequest request = new CreateTableRequest();
    request.setAttributeDefinitions(MarsDynamoDBManager.RESOURCE_TABLE_ATTRIBUTE_DEFINITIONS);
    request.setKeySchema(MarsDynamoDBManager.RESOURCE_TABLE_KEY_SCHEMA);
    request.setProvisionedThroughput(PROVISIONED_THROUGHPUT);
    request.setTableName(TABLE_NAME);

    DynamoDBManager.createTable(dynamoDB, request);
    PowerMock.expectLastCall().andReturn(null);
    PowerMock.replayAll();
    MarsDynamoDBManager.createResourceTable(dynamoDB, TABLE_NAME, PROVISIONED_THROUGHPUT);
    PowerMock.verifyAll();
}
 
Example #18
Source File: DynamoDBIOTestHelper.java    From beam with Apache License 2.0 6 votes vote down vote up
private static CreateTableResult createDynamoTable(String tableName) {

    ImmutableList<AttributeDefinition> attributeDefinitions =
        ImmutableList.of(
            new AttributeDefinition(ATTR_NAME_1, ScalarAttributeType.S),
            new AttributeDefinition(ATTR_NAME_2, ScalarAttributeType.N));

    ImmutableList<KeySchemaElement> ks =
        ImmutableList.of(
            new KeySchemaElement(ATTR_NAME_1, KeyType.HASH),
            new KeySchemaElement(ATTR_NAME_2, KeyType.RANGE));

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

    return dynamoDBClient.createTable(request);
  }
 
Example #19
Source File: UserAuthentication.java    From amazon-cognito-developer-authentication-sample with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #20
Source File: DeviceAuthentication.java    From amazon-cognito-developer-authentication-sample with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #21
Source File: DynamoDbDelegate.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 6 votes vote down vote up
void createTableAndWaitForActive(final CreateTableRequest request) throws BackendException {
    final String tableName = request.getTableName();
    Preconditions.checkArgument(!Strings.isNullOrEmpty(tableName), "Table name was null or empty");
    final TableDescription desc;
    try {
        desc = this.describeTable(tableName);
        if (null != desc && isTableAcceptingWrites(desc.getTableStatus())) {
            return; //store existed
        }
    } catch (BackendNotFoundException e) {
        log.debug(tableName + " did not exist yet, creating it", e);
    }

    createTable(request);
    waitForTableCreation(tableName, false /*verifyIndexesList*/, null /*expectedLsiList*/, null /*expectedGsiList*/);
}
 
Example #22
Source File: DynamoDbStore.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 6 votes vote down vote up
@Override
public CreateTableRequest getTableSchema() {
    return super.getTableSchema()
        .withAttributeDefinitions(
            new AttributeDefinition()
                .withAttributeName(Constants.JANUSGRAPH_HASH_KEY)
                .withAttributeType(ScalarAttributeType.S),
            new AttributeDefinition()
                .withAttributeName(Constants.JANUSGRAPH_RANGE_KEY)
                .withAttributeType(ScalarAttributeType.S))
        .withKeySchema(
            new KeySchemaElement()
                .withAttributeName(Constants.JANUSGRAPH_HASH_KEY)
                .withKeyType(KeyType.HASH),
            new KeySchemaElement()
                .withAttributeName(Constants.JANUSGRAPH_RANGE_KEY)
                .withKeyType(KeyType.RANGE));
}
 
Example #23
Source File: BaseDatabaseControllerTest.java    From nfscan with MIT License 6 votes vote down vote up
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);
}
 
Example #24
Source File: DynamoDBEmbeddedTest.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #25
Source File: MapperSaveConfigCryptoIntegrationTestBase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    DynamoDBCryptoIntegrationTestBase.setUp();
    dynamoMapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo);

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH))
            .withKeySchema(new KeySchemaElement().withAttributeName(rangeKeyName).withKeyType(KeyType.RANGE))
            .withAttributeDefinitions(new AttributeDefinition().withAttributeName(hashKeyName)
                    .withAttributeType(ScalarAttributeType.S))
            .withAttributeDefinitions(new AttributeDefinition().withAttributeName(rangeKeyName)
                    .withAttributeType(ScalarAttributeType.N));
    createTableRequest.setProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT);

    if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) {
        TableUtils.waitUntilActive(dynamo, tableName);
    }
}
 
Example #26
Source File: DynamoDBCryptoIntegrationTestBase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
protected static void setUpTableWithRangeAttribute() throws Exception {
    setUp();

    String keyName = DynamoDBCryptoIntegrationTestBase.KEY_NAME;
    String rangeKeyAttributeName = "rangeKey";

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(TABLE_WITH_RANGE_ATTRIBUTE)
            .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH),
                    new KeySchemaElement().withAttributeName(rangeKeyAttributeName).withKeyType(KeyType.RANGE))
            .withAttributeDefinitions(
                    new AttributeDefinition().withAttributeName(keyName).withAttributeType(
                            ScalarAttributeType.N),
                    new AttributeDefinition().withAttributeName(rangeKeyAttributeName).withAttributeType(
                            ScalarAttributeType.N));
    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L));

    if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) {
        TableUtils.waitUntilActive(dynamo, TABLE_WITH_RANGE_ATTRIBUTE);
    }
}
 
Example #27
Source File: DynamoDBCryptoIntegrationTestBase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    // Create a table
    DynamoDBTestBase.setUpTestBase();
    String keyName = KEY_NAME;
    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(TABLE_NAME)
            .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH))
            .withAttributeDefinitions(
                    new AttributeDefinition().withAttributeName(keyName).withAttributeType(
                            ScalarAttributeType.S));
    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L));

    if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) {
        TableUtils.waitUntilActive(dynamo, TABLE_NAME);
    }
}
 
Example #28
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 6 votes vote down vote up
private boolean createTable(final String qName, final boolean dataIndexTable) {
  return createTable(
      qName,
      dataIndexTable
          ? () -> new CreateTableRequest().withTableName(qName).withAttributeDefinitions(
              new AttributeDefinition(
                  DynamoDBRow.GW_PARTITION_ID_KEY,
                  ScalarAttributeType.B)).withKeySchema(
                      new KeySchemaElement(DynamoDBRow.GW_PARTITION_ID_KEY, KeyType.HASH))
          : () -> new CreateTableRequest().withTableName(qName).withAttributeDefinitions(
              new AttributeDefinition(DynamoDBRow.GW_PARTITION_ID_KEY, ScalarAttributeType.B),
              new AttributeDefinition(
                  DynamoDBRow.GW_RANGE_KEY,
                  ScalarAttributeType.B)).withKeySchema(
                      new KeySchemaElement(DynamoDBRow.GW_PARTITION_ID_KEY, KeyType.HASH),
                      new KeySchemaElement(DynamoDBRow.GW_RANGE_KEY, KeyType.RANGE)));
}
 
Example #29
Source File: TitanGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 5 votes vote down vote up
private void open(boolean batchLoading)
{
    if(type == GraphDatabaseType.TITAN_DYNAMODB && config.getDynamodbPrecreateTables()) {
        List<CreateTableRequest> requests = new LinkedList<>();
        long wcu = config.getDynamodbTps();
        long rcu = Math.max(1, config.dynamodbConsistentRead() ? wcu : (wcu / 2));
        for(String store : Constants.REQUIRED_BACKEND_STORES) {
            final String tableName = config.getDynamodbTablePrefix() + "_" + store;
            if(BackendDataModel.MULTI == config.getDynamodbDataModel()) {
                requests.add(DynamoDBStore.createTableRequest(tableName,
                    rcu, wcu));
            } else if(BackendDataModel.SINGLE == config.getDynamodbDataModel()) {
                requests.add(DynamoDBSingleRowStore.createTableRequest(tableName, rcu, wcu));
            }
        }
        //TODO is this autocloseable?
        final AmazonDynamoDB client =
            new AmazonDynamoDBClient(Client.createAWSCredentialsProvider(config.getDynamodbCredentialsFqClassName(),
                config.getDynamodbCredentialsCtorArguments() == null ? null : config.getDynamodbCredentialsCtorArguments().split(",")));
        client.setEndpoint(config.getDynamodbEndpoint());
        for(CreateTableRequest request : requests) {
            try {
                client.createTable(request);
            } catch(ResourceInUseException ignore) {
                //already created, good
            }
        }
        client.shutdown();
    }
    titanGraph = buildTitanGraph(type, dbStorageDirectory, config, batchLoading);
}
 
Example #30
Source File: DynamoDBUtils.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public static TableDescription createTable(AmazonDynamoDB client, String tableName) throws InterruptedException {
    CreateTableRequest tableReq = new CreateTableRequest().withTableName(tableName)
            .withKeySchema(new KeySchemaElement("Id", KeyType.HASH))
            .withAttributeDefinitions(new AttributeDefinition("Id", ScalarAttributeType.N))
            .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L))
            .withStreamSpecification(new StreamSpecification().withStreamEnabled(true).withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES));

    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.createTable(tableReq);
    return table.waitForActive();
}