Java Code Examples for org.apache.flink.runtime.taskmanager.Task#getJobID()

The following examples show how to use org.apache.flink.runtime.taskmanager.Task#getJobID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskSlotTable.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Add the given task to the slot identified by the task's allocation id.
 *
 * @param task to add to the task slot with the respective allocation id
 * @throws SlotNotFoundException if there was no slot for the given allocation id
 * @throws SlotNotActiveException if there was no slot active for task's job and allocation id
 * @return True if the task could be added to the task slot; otherwise false
 */
public boolean addTask(Task task) throws SlotNotFoundException, SlotNotActiveException {
	Preconditions.checkNotNull(task);

	TaskSlot taskSlot = getTaskSlot(task.getAllocationId());

	if (taskSlot != null) {
		if (taskSlot.isActive(task.getJobID(), task.getAllocationId())) {
			if (taskSlot.add(task)) {
				taskSlotMappings.put(task.getExecutionId(), new TaskSlotMapping(task, taskSlot));

				return true;
			} else {
				return false;
			}
		} else {
			throw new SlotNotActiveException(task.getJobID(), task.getAllocationId());
		}
	} else {
		throw new SlotNotFoundException(task.getAllocationId());
	}
}
 
Example 2
Source File: TaskSlotTable.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Add the given task to the slot identified by the task's allocation id.
 *
 * @param task to add to the task slot with the respective allocation id
 * @throws SlotNotFoundException if there was no slot for the given allocation id
 * @throws SlotNotActiveException if there was no slot active for task's job and allocation id
 * @return True if the task could be added to the task slot; otherwise false
 */
public boolean addTask(Task task) throws SlotNotFoundException, SlotNotActiveException {
	Preconditions.checkNotNull(task);

	TaskSlot taskSlot = getTaskSlot(task.getAllocationId());

	if (taskSlot != null) {
		if (taskSlot.isActive(task.getJobID(), task.getAllocationId())) {
			if (taskSlot.add(task)) {
				taskSlotMappings.put(task.getExecutionId(), new TaskSlotMapping(task, taskSlot));

				return true;
			} else {
				return false;
			}
		} else {
			throw new SlotNotActiveException(task.getJobID(), task.getAllocationId());
		}
	} else {
		throw new SlotNotFoundException(task.getAllocationId());
	}
}
 
Example 3
Source File: StreamTaskTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * This test checks that cancel calls that are issued before the operator is
 * instantiated still lead to proper canceling.
 */
@Test
public void testEarlyCanceling() throws Exception {
	final StreamConfig cfg = new StreamConfig(new Configuration());
	cfg.setOperatorID(new OperatorID(4711L, 42L));
	cfg.setStreamOperator(new SlowlyDeserializingOperator());
	cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime);

	final TaskManagerActions taskManagerActions = spy(new NoOpTaskManagerActions());
	final Task task = createTask(SourceStreamTask.class, cfg, new Configuration(), taskManagerActions);

	final TaskExecutionState state = new TaskExecutionState(
		task.getJobID(), task.getExecutionId(), ExecutionState.RUNNING);

	task.startTaskThread();

	verify(taskManagerActions, timeout(2000L)).updateTaskExecutionState(eq(state));

	// send a cancel. because the operator takes a long time to deserialize, this should
	// hit the task before the operator is deserialized
	task.cancelExecution();

	task.getExecutingThread().join();

	assertFalse("Task did not cancel", task.getExecutingThread().isAlive());
	assertEquals(ExecutionState.CANCELED, task.getExecutionState());
}
 
Example 4
Source File: StreamTaskTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This test checks that cancel calls that are issued before the operator is
 * instantiated still lead to proper canceling.
 */
@Test
public void testEarlyCanceling() throws Exception {
	final StreamConfig cfg = new StreamConfig(new Configuration());
	cfg.setOperatorID(new OperatorID(4711L, 42L));
	cfg.setStreamOperator(new SlowlyDeserializingOperator());
	cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime);

	final TaskManagerActions taskManagerActions = spy(new NoOpTaskManagerActions());
	final Task task = createTask(SourceStreamTask.class, cfg, new Configuration(), taskManagerActions);

	final TaskExecutionState state = new TaskExecutionState(
		task.getJobID(), task.getExecutionId(), ExecutionState.RUNNING);

	task.startTaskThread();

	verify(taskManagerActions, timeout(2000L)).updateTaskExecutionState(eq(state));

	// send a cancel. because the operator takes a long time to deserialize, this should
	// hit the task before the operator is deserialized
	task.cancelExecution();

	task.getExecutingThread().join();

	assertFalse("Task did not cancel", task.getExecutingThread().isAlive());
	assertEquals(ExecutionState.CANCELED, task.getExecutionState());
}
 
Example 5
Source File: StreamTaskTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This test checks that cancel calls that are issued before the operator is
 * instantiated still lead to proper canceling.
 */
@Test
public void testEarlyCanceling() throws Exception {
	final StreamConfig cfg = new StreamConfig(new Configuration());
	cfg.setOperatorID(new OperatorID(4711L, 42L));
	cfg.setStreamOperator(new SlowlyDeserializingOperator());
	cfg.setTimeCharacteristic(TimeCharacteristic.ProcessingTime);

	final TaskManagerActions taskManagerActions = spy(new NoOpTaskManagerActions());
	try (NettyShuffleEnvironment shuffleEnvironment = new NettyShuffleEnvironmentBuilder().build()) {
		final Task task =  new TestTaskBuilder(shuffleEnvironment)
			.setInvokable(SourceStreamTask.class)
			.setTaskConfig(cfg.getConfiguration())
			.setTaskManagerActions(taskManagerActions)
			.build();

		final TaskExecutionState state = new TaskExecutionState(
			task.getJobID(), task.getExecutionId(), ExecutionState.RUNNING);

		task.startTaskThread();

		verify(taskManagerActions, timeout(2000L)).updateTaskExecutionState(eq(state));

		// send a cancel. because the operator takes a long time to deserialize, this should
		// hit the task before the operator is deserialized
		task.cancelExecution();

		task.getExecutingThread().join();

		assertFalse("Task did not cancel", task.getExecutingThread().isAlive());
		assertEquals(ExecutionState.CANCELED, task.getExecutionState());
	}
}