Search in sources :

Example 1 with KinesisProducerConfiguration

use of com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration in project flink by apache.

the class KinesisConfigUtilTest method testThreadPoolSizeInProducerConfiguration.

@Test
public void testThreadPoolSizeInProducerConfiguration() {
    Properties testConfig = new Properties();
    testConfig.setProperty(AWSConfigConstants.AWS_REGION, "us-east-1");
    KinesisProducerConfiguration kpc = KinesisConfigUtil.getValidatedProducerConfiguration(testConfig);
    assertEquals(10, kpc.getThreadPoolSize());
    testConfig.setProperty(KinesisConfigUtil.THREAD_POOL_SIZE, "12");
    kpc = KinesisConfigUtil.getValidatedProducerConfiguration(testConfig);
    assertEquals(12, kpc.getThreadPoolSize());
}
Also used : KinesisProducerConfiguration(com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with KinesisProducerConfiguration

use of com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration in project flink by apache.

the class KinesisConfigUtilTest method testCorrectlySetRegionInProducerConfiguration.

@Test
public void testCorrectlySetRegionInProducerConfiguration() {
    String region = "us-east-1";
    Properties testConfig = new Properties();
    testConfig.setProperty(AWSConfigConstants.AWS_REGION, region);
    KinesisProducerConfiguration kpc = KinesisConfigUtil.getValidatedProducerConfiguration(testConfig);
    assertEquals("incorrect region", region, kpc.getRegion());
}
Also used : KinesisProducerConfiguration(com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with KinesisProducerConfiguration

use of com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration in project flink by apache.

the class KinesisConfigUtilTest method testRateLimitInProducerConfiguration.

@Test
public void testRateLimitInProducerConfiguration() {
    Properties testConfig = new Properties();
    testConfig.setProperty(AWSConfigConstants.AWS_REGION, "us-east-1");
    KinesisProducerConfiguration kpc = KinesisConfigUtil.getValidatedProducerConfiguration(testConfig);
    assertEquals(100, kpc.getRateLimit());
    testConfig.setProperty(KinesisConfigUtil.RATE_LIMIT, "150");
    kpc = KinesisConfigUtil.getValidatedProducerConfiguration(testConfig);
    assertEquals(150, kpc.getRateLimit());
}
Also used : KinesisProducerConfiguration(com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with KinesisProducerConfiguration

use of com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration in project flink by apache.

the class KinesisConfigUtilTest method testThreadingModelInProducerConfiguration.

@Test
public void testThreadingModelInProducerConfiguration() {
    Properties testConfig = new Properties();
    testConfig.setProperty(AWSConfigConstants.AWS_REGION, "us-east-1");
    KinesisProducerConfiguration kpc = KinesisConfigUtil.getValidatedProducerConfiguration(testConfig);
    assertEquals(KinesisProducerConfiguration.ThreadingModel.POOLED, kpc.getThreadingModel());
    testConfig.setProperty(KinesisConfigUtil.THREADING_MODEL, "PER_REQUEST");
    kpc = KinesisConfigUtil.getValidatedProducerConfiguration(testConfig);
    assertEquals(KinesisProducerConfiguration.ThreadingModel.PER_REQUEST, kpc.getThreadingModel());
}
Also used : KinesisProducerConfiguration(com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with KinesisProducerConfiguration

use of com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration in project flink by apache.

the class FlinkKinesisProducer method open.

// --------------------------- Lifecycle methods ---------------------------
@Override
public void open(Configuration parameters) throws Exception {
    super.open(parameters);
    schema.open(RuntimeContextInitializationContextAdapters.serializationAdapter(getRuntimeContext(), metricGroup -> metricGroup.addGroup("user")));
    // check and pass the configuration properties
    KinesisProducerConfiguration producerConfig = KinesisConfigUtil.getValidatedProducerConfiguration(configProps);
    producer = getKinesisProducer(producerConfig);
    final MetricGroup kinesisMectricGroup = getRuntimeContext().getMetricGroup().addGroup(KINESIS_PRODUCER_METRIC_GROUP);
    this.backpressureCycles = kinesisMectricGroup.counter(METRIC_BACKPRESSURE_CYCLES);
    kinesisMectricGroup.gauge(METRIC_OUTSTANDING_RECORDS_COUNT, producer::getOutstandingRecordsCount);
    backpressureLatch = new TimeoutLatch();
    callback = new FutureCallback<UserRecordResult>() {

        @Override
        public void onSuccess(UserRecordResult result) {
            backpressureLatch.trigger();
            if (!result.isSuccessful()) {
                if (failOnError) {
                    // only remember the first thrown exception
                    if (thrownException == null) {
                        thrownException = new RuntimeException("Record was not sent successful");
                    }
                } else {
                    LOG.warn("Record was not sent successful");
                }
            }
        }

        @Override
        public void onFailure(Throwable t) {
            backpressureLatch.trigger();
            if (failOnError) {
                thrownException = t;
            } else {
                LOG.warn("An exception occurred while processing a record", t);
            }
        }
    };
    if (this.customPartitioner != null) {
        this.customPartitioner.initialize(getRuntimeContext().getIndexOfThisSubtask(), getRuntimeContext().getNumberOfParallelSubtasks());
    }
    final RuntimeContext ctx = getRuntimeContext();
    ctx.registerUserCodeClassLoaderReleaseHookIfAbsent(KINESIS_PRODUCER_RELEASE_HOOK_NAME, () -> this.runClassLoaderReleaseHook(ctx.getUserCodeClassLoader()));
    LOG.info("Started Kinesis producer instance for region '{}'", producerConfig.getRegion());
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) RuntimeContext(org.apache.flink.api.common.functions.RuntimeContext) KinesisSerializationSchema(org.apache.flink.streaming.connectors.kinesis.serialization.KinesisSerializationSchema) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LoggerFactory(org.slf4j.LoggerFactory) PublicEvolving(org.apache.flink.annotation.PublicEvolving) RuntimeContextInitializationContextAdapters(org.apache.flink.api.common.serialization.RuntimeContextInitializationContextAdapters) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) KinesisProducerConfiguration(com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration) ByteBuffer(java.nio.ByteBuffer) KinesisProducer(com.amazonaws.services.kinesis.producer.KinesisProducer) InstantiationUtil(org.apache.flink.util.InstantiationUtil) TimeoutLatch(org.apache.flink.streaming.connectors.kinesis.util.TimeoutLatch) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) Properties(java.util.Properties) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) Configuration(org.apache.flink.configuration.Configuration) KinesisConfigUtil(org.apache.flink.streaming.connectors.kinesis.util.KinesisConfigUtil) Field(java.lang.reflect.Field) FutureCallback(com.google.common.util.concurrent.FutureCallback) RichSinkFunction(org.apache.flink.streaming.api.functions.sink.RichSinkFunction) UserRecordFailedException(com.amazonaws.services.kinesis.producer.UserRecordFailedException) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) TimeUnit(java.util.concurrent.TimeUnit) MetricGroup(org.apache.flink.metrics.MetricGroup) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) AwsSdkMetrics(com.amazonaws.metrics.AwsSdkMetrics) Attempt(com.amazonaws.services.kinesis.producer.Attempt) UserRecordResult(com.amazonaws.services.kinesis.producer.UserRecordResult) Counter(org.apache.flink.metrics.Counter) SerializationSchema(org.apache.flink.api.common.serialization.SerializationSchema) KinesisProducerConfiguration(com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration) TimeoutLatch(org.apache.flink.streaming.connectors.kinesis.util.TimeoutLatch) MetricGroup(org.apache.flink.metrics.MetricGroup) UserRecordResult(com.amazonaws.services.kinesis.producer.UserRecordResult) RuntimeContext(org.apache.flink.api.common.functions.RuntimeContext)

Aggregations

KinesisProducerConfiguration (com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration)6 Properties (java.util.Properties)5 Test (org.junit.Test)4 AwsSdkMetrics (com.amazonaws.metrics.AwsSdkMetrics)1 Attempt (com.amazonaws.services.kinesis.producer.Attempt)1 KinesisProducer (com.amazonaws.services.kinesis.producer.KinesisProducer)1 UserRecordFailedException (com.amazonaws.services.kinesis.producer.UserRecordFailedException)1 UserRecordResult (com.amazonaws.services.kinesis.producer.UserRecordResult)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 Field (java.lang.reflect.Field)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 PublicEvolving (org.apache.flink.annotation.PublicEvolving)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)1