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

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.ListTablesResponse. 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: DynamoDBAsync.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    // Creates a default async client with credentials and regions loaded from the environment
    DynamoDbAsyncClient client = DynamoDbAsyncClient.create();
    CompletableFuture<ListTablesResponse> response = client.listTables(ListTablesRequest.builder()
                                                                                        .build());

    // Map the response to another CompletableFuture containing just the table names
    CompletableFuture<List<String>> tableNames = response.thenApply(ListTablesResponse::tableNames);
    // When future is complete (either successfully or in error) handle the response
    tableNames.whenComplete((tables, err) -> {
        try {
        	if (tables != null) {
                tables.forEach(System.out::println);
            } else {
                // Handle error
                err.printStackTrace();
            }
        } finally {
            // Lets the application shut down. Only close the client when you are completely done with it.
            client.close();
        }
    });

    tableNames.join();
}
 
Example #2
Source File: AsyncPagination.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
private static void useThirdPartySubscriber() {
    // snippet-start:[dynamodb.java2.async_pagination.async]
    System.out.println("running AutoPagination - using third party subscriber...\n");

    DynamoDbAsyncClient asyncClient = DynamoDbAsyncClient.create();
    ListTablesPublisher publisher = asyncClient.listTablesPaginator(ListTablesRequest.builder()
                                                                                     .build());

    // The Flowable class has many helper methods that work with any reactive streams compatible publisher implementation
    List<String> tables = Flowable.fromPublisher(publisher)
                                  .flatMapIterable(ListTablesResponse::tableNames)
                                  .toList()
                                  .blockingGet();
    System.out.println(tables);
    
    // snippet-end:[dynamodb.java2.async_pagination.async]
}
 
Example #3
Source File: SyncPagination.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void manualPagination(DynamoDbClient client) {
    System.out.println("running ManualPagination...\n");

    ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build();
    boolean done = false;
    while (!done) {
        ListTablesResponse listTablesResponse = client.listTables(listTablesRequest);
        System.out.println(listTablesResponse.tableNames());

        if (listTablesResponse.lastEvaluatedTableName() == null) {
            done = true;
        }

        listTablesRequest = listTablesRequest.toBuilder()
                .exclusiveStartTableName(listTablesResponse.lastEvaluatedTableName())
                .build();
    }
}
 
Example #4
Source File: SyncPagination.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void autoPaginationWithResume(DynamoDbClient client) {

        System.out.println("running AutoPagination with resume in case of errors...\n");
        ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build();
        ListTablesIterable responses = client.listTablesPaginator(listTablesRequest);

        ListTablesResponse lastSuccessfulPage = null;
        try {
            for (ListTablesResponse response : responses) {
                response.tableNames().forEach(System.out::println);
                lastSuccessfulPage = response;
            }
        } catch (DynamoDbException exception) {
            if (lastSuccessfulPage != null) {
                System.out.println(exception.getMessage());
            }
        }
    }
 
Example #5
Source File: DynamoDBIOTestHelper.java    From beam with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: AWSDynamoUtils.java    From para with Apache License 2.0 6 votes vote down vote up
/**
 * Lists all table names for this account.
 * @return a list of DynamoDB tables
 */
public static List<String> listAllTables() {
	int items = 100;
	ListTablesResponse ltr = getClient().listTables(b -> b.limit(items));
	List<String> tables = new LinkedList<>();
	do {
		tables.addAll(ltr.tableNames());
		logger.info("Found {} tables. Total found: {}.", ltr.tableNames().size(), tables.size());
		if (ltr.lastEvaluatedTableName() == null) {
			break;
		}
		final String lastKey = ltr.lastEvaluatedTableName();
		ltr = getClient().listTables(b -> b.limit(items).exclusiveStartTableName(lastKey));
	} while (!ltr.tableNames().isEmpty());
	return tables;
}
 
Example #7
Source File: DynamoDBIntegrationTestBase.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Quick utility method to delete all tables when we have too much capacity
 * reserved for the region.
 */
public static void deleteAllTables() {
    ListTablesResponse listTables = dynamo.listTables(ListTablesRequest.builder().build());
    for (String name : listTables.tableNames()) {
        dynamo.deleteTable(DeleteTableRequest.builder().tableName(name).build());
    }
}
 
Example #8
Source File: AsyncPagination.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
private static void useThirdPartySubscriber_Reactor() {
    System.out.println("running AutoPagination - using third party subscriber...\n");

    DynamoDbAsyncClient asyncClient = DynamoDbAsyncClient.create();
    ListTablesPublisher publisher = asyncClient.listTablesPaginator(ListTablesRequest.builder()
                                                                                     .build());

    // The Flux class has many helper methods that work with any reactive streams compatible publisher implementation
    List<String> tables = Flux.from(publisher)
                              .flatMapIterable(ListTablesResponse::tableNames)
                              .collectList()
                              .block();
    System.out.println(tables);
}
 
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());
      });
}
 
Example #10
Source File: BaseResultIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Test
public void responseMetadataInBaseResultIsSameAsMetadataCache() {
    ListTablesRequest request = ListTablesRequest.builder().build();
    ListTablesResponse result = dynamoDB.listTables(request);
    assertThat(result.sdkHttpResponse().headers()).isNotNull();
}
 
Example #11
Source File: BaseResultIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Test
public void httpMetadataInBaseResultIsValid() {
    ListTablesResponse result = dynamoDB.listTables(ListTablesRequest.builder().build());
    assertThat(result.sdkHttpResponse().statusCode()).isEqualTo(200);
    assertThat(result.sdkHttpResponse().headers()).containsKey("x-amz-crc32");
}