List of usage examples for com.amazonaws.services.dynamodbv2.model CreateTableResult getTableDescription
public TableDescription getTableDescription()
Represents the properties of the table.
From source file:com.github.sporcina.mule.modules.DynamoDBConnector.java
License:Open Source License
/** * Create a new table/*from ww w .ja v a 2s. co m*/ * <p/> * {@sample.xml ../../../doc/DynamoDB-connector.xml.sample dynamodb:create-table} * * @param tableName * title of the table * @param readCapacityUnits * dedicated read units per second * @param writeCapacityUnits * dedicated write units per second * @param primaryKeyName * the name of the primary key for the table * @param waitFor * the number of minutes to wait for the table to become active * * @return the status of the table * * @throws TableNeverWentActiveException * the table never became ACTIVE within the time allotted */ @NotNull @Processor public String createTable(@NotNull final String tableName, @NotNull final Long readCapacityUnits, @NotNull final Long writeCapacityUnits, @NotNull final String primaryKeyName, @NotNull final Integer waitFor) throws TableNeverWentActiveException { try { return describeTable(tableName); } catch (ResourceNotFoundException e) { CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema( new KeySchemaElement().withAttributeName(primaryKeyName).withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName(primaryKeyName) .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); CreateTableResult result = getDynamoDBClient().createTable(createTableRequest); waitForTableToBecomeAvailable(tableName, waitFor); return result.getTableDescription().getTableStatus().toString(); } }
From source file:com.intuit.tank.persistence.databases.AmazonDynamoDatabaseDocApi.java
License:Open Source License
/** * /*w w w.ja v a 2 s. c om*/ * @{inheritDoc */ @Override public void createTable(String tableName) { try { if (!hasTable(tableName)) { logger.info("Creating table: " + tableName); HierarchicalConfiguration resultsProviderConfig = config.getVmManagerConfig() .getResultsProviderConfig(); long readCapacity = getCapacity(resultsProviderConfig, "read-capacity", 10L); long writeCapacity = getCapacity(resultsProviderConfig, "write-capacity", 50L); ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions .add(new AttributeDefinition().withAttributeName(DatabaseKeys.JOB_ID_KEY.getShortKey()) .withAttributeType(ScalarAttributeType.S)); attributeDefinitions.add( new AttributeDefinition().withAttributeName(DatabaseKeys.REQUEST_NAME_KEY.getShortKey()) .withAttributeType(ScalarAttributeType.S)); ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput() .withReadCapacityUnits(readCapacity).withWriteCapacityUnits(writeCapacity); KeySchemaElement hashKeyElement = new KeySchemaElement() .withAttributeName(DatabaseKeys.JOB_ID_KEY.getShortKey()).withKeyType(KeyType.HASH); KeySchemaElement rangeKeyElement = new KeySchemaElement() .withAttributeName(DatabaseKeys.REQUEST_NAME_KEY.getShortKey()).withKeyType(KeyType.RANGE); CreateTableRequest request = new CreateTableRequest().withTableName(tableName) .withKeySchema(hashKeyElement, rangeKeyElement) .withAttributeDefinitions(attributeDefinitions) .withProvisionedThroughput(provisionedThroughput); CreateTableResult result = dynamoDb.createTable(request); waitForStatus(tableName, TableStatus.ACTIVE); logger.info("Created table: " + result.getTableDescription().getTableName()); } } catch (Exception t) { logger.error(t, t); throw new RuntimeException(t); } }
From source file:com.makariev.dynamodb.data.tables.CreateTableService.java
License:Apache License
public String createPredefinedTables() { final StringBuilder sb = new StringBuilder(); for (Class<? extends TableRequestCreator> tableCreatorClass : tableCreators) { try {//from w w w . ja v a 2 s .co m final TableRequestCreator tableCreator = tableCreatorClass.newInstance(); final CreateTableRequest createTableRequest = tableCreator.getCreateTableRequest(); final CreateTableResult result = client.createTable(createTableRequest); final TableDescription tableDescription = result.getTableDescription(); sb.append(" table '").append(tableDescription.getTableName()).append("' SUCCESSFULLY CREATED;"); } catch (AmazonClientException | InstantiationException | IllegalAccessException | UnsupportedOperationException ex) { sb.append(" FAILED ex:").append(ex.toString()).append(';'); } } final String message = sb.toString(); return message.isEmpty() ? "nothing is executed" : message; }
From source file:kinesisadaptersample.StreamsAdapterDemoHelper.java
License:Open Source License
/** * @return StreamArn//from w w w. j a v a 2 s . c o m */ public static String createTable(AmazonDynamoDB client, String tableName) { java.util.List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N")); java.util.List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)); // Partition // key ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(2L) .withWriteCapacityUnits(2L); StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(StreamViewType.NEW_IMAGE); CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withAttributeDefinitions(attributeDefinitions).withKeySchema(keySchema) .withProvisionedThroughput(provisionedThroughput).withStreamSpecification(streamSpecification); try { System.out.println("Creating table " + tableName); CreateTableResult result = client.createTable(createTableRequest); return result.getTableDescription().getLatestStreamArn(); } catch (ResourceInUseException e) { System.out.println("Table already exists."); return describeTable(client, tableName).getTable().getLatestStreamArn(); } }
From source file:org.apache.beam.sdk.io.aws.dynamodb.DynamoDBIOTestHelper.java
License:Apache License
static void createTestTable(String tableName) { CreateTableResult res = createDynamoTable(tableName); TableDescription tableDesc = res.getTableDescription(); Assert.assertEquals(tableName, tableDesc.getTableName()); Assert.assertTrue(tableDesc.getKeySchema().toString().contains(ATTR_NAME_1)); Assert.assertTrue(tableDesc.getKeySchema().toString().contains(ATTR_NAME_2)); Assert.assertEquals(tableDesc.getProvisionedThroughput().getReadCapacityUnits(), Long.valueOf(1000)); Assert.assertEquals(tableDesc.getProvisionedThroughput().getWriteCapacityUnits(), Long.valueOf(1000)); Assert.assertEquals("ACTIVE", tableDesc.getTableStatus()); Assert.assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/" + tableName, tableDesc.getTableArn()); ListTablesResult tables = dynamoDBClient.listTables(); Assert.assertEquals(1, tables.getTableNames().size()); }
From source file:org.apache.metamodel.dynamodb.DynamoDbTableCreationBuilder.java
License:Apache License
@Override public Table execute() throws MetaModelException { final MutableTable table = getTable(); final String tableName = table.getName(); final Collection<AttributeDefinition> attributes = new ArrayList<>(); final Collection<KeySchemaElement> keySchema = new ArrayList<>(); final Collection<GlobalSecondaryIndex> globalSecondaryIndices = new ArrayList<>(); final long readCapacity = Long .parseLong(System.getProperty(DynamoDbDataContext.SYSTEM_PROPERTY_THROUGHPUT_READ_CAPACITY, "5")); final long writeCapacity = Long .parseLong(System.getProperty(DynamoDbDataContext.SYSTEM_PROPERTY_THROUGHPUT_WRITE_CAPACITY, "5")); final ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(readCapacity, writeCapacity); for (Column column : table.getColumns()) { if (column.isPrimaryKey()) { final KeyType keyType = getKeyType(column.getRemarks()); keySchema.add(new KeySchemaElement(column.getName(), keyType)); attributes.add(/*from ww w .j a v a2s.c o m*/ 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 AmazonDynamoDB client = getUpdateCallback().getDataContext().getDynamoDb(); final CreateTableResult createTableResult = client.createTable(createTableRequest); // await the table creation to be "done". { String tableStatus = createTableResult.getTableDescription().getTableStatus(); while (TableStatus.CREATING.name().equals(tableStatus)) { logger.debug("Waiting for table status to be ACTIVE. Currently: {}", tableStatus); try { Thread.sleep(300); } catch (InterruptedException e) { getUpdateCallback().setInterrupted(true); } tableStatus = client.describeTable(tableName).getTable().getTableStatus(); } } return table; }
From source file:org.iternine.jeppetto.testsupport.db.DynamoDBDatabase.java
License:Apache License
private void createTables(List<CreateTableRequest> createTableRequests) { for (CreateTableRequest createTableRequest : createTableRequests) { CreateTableResult result = amazonDynamoDB.createTable(createTableRequest); logger.debug("Created table: " + result.getTableDescription()); }//from w ww. jav a 2s.co m }