Search in sources :

Example 6 with InputOutputFormatContainer

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

the class TaskTestBase method registerFileOutputTask.

public void registerFileOutputTask(FileOutputFormat<Record> outputFormat, String outPath, Configuration formatParams) {
    outputFormat.setOutputFilePath(new Path(outPath));
    outputFormat.setWriteMode(WriteMode.OVERWRITE);
    OperatorID operatorID = new OperatorID();
    new InputOutputFormatContainer(Thread.currentThread().getContextClassLoader()).addOutputFormat(operatorID, outputFormat).addParameters(operatorID, formatParams).write(new TaskConfig(this.mockEnv.getTaskConfiguration()));
}
Also used : Path(org.apache.flink.core.fs.Path) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) InputOutputFormatContainer(org.apache.flink.runtime.jobgraph.InputOutputFormatContainer)

Example 7 with InputOutputFormatContainer

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

the class DataSourceTask method initInputFormat.

/**
 * Initializes the InputFormat implementation and configuration.
 *
 * @throws RuntimeException Throws if instance of InputFormat implementation can not be
 *     obtained.
 */
private void initInputFormat() {
    ClassLoader userCodeClassLoader = getUserCodeClassLoader();
    // obtain task configuration (including stub parameters)
    Configuration taskConf = getTaskConfiguration();
    this.config = new TaskConfig(taskConf);
    final Pair<OperatorID, InputFormat<OT, InputSplit>> operatorIdAndInputFormat;
    InputOutputFormatContainer formatContainer = new InputOutputFormatContainer(config, userCodeClassLoader);
    try {
        operatorIdAndInputFormat = formatContainer.getUniqueInputFormat();
        this.format = operatorIdAndInputFormat.getValue();
        // check if the class is a subclass, if the check is required
        if (!InputFormat.class.isAssignableFrom(this.format.getClass())) {
            throw new RuntimeException("The class '" + this.format.getClass().getName() + "' is not a subclass of '" + InputFormat.class.getName() + "' as is required.");
        }
    } catch (ClassCastException ccex) {
        throw new RuntimeException("The stub class is not a proper subclass of " + InputFormat.class.getName(), ccex);
    }
    Thread thread = Thread.currentThread();
    ClassLoader original = thread.getContextClassLoader();
    // user code
    try {
        thread.setContextClassLoader(userCodeClassLoader);
        this.format.configure(formatContainer.getParameters(operatorIdAndInputFormat.getKey()));
    } catch (Throwable t) {
        throw new RuntimeException("The user defined 'configure()' method caused an error: " + t.getMessage(), t);
    } finally {
        thread.setContextClassLoader(original);
    }
    // get the factory for the type serializer
    this.serializerFactory = this.config.getOutputSerializer(userCodeClassLoader);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) InputFormat(org.apache.flink.api.common.io.InputFormat) RichInputFormat(org.apache.flink.api.common.io.RichInputFormat) UserCodeClassLoader(org.apache.flink.util.UserCodeClassLoader) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) InputOutputFormatContainer(org.apache.flink.runtime.jobgraph.InputOutputFormatContainer)

Aggregations

InputOutputFormatContainer (org.apache.flink.runtime.jobgraph.InputOutputFormatContainer)7 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)7 TaskConfig (org.apache.flink.runtime.operators.util.TaskConfig)7 InputOutputFormatVertex (org.apache.flink.runtime.jobgraph.InputOutputFormatVertex)3 InputFormat (org.apache.flink.api.common.io.InputFormat)2 OutputFormat (org.apache.flink.api.common.io.OutputFormat)2 Configuration (org.apache.flink.configuration.Configuration)2 HashMap (java.util.HashMap)1 RichInputFormat (org.apache.flink.api.common.io.RichInputFormat)1 RichOutputFormat (org.apache.flink.api.common.io.RichOutputFormat)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 Path (org.apache.flink.core.fs.Path)1 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)1 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 InputFormatSourceFunction (org.apache.flink.streaming.api.functions.source.InputFormatSourceFunction)1 Record (org.apache.flink.types.Record)1 UserCodeClassLoader (org.apache.flink.util.UserCodeClassLoader)1