software.amazon.awssdk.services.kinesis.model.DescribeStreamResponse Java Examples
The following examples show how to use
software.amazon.awssdk.services.kinesis.model.DescribeStreamResponse.
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: StockTradesWriter.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
private static void validateStream(KinesisClient kinesisClient, String streamName) { try { DescribeStreamRequest describeStreamRequest = DescribeStreamRequest.builder() .streamName(streamName) .build(); DescribeStreamResponse describeStreamResponse = kinesisClient.describeStream(describeStreamRequest); if(!describeStreamResponse.streamDescription().streamStatus().toString().equals("ACTIVE")) { System.err.println("Stream " + streamName + " is not active. Please wait a few moments and try again."); System.exit(1); } }catch (KinesisException e) { System.err.println("Error found while describing the stream " + streamName); System.err.println(e); System.exit(1); } // snippet-end:[kinesis.java2.putrecord.main] }
Example #2
Source File: AwsKinesisScannerTest.java From clouditor with Apache License 2.0 | 5 votes |
@BeforeAll static void setUpOnce() throws IOException { discoverAssets( KinesisClient.class, AwsKinesisScanner::new, api -> { when(api.listStreams()) .thenReturn( ListStreamsResponse.builder() .streamNames("stream-encrypted", "stream-not-encrypted") .build()); when(api.describeStream( DescribeStreamRequest.builder().streamName("stream-encrypted").build())) .thenReturn( DescribeStreamResponse.builder() .streamDescription( StreamDescription.builder() .streamARN("arn:aws:kinesis:us-east-1:111122223333:encrypted") .encryptionType(EncryptionType.KMS) .build()) .build()); when(api.describeStream( DescribeStreamRequest.builder().streamName("stream-not-encrypted").build())) .thenReturn( DescribeStreamResponse.builder() .streamDescription( StreamDescription.builder() .streamARN("arn:aws:kinesis:us-east-1:111122223333:unencrypted") .encryptionType(EncryptionType.NONE) .build()) .build()); }); }
Example #3
Source File: KinesisIntegrationTests.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private List<Shard> waitForStream(final String streamName) throws InterruptedException { while (true) { DescribeStreamResponse result = client.describeStream(DescribeStreamRequest.builder().streamName(streamName).build()); Assert.assertNotNull(result); StreamDescription description = result.streamDescription(); Assert.assertNotNull(description); Assert.assertEquals(streamName, description.streamName()); Assert.assertNotNull(description.streamARN()); Assert.assertFalse(description.hasMoreShards()); StreamStatus status = description.streamStatus(); Assert.assertNotNull(status); if (status == StreamStatus.ACTIVE) { List<Shard> shards = description.shards(); validateShards(shards); return shards; } if (!(status == StreamStatus.CREATING || status == StreamStatus.UPDATING)) { Assert.fail("Unexpected status '" + status + "'"); } Thread.sleep(1000); } }
Example #4
Source File: KinesisStreamInfoProvider.java From synapse with Apache License 2.0 | 5 votes |
/** * Returns stream information for the given Kinesis stream. * * @param channelName the name of the stream * @return KinesisStreamInfo * @throws IllegalArgumentException if the stream does not exist */ public KinesisStreamInfo getStreamInfo(final String channelName) { try { final DescribeStreamRequest request = DescribeStreamRequest.builder().streamName(channelName).build(); DescribeStreamResponse response = kinesisAsyncClient.describeStream(request).join(); final KinesisStreamInfo.Builder streamInfoBuilder = builder() .withChannelName(channelName) .withArn(response.streamDescription().streamARN()); String lastSeenShardId = addShardInfoFromResponse(response, streamInfoBuilder); while (response.streamDescription().hasMoreShards()) { response = kinesisAsyncClient.describeStream(DescribeStreamRequest.builder() .streamName(channelName) .exclusiveStartShardId(lastSeenShardId) .build()) .join(); lastSeenShardId = addShardInfoFromResponse(response, streamInfoBuilder); } return streamInfoBuilder.build(); } catch (final ResourceNotFoundException e) { throw new IllegalArgumentException(format("Kinesis channel %s does not exist: %s", channelName, e.getMessage())); } }
Example #5
Source File: KinesisStreamInfoProvider.java From synapse with Apache License 2.0 | 5 votes |
private String addShardInfoFromResponse(DescribeStreamResponse response, KinesisStreamInfo.Builder streamInfoBuilder) { AtomicReference<String> lastShardId = new AtomicReference<>(null); response .streamDescription() .shards() .stream() .forEach(shard -> { lastShardId.set(shard.shardId()); streamInfoBuilder.withShard(shard.shardId(), isShardOpen(shard)); }); return lastShardId.get(); }
Example #6
Source File: KinesisAppender.java From kinesis-logback-appender with Apache License 2.0 | 5 votes |
@Override protected void validateStreamName(KinesisAsyncClient client, String streamName) { DescribeStreamResponse describeResult; try { describeResult = getClient().describeStream(b -> b.streamName(streamName).build()).get(); StreamStatus streamStatus = describeResult.streamDescription().streamStatus(); if(!StreamStatus.ACTIVE.equals(streamStatus) && !StreamStatus.UPDATING.equals(streamStatus)) { setInitializationFailed(true); addError("Stream " + streamName + " is not ready (in active/updating status) for appender: " + name); } } catch(InterruptedException ie) { setInitializationFailed(true); addError("Interrupted while attempting to describe " + streamName, ie); } catch(ExecutionException ee) { setInitializationFailed(true); addError("Error executing the operation", ee); } catch(ResourceNotFoundException rnfe) { setInitializationFailed(true); addError("Stream " + streamName + " doesn't exist for appender: " + name, rnfe); } catch(AwsServiceException ase) { setInitializationFailed(true); addError("Error connecting to AWS to verify stream " + streamName + " for appender: " + name, ase); } }
Example #7
Source File: GetRecords.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
public static void getStockTrades(KinesisClient kinesisClient, String streamName) { String shardIterator; String lastShardId = null; // Retrieve the shards from a data stream DescribeStreamRequest describeStreamRequest = DescribeStreamRequest.builder() .streamName(streamName) .build(); List<Shard> shards = new ArrayList<>(); DescribeStreamResponse streamRes; do { streamRes = kinesisClient.describeStream(describeStreamRequest); shards.addAll(streamRes.streamDescription().shards()); if (shards.size() > 0) { lastShardId = shards.get(shards.size() - 1).shardId(); } } while (streamRes.streamDescription().hasMoreShards()); GetShardIteratorRequest itReq = GetShardIteratorRequest.builder() .streamName(streamName) .shardIteratorType("TRIM_HORIZON") .shardId(shards.get(0).shardId()) .build(); GetShardIteratorResponse shardIteratorResult = kinesisClient.getShardIterator(itReq); shardIterator = shardIteratorResult.shardIterator(); // Continuously read data records from a shard List<Record> records; // Create a GetRecordsRequest with the existing shardIterator, // and set maximum records to return to 1000 GetRecordsRequest recordsRequest = GetRecordsRequest.builder() .shardIterator(shardIterator) .limit(1000) .build(); GetRecordsResponse result = kinesisClient.getRecords(recordsRequest); // Put result into a record list, result might be empty records = result.records(); // Print records for (Record record : records) { SdkBytes byteBuffer = record.data(); System.out.println(String.format("Seq No: %s - %s", record.sequenceNumber(), new String(byteBuffer.asByteArray()))); } }