Search in sources :

Example 46 with TaskConfig

use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.

the class JoinWithSolutionSetFirstDriver method initialize.

// --------------------------------------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
public void initialize() {
    final TypeSerializer<IT1> solutionSetSerializer;
    final TypeComparator<IT1> solutionSetComparator;
    // grab a handle to the hash table from the iteration broker
    if (taskContext instanceof AbstractIterativeTask) {
        AbstractIterativeTask<?, ?> iterativeTaskContext = (AbstractIterativeTask<?, ?>) taskContext;
        String identifier = iterativeTaskContext.brokerKey();
        Object table = SolutionSetBroker.instance().get(identifier);
        if (table instanceof CompactingHashTable) {
            this.hashTable = (CompactingHashTable<IT1>) table;
            solutionSetSerializer = this.hashTable.getBuildSideSerializer();
            solutionSetComparator = this.hashTable.getBuildSideComparator().duplicate();
        } else if (table instanceof JoinHashMap) {
            this.objectMap = (JoinHashMap<IT1>) table;
            solutionSetSerializer = this.objectMap.getBuildSerializer();
            solutionSetComparator = this.objectMap.getBuildComparator().duplicate();
        } else {
            throw new RuntimeException("Unrecognized solution set index: " + table);
        }
    } else {
        throw new RuntimeException("The task context of this driver is no iterative task context.");
    }
    TaskConfig config = taskContext.getTaskConfig();
    ClassLoader classLoader = taskContext.getUserCodeClassLoader();
    TypeSerializer<IT2> probeSideSerializer = taskContext.<IT2>getInputSerializer(0).getSerializer();
    TypeComparatorFactory<IT2> probeSideComparatorFactory = config.getDriverComparator(0, classLoader);
    this.probeSideComparator = probeSideComparatorFactory.createComparator();
    ExecutionConfig executionConfig = taskContext.getExecutionConfig();
    objectReuseEnabled = executionConfig.isObjectReuseEnabled();
    if (objectReuseEnabled) {
        solutionSideRecord = solutionSetSerializer.createInstance();
        probeSideRecord = probeSideSerializer.createInstance();
    }
    TypePairComparatorFactory<IT1, IT2> factory = taskContext.getTaskConfig().getPairComparatorFactory(taskContext.getUserCodeClassLoader());
    pairComparator = factory.createComparator21(solutionSetComparator, this.probeSideComparator);
}
Also used : AbstractIterativeTask(org.apache.flink.runtime.iterative.task.AbstractIterativeTask) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) CompactingHashTable(org.apache.flink.runtime.operators.hash.CompactingHashTable) JoinHashMap(org.apache.flink.api.common.operators.util.JoinHashMap)

Example 47 with TaskConfig

use of org.apache.flink.runtime.operators.util.TaskConfig 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);
    try {
        this.format = config.<InputFormat<OT, InputSplit>>getStubWrapper(userCodeClassLoader).getUserCodeObject(InputFormat.class, userCodeClassLoader);
        // 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();
    // configure the stub. catch exceptions here extra, to report them as originating from the user code
    try {
        thread.setContextClassLoader(userCodeClassLoader);
        this.format.configure(this.config.getStubParameters());
    } 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) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig)

Example 48 with TaskConfig

use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.

the class TaskTestBase method registerTask.

public void registerTask(AbstractInvokable task, @SuppressWarnings("rawtypes") Class<? extends Driver> driver, Class<? extends RichFunction> stubClass) {
    final TaskConfig config = new TaskConfig(this.mockEnv.getTaskConfiguration());
    config.setDriver(driver);
    config.setStubWrapper(new UserCodeClassWrapper<>(stubClass));
    task.setEnvironment(this.mockEnv);
}
Also used : TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig)

Aggregations

TaskConfig (org.apache.flink.runtime.operators.util.TaskConfig)48 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)13 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)12 IOException (java.io.IOException)9 BulkIterationPlanNode (org.apache.flink.optimizer.plan.BulkIterationPlanNode)9 BulkPartialSolutionPlanNode (org.apache.flink.optimizer.plan.BulkPartialSolutionPlanNode)9 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)9 IterationPlanNode (org.apache.flink.optimizer.plan.IterationPlanNode)9 NAryUnionPlanNode (org.apache.flink.optimizer.plan.NAryUnionPlanNode)9 PlanNode (org.apache.flink.optimizer.plan.PlanNode)9 SingleInputPlanNode (org.apache.flink.optimizer.plan.SingleInputPlanNode)9 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)9 SolutionSetPlanNode (org.apache.flink.optimizer.plan.SolutionSetPlanNode)9 SourcePlanNode (org.apache.flink.optimizer.plan.SourcePlanNode)9 WorksetIterationPlanNode (org.apache.flink.optimizer.plan.WorksetIterationPlanNode)9 WorksetPlanNode (org.apache.flink.optimizer.plan.WorksetPlanNode)9 Configuration (org.apache.flink.configuration.Configuration)8 CompilerException (org.apache.flink.optimizer.CompilerException)8 Channel (org.apache.flink.optimizer.plan.Channel)6 NamedChannel (org.apache.flink.optimizer.plan.NamedChannel)6