@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeStreamResult == false) return false; DescribeStreamResult other = (DescribeStreamResult) obj; if (other.getStreamDescription() == null ^ this.getStreamDescription() == null) return false; if (other.getStreamDescription() != null && other.getStreamDescription().equals(this.getStreamDescription()) == false) return false; return true; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getStreamDescription() == null) ? 0 : getStreamDescription().hashCode()); return hashCode; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getStreamDescription() != null) sb.append("StreamDescription: ").append(getStreamDescription()); sb.append("}"); return sb.toString(); }
@Override public Set<String> getPartitionIds(String stream) { checkIfClosed(); return kinesis.describeStream(stream) .getStreamDescription() .getShards() .stream() .map(Shard::getShardId).collect(Collectors.toSet()); }
List<Shard> getShardsForStream (String stream) { DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(stream); List<Shard> shards = new ArrayList<>(); String exclusiveStartShardId = null; do { describeStreamRequest.setExclusiveStartShardId(exclusiveStartShardId); DescribeStreamResult describeStreamResult = kinesisClient.describeStream(describeStreamRequest); shards.addAll(describeStreamResult.getStreamDescription().getShards()); if (describeStreamResult.getStreamDescription().getHasMoreShards() && shards.size() > 0) { exclusiveStartShardId = shards.get(shards.size() - 1).getShardId(); } else { exclusiveStartShardId = null; } } while ( exclusiveStartShardId != null ); LOG.info("Number of shards for stream " + stream + " are " + shards.size()); return shards; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeStreamResult == false) return false; DescribeStreamResult other = (DescribeStreamResult) obj; if (other.getStreamDescription() == null ^ this.getStreamDescription() == null) return false; if (other.getStreamDescription() != null && other.getStreamDescription().equals(this.getStreamDescription()) == false) return false; return true; } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getStreamDescription() == null) ? 0 : getStreamDescription().hashCode()); return hashCode; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getStreamDescription() != null) sb.append("StreamDescription: " + getStreamDescription()); sb.append("}"); return sb.toString(); }
/** * Return the state of a Amazon Kinesis stream. * * @param kinesisClient The {@link com.amazonaws.services.kinesis.AmazonKinesisClient} with Amazon Kinesis read privileges * @param streamName The Amazon Kinesis stream to get the state of * @return String representation of the Stream state */ private static String streamState(AmazonKinesisClient kinesisClient, String streamName) { DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); try { return kinesisClient.describeStream(describeStreamRequest).getStreamDescription().getStreamStatus(); } catch (AmazonServiceException e) { return null; } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeStreamResult == false) return false; DescribeStreamResult other = (DescribeStreamResult) obj; if (other.getStreamDescription() == null ^ this.getStreamDescription() == null) return false; if (other.getStreamDescription() != null && other.getStreamDescription().equals(this.getStreamDescription()) == false) return false; return true; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getStreamDescription() == null) ? 0 : getStreamDescription().hashCode()); return hashCode; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getStreamDescription() != null) sb.append("StreamDescription: ").append(getStreamDescription()); sb.append("}"); return sb.toString(); }
@Override public void startStream() { this.streamNames = this.config.getStreams(); for (final String stream : streamNames) { DescribeStreamResult describeStreamResult = client.describeStream(stream); if( "ACTIVE".equals(describeStreamResult.getStreamDescription().getStreamStatus())) { List<Shard> shardList = describeStreamResult.getStreamDescription().getShards(); for( Shard shard : shardList ) { executor.submit(new KinesisPersistReaderTask(this, stream, shard.getShardId())); } } } }
public List<Shard> listShards(final String streamName) throws TransientKinesisException { return wrapExceptions( () -> { List<Shard> shards = Lists.newArrayList(); String lastShardId = null; StreamDescription description; do { description = kinesis.describeStream(streamName, lastShardId).getStreamDescription(); shards.addAll(description.getShards()); lastShardId = shards.get(shards.size() - 1).getShardId(); } while (description.getHasMoreShards()); return shards; }); }
private void scanStream(String name) { rateLimit(); com.amazonaws.services.kinesis.model.DescribeStreamResult result = getClient().describeStream(name); StreamDescription description = result.getStreamDescription(); project(description); } private void project(StreamDescription description) {
/** * Get the available shards from the kinesis * @param streamName Name of the stream from where the shards to be accessed * @return the list of shards from the given stream */ public List<Shard> getShardList(String streamName) { assert client != null : "Illegal client"; DescribeStreamRequest describeRequest = new DescribeStreamRequest(); describeRequest.setStreamName(streamName); DescribeStreamResult describeResponse = client.describeStream(describeRequest); return describeResponse.getStreamDescription().getShards(); }
/** * Get the available shards from the kinesis * @param streamName Name of the stream from where the shards to be accessed * @return the list of shards from the given stream */ public List<Shard> getShardList(String streamName) { assert client != null:"Illegal client"; DescribeStreamRequest describeRequest = new DescribeStreamRequest(); describeRequest.setStreamName(streamName); DescribeStreamResult describeResponse = client.describeStream(describeRequest); return describeResponse.getStreamDescription().getShards(); }
@Override public String get() { return getKinesisClient().describeStream(getStreamName()).getStreamDescription().getStreamARN(); }
@Override public ImmutableSortedMap<String, ShardInfo> getShardList() { Map<String, ShardInfo> spoutShards = new HashMap<>(); DescribeStreamRequest input = new DescribeStreamRequest(); DescribeStreamResult out; input.setStreamName(streamName); input.setLimit(DESCRIBE_STREAM_LIMIT); out = getDescribeStreamResult(input); while (true) { String lastShard = addTruncatedShardList(spoutShards, out.getStreamDescription().getShards()); // If we have finished processing all the shards, we can stop looping if (!out.getStreamDescription().isHasMoreShards()) { break; } LOG.debug("There are more shards in the stream, continue paginated calls."); input.setExclusiveStartShardId(lastShard); out = getDescribeStreamResult(input); } return ImmutableSortedMap.copyOf(spoutShards, SHARD_ID_COMPARATOR); }
/** * Return the state of a Amazon Kinesis stream. * * @param kinesisClient * The {@link com.amazonaws.services.kinesis.AmazonKinesisClient} with Amazon Kinesis read privileges * @param streamName * The Amazon Kinesis stream to get the state of * @return String representation of the Stream state */ private static String streamState(AmazonKinesisClient kinesisClient, String streamName) { DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); try { return kinesisClient.describeStream(describeStreamRequest).getStreamDescription().getStreamStatus(); } catch (AmazonServiceException e) { return null; } }