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()); } }
setAttributeDefinitions(attributeDefinitions); setTableName(tableName); setKeySchema(keySchema); setProvisionedThroughput(provisionedThroughput);
@Override public CreateTableResult createTable(java.util.List<AttributeDefinition> attributeDefinitions, String tableName, java.util.List<KeySchemaElement> keySchema, ProvisionedThroughput provisionedThroughput) { return createTable(new CreateTableRequest().withAttributeDefinitions(attributeDefinitions).withTableName(tableName).withKeySchema(keySchema) .withProvisionedThroughput(provisionedThroughput)); }
/** * 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(); }
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); } } }
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);
private void createTable() { dynamoDBClient.createTable(new CreateTableRequest() .withTableName(tableConfig.getTableName()).withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(1L) .withWriteCapacityUnits(1L))); }
@Override public <T> CreateTableRequest generateCreateTableRequest(Class<T> clazz, DynamoDBMapperConfig config) { config = mergeConfig(config); final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); final CreateTableRequest request = new CreateTableRequest(); request.setTableName(getTableName(clazz, config)); request.withKeySchema(new KeySchemaElement(model.hashKey().name(), HASH)); if (model.rangeKeyIfExists() != null) { request.withKeySchema(new KeySchemaElement(model.rangeKey().name(), RANGE)); } request.setGlobalSecondaryIndexes(model.globalSecondaryIndexes()); request.setLocalSecondaryIndexes(model.localSecondaryIndexes()); for (final DynamoDBMapperFieldModel<T,Object> field : model.fields()) { if (field.keyType() != null || field.indexed()) { request.withAttributeDefinitions(new AttributeDefinition() .withAttributeType(ScalarAttributeType.valueOf(field.attributeType().name())) .withAttributeName(field.name()) ); } } return request; }
@Override public CreateTableRequest getTableSchema() { return super.getTableSchema() .withAttributeDefinitions( new AttributeDefinition() .withAttributeName(Constants.JANUSGRAPH_HASH_KEY) .withAttributeType(ScalarAttributeType.S)) .withKeySchema( new KeySchemaElement() .withAttributeName(Constants.JANUSGRAPH_HASH_KEY) .withKeyType(KeyType.HASH)); }
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); createTableRequest.setProvisionedThroughput(provisionedThroughput); final CreateTableResult createTableResult = client.createTable(createTableRequest); getUpdateCallback().setInterrupted(true); tableStatus = client.describeTable(tableName).getTable().getTableStatus();
keyAttrs.add(new KeySchemaElement(itemTransformer.getHashKeyAttributeName(), KeyType.HASH)); attrs.add(new AttributeDefinition(itemTransformer.getHashKeyAttributeName(), ScalarAttributeType.S)); keyAttrs.add(new KeySchemaElement(rangeKeyName, KeyType.RANGE)); attrs.add(new AttributeDefinition(rangeKeyName, ScalarAttributeType.S)); .withKeySchema(new KeySchemaElement(rangeKeyName, KeyType.HASH)) .withProjection(new Projection().withProjectionType(ProjectionType.ALL)) .withProvisionedThroughput(rwCapacity)); attrs.add(new AttributeDefinition(a, ScalarAttributeType.S)); CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(tableName) .withProvisionedThroughput(rwCapacity) .withSSESpecification(new SSESpecification().withEnabled(tableEncryptionAtRest)) .withKeySchema(keyAttrs) .withAttributeDefinitions(attrs); .withStreamSpecification( new StreamSpecification() .withStreamEnabled(true) createTableRequest.withGlobalSecondaryIndexes(gsIndices);
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); request.setAttributeDefinitions(attrs); request.setProvisionedThroughput( new ProvisionedThroughput( this.asLong(throughput, "ReadCapacityUnits"), this.asLong(throughput, "WriteCapacityUnits") indexes.add(gsi); request.setGlobalSecondaryIndexes(indexes); indexes.add(lsi); request.setLocalSecondaryIndexes(indexes); aws.createTable(request); Logger.info(this, "Waiting for table '%s' to become active", name); try {
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))); }
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); } }
status = verifyTableExists(tableName, definitions, keySchema, localIndexes); } catch(ResourceNotFoundException e) { status = client.createTable(new CreateTableRequest() .withTableName(tableName) .withAttributeDefinitions(definitions) .withKeySchema(keySchema) .withLocalSecondaryIndexes(localIndexes) .withProvisionedThroughput(provisionedThroughput)).getTableDescription().getTableStatus();
ItemConverter converter) { final CreateTableRequest createTableRequest = new CreateTableRequest(); createTableRequest.setTableName(DynamoDBMapper.internalGetTableName(clazz, null, config)); final AttributeDefinition pHashAttrDefinition = getKeyAttributeDefinition(pHashKeyGetter, converter); createTableRequest.withKeySchema(new KeySchemaElement(pHashAttrDefinition .getAttributeName(), KeyType.HASH)); if (pRangeKeyGetter != null) { pRangeAttrDefinition = getKeyAttributeDefinition(pRangeKeyGetter, converter); createTableRequest.withKeySchema(new KeySchemaElement(pRangeAttrDefinition .getAttributeName(), KeyType.RANGE)); createTableRequest.setGlobalSecondaryIndexes(indexesInfo.getGlobalSecondaryIndexes()); createTableRequest.setLocalSecondaryIndexes(indexesInfo.getLocalSecondaryIndexes()); putAfterCheckConflict(attrDefinitions, indexKeyAttrDefinition); createTableRequest.setAttributeDefinitions(attrDefinitions.values());
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); dynamoDBClient.createTable(request); } catch (ResourceInUseException e) { LOG.info("Table " + table + " already exists.");
/** * 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))); }
/** * 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; }