Search in sources :

Example 1 with InputOutputFormatVertex

use of org.apache.flink.runtime.jobgraph.InputOutputFormatVertex in project flink by apache.

the class StreamingJobGraphGeneratorTest method testInputOutputFormat.

@Test
public void testInputOutputFormat() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<Long> source = env.addSource(new InputFormatSourceFunction<>(new TypeSerializerInputFormat<>(TypeInformation.of(Long.class)), TypeInformation.of(Long.class)), TypeInformation.of(Long.class)).name("source");
    source.writeUsingOutputFormat(new DiscardingOutputFormat<>()).name("sink1");
    source.writeUsingOutputFormat(new DiscardingOutputFormat<>()).name("sink2");
    StreamGraph streamGraph = env.getStreamGraph();
    JobGraph jobGraph = StreamingJobGraphGenerator.createJobGraph(streamGraph);
    assertEquals(1, jobGraph.getNumberOfVertices());
    JobVertex jobVertex = jobGraph.getVertices().iterator().next();
    assertTrue(jobVertex instanceof InputOutputFormatVertex);
    InputOutputFormatContainer formatContainer = new InputOutputFormatContainer(new TaskConfig(jobVertex.getConfiguration()), Thread.currentThread().getContextClassLoader());
    Map<OperatorID, UserCodeWrapper<? extends InputFormat<?, ?>>> inputFormats = formatContainer.getInputFormats();
    Map<OperatorID, UserCodeWrapper<? extends OutputFormat<?>>> outputFormats = formatContainer.getOutputFormats();
    assertEquals(1, inputFormats.size());
    assertEquals(2, outputFormats.size());
    Map<String, OperatorID> nameToOperatorIds = new HashMap<>();
    StreamConfig headConfig = new StreamConfig(jobVertex.getConfiguration());
    nameToOperatorIds.put(headConfig.getOperatorName(), headConfig.getOperatorID());
    Map<Integer, StreamConfig> chainedConfigs = headConfig.getTransitiveChainedTaskConfigs(Thread.currentThread().getContextClassLoader());
    for (StreamConfig config : chainedConfigs.values()) {
        nameToOperatorIds.put(config.getOperatorName(), config.getOperatorID());
    }
    InputFormat<?, ?> sourceFormat = inputFormats.get(nameToOperatorIds.get("Source: source")).getUserCodeObject();
    assertTrue(sourceFormat instanceof TypeSerializerInputFormat);
    OutputFormat<?> sinkFormat1 = outputFormats.get(nameToOperatorIds.get("Sink: sink1")).getUserCodeObject();
    assertTrue(sinkFormat1 instanceof DiscardingOutputFormat);
    OutputFormat<?> sinkFormat2 = outputFormats.get(nameToOperatorIds.get("Sink: sink2")).getUserCodeObject();
    assertTrue(sinkFormat2 instanceof DiscardingOutputFormat);
}
Also used : HashMap(java.util.HashMap) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) InputFormatSourceFunction(org.apache.flink.streaming.api.functions.source.InputFormatSourceFunction) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) InputOutputFormatVertex(org.apache.flink.runtime.jobgraph.InputOutputFormatVertex) DiscardingOutputFormat(org.apache.flink.api.java.io.DiscardingOutputFormat) UserCodeWrapper(org.apache.flink.api.common.operators.util.UserCodeWrapper) InputOutputFormatContainer(org.apache.flink.runtime.jobgraph.InputOutputFormatContainer) DiscardingOutputFormat(org.apache.flink.api.java.io.DiscardingOutputFormat) OutputFormat(org.apache.flink.api.common.io.OutputFormat) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) TypeSerializerInputFormat(org.apache.flink.api.java.io.TypeSerializerInputFormat) InputFormat(org.apache.flink.api.common.io.InputFormat) TypeSerializerInputFormat(org.apache.flink.api.java.io.TypeSerializerInputFormat) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Example 2 with InputOutputFormatVertex

use of org.apache.flink.runtime.jobgraph.InputOutputFormatVertex in project flink by apache.

the class JobGraphGenerator method createDataSinkVertex.

private JobVertex createDataSinkVertex(SinkPlanNode node) throws CompilerException {
    final InputOutputFormatVertex vertex = new InputOutputFormatVertex(node.getNodeName());
    final TaskConfig config = new TaskConfig(vertex.getConfiguration());
    final OperatorID operatorID = new OperatorID();
    vertex.setResources(node.getMinResources(), node.getPreferredResources());
    vertex.setInvokableClass(DataSinkTask.class);
    vertex.setFormatDescription(operatorID, getDescriptionForUserCode(node.getProgramOperator().getUserCodeWrapper()));
    // set user code
    new InputOutputFormatContainer(Thread.currentThread().getContextClassLoader()).addOutputFormat(operatorID, (UserCodeWrapper<? extends OutputFormat<?>>) node.getProgramOperator().getUserCodeWrapper()).addParameters(operatorID, node.getProgramOperator().getParameters()).write(config);
    return vertex;
}
Also used : TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) InputOutputFormatVertex(org.apache.flink.runtime.jobgraph.InputOutputFormatVertex) InputOutputFormatContainer(org.apache.flink.runtime.jobgraph.InputOutputFormatContainer)

Example 3 with InputOutputFormatVertex

use of org.apache.flink.runtime.jobgraph.InputOutputFormatVertex in project flink by apache.

the class JobGraphGenerator method createDataSourceVertex.

private JobVertex createDataSourceVertex(SourcePlanNode node) throws CompilerException {
    final InputOutputFormatVertex vertex = new InputOutputFormatVertex(node.getNodeName());
    final TaskConfig config = new TaskConfig(vertex.getConfiguration());
    final OperatorID operatorID = new OperatorID();
    vertex.setResources(node.getMinResources(), node.getPreferredResources());
    vertex.setInvokableClass(DataSourceTask.class);
    vertex.setFormatDescription(operatorID, getDescriptionForUserCode(node.getProgramOperator().getUserCodeWrapper()));
    // set user code
    new InputOutputFormatContainer(Thread.currentThread().getContextClassLoader()).addInputFormat(operatorID, (UserCodeWrapper<? extends InputFormat<?, ?>>) node.getProgramOperator().getUserCodeWrapper()).addParameters(operatorID, node.getProgramOperator().getParameters()).write(config);
    config.setOutputSerializer(node.getSerializer());
    return vertex;
}
Also used : TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) InputOutputFormatVertex(org.apache.flink.runtime.jobgraph.InputOutputFormatVertex) InputOutputFormatContainer(org.apache.flink.runtime.jobgraph.InputOutputFormatContainer)

Example 4 with InputOutputFormatVertex

use of org.apache.flink.runtime.jobgraph.InputOutputFormatVertex in project flink by apache.

the class StreamingJobGraphGenerator method createJobVertex.

private StreamConfig createJobVertex(Integer streamNodeId, OperatorChainInfo chainInfo) {
    JobVertex jobVertex;
    StreamNode streamNode = streamGraph.getStreamNode(streamNodeId);
    byte[] hash = chainInfo.getHash(streamNodeId);
    if (hash == null) {
        throw new IllegalStateException("Cannot find node hash. " + "Did you generate them before calling this method?");
    }
    JobVertexID jobVertexId = new JobVertexID(hash);
    List<Tuple2<byte[], byte[]>> chainedOperators = chainInfo.getChainedOperatorHashes(streamNodeId);
    List<OperatorIDPair> operatorIDPairs = new ArrayList<>();
    if (chainedOperators != null) {
        for (Tuple2<byte[], byte[]> chainedOperator : chainedOperators) {
            OperatorID userDefinedOperatorID = chainedOperator.f1 == null ? null : new OperatorID(chainedOperator.f1);
            operatorIDPairs.add(OperatorIDPair.of(new OperatorID(chainedOperator.f0), userDefinedOperatorID));
        }
    }
    if (chainedInputOutputFormats.containsKey(streamNodeId)) {
        jobVertex = new InputOutputFormatVertex(chainedNames.get(streamNodeId), jobVertexId, operatorIDPairs);
        chainedInputOutputFormats.get(streamNodeId).write(new TaskConfig(jobVertex.getConfiguration()));
    } else {
        jobVertex = new JobVertex(chainedNames.get(streamNodeId), jobVertexId, operatorIDPairs);
    }
    for (OperatorCoordinator.Provider coordinatorProvider : chainInfo.getCoordinatorProviders()) {
        try {
            jobVertex.addOperatorCoordinator(new SerializedValue<>(coordinatorProvider));
        } catch (IOException e) {
            throw new FlinkRuntimeException(String.format("Coordinator Provider for node %s is not serializable.", chainedNames.get(streamNodeId)), e);
        }
    }
    jobVertex.setResources(chainedMinResources.get(streamNodeId), chainedPreferredResources.get(streamNodeId));
    jobVertex.setInvokableClass(streamNode.getJobVertexClass());
    int parallelism = streamNode.getParallelism();
    if (parallelism > 0) {
        jobVertex.setParallelism(parallelism);
    } else {
        parallelism = jobVertex.getParallelism();
    }
    jobVertex.setMaxParallelism(streamNode.getMaxParallelism());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Parallelism set: {} for {}", parallelism, streamNodeId);
    }
    jobVertices.put(streamNodeId, jobVertex);
    builtVertices.add(streamNodeId);
    jobGraph.addVertex(jobVertex);
    return new StreamConfig(jobVertex.getConfiguration());
}
Also used : JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) ArrayList(java.util.ArrayList) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) IOException(java.io.IOException) InputOutputFormatVertex(org.apache.flink.runtime.jobgraph.InputOutputFormatVertex) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) Tuple2(org.apache.flink.api.java.tuple.Tuple2) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) OperatorIDPair(org.apache.flink.runtime.OperatorIDPair)

Aggregations

InputOutputFormatVertex (org.apache.flink.runtime.jobgraph.InputOutputFormatVertex)4 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)4 TaskConfig (org.apache.flink.runtime.operators.util.TaskConfig)4 InputOutputFormatContainer (org.apache.flink.runtime.jobgraph.InputOutputFormatContainer)3 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 InputFormat (org.apache.flink.api.common.io.InputFormat)1 OutputFormat (org.apache.flink.api.common.io.OutputFormat)1 UserCodeWrapper (org.apache.flink.api.common.operators.util.UserCodeWrapper)1 DiscardingOutputFormat (org.apache.flink.api.java.io.DiscardingOutputFormat)1 TypeSerializerInputFormat (org.apache.flink.api.java.io.TypeSerializerInputFormat)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 OperatorIDPair (org.apache.flink.runtime.OperatorIDPair)1 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)1 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)1 OperatorCoordinator (org.apache.flink.runtime.operators.coordination.OperatorCoordinator)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 InputFormatSourceFunction (org.apache.flink.streaming.api.functions.source.InputFormatSourceFunction)1