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()));
}
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);
}
Aggregations