Search in sources :

Example 1 with DescribeStreamConsumerResponse

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());
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) DescribeStreamConsumerResponse(software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse) DescribeStreamConsumerRequest(software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerRequest) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Test(org.junit.Test)

Example 2 with DescribeStreamConsumerResponse

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);
        }
    }
}
Also used : DescribeStreamConsumerResponse(software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse) Instant(java.time.Instant) Duration(java.time.Duration) FlinkKinesisTimeoutException(org.apache.flink.streaming.connectors.kinesis.FlinkKinesisException.FlinkKinesisTimeoutException)

Example 3 with DescribeStreamConsumerResponse

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();
}
Also used : DescribeStreamConsumerResponse(software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse) Instant(java.time.Instant) Duration(java.time.Duration) FlinkKinesisTimeoutException(org.apache.flink.streaming.connectors.kinesis.FlinkKinesisException.FlinkKinesisTimeoutException)

Example 4 with DescribeStreamConsumerResponse

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());
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) DescribeStreamConsumerResponse(software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse) DescribeStreamConsumerRequest(software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerRequest) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Test(org.junit.Test)

Example 5 with DescribeStreamConsumerResponse

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;
}
Also used : DescribeStreamConsumerResponse(software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse) DescribeStreamSummaryResponse(software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryResponse)

Aggregations

DescribeStreamConsumerResponse (software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse)5 Duration (java.time.Duration)2 Instant (java.time.Instant)2 FlinkKinesisTimeoutException (org.apache.flink.streaming.connectors.kinesis.FlinkKinesisException.FlinkKinesisTimeoutException)2 Test (org.junit.Test)2 SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)2 KinesisAsyncClient (software.amazon.awssdk.services.kinesis.KinesisAsyncClient)2 DescribeStreamConsumerRequest (software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerRequest)2 DescribeStreamSummaryResponse (software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryResponse)1