use of com.amazonaws.services.kinesis.model.DescribeStreamResult 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.DescribeStreamResult in project camel by apache.
the class KinesisConsumerTest method setup.
@Before
public void setup() throws Exception {
KinesisEndpoint endpoint = new KinesisEndpoint(null, "streamName", component);
endpoint.setAmazonKinesisClient(kinesisClient);
endpoint.setIteratorType(ShardIteratorType.LATEST);
undertest = new KinesisConsumer(endpoint, processor);
when(kinesisClient.getRecords(any(GetRecordsRequest.class))).thenReturn(new GetRecordsResult().withNextShardIterator("nextShardIterator"));
when(kinesisClient.describeStream(any(DescribeStreamRequest.class))).thenReturn(new DescribeStreamResult().withStreamDescription(new StreamDescription().withShards(new Shard().withShardId("shardId"))));
when(kinesisClient.getShardIterator(any(GetShardIteratorRequest.class))).thenReturn(new GetShardIteratorResult().withShardIterator("shardIterator"));
}
use of com.amazonaws.services.kinesis.model.DescribeStreamResult in project beam by apache.
the class AmazonKinesisMock method describeStream.
@Override
public DescribeStreamResult describeStream(String streamName, String exclusiveStartShardId) {
int nextShardId = 0;
if (exclusiveStartShardId != null) {
nextShardId = parseInt(exclusiveStartShardId) + 1;
}
boolean hasMoreShards = nextShardId + 1 < shardedData.size();
List<Shard> shards = newArrayList();
if (nextShardId < shardedData.size()) {
shards.add(new Shard().withShardId(Integer.toString(nextShardId)));
}
return new DescribeStreamResult().withStreamDescription(new StreamDescription().withHasMoreShards(hasMoreShards).withShards(shards));
}
use of com.amazonaws.services.kinesis.model.DescribeStreamResult in project voltdb by VoltDB.
the class KinesisStreamImporterConfig method discoverShards.
/**
* connect to kinesis stream to discover the shards on the stream
*
* @param regionName The region name where the stream resides
* @param streamName The kinesis stream name
* @param accessKey The user access key
* @param secretKey The user secret key
* @param appName The name of stream application
* @return a list of shards
*/
public static List<Shard> discoverShards(String regionName, String streamName, String accessKey, String secretKey, String appName) {
try {
Region region = RegionUtils.getRegion(regionName);
if (region != null) {
final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonKinesis kinesisClient = new AmazonKinesisClient(credentials, getClientConfigWithUserAgent(appName));
kinesisClient.setRegion(region);
DescribeStreamResult result = kinesisClient.describeStream(streamName);
if (!"ACTIVE".equals(result.getStreamDescription().getStreamStatus())) {
throw new IllegalArgumentException("Kinesis stream " + streamName + " is not active.");
}
return result.getStreamDescription().getShards();
}
} catch (ResourceNotFoundException e) {
LOGGER.warn("Kinesis stream " + streamName + " does not exist.", e);
} catch (Exception e) {
LOGGER.warn("Error found while describing the kinesis stream " + streamName, e);
}
return null;
}
use of com.amazonaws.services.kinesis.model.DescribeStreamResult in project kafka-connect-kinesis by jcustenborder.
the class KinesisSourceConnector method start.
@Override
public void start(Map<String, String> settings) {
log.info("start()");
this.settings = settings;
this.config = new KinesisSourceConnectorConfig(settings);
this.kinesisClient = this.kinesisClientFactory.create(this.config);
DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest().withStreamName(this.config.kinesisStreamName);
DescribeStreamResult describeStreamResult = this.kinesisClient.describeStream(describeStreamRequest);
this.streamDescription = describeStreamResult.getStreamDescription();
}
Aggregations