Search in sources :

Example 1 with ListStreamsResult

use of com.amazonaws.services.dynamodbv2.model.ListStreamsResult in project camel by apache.

the class ShardIteratorHandler method getShardIterator.

String getShardIterator(String resumeFromSequenceNumber) {
    ShardIteratorType iteratorType = getEndpoint().getIteratorType();
    String sequenceNumber = getEndpoint().getSequenceNumber();
    if (resumeFromSequenceNumber != null) {
        // Reset things as we're in an error condition.
        currentShard = null;
        currentShardIterator = null;
        iteratorType = ShardIteratorType.AFTER_SEQUENCE_NUMBER;
        sequenceNumber = resumeFromSequenceNumber;
    }
    // either return a cached one or get a new one via a GetShardIterator request.
    if (currentShardIterator == null) {
        ListStreamsResult streamsListResult = getClient().listStreams(new ListStreamsRequest().withTableName(getEndpoint().getTableName()));
        // XXX assumes there is only one stream
        final String streamArn = streamsListResult.getStreams().get(0).getStreamArn();
        DescribeStreamResult streamDescriptionResult = getClient().describeStream(new DescribeStreamRequest().withStreamArn(streamArn));
        shardList.addAll(streamDescriptionResult.getStreamDescription().getShards());
        LOG.trace("Current shard is: {} (in {})", currentShard, shardList);
        if (currentShard == null) {
            currentShard = resolveNewShard(iteratorType, resumeFromSequenceNumber);
        } else {
            currentShard = shardList.nextAfter(currentShard);
        }
        shardList.removeOlderThan(currentShard);
        LOG.trace("Next shard is: {} (in {})", currentShard, shardList);
        GetShardIteratorResult result = getClient().getShardIterator(buildGetShardIteratorRequest(streamArn, iteratorType, sequenceNumber));
        currentShardIterator = result.getShardIterator();
    }
    LOG.trace("Shard Iterator is: {}", currentShardIterator);
    return currentShardIterator;
}
Also used : ShardIteratorType(com.amazonaws.services.dynamodbv2.model.ShardIteratorType) ListStreamsResult(com.amazonaws.services.dynamodbv2.model.ListStreamsResult) GetShardIteratorResult(com.amazonaws.services.dynamodbv2.model.GetShardIteratorResult) ListStreamsRequest(com.amazonaws.services.dynamodbv2.model.ListStreamsRequest) DescribeStreamResult(com.amazonaws.services.dynamodbv2.model.DescribeStreamResult) DescribeStreamRequest(com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest)

Example 2 with ListStreamsResult

use of com.amazonaws.services.dynamodbv2.model.ListStreamsResult in project camel by apache.

the class ShardIteratorHandlerTest method setup.

@Before
public void setup() throws Exception {
    endpoint.setAmazonDynamoDbStreamsClient(amazonDynamoDBStreams);
    undertest = new ShardIteratorHandler(endpoint);
    when(amazonDynamoDBStreams.listStreams(any(ListStreamsRequest.class))).thenReturn(new ListStreamsResult().withStreams(new Stream().withStreamArn("arn:aws:dynamodb:region:12345:table/table_name/stream/timestamp")));
    when(amazonDynamoDBStreams.describeStream(any(DescribeStreamRequest.class))).thenReturn(new DescribeStreamResult().withStreamDescription(new StreamDescription().withTableName("table_name").withShards(ShardListTest.createShardsWithSequenceNumbers(null, "a", "1", "5", "b", "8", "15", "c", "16", "16", "d", "20", null))));
    when(amazonDynamoDBStreams.getShardIterator(any(GetShardIteratorRequest.class))).thenAnswer(new Answer<GetShardIteratorResult>() {

        @Override
        public GetShardIteratorResult answer(InvocationOnMock invocation) throws Throwable {
            return new GetShardIteratorResult().withShardIterator("shard_iterator_" + ((GetShardIteratorRequest) invocation.getArguments()[0]).getShardId() + "_000");
        }
    });
}
Also used : GetShardIteratorRequest(com.amazonaws.services.dynamodbv2.model.GetShardIteratorRequest) ListStreamsRequest(com.amazonaws.services.dynamodbv2.model.ListStreamsRequest) DescribeStreamRequest(com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest) StreamDescription(com.amazonaws.services.dynamodbv2.model.StreamDescription) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ListStreamsResult(com.amazonaws.services.dynamodbv2.model.ListStreamsResult) GetShardIteratorResult(com.amazonaws.services.dynamodbv2.model.GetShardIteratorResult) Stream(com.amazonaws.services.dynamodbv2.model.Stream) DescribeStreamResult(com.amazonaws.services.dynamodbv2.model.DescribeStreamResult) Before(org.junit.Before)

Aggregations

DescribeStreamRequest (com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest)2 DescribeStreamResult (com.amazonaws.services.dynamodbv2.model.DescribeStreamResult)2 GetShardIteratorResult (com.amazonaws.services.dynamodbv2.model.GetShardIteratorResult)2 ListStreamsRequest (com.amazonaws.services.dynamodbv2.model.ListStreamsRequest)2 ListStreamsResult (com.amazonaws.services.dynamodbv2.model.ListStreamsResult)2 GetShardIteratorRequest (com.amazonaws.services.dynamodbv2.model.GetShardIteratorRequest)1 ShardIteratorType (com.amazonaws.services.dynamodbv2.model.ShardIteratorType)1 Stream (com.amazonaws.services.dynamodbv2.model.Stream)1 StreamDescription (com.amazonaws.services.dynamodbv2.model.StreamDescription)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1