List of usage examples for com.amazonaws.services.dynamodbv2.model CreateTableRequest getTableName
public String getTableName()
The name of the table to create.
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java
License:Open Source License
private CreateTableResult createTable(final CreateTableRequest request) throws BackendException { controlPlaneRateLimiter.acquire();//w ww . j av a 2 s .c o m final Timer.Context apiTimerContext = getTimerContext(CREATE_TABLE, request.getTableName()); CreateTableResult result; try { result = client.createTable(request); } catch (final Exception e) { throw processDynamoDbApiException(e, CREATE_TABLE, request.getTableName()); } finally { apiTimerContext.stop(); } return result; }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java
License:Open Source License
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 {/* w w w.j a v a 2s . c om*/ 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*/); }
From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.manager.DynamoDbTemplateInfrastructureManager.java
License:Apache License
private void createTable(final CreateTableRequest createTableRequest, final boolean asynchronous) { boolean tableCreationError = false; final long startTime = System.currentTimeMillis(); do {/*from w ww. jav a2 s. c o m*/ try { amazonDynamoDbClient.createTable(createTableRequest); } catch (final Exception e) { tableCreationError = true; try { // wait for 10s Thread.sleep(10000); } catch (final InterruptedException interruptedException) { throw new IllegalStateException(interruptedException); } } } while (tableCreationError && System.currentTimeMillis() - startTime < TABLE_CREATION_TIMEOUT_MS); if (!asynchronous) { final long tableCreationStartTime = System.currentTimeMillis(); while (System.currentTimeMillis() - tableCreationStartTime < TABLE_CREATION_TIMEOUT_MS) { try { Thread.sleep(1000); } catch (final InterruptedException e) { throw new IllegalStateException(e); } if (isTableCreated(createTableRequest.getTableName())) { break; } } } }
From source file:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java
License:Open Source License
public CreateTableResult createTable(CreateTableRequest request) throws BackendException { controlPlaneRateLimiter.acquire();/* w w w. j ava2 s .c o m*/ final Timer.Context apiTimerContext = getTimerContext(CREATE_TABLE, request.getTableName()); CreateTableResult result; try { result = client.createTable(request); } catch (Exception e) { throw processDynamoDBAPIException(e, CREATE_TABLE, request.getTableName()); } finally { apiTimerContext.stop(); } return result; }
From source file:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java
License:Open Source License
public void createTableAndWaitForActive(CreateTableRequest request) throws BackendException { final String tableName = request.getTableName(); TableDescription desc;/*from w w w. j a v a 2s .c om*/ try { desc = this.describeTable(tableName); if (null != desc) { if (isTableActive(desc.getTableStatus())) { return; //store existed } } } catch (BackendNotFoundException e) { //Swallow, table doesnt exist yet } createTable(request); waitForTableCreation(tableName, false /*verifyIndexesList*/, null /*expectedLsiList*/, null /*expectedGsiList*/); }
From source file:io.klerch.alexa.state.handler.AWSDynamoStateHandler.java
License:Open Source License
private void ensureTableExists() throws InterruptedException { // given custom table is always assumed as existing so you can have this option to bypass existance checks // for reason of least privileges on used AWS credentials or better performance if (!tableExistenceApproved || !tableExists()) { final ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>(); // describe keys attributeDefinitions.add(new AttributeDefinition().withAttributeName(pkUser).withAttributeType("S")); attributeDefinitions.add(new AttributeDefinition().withAttributeName(pkModel).withAttributeType("S")); // define keys final ArrayList<KeySchemaElement> keySchema = new ArrayList<>(); keySchema.add(new KeySchemaElement().withAttributeName(pkUser).withKeyType(KeyType.HASH)); keySchema.add(new KeySchemaElement().withAttributeName(pkModel).withKeyType(KeyType.RANGE)); // prepare table creation request final CreateTableRequest awsRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); // create on not existing table if (TableUtils.createTableIfNotExists(awsClient, awsRequest)) { log.info(String.format( "Table '%1$s' is created in DynamoDB. Now standing by for up to ten minutes for this table to be in active state.", tableName));/* w w w.j a va 2 s. co m*/ // wait for table to be in ACTIVE state in order to proceed with read or write // this could take up to possible ten minutes so be sure to run this code once before publishing your skill ;) TableUtils.waitUntilActive(awsClient, awsRequest.getTableName()); } } }
From source file:org.openhab.persistence.dynamodb.internal.DynamoDBPersistenceService.java
License:Open Source License
/** * Create table (if not present) and wait for table to become active. * * Synchronized in order to ensure that at most single thread is creating the table at a time * * @param mapper/*from w w w. ja v a 2 s .c om*/ * @param dtoClass * @return whether table creation succeeded. */ private synchronized boolean createTable(DynamoDBMapper mapper, Class<?> dtoClass) { if (db == null) { return false; } String tableName; try { ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(dbConfig.getReadCapacityUnits(), dbConfig.getWriteCapacityUnits()); CreateTableRequest request = mapper.generateCreateTableRequest(dtoClass); request.setProvisionedThroughput(provisionedThroughput); if (request.getGlobalSecondaryIndexes() != null) { for (GlobalSecondaryIndex index : request.getGlobalSecondaryIndexes()) { index.setProvisionedThroughput(provisionedThroughput); } } tableName = request.getTableName(); try { db.getDynamoClient().describeTable(tableName); } catch (ResourceNotFoundException e) { // No table present, continue with creation db.getDynamoClient().createTable(request); } catch (AmazonClientException e) { logger.error("Table creation failed due to error in describeTable operation", e); return false; } // table found or just created, wait return waitForTableToBecomeActive(tableName); } catch (AmazonClientException e) { logger.error("Exception when creating table", e); return false; } }
From source file:org.socialsignin.spring.data.dynamodb.repository.util.Entity2DynamoDBTableSynchronizer.java
License:Apache License
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);/*from w w w.j a v a2s .c o m*/ 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; }
From source file:org.socialsignin.spring.data.dynamodb.repository.util.Entity2DynamoDBTableSynchronizer.java
License:Apache License
/** * @param entityInformation// w w w . j av a 2s . com * 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; }