/** * Creates the table with the specified throughput; also populates the same * throughput for all global secondary indexes. * @param throughput The provisioned throughput. * @return The table decription. * @see com.amazonaws.services.dynamodbv2.AmazonDynamoDB#createTable * @see com.amazonaws.services.dynamodbv2.model.CreateTableRequest */ public TableDescription createTable(ProvisionedThroughput throughput) { final CreateTableRequest request = mapper.generateCreateTableRequest(model.targetType()); request.setProvisionedThroughput(throughput); if (request.getGlobalSecondaryIndexes() != null) { for (final GlobalSecondaryIndex gsi : request.getGlobalSecondaryIndexes()) { gsi.setProvisionedThroughput(throughput); } } return db.createTable(request).getTableDescription(); }
public void createTables() { ProvisionedThroughput throughput = new ProvisionedThroughput().withReadCapacityUnits(1000L).withWriteCapacityUnits(1000L); CreateTableRequest createEnvironments = dynamoDBMapper .generateCreateTableRequest(EnvironmentDDBRecord.class) .withProvisionedThroughput(throughput); createEnvironments .getGlobalSecondaryIndexes() .forEach(index -> index.withProvisionedThroughput(throughput)); CreateTableRequest createEnvironmentRevisions = dynamoDBMapper .generateCreateTableRequest(EnvironmentRevisionDDBRecord.class) .withProvisionedThroughput(throughput); amazonDynamoDB.createTable(createEnvironments); amazonDynamoDB.createTable(createEnvironmentRevisions); } }
/** * @param entityInformation * The entity to check for it's table * @throws IllegalStateException * is thrown if the existing table doesn't match the entity's * annotation */ private DescribeTableResult performValidate(DynamoDBEntityInformation<T, ID> entityInformation) throws IllegalStateException { Class<T> domainType = entityInformation.getJavaType(); CreateTableRequest expected = mapper.generateCreateTableRequest(domainType); DescribeTableResult result = amazonDynamoDB.describeTable(expected.getTableName()); TableDescription actual = result.getTable(); if (!expected.getKeySchema().equals(actual.getKeySchema())) { throw new IllegalStateException("KeySchema is not as expected. Expected: <" + expected.getKeySchema() + "> but found <" + actual.getKeySchema() + ">"); } LOGGER.debug("KeySchema is valid"); if (expected.getGlobalSecondaryIndexes() != null) { if (!Arrays.deepEquals(expected.getGlobalSecondaryIndexes().toArray(), actual.getGlobalSecondaryIndexes().toArray())) { throw new IllegalStateException("Global Secondary Indexes are not as expected. Expected: <" + expected.getGlobalSecondaryIndexes() + "> but found <" + actual.getGlobalSecondaryIndexes() + ">"); } } LOGGER.debug("Global Secondary Indexes are valid"); LOGGER.info("Validated table {} for entity{}", expected.getTableName(), domainType); return result; }
private boolean performCreate(DynamoDBEntityInformation<T, ID> entityInformation) throws TableNeverTransitionedToStateException, InterruptedException { Class<T> domainType = entityInformation.getJavaType(); CreateTableRequest ctr = mapper.generateCreateTableRequest(domainType); LOGGER.trace("Creating table {} for entity {}", ctr.getTableName(), domainType); ctr.setProvisionedThroughput(pt); if (ctr.getGlobalSecondaryIndexes() != null) { ctr.getGlobalSecondaryIndexes().forEach(gsi -> { gsi.setProjection(new Projection().withProjectionType(gsiProjectionType)); gsi.setProvisionedThroughput(pt); }); } boolean result = TableUtils.createTableIfNotExists(amazonDynamoDB, ctr); if (result) { TableUtils.waitUntilActive(amazonDynamoDB, ctr.getTableName()); LOGGER.debug("Created table {} for entity {}", ctr.getTableName(), domainType); } return result; }
/** * Creates the table with the specified throughput; also populates the same * throughput for all global secondary indexes. * @param throughput The provisioned throughput. * @return The table decription. * @see com.amazonaws.services.dynamodbv2.AmazonDynamoDB#createTable * @see com.amazonaws.services.dynamodbv2.model.CreateTableRequest */ public TableDescription createTable(ProvisionedThroughput throughput) { final CreateTableRequest request = mapper.generateCreateTableRequest(model.targetType()); request.setProvisionedThroughput(throughput); if (request.getGlobalSecondaryIndexes() != null) { for (final GlobalSecondaryIndex gsi : request.getGlobalSecondaryIndexes()) { gsi.setProvisionedThroughput(throughput); } } return db.createTable(request).getTableDescription(); }