Example usage for com.amazonaws.services.kinesis.model StreamDescription StreamDescription

List of usage examples for com.amazonaws.services.kinesis.model StreamDescription StreamDescription

Introduction

In this page you can find the example usage for com.amazonaws.services.kinesis.model StreamDescription StreamDescription.

Prototype

StreamDescription

Source Link

Usage

From source file:com.facebook.presto.kinesis.util.MockKinesisClient.java

License:Apache License

@Override
public DescribeStreamResult describeStream(DescribeStreamRequest describeStreamRequest)
        throws AmazonServiceException, AmazonClientException {
    InternalStream theStream = this.getStream(describeStreamRequest.getStreamName());
    if (theStream != null) {
        StreamDescription desc = new StreamDescription();
        desc = desc.withStreamName(theStream.getStreamName()).withStreamStatus(theStream.getStreamStatus())
                .withStreamARN(theStream.getStreamARN());

        if (describeStreamRequest.getExclusiveStartShardId() == null
                || describeStreamRequest.getExclusiveStartShardId().isEmpty()) {
            desc.setShards(this.getShards(theStream));
            desc.setHasMoreShards(false);
        } else {// w  ww . j  a  v  a 2  s. c o m
            // Filter from given shard Id, or may not have any more
            String startId = describeStreamRequest.getExclusiveStartShardId();
            desc.setShards(this.getShards(theStream, startId));
            desc.setHasMoreShards(false);
        }

        DescribeStreamResult result = new DescribeStreamResult();
        result = result.withStreamDescription(desc);
        return result;
    } else {
        throw new AmazonClientException("This stream does not exist!");
    }
}

From source file:org.apache.beam.sdk.io.kinesis.AmazonKinesisMock.java

License:Apache License

@Override
public DescribeStreamResult describeStream(String streamName, String exclusiveStartShardId) {
    int nextShardId = 0;
    if (exclusiveStartShardId != null) {
        nextShardId = parseInt(exclusiveStartShardId) + 1;
    }/*from  www  . j  av  a 2  s .  com*/
    boolean hasMoreShards = nextShardId + 1 < shardedData.size();

    List<Shard> shards = new ArrayList<>();
    if (nextShardId < shardedData.size()) {
        shards.add(new Shard().withShardId(Integer.toString(nextShardId)));
    }

    HttpResponse response = new HttpResponse(null, null);
    response.setStatusCode(200);
    DescribeStreamResult result = new DescribeStreamResult();
    result.setSdkHttpMetadata(SdkHttpMetadata.from(response));
    result.withStreamDescription(new StreamDescription().withHasMoreShards(hasMoreShards).withShards(shards)
            .withStreamName(streamName));
    return result;
}