software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse Java Examples

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse. 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: DynamoDBUtils.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static CompletableFuture<Boolean> retryAsync(Supplier<CompletableFuture<DescribeTableResponse>> action,
        final long endTime) {

    return action.get()
            .thenComposeAsync(result -> {
                if (result.table().tableStatus() == TableStatus.ACTIVE) {
                    return CompletableFuture.completedFuture(true);
                } else {
                    try {
                        Thread.sleep(DEFAULT_WAIT_INTERVAL);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                    LOG.info("Async table - Retry table created status");
                    if (System.currentTimeMillis() < endTime) {
                        return retryAsync(action, endTime);
                    } else {
                        return CompletableFuture.completedFuture(false);
                    }
                }
            });
}
 
Example #2
Source File: AWSDynamoUtils.java    From para with Apache License 2.0 6 votes vote down vote up
private static void waitForActive(String table) throws InterruptedException {
	int attempts = 0;
	boolean active = false;
	int	tries = 30;
	int sleep = 2000;
	while (attempts < tries) {
		DescribeTableResponse result = getClient().describeTable(b -> b.tableName(table));
		if (result.table().tableStatus().equals(TableStatus.ACTIVE)) {
			active = true;
			break;
		}
		Thread.sleep(sleep);
		attempts++;
	}
	if (!active) {
		logger.warn("DynamoDB table {} did not become active within {}s!", table, ((tries * sleep) / 1000));
	}
}
 
Example #3
Source File: AWSDynamoUtils.java    From para with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the main table exists in the database.
 * @param appid name of the {@link com.erudika.para.core.App}
 * @return true if the table exists
 */
public static boolean existsTable(String appid) {
	if (StringUtils.isBlank(appid)) {
		return false;
	}
	try {
		DescribeTableResponse res = getClient().describeTable(b -> b.tableName(getTableNameForAppid(appid)));
		return res != null;
	} catch (Exception e) {
		return false;
	}
}
 
Example #4
Source File: AWSDynamoUtils.java    From para with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Index object for the shared table.
 * @return the Index object or null
 */
public static GlobalSecondaryIndexDescription getSharedGlobalIndex() {
	try {
		DescribeTableResponse t = getClient().describeTable(b -> b.tableName(getTableNameForAppid(SHARED_TABLE)));
		return t.table().globalSecondaryIndexes().stream().
				filter(gsi -> gsi.indexName().equals(getSharedIndexName())).findFirst().orElse(null);
	} catch (Exception e) {
		logger.info("Could not get shared index: {}.", e.getMessage());
	}
	return null;
}
 
Example #5
Source File: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: AwsDynamoDbScannerTest.java    From clouditor with Apache License 2.0 4 votes vote down vote up
@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());
      });
}