Search in sources :

Example 1 with GetShardIteratorRequest

use of com.amazonaws.services.kinesis.model.GetShardIteratorRequest in project storm by apache.

the class KinesisConnection method getShardIterator.

String getShardIterator(String stream, String shardId, ShardIteratorType shardIteratorType, String sequenceNumber, Date timestamp) {
    String shardIterator = "";
    try {
        GetShardIteratorRequest getShardIteratorRequest = new GetShardIteratorRequest();
        getShardIteratorRequest.setStreamName(stream);
        getShardIteratorRequest.setShardId(shardId);
        getShardIteratorRequest.setShardIteratorType(shardIteratorType);
        if (shardIteratorType.equals(ShardIteratorType.AFTER_SEQUENCE_NUMBER) || shardIteratorType.equals(ShardIteratorType.AT_SEQUENCE_NUMBER)) {
            getShardIteratorRequest.setStartingSequenceNumber(sequenceNumber);
        } else if (shardIteratorType.equals(ShardIteratorType.AT_TIMESTAMP)) {
            getShardIteratorRequest.setTimestamp(timestamp);
        }
        GetShardIteratorResult getShardIteratorResult = kinesisClient.getShardIterator(getShardIteratorRequest);
        if (getShardIteratorResult != null) {
            shardIterator = getShardIteratorResult.getShardIterator();
        }
    } catch (Exception e) {
        LOG.warn("Exception occured while getting shardIterator for shard " + shardId + " shardIteratorType " + shardIteratorType + " sequence number " + sequenceNumber + " timestamp " + timestamp, e);
    }
    LOG.warn("Returning shardIterator " + shardIterator + " for shardId " + shardId + " shardIteratorType " + shardIteratorType + " sequenceNumber " + sequenceNumber + " timestamp" + timestamp);
    return shardIterator;
}
Also used : GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult)

Example 2 with GetShardIteratorRequest

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

the class SimplifiedKinesisClientTest method shouldReturnIteratorStartingWithTimestamp.

@Test
public void shouldReturnIteratorStartingWithTimestamp() throws Exception {
    Instant timestamp = Instant.now();
    given(kinesis.getShardIterator(new GetShardIteratorRequest().withStreamName(STREAM).withShardId(SHARD_1).withShardIteratorType(ShardIteratorType.AT_SEQUENCE_NUMBER).withTimestamp(timestamp.toDate()))).willReturn(new GetShardIteratorResult().withShardIterator(SHARD_ITERATOR));
    String stream = underTest.getShardIterator(STREAM, SHARD_1, ShardIteratorType.AT_SEQUENCE_NUMBER, null, timestamp);
    assertThat(stream).isEqualTo(SHARD_ITERATOR);
}
Also used : Instant(org.joda.time.Instant) GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) Test(org.junit.Test)

Example 3 with GetShardIteratorRequest

use of com.amazonaws.services.kinesis.model.GetShardIteratorRequest in project camel by apache.

the class KinesisConsumer method getShardItertor.

private String getShardItertor() {
    // either return a cached one or get a new one via a GetShardIterator request.
    if (currentShardIterator == null) {
        String shardId;
        //If ShardId supplied use it, else choose first one
        if (!getEndpoint().getShardId().isEmpty()) {
            shardId = getEndpoint().getShardId();
        } else {
            DescribeStreamRequest req1 = new DescribeStreamRequest().withStreamName(getEndpoint().getStreamName());
            DescribeStreamResult res1 = getClient().describeStream(req1);
            shardId = res1.getStreamDescription().getShards().get(0).getShardId();
        }
        LOG.debug("ShardId is: {}", shardId);
        GetShardIteratorRequest req = new GetShardIteratorRequest().withStreamName(getEndpoint().getStreamName()).withShardId(shardId).withShardIteratorType(getEndpoint().getIteratorType());
        if (hasSequenceNumber()) {
            req.withStartingSequenceNumber(getEndpoint().getSequenceNumber());
        }
        GetShardIteratorResult result = getClient().getShardIterator(req);
        currentShardIterator = result.getShardIterator();
    }
    LOG.debug("Shard Iterator is: {}", currentShardIterator);
    return currentShardIterator;
}
Also used : GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) DescribeStreamRequest(com.amazonaws.services.kinesis.model.DescribeStreamRequest) DescribeStreamResult(com.amazonaws.services.kinesis.model.DescribeStreamResult)

Example 4 with GetShardIteratorRequest

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

the class SimplifiedKinesisClientTest method shouldReturnIteratorStartingWithSequenceNumber.

@Test
public void shouldReturnIteratorStartingWithSequenceNumber() throws Exception {
    given(kinesis.getShardIterator(new GetShardIteratorRequest().withStreamName(STREAM).withShardId(SHARD_1).withShardIteratorType(ShardIteratorType.AT_SEQUENCE_NUMBER).withStartingSequenceNumber(SEQUENCE_NUMBER))).willReturn(new GetShardIteratorResult().withShardIterator(SHARD_ITERATOR));
    String stream = underTest.getShardIterator(STREAM, SHARD_1, ShardIteratorType.AT_SEQUENCE_NUMBER, SEQUENCE_NUMBER, null);
    assertThat(stream).isEqualTo(SHARD_ITERATOR);
}
Also used : GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) Test(org.junit.Test)

Example 5 with GetShardIteratorRequest

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

the class SimplifiedKinesisClientTest method shouldHandleGetShardIteratorError.

private void shouldHandleGetShardIteratorError(Exception thrownException, Class<? extends Exception> expectedExceptionClass) {
    GetShardIteratorRequest request = new GetShardIteratorRequest().withStreamName(STREAM).withShardId(SHARD_1).withShardIteratorType(ShardIteratorType.LATEST);
    given(kinesis.getShardIterator(request)).willThrow(thrownException);
    try {
        underTest.getShardIterator(STREAM, SHARD_1, ShardIteratorType.LATEST, null, null);
        failBecauseExceptionWasNotThrown(expectedExceptionClass);
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(expectedExceptionClass);
    } finally {
        reset(kinesis);
    }
}
Also used : GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) ProvisionedThroughputExceededException(com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException) LimitExceededException(com.amazonaws.services.kinesis.model.LimitExceededException) ExpiredIteratorException(com.amazonaws.services.kinesis.model.ExpiredIteratorException)

Aggregations

GetShardIteratorRequest (com.amazonaws.services.kinesis.model.GetShardIteratorRequest)5 GetShardIteratorResult (com.amazonaws.services.kinesis.model.GetShardIteratorResult)4 Test (org.junit.Test)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 DescribeStreamRequest (com.amazonaws.services.kinesis.model.DescribeStreamRequest)1 DescribeStreamResult (com.amazonaws.services.kinesis.model.DescribeStreamResult)1 ExpiredIteratorException (com.amazonaws.services.kinesis.model.ExpiredIteratorException)1 LimitExceededException (com.amazonaws.services.kinesis.model.LimitExceededException)1 ProvisionedThroughputExceededException (com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException)1 Instant (org.joda.time.Instant)1