Search in sources :

Example 1 with SetupableStreamOperator

use of org.apache.flink.streaming.api.operators.SetupableStreamOperator in project flink by apache.

the class OperatorChainTest method setupOperatorChain.

// ------------------------------------------------------------------------
// Operator Chain Setup Utils
// ------------------------------------------------------------------------
@SafeVarargs
public static <T, OP extends StreamOperator<T>> OperatorChain<T, OP> setupOperatorChain(OneInputStreamOperator<T, T>... operators) throws Exception {
    checkNotNull(operators);
    checkArgument(operators.length > 0);
    try (MockEnvironment env = MockEnvironment.builder().build()) {
        final StreamTask<?, ?> containingTask = new MockStreamTaskBuilder(env).build();
        final StreamConfig cfg = new StreamConfig(new Configuration());
        cfg.setOperatorID(new OperatorID());
        cfg.setStateKeySerializer(new StringSerializer());
        final List<StreamOperatorWrapper<?, ?>> operatorWrappers = new ArrayList<>();
        // initial output goes to nowhere
        @SuppressWarnings({ "unchecked", "rawtypes" }) WatermarkGaugeExposingOutput<StreamRecord<T>> lastWriter = new BroadcastingOutputCollector<>(new Output[0]);
        // build the reverse operators array
        for (int i = 0; i < operators.length; i++) {
            int operatorIndex = operators.length - i - 1;
            OneInputStreamOperator<T, T> op = operators[operatorIndex];
            if (op instanceof SetupableStreamOperator) {
                ((SetupableStreamOperator) op).setup(containingTask, cfg, lastWriter);
            }
            lastWriter = new ChainingOutput<>(op, null);
            ProcessingTimeService processingTimeService = null;
            if (op instanceof AbstractStreamOperator) {
                processingTimeService = ((AbstractStreamOperator) op).getProcessingTimeService();
            }
            operatorWrappers.add(new StreamOperatorWrapper<>(op, Optional.ofNullable(processingTimeService), containingTask.getMailboxExecutorFactory().createExecutor(i), operatorIndex == 0));
        }
        @SuppressWarnings("unchecked") final StreamOperatorWrapper<T, OP> headOperatorWrapper = (StreamOperatorWrapper<T, OP>) operatorWrappers.get(operatorWrappers.size() - 1);
        return new RegularOperatorChain<>(operatorWrappers, new RecordWriterOutput<?>[0], lastWriter, headOperatorWrapper);
    }
}
Also used : MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) Configuration(org.apache.flink.configuration.Configuration) ArrayList(java.util.ArrayList) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) SetupableStreamOperator(org.apache.flink.streaming.api.operators.SetupableStreamOperator)

Example 2 with SetupableStreamOperator

use of org.apache.flink.streaming.api.operators.SetupableStreamOperator in project flink by apache.

the class StateBootstrapWrapperOperator method setup.

@Override
public void setup(StreamTask<?, ?> containingTask, StreamConfig config, Output<StreamRecord<TaggedOperatorSubtaskState>> output) {
    ((SetupableStreamOperator) operator).setup(containingTask, config, new VoidOutput<>());
    operator.setProcessingTimeService(new NeverFireProcessingTimeService());
    this.output = output;
}
Also used : NeverFireProcessingTimeService(org.apache.flink.state.api.runtime.NeverFireProcessingTimeService) SetupableStreamOperator(org.apache.flink.streaming.api.operators.SetupableStreamOperator)

Example 3 with SetupableStreamOperator

use of org.apache.flink.streaming.api.operators.SetupableStreamOperator in project flink by apache.

the class AbstractStreamOperatorTestHarness method setup.

/**
 * Calls {@link SetupableStreamOperator#setup(StreamTask, StreamConfig, Output)} ()}.
 */
public void setup(TypeSerializer<OUT> outputSerializer) {
    if (!setupCalled) {
        streamTaskStateInitializer = createStreamTaskStateManager(environment, stateBackend, ttlTimeProvider, timeServiceManagerProvider);
        mockTask.setStreamTaskStateInitializer(streamTaskStateInitializer);
        if (operator == null) {
            this.operator = StreamOperatorFactoryUtil.createOperator(factory, mockTask, config, new MockOutput(outputSerializer), new OperatorEventDispatcherImpl(this.getClass().getClassLoader(), new NoOpTaskOperatorEventGateway())).f0;
        } else {
            if (operator instanceof AbstractStreamOperator) {
                ((AbstractStreamOperator) operator).setProcessingTimeService(processingTimeService);
            }
            if (operator instanceof SetupableStreamOperator) {
                ((SetupableStreamOperator) operator).setup(mockTask, config, new MockOutput(outputSerializer));
            }
        }
        setupCalled = true;
        this.mockTask.init();
    }
}
Also used : NoOpTaskOperatorEventGateway(org.apache.flink.runtime.taskmanager.NoOpTaskOperatorEventGateway) SetupableStreamOperator(org.apache.flink.streaming.api.operators.SetupableStreamOperator) OperatorEventDispatcherImpl(org.apache.flink.streaming.runtime.tasks.OperatorEventDispatcherImpl) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator)

Aggregations

SetupableStreamOperator (org.apache.flink.streaming.api.operators.SetupableStreamOperator)3 AbstractStreamOperator (org.apache.flink.streaming.api.operators.AbstractStreamOperator)2 ArrayList (java.util.ArrayList)1 StringSerializer (org.apache.flink.api.common.typeutils.base.StringSerializer)1 Configuration (org.apache.flink.configuration.Configuration)1 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)1 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)1 NoOpTaskOperatorEventGateway (org.apache.flink.runtime.taskmanager.NoOpTaskOperatorEventGateway)1 NeverFireProcessingTimeService (org.apache.flink.state.api.runtime.NeverFireProcessingTimeService)1 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)1 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)1 OperatorEventDispatcherImpl (org.apache.flink.streaming.runtime.tasks.OperatorEventDispatcherImpl)1 MockStreamTaskBuilder (org.apache.flink.streaming.util.MockStreamTaskBuilder)1