private void runTest(AmazonDynamoDB client) { 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("foo"); client.createTable(request); final TableDescription tableDescription = client.describeTable("foo").getTable(); assertNotNull("the description is not null", tableDescription); assertEquals("the table has the right name", "foo", tableDescription.getTableName()); assertEquals("the name has the right primary key", "Name", tableDescription.getKeySchema().get(0).getAttributeName()); } }
private void createTable() { dynamoDBClient.createTable(new CreateTableRequest() .withTableName(tableConfig.getTableName()).withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(1L) .withWriteCapacityUnits(1L))); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getReadCapacityUnits() == null) ? 0 : getReadCapacityUnits().hashCode()); hashCode = prime * hashCode + ((getWriteCapacityUnits() == null) ? 0 : getWriteCapacityUnits().hashCode()); return hashCode; }
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); } }
public ProvisionedThroughput unmarshall(JsonUnmarshallerContext context) throws Exception { ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(); if (context.testExpression("ReadCapacityUnits", targetDepth)) { context.nextToken(); provisionedThroughput.setReadCapacityUnits(context.getUnmarshaller(Long.class).unmarshall(context)); provisionedThroughput.setWriteCapacityUnits(context.getUnmarshaller(Long.class).unmarshall(context));
private void autoCreateTableIfNotExists() { if (autoCreateTable) { AttributeDefinition partitionKeyDefinition = new AttributeDefinition() .withAttributeName(partitionKeyName) .withAttributeType(ScalarAttributeType.S); KeySchemaElement partitionKeySchema = new KeySchemaElement() .withAttributeName(partitionKeyName) .withKeyType(KeyType.HASH); ProvisionedThroughput throughput = new ProvisionedThroughput() .withReadCapacityUnits(5L) .withWriteCapacityUnits(5L); try { TableUtils.createTableIfNotExists(dynamoDb, new CreateTableRequest() .withTableName(tableName) .withAttributeDefinitions(partitionKeyDefinition) .withKeySchema(partitionKeySchema) .withProvisionedThroughput(throughput)); } catch (AmazonDynamoDBException e) { throw new PersistenceException("Create table request failed", e); } } }
keySchema.add(new KeySchemaElement() .withAttributeName(hashKeyName) .withKeyType(KeyType.HASH)); attributeDefinitions.add(new AttributeDefinition() .withAttributeName(hashKeyName) .withAttributeType(hashKeyType)); CreateTableRequest request = new CreateTableRequest() .withTableName(tableName) .withKeySchema(keySchema) .withProvisionedThroughput( new ProvisionedThroughput() .withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH), new KeySchemaElement() .withAttributeName("PostedBy") .withKeyType(KeyType.RANGE)) .withProjection(new Projection() .withProjectionType(ProjectionType.KEYS_ONLY))); request.setLocalSecondaryIndexes(localSecondaryIndexes);
GlobalSecondaryIndex secIndex = new GlobalSecondaryIndex(). withIndexName(getSharedIndexName()). withProvisionedThroughput(new ProvisionedThroughput(). withReadCapacityUnits(1L). withWriteCapacityUnits(1L)). withProjection(new Projection().withProjectionType(ProjectionType.ALL)). withKeySchema(new KeySchemaElement().withAttributeName(Config._APPID).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(Config._ID).withKeyType(KeyType.RANGE)); getClient().createTable(new CreateTableRequest().withTableName(getTableNameForAppid(SHARED_TABLE)). withKeySchema(new KeySchemaElement(Config._KEY, KeyType.HASH)). withSSESpecification(new SSESpecification().withEnabled(ENCRYPTION_AT_REST_ENABLED)). withAttributeDefinitions(new AttributeDefinition(Config._KEY, ScalarAttributeType.S), new AttributeDefinition(Config._APPID, ScalarAttributeType.S), new AttributeDefinition(Config._ID, ScalarAttributeType.S)). withGlobalSecondaryIndexes(secIndex). withProvisionedThroughput(new ProvisionedThroughput(readCapacity, writeCapacity))); } catch (Exception e) { logger.error(null, e);
keySchema.add(new KeySchemaElement() .withAttributeName(hashKeyName) .withKeyType(KeyType.HASH)); attributeDefinitions.add(new AttributeDefinition() .withAttributeName(hashKeyName) .withAttributeType(hashKeyType)); keySchema, attributeDefinitions, new ProvisionedThroughput() .withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); System.out.println("Waiting for " + tableName + " to be created...this may take a while...");
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(); }
attributeDefinitions.add(new AttributeDefinition().withAttributeName("videoid").withAttributeType("S")); attributeDefinitions.add(new AttributeDefinition().withAttributeName("category").withAttributeType("S")); keySchema.add(new KeySchemaElement().withAttributeName("videoid").withKeyType(KeyType.HASH)); keySchema.add(new KeySchemaElement().withAttributeName("category").withKeyType(KeyType.RANGE)); ProvisionedThroughput ptIndex = new ProvisionedThroughput().withReadCapacityUnits(150L) .withWriteCapacityUnits(150L); .withKeySchema(new KeySchemaElement().withAttributeName("category").withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName("videoid").withKeyType(KeyType.RANGE)) .withProjection(new Projection().withProjectionType(ProjectionType.ALL)); createTableRequest = new CreateTableRequest().withTableName(tableName).withKeySchema(keySchema) .withAttributeDefinitions(attributeDefinitions) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(100L).withWriteCapacityUnits(100L)) .withGlobalSecondaryIndexes(videoCategoryGsi);
final long writeCapacity = Long.parseLong(System.getProperty( DynamoDbDataContext.SYSTEM_PROPERTY_THROUGHPUT_WRITE_CAPACITY, "5")); final ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(readCapacity, writeCapacity); keySchema.add(new KeySchemaElement(column.getName(), keyType)); attributes.add(new AttributeDefinition(column.getName(), DynamoDbUtils.toAttributeType(column .getType()))); final CreateTableRequest createTableRequest = new CreateTableRequest(); createTableRequest.setTableName(tableName); createTableRequest.setAttributeDefinitions(attributes); createTableRequest.setGlobalSecondaryIndexes(globalSecondaryIndices); createTableRequest.setKeySchema(keySchema);
/** * Sets the provisioned throughput for the specified table * * @param tableName * @param readCapUnits * @param writeCapUnits */ public void setProvisionedThroughput(String tableName, long readCapUnits, long writeCapUnits) { ProvisionedThroughput ptDesc = new ProvisionedThroughput() .withReadCapacityUnits(readCapUnits).withWriteCapacityUnits( writeCapUnits); }
final String name = json.getString("TableName"); final CreateTableRequest request = new CreateTableRequest().withTableName(name); if (json.containsKey("KeySchema")) { final Collection<KeySchemaElement> keys = this.keySchema(json); request.setKeySchema(keys); for (final JsonObject defn : schema.getValuesAs(JsonObject.class)) { attrs.add( new AttributeDefinition( defn.getString("AttributeName"), defn.getString("AttributeType") json.getJsonObject("ProvisionedThroughput"); request.setProvisionedThroughput( new ProvisionedThroughput( this.asLong(throughput, "ReadCapacityUnits"), this.asLong(throughput, "WriteCapacityUnits") .withProjection(this.projection(index)) .withProvisionedThroughput( new ProvisionedThroughput( this.asLong(throughput, "ReadCapacityUnits"), this.asLong(throughput, "WriteCapacityUnits")
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); } } }
/** * Creates the schemata for the DynamoDB table or tables each store requires. * Implementations should override and reuse this logic * @return a create table request appropriate for the schema of the selected implementation. */ public CreateTableRequest getTableSchema() { return new CreateTableRequest() .withTableName(tableName) .withProvisionedThroughput(new ProvisionedThroughput(client.readCapacity(tableName), client.writeCapacity(tableName))); }
/** * Decides which throughput value is the most suitable according to * certain parameters of elasticity/scalability. * @return Throughput settings. * @todo #10 The exact algorithm for figuring out read and write * capacities should be based on a CloudWatch metric accessed with * credentials of this.table.region().aws(). */ private static ProvisionedThroughput suitableThroughput() { return new ProvisionedThroughput( (long) Tv.HUNDRED, (long) Tv.HUNDRED ); } }
CreateTableRequest request = new CreateTableRequest(); request.setTableName(table); request.setKeySchema(serializer.getKeySchema()); request.setAttributeDefinitions(serializer.getAttributeDefinitions()); ProvisionedThroughput throughput = new ProvisionedThroughput(); throughput.setReadCapacityUnits(readCapacity); throughput.setWriteCapacityUnits(writeCapacity); request.setProvisionedThroughput(throughput);
ProvisionedThroughput thorughput = new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L); KeySchemaElement schemaElement = new KeySchemaElement().withAttributeName("Name").withAttributeType(ScalarAttributeType.S); CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(TOPIC_TABLE).withProvisionedThroughput(thorughput).withKeySchema(new KeySchema(schemaElement)); client.createTable(createTableRequest);
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; }