use of software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse in project flink by apache.
the class KinesisProxyV2Test method testDescribeStreamConsumerWithStreamConsumerArn.
@Test
public void testDescribeStreamConsumerWithStreamConsumerArn() throws Exception {
KinesisAsyncClient client = mock(KinesisAsyncClient.class);
KinesisProxyV2 proxy = new KinesisProxyV2(client, mock(SdkAsyncHttpClient.class), createConfiguration(), mock(FullJitterBackoff.class));
DescribeStreamConsumerResponse expected = DescribeStreamConsumerResponse.builder().build();
ArgumentCaptor<DescribeStreamConsumerRequest> requestCaptor = ArgumentCaptor.forClass(DescribeStreamConsumerRequest.class);
when(client.describeStreamConsumer(requestCaptor.capture())).thenReturn(CompletableFuture.completedFuture(expected));
DescribeStreamConsumerResponse actual = proxy.describeStreamConsumer("arn");
assertEquals(expected, actual);
DescribeStreamConsumerRequest request = requestCaptor.getValue();
assertEquals("arn", request.consumerARN());
}
use of software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse in project flink by apache.
the class StreamConsumerRegistrar method waitForConsumerToDeregister.
private void waitForConsumerToDeregister(@Nullable final DescribeStreamConsumerResponse describeStreamConsumerResponse, final String streamConsumerArn, final int initialAttempt) throws InterruptedException, ExecutionException {
int attempt = initialAttempt;
Instant start = Instant.now();
Duration timeout = configuration.getDeregisterStreamConsumerTimeout();
Optional<DescribeStreamConsumerResponse> response = Optional.ofNullable(describeStreamConsumerResponse);
while (response.isPresent() && response.get().consumerDescription().consumerStatus() != DELETING) {
LOG.debug("Waiting for stream consumer to deregister, attempt {} - {}", attempt, streamConsumerArn);
deregistrationBackoff(configuration, backoff, attempt++);
response = describeStreamConsumer(streamConsumerArn);
if (Duration.between(start, Instant.now()).compareTo(timeout) > 0) {
throw new FlinkKinesisTimeoutException("Timeout waiting for stream consumer to deregister: " + streamConsumerArn);
}
}
}
use of software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse in project flink by apache.
the class StreamConsumerRegistrar method waitForConsumerToBecomeActive.
private String waitForConsumerToBecomeActive(@Nullable final DescribeStreamConsumerResponse describeStreamConsumerResponse, final String streamArn, final String streamConsumerName, final int initialAttempt) throws InterruptedException, ExecutionException {
int attempt = initialAttempt;
Instant start = Instant.now();
Duration timeout = configuration.getRegisterStreamConsumerTimeout();
DescribeStreamConsumerResponse response = describeStreamConsumerResponse;
while (response == null || response.consumerDescription().consumerStatus() != ACTIVE) {
LOG.debug("Waiting for stream consumer to become active, attempt {} - {} on {}", attempt, streamConsumerName, streamArn);
registrationBackoff(configuration, backoff, attempt++);
response = kinesisProxyV2Interface.describeStreamConsumer(streamArn, streamConsumerName);
if (Duration.between(start, Instant.now()).compareTo(timeout) > 0) {
throw new FlinkKinesisTimeoutException("Timeout waiting for stream consumer to become active: " + streamConsumerName + " on " + streamArn);
}
}
return response.consumerDescription().consumerARN();
}
use of software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse in project flink by apache.
the class KinesisProxyV2Test method testDescribeStreamConsumerWithStreamArnAndConsumerName.
@Test
public void testDescribeStreamConsumerWithStreamArnAndConsumerName() throws Exception {
KinesisAsyncClient client = mock(KinesisAsyncClient.class);
KinesisProxyV2 proxy = new KinesisProxyV2(client, mock(SdkAsyncHttpClient.class), createConfiguration(), mock(FullJitterBackoff.class));
DescribeStreamConsumerResponse expected = DescribeStreamConsumerResponse.builder().build();
ArgumentCaptor<DescribeStreamConsumerRequest> requestCaptor = ArgumentCaptor.forClass(DescribeStreamConsumerRequest.class);
when(client.describeStreamConsumer(requestCaptor.capture())).thenReturn(CompletableFuture.completedFuture(expected));
DescribeStreamConsumerResponse actual = proxy.describeStreamConsumer("arn", "name");
assertEquals(expected, actual);
DescribeStreamConsumerRequest request = requestCaptor.getValue();
assertEquals("arn", request.streamARN());
assertEquals("name", request.consumerName());
}
use of software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse in project flink by apache.
the class StreamConsumerRegistrar method registerStreamConsumer.
/**
* Register a stream consumer with the given name against the given stream. Blocks until the
* consumer becomes active. If the stream consumer already exists, the ARN is returned.
*
* @param stream the stream to register the stream consumer against
* @param streamConsumerName the name of the new stream consumer
* @return the stream consumer ARN
* @throws ExecutionException
* @throws InterruptedException
*/
public String registerStreamConsumer(final String stream, final String streamConsumerName) throws ExecutionException, InterruptedException {
LOG.debug("Registering stream consumer - {}::{}", stream, streamConsumerName);
int attempt = 1;
if (configuration.getEfoRegistrationType() == LAZY) {
registrationBackoff(configuration, backoff, attempt++);
}
DescribeStreamSummaryResponse describeStreamSummaryResponse = kinesisProxyV2Interface.describeStreamSummary(stream);
String streamArn = describeStreamSummaryResponse.streamDescriptionSummary().streamARN();
LOG.debug("Found stream ARN - {}", streamArn);
Optional<DescribeStreamConsumerResponse> describeStreamConsumerResponse = describeStreamConsumer(streamArn, streamConsumerName);
if (!describeStreamConsumerResponse.isPresent()) {
invokeIgnoringResourceInUse(() -> kinesisProxyV2Interface.registerStreamConsumer(streamArn, streamConsumerName));
}
String streamConsumerArn = waitForConsumerToBecomeActive(describeStreamConsumerResponse.orElse(null), streamArn, streamConsumerName, attempt);
LOG.debug("Using stream consumer - {}", streamConsumerArn);
return streamConsumerArn;
}
Aggregations