Search in sources :

Example 11 with ListShardsRequest

use of com.amazonaws.services.kinesis.model.ListShardsRequest in project hazelcast by hazelcast.

the class RangeMonitor method listAllShardsRequest.

public static ListShardsRequest listAllShardsRequest(String stream, @Nullable String nextToken, ShardFilterType filterType) {
    ListShardsRequest request = new ListShardsRequest();
    if (nextToken == null) {
        request.setStreamName(stream);
    } else {
        request.setNextToken(nextToken);
    }
    // include all the shards within the retention period of the data stream
    request.setShardFilter(new ShardFilter().withType(filterType));
    return request;
}
Also used : ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ShardFilter(com.amazonaws.services.kinesis.model.ShardFilter)

Example 12 with ListShardsRequest

use of com.amazonaws.services.kinesis.model.ListShardsRequest in project hazelcast by hazelcast.

the class RangeMonitor method listAllShardsAsync.

private Future<ListShardsResult> listAllShardsAsync(String nextToken) {
    ShardFilterType filterType = ShardFilterType.FROM_TRIM_HORIZON;
    // all shards within the retention period (including closed, excluding expired)
    ListShardsRequest request = listAllShardsRequest(streamName, nextToken, filterType);
    return kinesis.listShardsAsync(request);
}
Also used : ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ShardFilterType(com.amazonaws.services.kinesis.model.ShardFilterType)

Example 13 with ListShardsRequest

use of com.amazonaws.services.kinesis.model.ListShardsRequest in project druid by druid-io.

the class KinesisRecordSupplier method getShards.

/**
 * Use the API listShards which is the recommended way instead of describeStream
 * listShards can return 1000 shards per call and has a limit of 100TPS
 * This makes the method resilient to LimitExceeded exceptions (compared to 100 shards, 10 TPS of describeStream)
 *
 * @param stream name of stream
 * @return Immutable set of shards
 */
public Set<Shard> getShards(String stream) {
    ImmutableSet.Builder<Shard> shards = ImmutableSet.builder();
    ListShardsRequest request = new ListShardsRequest().withStreamName(stream);
    while (true) {
        ListShardsResult result = kinesis.listShards(request);
        shards.addAll(result.getShards());
        String nextToken = result.getNextToken();
        if (nextToken == null) {
            return shards.build();
        }
        request = new ListShardsRequest().withNextToken(nextToken);
    }
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ImmutableSet(com.google.common.collect.ImmutableSet) Shard(com.amazonaws.services.kinesis.model.Shard)

Example 14 with ListShardsRequest

use of com.amazonaws.services.kinesis.model.ListShardsRequest in project beam by apache.

the class SimplifiedKinesisClientTest method shouldListAllShardsForExclusiveStartShardId.

@Test
public void shouldListAllShardsForExclusiveStartShardId() throws Exception {
    Shard shard1 = new Shard().withShardId(SHARD_1);
    Shard shard2 = new Shard().withShardId(SHARD_2);
    Shard shard3 = new Shard().withShardId(SHARD_3);
    String exclusiveStartShardId = "exclusiveStartShardId";
    when(kinesis.listShards(new ListShardsRequest().withStreamName(STREAM).withMaxResults(1_000).withShardFilter(new ShardFilter().withType(ShardFilterType.AFTER_SHARD_ID).withShardId(exclusiveStartShardId)))).thenReturn(new ListShardsResult().withShards(shard1, shard2, shard3).withNextToken(null));
    List<Shard> shards = underTest.listShardsFollowingClosedShard(STREAM, exclusiveStartShardId);
    assertThat(shards).containsOnly(shard1, shard2, shard3);
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ShardFilter(com.amazonaws.services.kinesis.model.ShardFilter) Shard(com.amazonaws.services.kinesis.model.Shard) Test(org.junit.Test)

Example 15 with ListShardsRequest

use of com.amazonaws.services.kinesis.model.ListShardsRequest in project beam by apache.

the class SimplifiedKinesisClientTest method shouldListAllShardsForTrimHorizonWithPagedResults.

@Test
public void shouldListAllShardsForTrimHorizonWithPagedResults() throws Exception {
    Shard shard1 = new Shard().withShardId(SHARD_1);
    Shard shard2 = new Shard().withShardId(SHARD_2);
    Shard shard3 = new Shard().withShardId(SHARD_3);
    ShardFilter shardFilter = new ShardFilter().withType(ShardFilterType.AT_TRIM_HORIZON);
    String nextListShardsToken = "testNextToken";
    when(kinesis.listShards(new ListShardsRequest().withStreamName(STREAM).withShardFilter(shardFilter).withMaxResults(1_000))).thenReturn(new ListShardsResult().withShards(shard1, shard2).withNextToken(nextListShardsToken));
    when(kinesis.listShards(new ListShardsRequest().withMaxResults(1_000).withShardFilter(shardFilter).withNextToken(nextListShardsToken))).thenReturn(new ListShardsResult().withShards(shard3).withNextToken(null));
    List<Shard> shards = underTest.listShardsAtPoint(STREAM, new StartingPoint(InitialPositionInStream.TRIM_HORIZON));
    assertThat(shards).containsOnly(shard1, shard2, shard3);
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ShardFilter(com.amazonaws.services.kinesis.model.ShardFilter) Shard(com.amazonaws.services.kinesis.model.Shard) Test(org.junit.Test)

Aggregations

ListShardsRequest (com.amazonaws.services.kinesis.model.ListShardsRequest)18 ListShardsResult (com.amazonaws.services.kinesis.model.ListShardsResult)15 Shard (com.amazonaws.services.kinesis.model.Shard)14 Test (org.junit.Test)10 ShardFilter (com.amazonaws.services.kinesis.model.ShardFilter)9 DescribeStreamSummaryRequest (com.amazonaws.services.kinesis.model.DescribeStreamSummaryRequest)5 DescribeStreamSummaryResult (com.amazonaws.services.kinesis.model.DescribeStreamSummaryResult)5 Instant (org.joda.time.Instant)5 StreamDescriptionSummary (com.amazonaws.services.kinesis.model.StreamDescriptionSummary)4 Datapoint (com.amazonaws.services.cloudwatch.model.Datapoint)3 LimitExceededException (com.amazonaws.services.kinesis.model.LimitExceededException)3 AmazonKinesis (com.amazonaws.services.kinesis.AmazonKinesis)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)1 ResponseMetadata (com.amazonaws.ResponseMetadata)1 SdkClientException (com.amazonaws.SdkClientException)1 HttpResponse (com.amazonaws.http.HttpResponse)1 SdkHttpMetadata (com.amazonaws.http.SdkHttpMetadata)1 Region (com.amazonaws.regions.Region)1 AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)1