software.amazon.awssdk.services.dynamodb.model.TableDescription Java Examples
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.TableDescription.
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: 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 #2
Source File: AWSDynamoUtils.java From para with Apache License 2.0 | 6 votes |
/** * Gives basic information about a DynamoDB table (status, creation date, size). * @param appid name of the {@link com.erudika.para.core.App} * @return a map */ public static Map<String, Object> getTableStatus(final String appid) { if (StringUtils.isBlank(appid)) { return Collections.emptyMap(); } try { final TableDescription td = getClient().describeTable(b -> b.tableName(getTableNameForAppid(appid))).table(); HashMap<String, Object> dbStatus = new HashMap<>(); dbStatus.put("id", appid); dbStatus.put("status", td.tableStatus().name()); dbStatus.put("created", td.creationDateTime().toEpochMilli()); dbStatus.put("sizeBytes", td.tableSizeBytes()); dbStatus.put("itemCount", td.itemCount()); dbStatus.put("readCapacityUnits", td.provisionedThroughput().readCapacityUnits()); dbStatus.put("writeCapacityUnits", td.provisionedThroughput().writeCapacityUnits()); return dbStatus; } catch (Exception e) { logger.error(null, e); } return Collections.emptyMap(); }
Example #3
Source File: AwsDynamoDbScanner.java From clouditor with Apache License 2.0 | 5 votes |
@Override protected List<TableDescription> list() { return this.api.listTables().tableNames().stream() .map( tableName -> this.api .describeTable(DescribeTableRequest.builder().tableName(tableName).build()) .table()) .collect(Collectors.toList()); }
Example #4
Source File: DynamoDBTableResource.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public ResourceStatus getResourceStatus() { CreateTableRequest createRequest = getCreateTableRequest(); TableDescription table; try { table = getClient().describeTable(DescribeTableRequest.builder().tableName( createRequest.tableName()).build()).table(); } catch (AwsServiceException exception) { if (exception.awsErrorDetails().errorCode().equalsIgnoreCase("ResourceNotFoundException")) { return ResourceStatus.NOT_EXIST; } throw exception; } if (table.tableStatus() == TableStatus.ACTIVE) { // returns AVAILABLE only if table KeySchema + LSIs + GSIs all match. if (UnorderedCollectionComparator.equalUnorderedCollections(createRequest.keySchema(), table.keySchema()) && equalUnorderedGsiLists(createRequest.globalSecondaryIndexes(), table.globalSecondaryIndexes()) && equalUnorderedLsiLists(createRequest.localSecondaryIndexes(), table.localSecondaryIndexes())) { return ResourceStatus.AVAILABLE; } else { return ResourceStatus.EXIST_INCOMPATIBLE_RESOURCE; } } else if (table.tableStatus() == TableStatus.CREATING || table.tableStatus() == TableStatus.UPDATING || table.tableStatus() == TableStatus.DELETING) { return ResourceStatus.TRANSIENT; } else { return ResourceStatus.NOT_EXIST; } }
Example #5
Source File: TableUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Wait for the table to reach the desired status and returns the table * description * * @param dynamo * Dynamo client to use * @param tableName * Table name to poll status of * @param desiredStatus * Desired {@link TableStatus} to wait for. If null this method * simply waits until DescribeTable returns something non-null * (i.e. any status) * @param timeout * Timeout in milliseconds to continue to poll for desired status * @param interval * Time to wait in milliseconds between poll attempts * @return Null if DescribeTables never returns a result, otherwise the * result of the last poll attempt (which may or may not have the * desired state) * @throws {@link * IllegalArgumentException} If timeout or interval is invalid */ private static TableDescription waitForTableDescription(final DynamoDbClient dynamo, final String tableName, TableStatus desiredStatus, final int timeout, final int interval) throws InterruptedException, IllegalArgumentException { if (timeout < 0) { throw new IllegalArgumentException("Timeout must be >= 0"); } if (interval <= 0 || interval >= timeout) { throw new IllegalArgumentException("Interval must be > 0 and < timeout"); } long startTime = System.currentTimeMillis(); long endTime = startTime + timeout; TableDescription table = null; while (System.currentTimeMillis() < endTime) { try { table = dynamo.describeTable(DescribeTableRequest.builder().tableName(tableName).build()).table(); if (desiredStatus == null || table.tableStatus().equals(desiredStatus)) { return table; } } catch (ResourceNotFoundException rnfe) { // ResourceNotFound means the table doesn't exist yet, // so ignore this error and just keep polling. } Thread.sleep(interval); } return table; }
Example #6
Source File: DynamoDBLeaseRefresherTest.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Test public void testWaitUntilLeaseTableExistsUpdatingStatus() throws Exception { when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture); when(mockDescribeTableFuture.get(anyLong(), any())) .thenReturn(DescribeTableResponse.builder() .table(TableDescription.builder().tableStatus(TableStatus.UPDATING).build()) .build()); assertTrue(leaseRefresher.waitUntilLeaseTableExists(0, 0)); }
Example #7
Source File: DynamoDBLeaseRefresherTest.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Test public void testWaitUntilLeaseTableExistsActiveStatus() throws Exception { when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture); when(mockDescribeTableFuture.get(anyLong(), any())) .thenReturn(DescribeTableResponse.builder() .table(TableDescription.builder().tableStatus(TableStatus.ACTIVE).build()) .build()); assertTrue(leaseRefresher.waitUntilLeaseTableExists(0, 0)); }
Example #8
Source File: DynamoDBLeaseRefresherTest.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Test public void testWaitUntilLeaseTableExistsCreatingStatus() throws Exception { when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture); when(mockDescribeTableFuture.get(anyLong(), any())) .thenReturn(DescribeTableResponse.builder() .table(TableDescription.builder().tableStatus(TableStatus.CREATING).build()) .build()); assertFalse(leaseRefresher.waitUntilLeaseTableExists(0, 0)); }
Example #9
Source File: DynamoDBLeaseRefresherTest.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Test public void testWaitUntilLeaseTableExistsDeletingStatus() throws Exception { when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture); when(mockDescribeTableFuture.get(anyLong(), any())) .thenReturn(DescribeTableResponse.builder() .table(TableDescription.builder().tableStatus(TableStatus.DELETING).build()) .build()); assertFalse(leaseRefresher.waitUntilLeaseTableExists(0, 0)); }
Example #10
Source File: AwsDynamoDbScanner.java From clouditor with Apache License 2.0 | 4 votes |
public AwsDynamoDbScanner() { super(DynamoDbClient::builder, TableDescription::tableArn, TableDescription::tableName); }
Example #11
Source File: AwsDynamoDbScannerTest.java From clouditor with Apache License 2.0 | 4 votes |
@BeforeAll static void setUpOnce() { discoverAssets( DynamoDbClient.class, AwsDynamoDbScanner::new, api -> { when(api.listTables()) .thenReturn( ListTablesResponse.builder() .tableNames( "enabled_encryption", "enabling_encryption", "disabled_encryption", "disabling_encryption") .build()); when(api.describeTable( DescribeTableRequest.builder().tableName("enabled_encryption").build())) .thenReturn( DescribeTableResponse.builder() .table( TableDescription.builder() .sseDescription( SSEDescription.builder().status(SSEStatus.ENABLED).build()) .tableArn( "arn:aws:dynamodb:eu-central-1:123456789:table/encryption-enabled-table") .build()) .build()); when(api.describeTable( DescribeTableRequest.builder().tableName("enabling_encryption").build())) .thenReturn( DescribeTableResponse.builder() .table( TableDescription.builder() .sseDescription( SSEDescription.builder().status(SSEStatus.ENABLING).build()) .tableArn( "arn:aws:dynamodb:eu-central-1:123456789:table/encryption-enabling-table") .build()) .build()); when(api.describeTable( DescribeTableRequest.builder().tableName("disabling_encryption").build())) .thenReturn( DescribeTableResponse.builder() .table( TableDescription.builder() .sseDescription( SSEDescription.builder().status(SSEStatus.DISABLING).build()) .tableArn( "arn:aws:dynamodb:eu-central-1:123456789:table/encryption-disabling-table") .build()) .build()); when(api.describeTable( DescribeTableRequest.builder().tableName("disabled_encryption").build())) .thenReturn( DescribeTableResponse.builder() .table( TableDescription.builder() .sseDescription( SSEDescription.builder().status(SSEStatus.DISABLED).build()) .tableArn( "arn:aws:dynamodb:eu-central-1:123456789:table/encryption-disabled-table") .build()) .build()); }); }
Example #12
Source File: SecondaryIndexesIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
/** * Assert the tableDescription is as expected */ @Test public void testDescribeTempTableWithIndexes() { TableDescription tableDescription = dynamo.describeTable(DescribeTableRequest.builder().tableName(tableName).build()).table(); assertEquals(tableName, tableDescription.tableName()); assertNotNull(tableDescription.tableStatus()); assertEquals(2, tableDescription.keySchema().size()); assertEquals(HASH_KEY_NAME, tableDescription.keySchema().get(0) .attributeName()); assertEquals(KeyType.HASH, tableDescription .keySchema().get(0).keyType()); assertEquals(RANGE_KEY_NAME, tableDescription.keySchema() .get(1).attributeName()); assertEquals(KeyType.RANGE, tableDescription .keySchema().get(1).keyType()); assertEquals(1, tableDescription.localSecondaryIndexes().size()); assertEquals(LSI_NAME, tableDescription .localSecondaryIndexes().get(0).indexName()); assertEquals(2, tableDescription .localSecondaryIndexes().get(0).keySchema().size()); assertEquals(HASH_KEY_NAME, tableDescription .localSecondaryIndexes().get(0).keySchema().get(0).attributeName()); assertEquals(KeyType.HASH, tableDescription .localSecondaryIndexes().get(0).keySchema().get(0).keyType()); assertEquals(LSI_RANGE_KEY_NAME, tableDescription .localSecondaryIndexes().get(0).keySchema().get(1).attributeName()); assertEquals(KeyType.RANGE, tableDescription .localSecondaryIndexes().get(0).keySchema().get(1).keyType()); assertEquals(ProjectionType.KEYS_ONLY, tableDescription.localSecondaryIndexes().get(0) .projection().projectionType()); assertTrue(tableDescription.localSecondaryIndexes().get(0) .projection().nonKeyAttributes() instanceof SdkAutoConstructList); assertEquals(1, tableDescription.globalSecondaryIndexes().size()); assertEquals(GSI_NAME, tableDescription .globalSecondaryIndexes().get(0).indexName()); assertEquals(2, tableDescription .globalSecondaryIndexes().get(0).keySchema().size()); assertEquals(GSI_HASH_KEY_NAME, tableDescription .globalSecondaryIndexes().get(0).keySchema().get(0).attributeName()); assertEquals(KeyType.HASH, tableDescription .globalSecondaryIndexes().get(0).keySchema().get(0).keyType()); assertEquals(GSI_RANGE_KEY_NAME, tableDescription .globalSecondaryIndexes().get(0).keySchema().get(1).attributeName()); assertEquals(KeyType.RANGE, tableDescription .globalSecondaryIndexes().get(0).keySchema().get(1).keyType()); assertEquals(ProjectionType.KEYS_ONLY, tableDescription.globalSecondaryIndexes().get(0) .projection().projectionType()); assertTrue(tableDescription.globalSecondaryIndexes().get(0) .projection().nonKeyAttributes() instanceof SdkAutoConstructList); }
Example #13
Source File: DescribeTable.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
public static void describeDymamoDBTable(DynamoDbClient ddb,String tableName ) { DescribeTableRequest request = DescribeTableRequest.builder() .tableName(tableName) .build(); try { TableDescription tableInfo = ddb.describeTable(request).table(); if (tableInfo != null) { System.out.format("Table name : %s\n", tableInfo.tableName()); System.out.format("Table ARN : %s\n", tableInfo.tableArn()); System.out.format("Status : %s\n", tableInfo.tableStatus()); System.out.format("Item count : %d\n", tableInfo.itemCount().longValue()); System.out.format("Size (bytes): %d\n", tableInfo.tableSizeBytes().longValue()); ProvisionedThroughputDescription throughputInfo = tableInfo.provisionedThroughput(); System.out.println("Throughput"); System.out.format(" Read Capacity : %d\n", throughputInfo.readCapacityUnits().longValue()); System.out.format(" Write Capacity: %d\n", throughputInfo.writeCapacityUnits().longValue()); List<AttributeDefinition> attributes = tableInfo.attributeDefinitions(); System.out.println("Attributes"); for (AttributeDefinition a : attributes) { System.out.format(" %s (%s)\n", a.attributeName(), a.attributeType()); } } } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.describe_table.main] System.out.println("\nDone!"); }
Example #14
Source File: TableUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 3 votes |
/** * Waits up to a specified amount of time for a specified DynamoDB table to * resolve, indicating that it exists. If the table doesn't return a result * after this time, a SdkClientException is thrown. * * @param dynamo * The DynamoDB client to use to make requests. * @param tableName * The name of the table being resolved. * @param timeout * The maximum number of milliseconds to wait. * @param interval * The poll interval in milliseconds. * * @throws SdkClientException * If the specified table does not resolve before this method * times out and stops polling. * @throws InterruptedException * If the thread is interrupted while waiting for the table to * resolve. */ public static void waitUntilExists(final DynamoDbClient dynamo, final String tableName, final int timeout, final int interval) throws InterruptedException { TableDescription table = waitForTableDescription(dynamo, tableName, null, timeout, interval); if (table == null) { throw SdkClientException.builder().message("Table " + tableName + " never returned a result").build(); } }
Example #15
Source File: TableUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 3 votes |
/** * Waits up to a specified amount of time for a specified DynamoDB table to * move into the <code>ACTIVE</code> state. If the table does not exist or * does not transition to the <code>ACTIVE</code> state after this time, * then a SdkClientException is thrown. * * @param dynamo * The DynamoDB client to use to make requests. * @param tableName * The name of the table whose status is being checked. * @param timeout * The maximum number of milliseconds to wait. * @param interval * The poll interval in milliseconds. * * @throws TableNeverTransitionedToStateException * If the specified table does not exist or does not transition * into the <code>ACTIVE</code> state before this method times * out and stops polling. * @throws InterruptedException * If the thread is interrupted while waiting for the table to * transition into the <code>ACTIVE</code> state. */ public static void waitUntilActive(final DynamoDbClient dynamo, final String tableName, final int timeout, final int interval) throws InterruptedException, TableNeverTransitionedToStateException { TableDescription table = waitForTableDescription(dynamo, tableName, TableStatus.ACTIVE, timeout, interval); if (table == null || !table.tableStatus().equals(TableStatus.ACTIVE)) { throw new TableNeverTransitionedToStateException(tableName, TableStatus.ACTIVE); } }