com.amazonaws.services.kinesis.model.DescribeStreamRequest Java Examples
The following examples show how to use
com.amazonaws.services.kinesis.model.DescribeStreamRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KinesisStreamProvisionerTests.java From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 | 6 votes |
@Test void testProvisionProducerSuccessfulWithExistingStream() { AmazonKinesis amazonKinesisMock = mock(AmazonKinesis.class); KinesisBinderConfigurationProperties binderProperties = new KinesisBinderConfigurationProperties(); KinesisStreamProvisioner provisioner = new KinesisStreamProvisioner( amazonKinesisMock, binderProperties); ExtendedProducerProperties<KinesisProducerProperties> extendedProducerProperties = new ExtendedProducerProperties<>(new KinesisProducerProperties()); String name = "test-stream"; DescribeStreamResult describeStreamResult = describeStreamResultWithShards( Collections.singletonList(new Shard())); when(amazonKinesisMock.describeStream(any(DescribeStreamRequest.class))) .thenReturn(describeStreamResult); ProducerDestination destination = provisioner.provisionProducerDestination(name, extendedProducerProperties); verify(amazonKinesisMock).describeStream(any(DescribeStreamRequest.class)); assertThat(destination.getName()).isEqualTo(name); }
Example #2
Source File: MockKinesisClient.java From presto with Apache License 2.0 | 5 votes |
@Override public DescribeStreamResult describeStream(DescribeStreamRequest describeStreamRequest) throws AmazonClientException { InternalStream theStream = this.getStream(describeStreamRequest.getStreamName()); if (theStream == null) { throw new AmazonClientException("This stream does not exist!"); } StreamDescription desc = new StreamDescription(); desc = desc.withStreamName(theStream.getStreamName()).withStreamStatus(theStream.getStreamStatus()).withStreamARN(theStream.getStreamAmazonResourceName()); if (describeStreamRequest.getExclusiveStartShardId() == null || describeStreamRequest.getExclusiveStartShardId().isEmpty()) { desc.setShards(this.getShards(theStream)); desc.setHasMoreShards(false); } else { // 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; }
Example #3
Source File: KinesisUtils.java From amazon-kinesis-connectors with Apache License 2.0 | 5 votes |
/** * Return the state of a Amazon Kinesis stream. * * @param kinesisClient * The {@link 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; } }
Example #4
Source File: KinesisUtils.java From amazon-kinesis-connectors with Apache License 2.0 | 5 votes |
/** * Helper method to determine if an Amazon Kinesis stream exists. * * @param kinesisClient * The {@link AmazonKinesisClient} with Amazon Kinesis read privileges * @param streamName * The Amazon Kinesis stream to check for * @return true if the Amazon Kinesis stream exists, otherwise return false */ private static boolean streamExists(AmazonKinesisClient kinesisClient, String streamName) { DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); try { kinesisClient.describeStream(describeStreamRequest); return true; } catch (ResourceNotFoundException e) { return false; } }
Example #5
Source File: KinesisUtils.java From wildfly-camel with Apache License 2.0 | 5 votes |
public static void createStream(AmazonKinesisClient client, String streamName) throws Exception { client.createStream(streamName, 1); Waiter<DescribeStreamRequest> waiter = client.waiters().streamExists(); DescribeStreamRequest request = new DescribeStreamRequest().withStreamName(streamName); Assert.assertNotNull("Cannot obtain stream description", request); Future<Void> future = waiter.runAsync(new WaiterParameters<DescribeStreamRequest>(request), new NoOpWaiterHandler()); future.get(1, TimeUnit.MINUTES); }
Example #6
Source File: KinesisProxy.java From flink with Apache License 2.0 | 5 votes |
/** * Get metainfo for a Kinesis stream, which contains information about which shards this * Kinesis stream possess. * * <p>This method is using a "full jitter" approach described in AWS's article, * <a href="https://www.awsarchitectureblog.com/2015/03/backoff.html"> * "Exponential Backoff and Jitter"</a>. * This is necessary because concurrent calls will be made by all parallel subtask's fetcher. * This jitter backoff approach will help distribute calls across the fetchers over time. * * @param streamName the stream to describe * @param startShardId which shard to start with for this describe operation * * @return the result of the describe stream operation */ protected DescribeStreamResult describeStream(String streamName, @Nullable String startShardId) throws InterruptedException { final DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); describeStreamRequest.setExclusiveStartShardId(startShardId); DescribeStreamResult describeStreamResult = null; // Call DescribeStream, with full-jitter backoff (if we get LimitExceededException). int attemptCount = 0; while (describeStreamResult == null) { // retry until we get a result try { describeStreamResult = kinesisClient.describeStream(describeStreamRequest); } catch (LimitExceededException le) { long backoffMillis = fullJitterBackoff( describeStreamBaseBackoffMillis, describeStreamMaxBackoffMillis, describeStreamExpConstant, attemptCount++); LOG.warn(String.format("Got LimitExceededException when describing stream %s. " + "Backing off for %d millis.", streamName, backoffMillis)); Thread.sleep(backoffMillis); } catch (ResourceNotFoundException re) { throw new RuntimeException("Error while getting stream details", re); } } String streamStatus = describeStreamResult.getStreamDescription().getStreamStatus(); if (!(streamStatus.equals(StreamStatus.ACTIVE.toString()) || streamStatus.equals(StreamStatus.UPDATING.toString()))) { if (LOG.isWarnEnabled()) { LOG.warn(String.format("The status of stream %s is %s ; result of the current " + "describeStream operation will not contain any shard information.", streamName, streamStatus)); } } return describeStreamResult; }
Example #7
Source File: KinesisUtils.java From aws-big-data-blog with Apache License 2.0 | 5 votes |
/** * Return the state of a Amazon Kinesis stream. * * @param kinesisClient * The {@link 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; } }
Example #8
Source File: KinesisUtils.java From aws-big-data-blog with Apache License 2.0 | 5 votes |
/** * Helper method to determine if an Amazon Kinesis stream exists. * * @param kinesisClient * The {@link AmazonKinesisClient} with Amazon Kinesis read privileges * @param streamName * The Amazon Kinesis stream to check for * @return true if the Amazon Kinesis stream exists, otherwise return false */ private static boolean streamExists(AmazonKinesisClient kinesisClient, String streamName) { DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); try { kinesisClient.describeStream(describeStreamRequest); return true; } catch (ResourceNotFoundException e) { return false; } }
Example #9
Source File: EmbeddedKinesisStream.java From presto-kinesis with Apache License 2.0 | 5 votes |
private String checkStreamStatus(String streamName) { DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); StreamDescription streamDescription = amazonKinesisClient.describeStream(describeStreamRequest).getStreamDescription(); return streamDescription.getStreamStatus(); }
Example #10
Source File: MockKinesisClient.java From presto-kinesis with Apache License 2.0 | 5 votes |
@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 { // 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!"); } }
Example #11
Source File: KinesisSplitManager.java From presto-kinesis with Apache License 2.0 | 5 votes |
/** * Internal method to retrieve the stream description and get the shards from AWS. * * Gets from the internal cache unless not yet created or too old. * * @param streamName Kinesis stream name * @return Returns kinesis stream description */ protected InternalStreamDescription getStreamDescription(String streamName) { InternalStreamDescription desc = this.streamMap.get(streamName); if (desc == null || System.currentTimeMillis() - desc.getCreateTimeStamp() >= MAX_CACHE_AGE_MILLIS) { desc = new InternalStreamDescription(streamName); DescribeStreamRequest describeStreamRequest = clientManager.getDescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); // Collect shards from Kinesis String exclusiveStartShardId = null; List<Shard> shards = new ArrayList<>(); do { describeStreamRequest.setExclusiveStartShardId(exclusiveStartShardId); DescribeStreamResult describeStreamResult = clientManager.getClient().describeStream(describeStreamRequest); String streamStatus = describeStreamResult.getStreamDescription().getStreamStatus(); if (!streamStatus.equals("ACTIVE") && !streamStatus.equals("UPDATING")) { throw new ResourceNotFoundException("Stream not Active"); } desc.addAllShards(describeStreamResult.getStreamDescription().getShards()); if (describeStreamResult.getStreamDescription().getHasMoreShards() && (shards.size() > 0)) { exclusiveStartShardId = shards.get(shards.size() - 1).getShardId(); } else { exclusiveStartShardId = null; } } while (exclusiveStartShardId != null); this.streamMap.put(streamName, desc); } return desc; }
Example #12
Source File: KinesisSourceIT.java From datacollector with Apache License 2.0 | 5 votes |
private static boolean streamActive(AmazonKinesis client, String streamName) { try { DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); DescribeStreamResult describeStreamResult = client.describeStream(describeStreamRequest); String streamStatus = describeStreamResult.getStreamDescription().getStreamStatus(); if ("ACTIVE".equals(streamStatus)) { return true; } } catch (Exception e) { return false; } return false; }
Example #13
Source File: KinesisBinderTests.java From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 | 5 votes |
private List<Shard> describeStream(String stream) { String exclusiveStartShardId = null; DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest() .withStreamName(stream); List<Shard> shardList = new ArrayList<>(); while (true) { DescribeStreamResult describeStreamResult; describeStreamRequest.withExclusiveStartShardId(exclusiveStartShardId); describeStreamResult = AMAZON_KINESIS.describeStream(describeStreamRequest); StreamDescription streamDescription = describeStreamResult .getStreamDescription(); if (StreamStatus.ACTIVE.toString() .equals(streamDescription.getStreamStatus())) { shardList.addAll(streamDescription.getShards()); if (streamDescription.getHasMoreShards()) { exclusiveStartShardId = shardList.get(shardList.size() - 1) .getShardId(); continue; } else { return shardList; } } try { Thread.sleep(100); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new IllegalStateException(ex); } } }
Example #14
Source File: KinesisStreamProvisionerTests.java From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 | 5 votes |
@Test void testProvisionConsumerResourceNotFoundException() { AmazonKinesis amazonKinesisMock = mock(AmazonKinesis.class); KinesisBinderConfigurationProperties binderProperties = new KinesisBinderConfigurationProperties(); binderProperties.setAutoCreateStream(false); KinesisStreamProvisioner provisioner = new KinesisStreamProvisioner( amazonKinesisMock, binderProperties); int instanceCount = 1; int concurrency = 1; ExtendedConsumerProperties<KinesisConsumerProperties> extendedConsumerProperties = new ExtendedConsumerProperties<>( new KinesisConsumerProperties()); extendedConsumerProperties.setInstanceCount(instanceCount); extendedConsumerProperties.setConcurrency(concurrency); String name = "test-stream"; String group = "test-group"; when(amazonKinesisMock.describeStream(any(DescribeStreamRequest.class))) .thenThrow(new ResourceNotFoundException("Stream not found")); assertThatThrownBy(() -> provisioner.provisionConsumerDestination(name, group, extendedConsumerProperties)) .isInstanceOf(ProvisioningException.class) .hasMessageContaining( "The stream [test-stream] was not found and auto creation is disabled.") .hasCauseInstanceOf(ResourceNotFoundException.class); verify(amazonKinesisMock, times(1)) .describeStream(any(DescribeStreamRequest.class)); verify(amazonKinesisMock, never()).createStream(name, instanceCount * concurrency); }
Example #15
Source File: KinesisStreamProvisionerTests.java From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 | 5 votes |
@Test void testProvisionConsumerSuccessfulWithNewStream() { AmazonKinesis amazonKinesisMock = mock(AmazonKinesis.class); KinesisBinderConfigurationProperties binderProperties = new KinesisBinderConfigurationProperties(); KinesisStreamProvisioner provisioner = new KinesisStreamProvisioner( amazonKinesisMock, binderProperties); int instanceCount = 1; int concurrency = 1; ExtendedConsumerProperties<KinesisConsumerProperties> extendedConsumerProperties = new ExtendedConsumerProperties<>( new KinesisConsumerProperties()); extendedConsumerProperties.setInstanceCount(instanceCount); extendedConsumerProperties.setConcurrency(concurrency); String name = "test-stream"; String group = "test-group"; DescribeStreamResult describeStreamResult = describeStreamResultWithShards( Collections.singletonList(new Shard())); when(amazonKinesisMock.describeStream(any(DescribeStreamRequest.class))) .thenThrow(new ResourceNotFoundException("I got nothing")) .thenReturn(describeStreamResult); when(amazonKinesisMock.createStream(name, instanceCount * concurrency)) .thenReturn(new CreateStreamResult()); ConsumerDestination destination = provisioner.provisionConsumerDestination(name, group, extendedConsumerProperties); verify(amazonKinesisMock, times(2)) .describeStream(any(DescribeStreamRequest.class)); verify(amazonKinesisMock).createStream(name, instanceCount * concurrency); assertThat(destination.getName()).isEqualTo(name); }
Example #16
Source File: KinesisStreamProvisionerTests.java From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 | 5 votes |
@Test void testProvisionProducerUpdateShards() { AmazonKinesis amazonKinesisMock = mock(AmazonKinesis.class); ArgumentCaptor<UpdateShardCountRequest> updateShardCaptor = ArgumentCaptor .forClass(UpdateShardCountRequest.class); String name = "test-stream"; String group = "test-group"; int targetShardCount = 2; KinesisBinderConfigurationProperties binderProperties = new KinesisBinderConfigurationProperties(); binderProperties.setMinShardCount(targetShardCount); binderProperties.setAutoAddShards(true); KinesisStreamProvisioner provisioner = new KinesisStreamProvisioner( amazonKinesisMock, binderProperties); ExtendedConsumerProperties<KinesisConsumerProperties> extendedConsumerProperties = new ExtendedConsumerProperties<>( new KinesisConsumerProperties()); DescribeStreamResult describeOriginalStream = describeStreamResultWithShards( Collections.singletonList(new Shard())); DescribeStreamResult describeUpdatedStream = describeStreamResultWithShards( Arrays.asList(new Shard(), new Shard())); when(amazonKinesisMock.describeStream(any(DescribeStreamRequest.class))) .thenReturn(describeOriginalStream).thenReturn(describeUpdatedStream); provisioner.provisionConsumerDestination(name, group, extendedConsumerProperties); verify(amazonKinesisMock, times(1)).updateShardCount(updateShardCaptor.capture()); assertThat(updateShardCaptor.getValue().getStreamName()).isEqualTo(name); assertThat(updateShardCaptor.getValue().getScalingType()) .isEqualTo(ScalingType.UNIFORM_SCALING.name()); assertThat(updateShardCaptor.getValue().getTargetShardCount()) .isEqualTo(targetShardCount); }
Example #17
Source File: KinesisStreamProvisionerTests.java From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 | 5 votes |
@Test void testProvisionProducerSuccessfulWithNewStream() { AmazonKinesis amazonKinesisMock = mock(AmazonKinesis.class); KinesisBinderConfigurationProperties binderProperties = new KinesisBinderConfigurationProperties(); KinesisStreamProvisioner provisioner = new KinesisStreamProvisioner( amazonKinesisMock, binderProperties); ExtendedProducerProperties<KinesisProducerProperties> extendedProducerProperties = new ExtendedProducerProperties<>( new KinesisProducerProperties()); String name = "test-stream"; Integer shards = 1; DescribeStreamResult describeStreamResult = describeStreamResultWithShards( Collections.singletonList(new Shard())); when(amazonKinesisMock.describeStream(any(DescribeStreamRequest.class))) .thenThrow(new ResourceNotFoundException("I got nothing")) .thenReturn(describeStreamResult); when(amazonKinesisMock.createStream(name, shards)) .thenReturn(new CreateStreamResult()); ProducerDestination destination = provisioner.provisionProducerDestination(name, extendedProducerProperties); verify(amazonKinesisMock, times(2)) .describeStream(any(DescribeStreamRequest.class)); verify(amazonKinesisMock).createStream(name, shards); assertThat(destination.getName()).isEqualTo(name); }
Example #18
Source File: KinesisStreamProvisionerTests.java From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 | 5 votes |
@Test void testProvisionConsumerExistingStreamUpdateShards() { AmazonKinesis amazonKinesisMock = mock(AmazonKinesis.class); ArgumentCaptor<UpdateShardCountRequest> updateShardCaptor = ArgumentCaptor .forClass(UpdateShardCountRequest.class); String name = "test-stream"; String group = "test-group"; int targetShardCount = 2; KinesisBinderConfigurationProperties binderProperties = new KinesisBinderConfigurationProperties(); binderProperties.setMinShardCount(targetShardCount); binderProperties.setAutoAddShards(true); KinesisStreamProvisioner provisioner = new KinesisStreamProvisioner( amazonKinesisMock, binderProperties); ExtendedConsumerProperties<KinesisConsumerProperties> extendedConsumerProperties = new ExtendedConsumerProperties<>( new KinesisConsumerProperties()); DescribeStreamResult describeOriginalStream = describeStreamResultWithShards( Collections.singletonList(new Shard())); DescribeStreamResult describeUpdatedStream = describeStreamResultWithShards( Arrays.asList(new Shard(), new Shard())); when(amazonKinesisMock.describeStream(any(DescribeStreamRequest.class))) .thenReturn(describeOriginalStream).thenReturn(describeUpdatedStream); provisioner.provisionConsumerDestination(name, group, extendedConsumerProperties); verify(amazonKinesisMock, times(1)).updateShardCount(updateShardCaptor.capture()); assertThat(updateShardCaptor.getValue().getStreamName()).isEqualTo(name); assertThat(updateShardCaptor.getValue().getScalingType()) .isEqualTo(ScalingType.UNIFORM_SCALING.name()); assertThat(updateShardCaptor.getValue().getTargetShardCount()) .isEqualTo(targetShardCount); }
Example #19
Source File: KinesisStreamProvisionerTests.java From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 | 5 votes |
@Test void testProvisionConsumerSuccessfulWithExistingStream() { AmazonKinesis amazonKinesisMock = mock(AmazonKinesis.class); KinesisBinderConfigurationProperties binderProperties = new KinesisBinderConfigurationProperties(); KinesisStreamProvisioner provisioner = new KinesisStreamProvisioner( amazonKinesisMock, binderProperties); ExtendedConsumerProperties<KinesisConsumerProperties> extendedConsumerProperties = new ExtendedConsumerProperties<>( new KinesisConsumerProperties()); String name = "test-stream"; String group = "test-group"; DescribeStreamResult describeStreamResult = describeStreamResultWithShards( Collections.singletonList(new Shard())); when(amazonKinesisMock.describeStream(any(DescribeStreamRequest.class))) .thenReturn(describeStreamResult); ConsumerDestination destination = provisioner.provisionConsumerDestination(name, group, extendedConsumerProperties); verify(amazonKinesisMock).describeStream(any(DescribeStreamRequest.class)); assertThat(destination.getName()).isEqualTo(name); }
Example #20
Source File: KinesisProxy.java From flink with Apache License 2.0 | 5 votes |
/** * Get metainfo for a Kinesis stream, which contains information about which shards this * Kinesis stream possess. * * <p>This method is using a "full jitter" approach described in AWS's article, * <a href="https://www.awsarchitectureblog.com/2015/03/backoff.html"> * "Exponential Backoff and Jitter"</a>. * This is necessary because concurrent calls will be made by all parallel subtask's fetcher. * This jitter backoff approach will help distribute calls across the fetchers over time. * * @param streamName the stream to describe * @param startShardId which shard to start with for this describe operation * * @return the result of the describe stream operation */ protected DescribeStreamResult describeStream(String streamName, @Nullable String startShardId) throws InterruptedException { final DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); describeStreamRequest.setExclusiveStartShardId(startShardId); DescribeStreamResult describeStreamResult = null; // Call DescribeStream, with full-jitter backoff (if we get LimitExceededException). int attemptCount = 0; while (describeStreamResult == null) { // retry until we get a result try { describeStreamResult = kinesisClient.describeStream(describeStreamRequest); } catch (LimitExceededException le) { long backoffMillis = fullJitterBackoff( describeStreamBaseBackoffMillis, describeStreamMaxBackoffMillis, describeStreamExpConstant, attemptCount++); LOG.warn(String.format("Got LimitExceededException when describing stream %s. " + "Backing off for %d millis.", streamName, backoffMillis)); Thread.sleep(backoffMillis); } catch (ResourceNotFoundException re) { throw new RuntimeException("Error while getting stream details", re); } } String streamStatus = describeStreamResult.getStreamDescription().getStreamStatus(); if (!(streamStatus.equals(StreamStatus.ACTIVE.toString()) || streamStatus.equals(StreamStatus.UPDATING.toString()))) { if (LOG.isWarnEnabled()) { LOG.warn(String.format("The status of stream %s is %s ; result of the current " + "describeStream operation will not contain any shard information.", streamName, streamStatus)); } } return describeStreamResult; }
Example #21
Source File: KinesisProxy.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Get metainfo for a Kinesis stream, which contains information about which shards this * Kinesis stream possess. * * <p>This method is using a "full jitter" approach described in AWS's article, * <a href="https://www.awsarchitectureblog.com/2015/03/backoff.html"> * "Exponential Backoff and Jitter"</a>. * This is necessary because concurrent calls will be made by all parallel subtask's fetcher. * This jitter backoff approach will help distribute calls across the fetchers over time. * * @param streamName the stream to describe * @param startShardId which shard to start with for this describe operation * * @return the result of the describe stream operation */ protected DescribeStreamResult describeStream(String streamName, @Nullable String startShardId) throws InterruptedException { final DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); describeStreamRequest.setExclusiveStartShardId(startShardId); DescribeStreamResult describeStreamResult = null; // Call DescribeStream, with full-jitter backoff (if we get LimitExceededException). int attemptCount = 0; while (describeStreamResult == null) { // retry until we get a result try { describeStreamResult = kinesisClient.describeStream(describeStreamRequest); } catch (LimitExceededException le) { long backoffMillis = fullJitterBackoff( describeStreamBaseBackoffMillis, describeStreamMaxBackoffMillis, describeStreamExpConstant, attemptCount++); LOG.warn(String.format("Got LimitExceededException when describing stream %s. " + "Backing off for %d millis.", streamName, backoffMillis)); Thread.sleep(backoffMillis); } catch (ResourceNotFoundException re) { throw new RuntimeException("Error while getting stream details", re); } } String streamStatus = describeStreamResult.getStreamDescription().getStreamStatus(); if (!(streamStatus.equals(StreamStatus.ACTIVE.toString()) || streamStatus.equals(StreamStatus.UPDATING.toString()))) { if (LOG.isWarnEnabled()) { LOG.warn(String.format("The status of stream %s is %s ; result of the current " + "describeStream operation will not contain any shard information.", streamName, streamStatus)); } } return describeStreamResult; }
Example #22
Source File: EmbeddedKinesisStream.java From presto with Apache License 2.0 | 5 votes |
private String checkStreamStatus(String streamName) { DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); StreamDescription streamDescription = amazonKinesisClient.describeStream(describeStreamRequest).getStreamDescription(); return streamDescription.getStreamStatus(); }
Example #23
Source File: KinesisSplitManager.java From presto with Apache License 2.0 | 5 votes |
/** * Internal method to retrieve the stream description and get the shards from AWS. * <p> * Gets from the internal cache unless not yet created or too old. */ protected InternalStreamDescription getStreamDescription(String streamName) { InternalStreamDescription internalStreamDescription = this.streamMap.get(streamName); if (internalStreamDescription == null || System.currentTimeMillis() - internalStreamDescription.getCreateTimeStamp() >= MAX_CACHE_AGE_MILLIS) { internalStreamDescription = new InternalStreamDescription(streamName); DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest(); describeStreamRequest.setStreamName(streamName); // Collect shards from Kinesis String exclusiveStartShardId = null; List<Shard> shards = new ArrayList<>(); do { describeStreamRequest.setExclusiveStartShardId(exclusiveStartShardId); DescribeStreamResult describeStreamResult = clientManager.getClient().describeStream(describeStreamRequest); String streamStatus = describeStreamResult.getStreamDescription().getStreamStatus(); if (!streamStatus.equals("ACTIVE") && !streamStatus.equals("UPDATING")) { throw new ResourceNotFoundException("Stream not Active"); } internalStreamDescription.addAllShards(describeStreamResult.getStreamDescription().getShards()); if (describeStreamResult.getStreamDescription().getHasMoreShards() && (shards.size() > 0)) { exclusiveStartShardId = shards.get(shards.size() - 1).getShardId(); } else { exclusiveStartShardId = null; } } while (exclusiveStartShardId != null); this.streamMap.put(streamName, internalStreamDescription); } return internalStreamDescription; }
Example #24
Source File: AmazonKinesisMock.java From beam with Apache License 2.0 | 4 votes |
@Override public DescribeStreamResult describeStream(DescribeStreamRequest describeStreamRequest) { throw new RuntimeException("Not implemented"); }
Example #25
Source File: KinesisClientManager.java From presto-kinesis with Apache License 2.0 | 4 votes |
@Override public DescribeStreamRequest getDescribeStreamRequest() { return new DescribeStreamRequest(); }
Example #26
Source File: KinesisTestClientManager.java From presto-kinesis with Apache License 2.0 | 4 votes |
@Override public DescribeStreamRequest getDescribeStreamRequest() { return new DescribeStreamRequest(); }
Example #27
Source File: KinesisInventoryUtil.java From pacbot with Apache License 2.0 | 4 votes |
public static Map<String,List<DataStreamVH>> fetchDataStreamInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<DataStreamVH>> dataStream = new LinkedHashMap<>(); AmazonKinesis amazonKinesis; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource\" ,\"type\": \"datastream\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ amazonKinesis = AmazonKinesisClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); ListStreamsResult listStreamsResult = amazonKinesis.listStreams(); List<String> streamNamesTemp = listStreamsResult.getStreamNames(); List<String> streamNames = new ArrayList<>(streamNamesTemp); while (listStreamsResult.isHasMoreStreams() && !streamNamesTemp.isEmpty()) { listStreamsResult = amazonKinesis.listStreams(streamNamesTemp.get(streamNamesTemp.size() - 1)); streamNamesTemp = listStreamsResult.getStreamNames(); streamNames.addAll(streamNamesTemp); } List<DataStreamVH> dataStreamList = new ArrayList<>(); for(String streamName : streamNames) { StreamDescription streamDescription = amazonKinesis.describeStream(new DescribeStreamRequest().withStreamName(streamName)).getStreamDescription(); ListTagsForStreamResult listTagsForStreamResult = amazonKinesis.listTagsForStream(new ListTagsForStreamRequest().withStreamName(streamName)); List<com.amazonaws.services.kinesis.model.Tag> tagsTemp = listTagsForStreamResult.getTags(); List<com.amazonaws.services.kinesis.model.Tag> tags = new ArrayList<>(tagsTemp); while (listTagsForStreamResult.isHasMoreTags() && !tagsTemp.isEmpty()) { listTagsForStreamResult = amazonKinesis.listTagsForStream(new ListTagsForStreamRequest().withExclusiveStartTagKey(tagsTemp.get(tagsTemp.size() - 1).getKey())); tagsTemp = listTagsForStreamResult.getTags(); tags.addAll(tagsTemp); } dataStreamList.add(new DataStreamVH(streamDescription, tags)); } if( !dataStreamList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : datastream "+region.getName() + " >> "+dataStreamList.size()); dataStream.put(accountId+delimiter+accountName+delimiter+region.getName(),dataStreamList); } } } catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId, region.getName(),"datastream",e.getMessage()); } } return dataStream; }
Example #28
Source File: KinesisClientProvider.java From presto-kinesis with Apache License 2.0 | votes |
DescribeStreamRequest getDescribeStreamRequest();