Search in sources :

Example 6 with DescribeStreamResult

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;
}
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 7 with DescribeStreamResult

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"));
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) StreamDescription(com.amazonaws.services.kinesis.model.StreamDescription) 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) Shard(com.amazonaws.services.kinesis.model.Shard) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest) Before(org.junit.Before)

Example 8 with DescribeStreamResult

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));
}
Also used : StreamDescription(com.amazonaws.services.kinesis.model.StreamDescription) Shard(com.amazonaws.services.kinesis.model.Shard) DescribeStreamResult(com.amazonaws.services.kinesis.model.DescribeStreamResult)

Example 9 with DescribeStreamResult

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;
}
Also used : AmazonKinesisClient(com.amazonaws.services.kinesis.AmazonKinesisClient) Region(com.amazonaws.regions.Region) DescribeStreamResult(com.amazonaws.services.kinesis.model.DescribeStreamResult) ResourceNotFoundException(com.amazonaws.services.kinesis.model.ResourceNotFoundException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ResourceNotFoundException(com.amazonaws.services.kinesis.model.ResourceNotFoundException) AmazonKinesis(com.amazonaws.services.kinesis.AmazonKinesis)

Example 10 with DescribeStreamResult

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();
}
Also used : DescribeStreamRequest(com.amazonaws.services.kinesis.model.DescribeStreamRequest) DescribeStreamResult(com.amazonaws.services.kinesis.model.DescribeStreamResult)

Aggregations

DescribeStreamResult (com.amazonaws.services.kinesis.model.DescribeStreamResult)15 DescribeStreamRequest (com.amazonaws.services.kinesis.model.DescribeStreamRequest)9 Shard (com.amazonaws.services.kinesis.model.Shard)8 StreamDescription (com.amazonaws.services.kinesis.model.StreamDescription)4 ArrayList (java.util.ArrayList)4 AmazonKinesis (com.amazonaws.services.kinesis.AmazonKinesis)3 GetShardIteratorRequest (com.amazonaws.services.kinesis.model.GetShardIteratorRequest)3 GetShardIteratorResult (com.amazonaws.services.kinesis.model.GetShardIteratorResult)3 ResourceNotFoundException (com.amazonaws.services.kinesis.model.ResourceNotFoundException)3 LimitExceededException (com.amazonaws.services.kinesis.model.LimitExceededException)2 Properties (java.util.Properties)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)2 Configuration (org.apache.flink.configuration.Configuration)2 MiniClusterResource (org.apache.flink.runtime.testutils.MiniClusterResource)2 MiniClusterResourceConfiguration (org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration)2 ExactlyOnceValidatingConsumerThread (org.apache.flink.streaming.connectors.kinesis.testutils.ExactlyOnceValidatingConsumerThread)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 Region (com.amazonaws.regions.Region)1