Search in sources :

Example 1 with StreamTaskSourceInput

use of org.apache.flink.streaming.runtime.io.StreamTaskSourceInput in project flink by apache.

the class OperatorChain method createChainedSources.

@SuppressWarnings("rawtypes")
private Map<StreamConfig.SourceInputConfig, ChainedSource> createChainedSources(StreamTask<OUT, OP> containingTask, StreamConfig.InputConfig[] configuredInputs, Map<Integer, StreamConfig> chainedConfigs, ClassLoader userCodeClassloader, List<StreamOperatorWrapper<?, ?>> allOpWrappers) {
    if (Arrays.stream(configuredInputs).noneMatch(input -> input instanceof StreamConfig.SourceInputConfig)) {
        return Collections.emptyMap();
    }
    checkState(mainOperatorWrapper.getStreamOperator() instanceof MultipleInputStreamOperator, "Creating chained input is only supported with MultipleInputStreamOperator and MultipleInputStreamTask");
    Map<StreamConfig.SourceInputConfig, ChainedSource> chainedSourceInputs = new HashMap<>();
    MultipleInputStreamOperator<?> multipleInputOperator = (MultipleInputStreamOperator<?>) mainOperatorWrapper.getStreamOperator();
    List<Input> operatorInputs = multipleInputOperator.getInputs();
    int sourceInputGateIndex = Arrays.stream(containingTask.getEnvironment().getAllInputGates()).mapToInt(IndexedInputGate::getInputGateIndex).max().orElse(-1) + 1;
    for (int inputId = 0; inputId < configuredInputs.length; inputId++) {
        if (!(configuredInputs[inputId] instanceof StreamConfig.SourceInputConfig)) {
            continue;
        }
        StreamConfig.SourceInputConfig sourceInput = (StreamConfig.SourceInputConfig) configuredInputs[inputId];
        int sourceEdgeId = sourceInput.getInputEdge().getSourceId();
        StreamConfig sourceInputConfig = chainedConfigs.get(sourceEdgeId);
        OutputTag outputTag = sourceInput.getInputEdge().getOutputTag();
        WatermarkGaugeExposingOutput chainedSourceOutput = createChainedSourceOutput(containingTask, sourceInputConfig, userCodeClassloader, getFinishedOnRestoreInputOrDefault(operatorInputs.get(inputId)), multipleInputOperator.getMetricGroup(), outputTag);
        SourceOperator<?, ?> sourceOperator = (SourceOperator<?, ?>) createOperator(containingTask, sourceInputConfig, userCodeClassloader, (WatermarkGaugeExposingOutput<StreamRecord<OUT>>) chainedSourceOutput, allOpWrappers, true);
        chainedSourceInputs.put(sourceInput, new ChainedSource(chainedSourceOutput, this.isTaskDeployedAsFinished() ? new StreamTaskFinishedOnRestoreSourceInput<>(sourceOperator, sourceInputGateIndex++, inputId) : new StreamTaskSourceInput<>(sourceOperator, sourceInputGateIndex++, inputId)));
    }
    return chainedSourceInputs;
}
Also used : HashMap(java.util.HashMap) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) BoundedMultiInput(org.apache.flink.streaming.api.operators.BoundedMultiInput) StreamTaskSourceInput(org.apache.flink.streaming.runtime.io.StreamTaskSourceInput) Input(org.apache.flink.streaming.api.operators.Input) MultipleInputStreamOperator(org.apache.flink.streaming.api.operators.MultipleInputStreamOperator) SourceOperator(org.apache.flink.streaming.api.operators.SourceOperator) OutputTag(org.apache.flink.util.OutputTag)

Aggregations

HashMap (java.util.HashMap)1 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)1 BoundedMultiInput (org.apache.flink.streaming.api.operators.BoundedMultiInput)1 Input (org.apache.flink.streaming.api.operators.Input)1 MultipleInputStreamOperator (org.apache.flink.streaming.api.operators.MultipleInputStreamOperator)1 SourceOperator (org.apache.flink.streaming.api.operators.SourceOperator)1 StreamTaskSourceInput (org.apache.flink.streaming.runtime.io.StreamTaskSourceInput)1 OutputTag (org.apache.flink.util.OutputTag)1