software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest Java Examples
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest.
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: DynamoDBLeaseRefresherTest.java From amazon-kinesis-client with Apache License 2.0 | 6 votes |
@Test public void testCreateLeaseTableBillingMode() throws Exception { leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS, tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PAY_PER_REQUEST); TimeoutException te = setRuleForDependencyTimeout(); when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture); when(mockDescribeTableFuture.get(anyLong(), any())) .thenThrow(ResourceNotFoundException.builder().message("Table doesn't exist").build()); when(dynamoDbClient.createTable(any(CreateTableRequest.class))).thenReturn(mockCreateTableFuture); when(mockCreateTableFuture.get(anyLong(), any())).thenThrow(te); verifyCancel(mockCreateTableFuture, () -> leaseRefresher.createLeaseTableIfNotExists(10L, 10L)); }
Example #2
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 #3
Source File: DynamoDBUtils.java From quarkus with Apache License 2.0 | 5 votes |
private static CompletableFuture<Boolean> waitUntilTableActiveAsync(final DynamoDbAsyncClient dynamo, final String table) { final long startTime = System.currentTimeMillis(); final long endTime = startTime + DEFAULT_WAIT_TIMEOUT; return retryAsync(() -> dynamo.describeTable(DescribeTableRequest.builder().tableName(table).build()), endTime); }
Example #4
Source File: DynamoDbJavaClientExceptionIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void testResourceNotFoundException() { try { ddb.describeTable(DescribeTableRequest.builder().tableName(UUID.randomUUID().toString()).build()); Assert.fail("ResourceNotFoundException is expected."); } catch (ResourceNotFoundException e) { Assert.assertNotNull(e.awsErrorDetails().errorCode()); Assert.assertNotNull(e.awsErrorDetails().errorMessage()); Assert.assertNotNull(e.awsErrorDetails().rawResponse()); } }
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: DynamoDBLeaseRefresherTest.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Test public void testLeaseTableExistsTimesOut() throws Exception { TimeoutException te = setRuleForDependencyTimeout(); when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture); when(mockDescribeTableFuture.get(anyLong(), any())).thenThrow(te); verifyCancel(mockDescribeTableFuture, () -> leaseRefresher.leaseTableExists()); }
Example #12
Source File: DynamoDBLeaseRefresherTest.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Test public void testCreateLeaseTableTimesOut() throws Exception { TimeoutException te = setRuleForDependencyTimeout(); when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture); when(mockDescribeTableFuture.get(anyLong(), any())) .thenThrow(ResourceNotFoundException.builder().message("Table doesn't exist").build()); when(dynamoDbClient.createTable(any(CreateTableRequest.class))).thenReturn(mockCreateTableFuture); when(mockCreateTableFuture.get(anyLong(), any())).thenThrow(te); verifyCancel(mockCreateTableFuture, () -> leaseRefresher.createLeaseTableIfNotExists(10L, 10L)); }
Example #13
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 #14
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 #15
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 #16
Source File: DynamoDBLockProviderIntegrationTest.java From ShedLock with Apache License 2.0 | 4 votes |
private static TableStatus getTableStatus(String lockTable) { return dynamodb.describeTable(DescribeTableRequest.builder().tableName(lockTable).build()).table().tableStatus(); }