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;
}
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);
}
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;
}
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);
}
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);
}
}
Aggregations