software.amazon.awssdk.services.dynamodb.model.CreateTableResponse Java Examples
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.CreateTableResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Aws2Test.java From java-specialagent with Apache License 2.0 | 6 votes |
@Test public void testAsyncClient(final MockTracer tracer) { final DynamoDbAsyncClient dbClient = buildAsyncClient(); final CompletableFuture<CreateTableResponse> createTableResultFuture = createTableAsync(dbClient, "asyncRequest"); try { final CreateTableResponse result = createTableResultFuture.get(60, TimeUnit.SECONDS); // The following assertion is only relevant when a local instance of dynamodb is present. // If a local instance of dynamodb is NOT present, an exception is thrown. assertEquals("asyncRequest", result.tableDescription().tableName()); } catch (final Exception e) { logger.log(Level.WARNING, e.getMessage()); } await().atMost(60, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(1)); final List<MockSpan> spans = tracer.finishedSpans(); assertEquals(1, spans.size()); assertEquals("CreateTableRequest", spans.get(0).operationName()); }
Example #2
Source File: DynamoDBIOTestHelper.java From beam with Apache License 2.0 | 6 votes |
static void createTestTable(String tableName) { CreateTableResponse res = createDynamoTable(tableName); TableDescription tableDesc = res.tableDescription(); Assert.assertEquals(tableName, tableDesc.tableName()); Assert.assertTrue(tableDesc.keySchema().toString().contains(ATTR_NAME_1)); Assert.assertTrue(tableDesc.keySchema().toString().contains(ATTR_NAME_2)); Assert.assertEquals(tableDesc.provisionedThroughput().readCapacityUnits(), Long.valueOf(1000)); Assert.assertEquals(tableDesc.provisionedThroughput().writeCapacityUnits(), Long.valueOf(1000)); Assert.assertEquals(TableStatus.ACTIVE, tableDesc.tableStatus()); Assert.assertEquals( "arn:aws:dynamodb:ddblocal:000000000000:table/" + tableName, tableDesc.tableArn()); ListTablesResponse tables = dynamoDBClient.listTables(); Assert.assertEquals(1, tables.tableNames().size()); }
Example #3
Source File: MetaStore.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * Creates a DynamoDB Table with the correct properties to be used with a ProviderStore. * * @param ddb interface for accessing DynamoDB * @param tableName name of table that stores the meta data of the material. * @param provisionedThroughput required provisioned throughput of the this table. * @return result of create table request. */ public static CreateTableResponse createTable(final DynamoDbClient ddb, final String tableName, final ProvisionedThroughput provisionedThroughput) { return ddb.createTable( CreateTableRequest.builder() .tableName(tableName) .attributeDefinitions(Arrays.asList( AttributeDefinition.builder() .attributeName(DEFAULT_HASH_KEY) .attributeType(ScalarAttributeType.S) .build(), AttributeDefinition.builder() .attributeName(DEFAULT_RANGE_KEY) .attributeType(ScalarAttributeType.N).build())) .keySchema(Arrays.asList( KeySchemaElement.builder() .attributeName(DEFAULT_HASH_KEY) .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName(DEFAULT_RANGE_KEY) .keyType(KeyType.RANGE) .build())) .provisionedThroughput(provisionedThroughput).build()); }
Example #4
Source File: Aws2Test.java From java-specialagent with Apache License 2.0 | 5 votes |
private static CompletableFuture<CreateTableResponse> createTableAsync(final DynamoDbAsyncClient dbClient, final String tableName) { final String partitionKeyName = tableName + "Id"; final CreateTableRequest createTableRequest = CreateTableRequest.builder() .tableName(tableName).keySchema(KeySchemaElement.builder().attributeName(partitionKeyName).keyType(KeyType.HASH).build()) .attributeDefinitions(AttributeDefinition.builder().attributeName(partitionKeyName).attributeType("S").build()) .provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(10L).writeCapacityUnits(5L).build()).build(); return dbClient.createTable(createTableRequest); }
Example #5
Source File: CreateTableOperation.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public Void transformResponse(CreateTableResponse response, TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { // This operation does not return results return null; }
Example #6
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void getServiceCall_makesTheRightCallAndReturnsResponse() { CreateTableOperation<FakeItem> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().build()); CreateTableRequest createTableRequest = CreateTableRequest.builder().build(); CreateTableResponse expectedResponse = CreateTableResponse.builder().build(); when(mockDynamoDbClient.createTable(any(CreateTableRequest.class))).thenReturn(expectedResponse); CreateTableResponse actualResponse = operation.serviceCall(mockDynamoDbClient).apply(createTableRequest); assertThat(actualResponse, sameInstance(expectedResponse)); verify(mockDynamoDbClient).createTable(same(createTableRequest)); }
Example #7
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void transformResults_doesNothing() { CreateTableOperation<FakeItem> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().build()); CreateTableResponse response = CreateTableResponse.builder().build(); operation.transformResponse(response, FakeItem.getTableSchema(), PRIMARY_CONTEXT, null); }
Example #8
Source File: CreateTable.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static String createTable(DynamoDbClient ddb, String tableName, String key) { // Create the CreateTableRequest object CreateTableRequest request = CreateTableRequest.builder() .attributeDefinitions(AttributeDefinition.builder() .attributeName(key) .attributeType(ScalarAttributeType.S) .build()) .keySchema(KeySchemaElement.builder() .attributeName(key) .keyType(KeyType.HASH) .build()) .provisionedThroughput(ProvisionedThroughput.builder() .readCapacityUnits(new Long(10)) .writeCapacityUnits(new Long(10)) .build()) .tableName(tableName) .build(); String newTable =""; try { CreateTableResponse response = ddb.createTable(request); newTable = response.tableDescription().tableName(); return newTable; } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.create_table.main] return ""; }
Example #9
Source File: DynamoDBIOTestHelper.java From beam with Apache License 2.0 | 5 votes |
private static CreateTableResponse createDynamoTable(String tableName) { ImmutableList<AttributeDefinition> attributeDefinitions = ImmutableList.of( AttributeDefinition.builder() .attributeName(ATTR_NAME_1) .attributeType(ScalarAttributeType.S) .build(), AttributeDefinition.builder() .attributeName(ATTR_NAME_2) .attributeType(ScalarAttributeType.N) .build()); ImmutableList<KeySchemaElement> ks = ImmutableList.of( KeySchemaElement.builder().attributeName(ATTR_NAME_1).keyType(KeyType.HASH).build(), KeySchemaElement.builder().attributeName(ATTR_NAME_2).keyType(KeyType.RANGE).build()); ProvisionedThroughput provisionedthroughput = ProvisionedThroughput.builder().readCapacityUnits(1000L).writeCapacityUnits(1000L).build(); CreateTableRequest request = CreateTableRequest.builder() .tableName(tableName) .attributeDefinitions(attributeDefinitions) .keySchema(ks) .provisionedThroughput(provisionedthroughput) .build(); return dynamoDBClient.createTable(request); }
Example #10
Source File: AWSDynamoUtils.java From para with Apache License 2.0 | 5 votes |
/** * Creates a table in AWS DynamoDB. * @param appid name of the {@link com.erudika.para.core.App} * @param readCapacity read capacity * @param writeCapacity write capacity * @return true if created */ public static boolean createTable(String appid, long readCapacity, long writeCapacity) { if (StringUtils.isBlank(appid)) { return false; } else if (StringUtils.containsWhitespace(appid)) { logger.warn("DynamoDB table name contains whitespace. The name '{}' is invalid.", appid); return false; } else if (existsTable(appid)) { logger.warn("DynamoDB table '{}' already exists.", appid); return false; } try { String table = getTableNameForAppid(appid); CreateTableResponse tbl = getClient().createTable(b -> b.tableName(table). sseSpecification(b2 -> b2.enabled(ENCRYPTION_AT_REST_ENABLED)). provisionedThroughput(b4 -> b4.readCapacityUnits(readCapacity).writeCapacityUnits(writeCapacity)). keySchema(KeySchemaElement.builder().attributeName(Config._KEY).keyType(KeyType.HASH).build()). attributeDefinitions(AttributeDefinition.builder(). attributeName(Config._KEY).attributeType(ScalarAttributeType.S).build())); logger.info("Waiting for DynamoDB table to become ACTIVE..."); waitForActive(table); // NOT IMPLEMENTED in SDK v2: // String status = tbl.waitForActive().getTableStatus(); logger.info("Created DynamoDB table '{}', status {}.", table, tbl.tableDescription().tableStatus()); } catch (Exception e) { logger.error(null, e); return false; } return true; }
Example #11
Source File: AWSDynamoUtils.java From para with Apache License 2.0 | 5 votes |
/** * Creates a table in AWS DynamoDB which will be shared between apps. * @param readCapacity read capacity * @param writeCapacity write capacity * @return true if created */ public static boolean createSharedTable(long readCapacity, long writeCapacity) { if (StringUtils.isBlank(SHARED_TABLE) || StringUtils.containsWhitespace(SHARED_TABLE) || existsTable(SHARED_TABLE)) { return false; } String table = getTableNameForAppid(SHARED_TABLE); try { GlobalSecondaryIndex secIndex = GlobalSecondaryIndex.builder(). indexName(getSharedIndexName()). provisionedThroughput(b -> b.readCapacityUnits(1L).writeCapacityUnits(1L)). projection(Projection.builder().projectionType(ProjectionType.ALL).build()). keySchema(KeySchemaElement.builder().attributeName(Config._APPID).keyType(KeyType.HASH).build(), KeySchemaElement.builder().attributeName(Config._ID).keyType(KeyType.RANGE).build()).build(); AttributeDefinition[] attributes = new AttributeDefinition[] { AttributeDefinition.builder().attributeName(Config._KEY).attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName(Config._APPID).attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName(Config._ID).attributeType(ScalarAttributeType.S).build() }; CreateTableResponse tbl = getClient().createTable(b -> b.tableName(table). keySchema(KeySchemaElement.builder().attributeName(Config._KEY).keyType(KeyType.HASH).build()). sseSpecification(b2 -> b2.enabled(ENCRYPTION_AT_REST_ENABLED)). attributeDefinitions(attributes). globalSecondaryIndexes(secIndex). provisionedThroughput(b6 -> b6.readCapacityUnits(readCapacity).writeCapacityUnits(writeCapacity))); logger.info("Waiting for DynamoDB table to become ACTIVE..."); waitForActive(table); logger.info("Created shared table '{}', status {}.", table, tbl.tableDescription().tableStatus()); } catch (Exception e) { logger.error(null, e); return false; } return true; }
Example #12
Source File: CreateTableOperation.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public Function<CreateTableRequest, CreateTableResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::createTable; }
Example #13
Source File: CreateTableOperation.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public Function<CreateTableRequest, CompletableFuture<CreateTableResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::createTable; }
Example #14
Source File: CreateTableCompositeKey.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
public static String createTableComKey(DynamoDbClient ddb, String tableName) { CreateTableRequest request = CreateTableRequest.builder() .attributeDefinitions( AttributeDefinition.builder() .attributeName("Language") .attributeType(ScalarAttributeType.S) .build(), AttributeDefinition.builder() .attributeName("Greeting") .attributeType(ScalarAttributeType.S) .build()) .keySchema( KeySchemaElement.builder() .attributeName("Language") .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName("Greeting") .keyType(KeyType.RANGE) .build()) .provisionedThroughput( ProvisionedThroughput.builder() .readCapacityUnits(new Long(10)) .writeCapacityUnits(new Long(10)).build()) .tableName(tableName) .build(); String tableId = ""; try { CreateTableResponse result = ddb.createTable(request); tableId = result.tableDescription().tableId(); return tableId; } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.create_table_composite_key.main] return ""; }
Example #15
Source File: LocalDynamoDb.java From aws-dynamodb-encryption-java with Apache License 2.0 | 4 votes |
@Override public CreateTableResponse createTable(CreateTableRequest createTableRequest) { return wrappedClient.createTable(createTableRequest); }