Search in sources :

Example 21 with TaskInfo

use of org.apache.flink.api.common.TaskInfo in project flink by apache.

the class CollectionExecutor method executeDataSource.

private <OUT> List<OUT> executeDataSource(GenericDataSourceBase<?, ?> source, int superStep) throws Exception {
    @SuppressWarnings("unchecked") GenericDataSourceBase<OUT, ?> typedSource = (GenericDataSourceBase<OUT, ?>) source;
    // build the runtime context and compute broadcast variables, if necessary
    TaskInfo taskInfo = new TaskInfo(typedSource.getName(), 1, 0, 1, 0);
    RuntimeUDFContext ctx;
    MetricGroup metrics = new UnregisteredMetricsGroup();
    if (RichInputFormat.class.isAssignableFrom(typedSource.getUserCodeWrapper().getUserCodeClass())) {
        ctx = superStep == 0 ? new RuntimeUDFContext(taskInfo, classLoader, executionConfig, cachedFiles, accumulators, metrics) : new IterationRuntimeUDFContext(taskInfo, classLoader, executionConfig, cachedFiles, accumulators, metrics);
    } else {
        ctx = null;
    }
    return typedSource.executeOnCollections(ctx, executionConfig);
}
Also used : TaskInfo(org.apache.flink.api.common.TaskInfo) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) RuntimeUDFContext(org.apache.flink.api.common.functions.util.RuntimeUDFContext) MetricGroup(org.apache.flink.metrics.MetricGroup)

Example 22 with TaskInfo

use of org.apache.flink.api.common.TaskInfo in project flink by apache.

the class CollectionExecutor method executeDataSink.

// --------------------------------------------------------------------------------------------
//  Operator class specific execution methods
// --------------------------------------------------------------------------------------------
private <IN> void executeDataSink(GenericDataSinkBase<?> sink, int superStep) throws Exception {
    Operator<?> inputOp = sink.getInput();
    if (inputOp == null) {
        throw new InvalidProgramException("The data sink " + sink.getName() + " has no input.");
    }
    @SuppressWarnings("unchecked") List<IN> input = (List<IN>) execute(inputOp);
    @SuppressWarnings("unchecked") GenericDataSinkBase<IN> typedSink = (GenericDataSinkBase<IN>) sink;
    // build the runtime context and compute broadcast variables, if necessary
    TaskInfo taskInfo = new TaskInfo(typedSink.getName(), 1, 0, 1, 0);
    RuntimeUDFContext ctx;
    MetricGroup metrics = new UnregisteredMetricsGroup();
    if (RichOutputFormat.class.isAssignableFrom(typedSink.getUserCodeWrapper().getUserCodeClass())) {
        ctx = superStep == 0 ? new RuntimeUDFContext(taskInfo, classLoader, executionConfig, cachedFiles, accumulators, metrics) : new IterationRuntimeUDFContext(taskInfo, classLoader, executionConfig, cachedFiles, accumulators, metrics);
    } else {
        ctx = null;
    }
    typedSink.executeOnCollections(input, ctx, executionConfig);
}
Also used : UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) TaskInfo(org.apache.flink.api.common.TaskInfo) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) RuntimeUDFContext(org.apache.flink.api.common.functions.util.RuntimeUDFContext) ArrayList(java.util.ArrayList) List(java.util.List)

Example 23 with TaskInfo

use of org.apache.flink.api.common.TaskInfo in project flink by apache.

the class RichInputFormatTest method testCheckRuntimeContextAccess.

@Test
public void testCheckRuntimeContextAccess() {
    final SerializedInputFormat<Value> inputFormat = new SerializedInputFormat<Value>();
    final TaskInfo taskInfo = new TaskInfo("test name", 3, 1, 3, 0);
    inputFormat.setRuntimeContext(new RuntimeUDFContext(taskInfo, getClass().getClassLoader(), new ExecutionConfig(), new HashMap<String, Future<Path>>(), new HashMap<String, Accumulator<?, ?>>(), new UnregisteredMetricsGroup()));
    assertEquals(inputFormat.getRuntimeContext().getIndexOfThisSubtask(), 1);
    assertEquals(inputFormat.getRuntimeContext().getNumberOfParallelSubtasks(), 3);
}
Also used : TaskInfo(org.apache.flink.api.common.TaskInfo) Path(org.apache.flink.core.fs.Path) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) HashMap(java.util.HashMap) Value(org.apache.flink.types.Value) RuntimeUDFContext(org.apache.flink.api.common.functions.util.RuntimeUDFContext) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 24 with TaskInfo

use of org.apache.flink.api.common.TaskInfo in project flink by apache.

the class RichOutputFormatTest method testCheckRuntimeContextAccess.

@Test
public void testCheckRuntimeContextAccess() {
    final SerializedOutputFormat<Value> inputFormat = new SerializedOutputFormat<Value>();
    final TaskInfo taskInfo = new TaskInfo("test name", 3, 1, 3, 0);
    inputFormat.setRuntimeContext(new RuntimeUDFContext(taskInfo, getClass().getClassLoader(), new ExecutionConfig(), new HashMap<String, Future<Path>>(), new HashMap<String, Accumulator<?, ?>>(), new UnregisteredMetricsGroup()));
    assertEquals(inputFormat.getRuntimeContext().getIndexOfThisSubtask(), 1);
    assertEquals(inputFormat.getRuntimeContext().getNumberOfParallelSubtasks(), 3);
}
Also used : TaskInfo(org.apache.flink.api.common.TaskInfo) Path(org.apache.flink.core.fs.Path) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) HashMap(java.util.HashMap) Value(org.apache.flink.types.Value) RuntimeUDFContext(org.apache.flink.api.common.functions.util.RuntimeUDFContext) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 25 with TaskInfo

use of org.apache.flink.api.common.TaskInfo in project flink by apache.

the class FlatMapOperatorCollectionTest method testExecuteOnCollection.

private void testExecuteOnCollection(FlatMapFunction<String, String> udf, List<String> input, boolean mutableSafe) throws Exception {
    ExecutionConfig executionConfig = new ExecutionConfig();
    if (mutableSafe) {
        executionConfig.disableObjectReuse();
    } else {
        executionConfig.enableObjectReuse();
    }
    final TaskInfo taskInfo = new TaskInfo("Test UDF", 4, 0, 4, 0);
    // run on collections
    final List<String> result = getTestFlatMapOperator(udf).executeOnCollections(input, new RuntimeUDFContext(taskInfo, null, executionConfig, new HashMap<String, Future<Path>>(), new HashMap<String, Accumulator<?, ?>>(), new UnregisteredMetricsGroup()), executionConfig);
    Assert.assertEquals(input.size(), result.size());
    Assert.assertEquals(input, result);
}
Also used : TaskInfo(org.apache.flink.api.common.TaskInfo) Path(org.apache.flink.core.fs.Path) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) HashMap(java.util.HashMap) RuntimeUDFContext(org.apache.flink.api.common.functions.util.RuntimeUDFContext) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig)

Aggregations

TaskInfo (org.apache.flink.api.common.TaskInfo)35 Test (org.junit.Test)24 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)20 RuntimeUDFContext (org.apache.flink.api.common.functions.util.RuntimeUDFContext)17 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)17 HashMap (java.util.HashMap)15 Configuration (org.apache.flink.configuration.Configuration)15 Path (org.apache.flink.core.fs.Path)13 Environment (org.apache.flink.runtime.execution.Environment)12 ArrayList (java.util.ArrayList)10 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)8 Accumulator (org.apache.flink.api.common.accumulators.Accumulator)7 Future (java.util.concurrent.Future)6 TestingTaskManagerRuntimeInfo (org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)5 KryoSerializer (org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer)5 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)5 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)5