Search in sources :

Example 6 with Task

use of org.apache.flink.runtime.taskmanager.Task in project flink by apache.

the class TaskExecutor method stopTask.

@RpcMethod
public Acknowledge stopTask(ExecutionAttemptID executionAttemptID) throws TaskException {
    final Task task = taskSlotTable.getTask(executionAttemptID);
    if (task != null) {
        try {
            task.stopExecution();
            return Acknowledge.get();
        } catch (Throwable t) {
            throw new TaskException("Cannot stop task for execution " + executionAttemptID + '.', t);
        }
    } else {
        final String message = "Cannot find task to stop for execution " + executionAttemptID + '.';
        log.debug(message);
        throw new TaskException(message);
    }
}
Also used : Task(org.apache.flink.runtime.taskmanager.Task) TaskException(org.apache.flink.runtime.taskexecutor.exceptions.TaskException) RpcMethod(org.apache.flink.runtime.rpc.RpcMethod)

Example 7 with Task

use of org.apache.flink.runtime.taskmanager.Task in project flink by apache.

the class TaskExecutor method triggerCheckpoint.

// ----------------------------------------------------------------------
// Checkpointing RPCs
// ----------------------------------------------------------------------
@RpcMethod
public Acknowledge triggerCheckpoint(ExecutionAttemptID executionAttemptID, long checkpointId, long checkpointTimestamp, CheckpointOptions checkpointOptions) throws CheckpointException {
    log.debug("Trigger checkpoint {}@{} for {}.", checkpointId, checkpointTimestamp, executionAttemptID);
    final Task task = taskSlotTable.getTask(executionAttemptID);
    if (task != null) {
        task.triggerCheckpointBarrier(checkpointId, checkpointTimestamp, checkpointOptions);
        return Acknowledge.get();
    } else {
        final String message = "TaskManager received a checkpoint request for unknown task " + executionAttemptID + '.';
        log.debug(message);
        throw new CheckpointException(message);
    }
}
Also used : Task(org.apache.flink.runtime.taskmanager.Task) CheckpointException(org.apache.flink.runtime.taskexecutor.exceptions.CheckpointException) RpcMethod(org.apache.flink.runtime.rpc.RpcMethod)

Example 8 with Task

use of org.apache.flink.runtime.taskmanager.Task in project flink by apache.

the class TaskExecutor method cancelTask.

@RpcMethod
public Acknowledge cancelTask(ExecutionAttemptID executionAttemptID) throws TaskException {
    final Task task = taskSlotTable.getTask(executionAttemptID);
    if (task != null) {
        try {
            task.cancelExecution();
            return Acknowledge.get();
        } catch (Throwable t) {
            throw new TaskException("Cannot cancel task for execution " + executionAttemptID + '.', t);
        }
    } else {
        final String message = "Cannot find task to stop for execution " + executionAttemptID + '.';
        log.debug(message);
        throw new TaskException(message);
    }
}
Also used : Task(org.apache.flink.runtime.taskmanager.Task) TaskException(org.apache.flink.runtime.taskexecutor.exceptions.TaskException) RpcMethod(org.apache.flink.runtime.rpc.RpcMethod)

Example 9 with Task

use of org.apache.flink.runtime.taskmanager.Task in project flink by apache.

the class StreamTaskTest method testCancellationNotBlockedOnLock.

@Test
public void testCancellationNotBlockedOnLock() throws Exception {
    SYNC_LATCH = new OneShotLatch();
    StreamConfig cfg = new StreamConfig(new Configuration());
    Task task = createTask(CancelLockingTask.class, cfg, new Configuration());
    // start the task and wait until it runs
    // execution state RUNNING is not enough, we need to wait until the stream task's run() method
    // is entered
    task.startTaskThread();
    SYNC_LATCH.await();
    // cancel the execution - this should lead to smooth shutdown
    task.cancelExecution();
    task.getExecutingThread().join();
    assertEquals(ExecutionState.CANCELED, task.getExecutionState());
}
Also used : Task(org.apache.flink.runtime.taskmanager.Task) Configuration(org.apache.flink.configuration.Configuration) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with Task

use of org.apache.flink.runtime.taskmanager.Task in project flink by apache.

the class StreamTaskTest method createTask.

public static Task createTask(Class<? extends AbstractInvokable> invokable, StreamConfig taskConfig, Configuration taskManagerConfig) throws Exception {
    LibraryCacheManager libCache = mock(LibraryCacheManager.class);
    when(libCache.getClassLoader(any(JobID.class))).thenReturn(StreamTaskTest.class.getClassLoader());
    ResultPartitionManager partitionManager = mock(ResultPartitionManager.class);
    ResultPartitionConsumableNotifier consumableNotifier = mock(ResultPartitionConsumableNotifier.class);
    PartitionProducerStateChecker partitionProducerStateChecker = mock(PartitionProducerStateChecker.class);
    Executor executor = mock(Executor.class);
    NetworkEnvironment network = mock(NetworkEnvironment.class);
    when(network.getResultPartitionManager()).thenReturn(partitionManager);
    when(network.getDefaultIOMode()).thenReturn(IOManager.IOMode.SYNC);
    when(network.createKvStateTaskRegistry(any(JobID.class), any(JobVertexID.class))).thenReturn(mock(TaskKvStateRegistry.class));
    JobInformation jobInformation = new JobInformation(new JobID(), "Job Name", new SerializedValue<>(new ExecutionConfig()), new Configuration(), Collections.<BlobKey>emptyList(), Collections.<URL>emptyList());
    TaskInformation taskInformation = new TaskInformation(new JobVertexID(), "Test Task", 1, 1, invokable.getName(), taskConfig.getConfiguration());
    return new Task(jobInformation, taskInformation, new ExecutionAttemptID(), new AllocationID(), 0, 0, Collections.<ResultPartitionDeploymentDescriptor>emptyList(), Collections.<InputGateDeploymentDescriptor>emptyList(), 0, new TaskStateHandles(), mock(MemoryManager.class), mock(IOManager.class), network, mock(BroadcastVariableManager.class), mock(TaskManagerActions.class), mock(InputSplitProvider.class), mock(CheckpointResponder.class), libCache, mock(FileCache.class), new TestingTaskManagerRuntimeInfo(taskManagerConfig, new String[] { System.getProperty("java.io.tmpdir") }), new UnregisteredTaskMetricsGroup(), consumableNotifier, partitionProducerStateChecker, executor);
}
Also used : Task(org.apache.flink.runtime.taskmanager.Task) Configuration(org.apache.flink.configuration.Configuration) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Matchers.anyString(org.mockito.Matchers.anyString) TaskManagerActions(org.apache.flink.runtime.taskmanager.TaskManagerActions) Executor(java.util.concurrent.Executor) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) BroadcastVariableManager(org.apache.flink.runtime.broadcast.BroadcastVariableManager) PartitionProducerStateChecker(org.apache.flink.runtime.io.network.netty.PartitionProducerStateChecker) ResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.ResultPartitionConsumableNotifier) InputSplitProvider(org.apache.flink.runtime.jobgraph.tasks.InputSplitProvider) UnregisteredTaskMetricsGroup(org.apache.flink.runtime.operators.testutils.UnregisteredTaskMetricsGroup) JobInformation(org.apache.flink.runtime.executiongraph.JobInformation) TaskInformation(org.apache.flink.runtime.executiongraph.TaskInformation) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) CheckpointResponder(org.apache.flink.runtime.taskmanager.CheckpointResponder) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) LibraryCacheManager(org.apache.flink.runtime.execution.librarycache.LibraryCacheManager) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) FileCache(org.apache.flink.runtime.filecache.FileCache) TaskStateHandles(org.apache.flink.runtime.state.TaskStateHandles) NetworkEnvironment(org.apache.flink.runtime.io.network.NetworkEnvironment) JobID(org.apache.flink.api.common.JobID)

Aggregations

Task (org.apache.flink.runtime.taskmanager.Task)25 Configuration (org.apache.flink.configuration.Configuration)13 Test (org.junit.Test)10 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)9 JobID (org.apache.flink.api.common.JobID)6 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)6 RpcMethod (org.apache.flink.runtime.rpc.RpcMethod)6 JobInformation (org.apache.flink.runtime.executiongraph.JobInformation)5 TaskInformation (org.apache.flink.runtime.executiongraph.TaskInformation)5 PartitionProducerStateChecker (org.apache.flink.runtime.io.network.netty.PartitionProducerStateChecker)5 ResultPartitionConsumableNotifier (org.apache.flink.runtime.io.network.partition.ResultPartitionConsumableNotifier)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)4 BroadcastVariableManager (org.apache.flink.runtime.broadcast.BroadcastVariableManager)4 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)4 FileCache (org.apache.flink.runtime.filecache.FileCache)4 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)4 NetworkEnvironment (org.apache.flink.runtime.io.network.NetworkEnvironment)4 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)4 InputSplitProvider (org.apache.flink.runtime.jobgraph.tasks.InputSplitProvider)4