Java Code Examples for org.apache.flink.runtime.execution.ExecutionState#DEPLOYING

The following examples show how to use org.apache.flink.runtime.execution.ExecutionState#DEPLOYING . 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: TaskExecutionStateTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization() {
	try {
		final JobID jid = new JobID();
		final ExecutionAttemptID executionId = new ExecutionAttemptID();
		final ExecutionState state = ExecutionState.DEPLOYING;
		final Throwable error = new IOException("fubar");
		
		TaskExecutionState original1 = new TaskExecutionState(jid, executionId, state, error);
		TaskExecutionState original2 = new TaskExecutionState(jid, executionId, state);
		
		TaskExecutionState javaSerCopy1 = CommonTestUtils.createCopySerializable(original1);
		TaskExecutionState javaSerCopy2 = CommonTestUtils.createCopySerializable(original2);

		// equalities
		assertEquals(original1, javaSerCopy1);
		assertEquals(javaSerCopy1, original1);

		assertEquals(original2, javaSerCopy2);
		assertEquals(javaSerCopy2, original2);

		// hash codes
		assertEquals(original1.hashCode(), javaSerCopy1.hashCode());
		assertEquals(original2.hashCode(), javaSerCopy2.hashCode());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 2
Source File: RemoteChannelStateChecker.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean isProducerConsumerReady(ResponseHandle responseHandle) {
	ExecutionState producerState = getProducerState(responseHandle);
	return producerState == ExecutionState.SCHEDULED ||
		producerState == ExecutionState.DEPLOYING ||
		producerState == ExecutionState.RUNNING ||
		producerState == ExecutionState.FINISHED;
}
 
Example 3
Source File: TaskExecutionStateTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization() {
	try {
		final JobID jid = new JobID();
		final ExecutionAttemptID executionId = new ExecutionAttemptID();
		final ExecutionState state = ExecutionState.DEPLOYING;
		final Throwable error = new IOException("fubar");
		
		TaskExecutionState original1 = new TaskExecutionState(jid, executionId, state, error);
		TaskExecutionState original2 = new TaskExecutionState(jid, executionId, state);
		
		TaskExecutionState javaSerCopy1 = CommonTestUtils.createCopySerializable(original1);
		TaskExecutionState javaSerCopy2 = CommonTestUtils.createCopySerializable(original2);

		// equalities
		assertEquals(original1, javaSerCopy1);
		assertEquals(javaSerCopy1, original1);

		assertEquals(original2, javaSerCopy2);
		assertEquals(javaSerCopy2, original2);

		// hash codes
		assertEquals(original1.hashCode(), javaSerCopy1.hashCode());
		assertEquals(original2.hashCode(), javaSerCopy2.hashCode());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 4
Source File: RemoteChannelStateChecker.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean isProducerConsumerReady(ResponseHandle responseHandle) {
	ExecutionState producerState = getProducerState(responseHandle);
	return producerState == ExecutionState.SCHEDULED ||
		producerState == ExecutionState.DEPLOYING ||
		producerState == ExecutionState.RUNNING ||
		producerState == ExecutionState.FINISHED;
}
 
Example 5
Source File: TaskExecutionStateTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization() {
	try {
		final JobID jid = new JobID();
		final ExecutionAttemptID executionId = new ExecutionAttemptID();
		final ExecutionState state = ExecutionState.DEPLOYING;
		final Throwable error = new IOException("fubar");
		
		TaskExecutionState original1 = new TaskExecutionState(jid, executionId, state, error);
		TaskExecutionState original2 = new TaskExecutionState(jid, executionId, state);
		
		TaskExecutionState javaSerCopy1 = CommonTestUtils.createCopySerializable(original1);
		TaskExecutionState javaSerCopy2 = CommonTestUtils.createCopySerializable(original2);

		// equalities
		assertEquals(original1, javaSerCopy1);
		assertEquals(javaSerCopy1, original1);

		assertEquals(original2, javaSerCopy2);
		assertEquals(javaSerCopy2, original2);

		// hash codes
		assertEquals(original1.hashCode(), javaSerCopy1.hashCode());
		assertEquals(original2.hashCode(), javaSerCopy2.hashCode());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 6
Source File: Task.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private void cancelOrFailAndCancelInvokable(ExecutionState targetState, Throwable cause) {
	while (true) {
		ExecutionState current = executionState;

		// if the task is already canceled (or canceling) or finished or failed,
		// then we need not do anything
		if (current.isTerminal() || current == ExecutionState.CANCELING) {
			LOG.info("Task {} is already in state {}", taskNameWithSubtask, current);
			return;
		}

		if (current == ExecutionState.DEPLOYING || current == ExecutionState.CREATED) {
			if (transitionState(current, targetState, cause)) {
				// if we manage this state transition, then the invokable gets never called
				// we need not call cancel on it
				this.failureCause = cause;
				return;
			}
		}
		else if (current == ExecutionState.RUNNING) {
			if (transitionState(ExecutionState.RUNNING, targetState, cause)) {
				// we are canceling / failing out of the running state
				// we need to cancel the invokable

				// copy reference to guard against concurrent null-ing out the reference
				final AbstractInvokable invokable = this.invokable;

				if (invokable != null && invokableHasBeenCanceled.compareAndSet(false, true)) {
					this.failureCause = cause;

					LOG.info("Triggering cancellation of task code {} ({}).", taskNameWithSubtask, executionId);

					// because the canceling may block on user code, we cancel from a separate thread
					// we do not reuse the async call handler, because that one may be blocked, in which
					// case the canceling could not continue

					// The canceller calls cancel and interrupts the executing thread once
					Runnable canceler = new TaskCanceler(
							LOG,
							invokable,
							executingThread,
							taskNameWithSubtask,
							producedPartitions,
							inputGates);

					Thread cancelThread = new Thread(
							executingThread.getThreadGroup(),
							canceler,
							String.format("Canceler for %s (%s).", taskNameWithSubtask, executionId));
					cancelThread.setDaemon(true);
					cancelThread.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE);
					cancelThread.start();

					// the periodic interrupting thread - a different thread than the canceller, in case
					// the application code does blocking stuff in its cancellation paths.
					if (invokable.shouldInterruptOnCancel()) {
						Runnable interrupter = new TaskInterrupter(
								LOG,
								invokable,
								executingThread,
								taskNameWithSubtask,
								taskCancellationInterval);

						Thread interruptingThread = new Thread(
								executingThread.getThreadGroup(),
								interrupter,
								String.format("Canceler/Interrupts for %s (%s).", taskNameWithSubtask, executionId));
						interruptingThread.setDaemon(true);
						interruptingThread.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE);
						interruptingThread.start();
					}

					// if a cancellation timeout is set, the watchdog thread kills the process
					// if graceful cancellation does not succeed
					if (taskCancellationTimeout > 0) {
						Runnable cancelWatchdog = new TaskCancelerWatchDog(
								executingThread,
								taskManagerActions,
								taskCancellationTimeout,
								LOG);

						Thread watchDogThread = new Thread(
								executingThread.getThreadGroup(),
								cancelWatchdog,
								String.format("Cancellation Watchdog for %s (%s).",
										taskNameWithSubtask, executionId));
						watchDogThread.setDaemon(true);
						watchDogThread.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE);
						watchDogThread.start();
					}
				}
				return;
			}
		}
		else {
			throw new IllegalStateException(String.format("Unexpected state: %s of task %s (%s).",
				current, taskNameWithSubtask, executionId));
		}
	}
}
 
Example 7
Source File: Task.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Answer to a partition state check issued after a failed partition request.
 */
@VisibleForTesting
void onPartitionStateUpdate(
		IntermediateDataSetID intermediateDataSetId,
		ResultPartitionID resultPartitionId,
		ExecutionState producerState) throws IOException, InterruptedException {

	if (executionState == ExecutionState.RUNNING) {
		final SingleInputGate inputGate = inputGatesById.get(intermediateDataSetId);

		if (inputGate != null) {
			if (producerState == ExecutionState.SCHEDULED
				|| producerState == ExecutionState.DEPLOYING
				|| producerState == ExecutionState.RUNNING
				|| producerState == ExecutionState.FINISHED) {

				// Retrigger the partition request
				inputGate.retriggerPartitionRequest(resultPartitionId.getPartitionId());

			} else if (producerState == ExecutionState.CANCELING
				|| producerState == ExecutionState.CANCELED
				|| producerState == ExecutionState.FAILED) {

				// The producing execution has been canceled or failed. We
				// don't need to re-trigger the request since it cannot
				// succeed.
				if (LOG.isDebugEnabled()) {
					LOG.debug("Cancelling task {} after the producer of partition {} with attempt ID {} has entered state {}.",
						taskNameWithSubtask,
						resultPartitionId.getPartitionId(),
						resultPartitionId.getProducerId(),
						producerState);
				}

				cancelExecution();
			} else {
				// Any other execution state is unexpected. Currently, only
				// state CREATED is left out of the checked states. If we
				// see a producer in this state, something went wrong with
				// scheduling in topological order.
				String msg = String.format("Producer with attempt ID %s of partition %s in unexpected state %s.",
					resultPartitionId.getProducerId(),
					resultPartitionId.getPartitionId(),
					producerState);

				failExternally(new IllegalStateException(msg));
			}
		} else {
			failExternally(new IllegalStateException("Received partition producer state for " +
					"unknown input gate " + intermediateDataSetId + "."));
		}
	} else {
		LOG.debug("Task {} ignored a partition producer state notification, because it's not running.", taskNameWithSubtask);
	}
}
 
Example 8
Source File: InputChannelDeploymentDescriptorTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the deployment descriptors for local, remote, and unknown partition
 * locations (with lazy deployment allowed and all execution states for the
 * producers).
 */
@Test
public void testMixedLocalRemoteUnknownDeployment() throws Exception {
	boolean allowLazyDeployment = true;

	ResourceID consumerResourceId = ResourceID.generate();
	ExecutionVertex consumer = mock(ExecutionVertex.class);
	LogicalSlot consumerSlot = mockSlot(consumerResourceId);

	// Local and remote channel are only allowed for certain execution
	// states.
	for (ExecutionState state : ExecutionState.values()) {
		// Local partition
		ExecutionVertex localProducer = mockExecutionVertex(state, consumerResourceId);
		IntermediateResultPartition localPartition = mockPartition(localProducer);
		ResultPartitionID localPartitionId = new ResultPartitionID(localPartition.getPartitionId(), localProducer.getCurrentExecutionAttempt().getAttemptId());
		ExecutionEdge localEdge = new ExecutionEdge(localPartition, consumer, 0);

		// Remote partition
		ExecutionVertex remoteProducer = mockExecutionVertex(state, ResourceID.generate()); // new resource ID
		IntermediateResultPartition remotePartition = mockPartition(remoteProducer);
		ResultPartitionID remotePartitionId = new ResultPartitionID(remotePartition.getPartitionId(), remoteProducer.getCurrentExecutionAttempt().getAttemptId());
		ConnectionID remoteConnectionId = new ConnectionID(remoteProducer.getCurrentAssignedResource().getTaskManagerLocation(), 0);
		ExecutionEdge remoteEdge = new ExecutionEdge(remotePartition, consumer, 1);

		// Unknown partition
		ExecutionVertex unknownProducer = mockExecutionVertex(state, null); // no assigned resource
		IntermediateResultPartition unknownPartition = mockPartition(unknownProducer);
		ResultPartitionID unknownPartitionId = new ResultPartitionID(unknownPartition.getPartitionId(), unknownProducer.getCurrentExecutionAttempt().getAttemptId());
		ExecutionEdge unknownEdge = new ExecutionEdge(unknownPartition, consumer, 2);

		InputChannelDeploymentDescriptor[] desc = InputChannelDeploymentDescriptor.fromEdges(
			new ExecutionEdge[]{localEdge, remoteEdge, unknownEdge},
			consumerSlot.getTaskManagerLocation().getResourceID(),
			allowLazyDeployment);

		assertEquals(3, desc.length);

		// These states are allowed
		if (state == ExecutionState.RUNNING || state == ExecutionState.FINISHED ||
			state == ExecutionState.SCHEDULED || state == ExecutionState.DEPLOYING) {

			// Create local or remote channels
			assertEquals(localPartitionId, desc[0].getConsumedPartitionId());
			assertTrue(desc[0].getConsumedPartitionLocation().isLocal());
			assertNull(desc[0].getConsumedPartitionLocation().getConnectionId());

			assertEquals(remotePartitionId, desc[1].getConsumedPartitionId());
			assertTrue(desc[1].getConsumedPartitionLocation().isRemote());
			assertEquals(remoteConnectionId, desc[1].getConsumedPartitionLocation().getConnectionId());
		} else {
			// Unknown (lazy deployment allowed)
			assertEquals(localPartitionId, desc[0].getConsumedPartitionId());
			assertTrue(desc[0].getConsumedPartitionLocation().isUnknown());
			assertNull(desc[0].getConsumedPartitionLocation().getConnectionId());

			assertEquals(remotePartitionId, desc[1].getConsumedPartitionId());
			assertTrue(desc[1].getConsumedPartitionLocation().isUnknown());
			assertNull(desc[1].getConsumedPartitionLocation().getConnectionId());
		}

		assertEquals(unknownPartitionId, desc[2].getConsumedPartitionId());
		assertTrue(desc[2].getConsumedPartitionLocation().isUnknown());
		assertNull(desc[2].getConsumedPartitionLocation().getConnectionId());
	}
}
 
Example 9
Source File: TaskDeploymentDescriptorFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
private static boolean isProducerAvailable(ExecutionState producerState) {
	return producerState == ExecutionState.RUNNING ||
		producerState == ExecutionState.FINISHED ||
		producerState == ExecutionState.SCHEDULED ||
		producerState == ExecutionState.DEPLOYING;
}
 
Example 10
Source File: Task.java    From flink with Apache License 2.0 4 votes vote down vote up
private void cancelOrFailAndCancelInvokable(ExecutionState targetState, Throwable cause) {
	while (true) {
		ExecutionState current = executionState;

		// if the task is already canceled (or canceling) or finished or failed,
		// then we need not do anything
		if (current.isTerminal() || current == ExecutionState.CANCELING) {
			LOG.info("Task {} is already in state {}", taskNameWithSubtask, current);
			return;
		}

		if (current == ExecutionState.DEPLOYING || current == ExecutionState.CREATED) {
			if (transitionState(current, targetState, cause)) {
				// if we manage this state transition, then the invokable gets never called
				// we need not call cancel on it
				this.failureCause = cause;
				return;
			}
		}
		else if (current == ExecutionState.RUNNING) {
			if (transitionState(ExecutionState.RUNNING, targetState, cause)) {
				// we are canceling / failing out of the running state
				// we need to cancel the invokable

				// copy reference to guard against concurrent null-ing out the reference
				final AbstractInvokable invokable = this.invokable;

				if (invokable != null && invokableHasBeenCanceled.compareAndSet(false, true)) {
					this.failureCause = cause;

					LOG.info("Triggering cancellation of task code {} ({}).", taskNameWithSubtask, executionId);

					// because the canceling may block on user code, we cancel from a separate thread
					// we do not reuse the async call handler, because that one may be blocked, in which
					// case the canceling could not continue

					// The canceller calls cancel and interrupts the executing thread once
					Runnable canceler = new TaskCanceler(LOG, this :: closeNetworkResources, invokable, executingThread, taskNameWithSubtask);

					Thread cancelThread = new Thread(
							executingThread.getThreadGroup(),
							canceler,
							String.format("Canceler for %s (%s).", taskNameWithSubtask, executionId));
					cancelThread.setDaemon(true);
					cancelThread.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE);
					cancelThread.start();

					// the periodic interrupting thread - a different thread than the canceller, in case
					// the application code does blocking stuff in its cancellation paths.
					if (invokable.shouldInterruptOnCancel()) {
						Runnable interrupter = new TaskInterrupter(
								LOG,
								invokable,
								executingThread,
								taskNameWithSubtask,
								taskCancellationInterval);

						Thread interruptingThread = new Thread(
								executingThread.getThreadGroup(),
								interrupter,
								String.format("Canceler/Interrupts for %s (%s).", taskNameWithSubtask, executionId));
						interruptingThread.setDaemon(true);
						interruptingThread.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE);
						interruptingThread.start();
					}

					// if a cancellation timeout is set, the watchdog thread kills the process
					// if graceful cancellation does not succeed
					if (taskCancellationTimeout > 0) {
						Runnable cancelWatchdog = new TaskCancelerWatchDog(
								executingThread,
								taskManagerActions,
								taskCancellationTimeout,
								LOG);

						Thread watchDogThread = new Thread(
								executingThread.getThreadGroup(),
								cancelWatchdog,
								String.format("Cancellation Watchdog for %s (%s).",
										taskNameWithSubtask, executionId));
						watchDogThread.setDaemon(true);
						watchDogThread.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE);
						watchDogThread.start();
					}
				}
				return;
			}
		}
		else {
			throw new IllegalStateException(String.format("Unexpected state: %s of task %s (%s).",
				current, taskNameWithSubtask, executionId));
		}
	}
}
 
Example 11
Source File: RemoteChannelStateChecker.java    From flink with Apache License 2.0 4 votes vote down vote up
private static boolean isConsumerStateValidForConsumption(
		ExecutionState consumerExecutionState) {
	return consumerExecutionState == ExecutionState.RUNNING ||
		consumerExecutionState == ExecutionState.DEPLOYING;
}
 
Example 12
Source File: ShuffleDescriptorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the deployment descriptors for local, remote, and unknown partition
 * locations (with lazy deployment allowed and all execution states for the
 * producers).
 */
@Test
public void testMixedLocalRemoteUnknownDeployment() throws Exception {
	ResourceID consumerResourceID = ResourceID.generate();

	// Local and remote channel are only allowed for certain execution
	// states.
	for (ExecutionState state : ExecutionState.values()) {
		ResultPartitionID localPartitionId = new ResultPartitionID();
		ResultPartitionDeploymentDescriptor localPartition =
			createResultPartitionDeploymentDescriptor(localPartitionId, consumerResourceID);

		ResultPartitionID remotePartitionId = new ResultPartitionID();
		ResultPartitionDeploymentDescriptor remotePartition =
			createResultPartitionDeploymentDescriptor(remotePartitionId, ResourceID.generate());

		ResultPartitionID unknownPartitionId = new ResultPartitionID();

		ShuffleDescriptor localShuffleDescriptor =
			getConsumedPartitionShuffleDescriptor(localPartitionId, state, localPartition, true);
		ShuffleDescriptor remoteShuffleDescriptor =
			getConsumedPartitionShuffleDescriptor(remotePartitionId, state, remotePartition, true);
		ShuffleDescriptor unknownShuffleDescriptor =
			getConsumedPartitionShuffleDescriptor(unknownPartitionId, state, null, true);

		// These states are allowed
		if (state == ExecutionState.RUNNING ||
			state == ExecutionState.FINISHED ||
			state == ExecutionState.SCHEDULED ||
			state == ExecutionState.DEPLOYING) {
			NettyShuffleDescriptor nettyShuffleDescriptor;

			// Create local or remote channels
			verifyShuffleDescriptor(localShuffleDescriptor, NettyShuffleDescriptor.class, false, localPartitionId);
			nettyShuffleDescriptor = (NettyShuffleDescriptor) localShuffleDescriptor;
			assertThat(nettyShuffleDescriptor.isLocalTo(consumerResourceID), is(true));

			verifyShuffleDescriptor(remoteShuffleDescriptor, NettyShuffleDescriptor.class, false, remotePartitionId);
			nettyShuffleDescriptor = (NettyShuffleDescriptor) remoteShuffleDescriptor;
			assertThat(nettyShuffleDescriptor.isLocalTo(consumerResourceID), is(false));
			assertThat(nettyShuffleDescriptor.getConnectionId(), is(STUB_CONNECTION_ID));
		} else {
			// Unknown (lazy deployment allowed)
			verifyShuffleDescriptor(localShuffleDescriptor, UnknownShuffleDescriptor.class, true, localPartitionId);
			verifyShuffleDescriptor(remoteShuffleDescriptor, UnknownShuffleDescriptor.class, true, remotePartitionId);
		}

		verifyShuffleDescriptor(unknownShuffleDescriptor, UnknownShuffleDescriptor.class, true, unknownPartitionId);
	}
}
 
Example 13
Source File: TaskDeploymentDescriptorFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
private static boolean isProducerAvailable(ExecutionState producerState) {
	return producerState == ExecutionState.RUNNING ||
		producerState == ExecutionState.FINISHED ||
		producerState == ExecutionState.SCHEDULED ||
		producerState == ExecutionState.DEPLOYING;
}
 
Example 14
Source File: Task.java    From flink with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
void cancelOrFailAndCancelInvokableInternal(ExecutionState targetState, Throwable cause) {
	while (true) {
		ExecutionState current = executionState;

		// if the task is already canceled (or canceling) or finished or failed,
		// then we need not do anything
		if (current.isTerminal() || current == ExecutionState.CANCELING) {
			LOG.info("Task {} is already in state {}", taskNameWithSubtask, current);
			return;
		}

		if (current == ExecutionState.DEPLOYING || current == ExecutionState.CREATED) {
			if (transitionState(current, targetState, cause)) {
				// if we manage this state transition, then the invokable gets never called
				// we need not call cancel on it
				this.failureCause = cause;
				return;
			}
		}
		else if (current == ExecutionState.RUNNING) {
			if (transitionState(ExecutionState.RUNNING, targetState, cause)) {
				// we are canceling / failing out of the running state
				// we need to cancel the invokable

				// copy reference to guard against concurrent null-ing out the reference
				final AbstractInvokable invokable = this.invokable;

				if (invokable != null && invokableHasBeenCanceled.compareAndSet(false, true)) {
					this.failureCause = cause;

					LOG.info("Triggering cancellation of task code {} ({}).", taskNameWithSubtask, executionId);

					// because the canceling may block on user code, we cancel from a separate thread
					// we do not reuse the async call handler, because that one may be blocked, in which
					// case the canceling could not continue

					// The canceller calls cancel and interrupts the executing thread once
					Runnable canceler = new TaskCanceler(LOG, this::closeNetworkResources, invokable, executingThread, taskNameWithSubtask);

					Thread cancelThread = new Thread(
							executingThread.getThreadGroup(),
							canceler,
							String.format("Canceler for %s (%s).", taskNameWithSubtask, executionId));
					cancelThread.setDaemon(true);
					cancelThread.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE);
					cancelThread.start();

					// the periodic interrupting thread - a different thread than the canceller, in case
					// the application code does blocking stuff in its cancellation paths.
					if (invokable.shouldInterruptOnCancel()) {
						Runnable interrupter = new TaskInterrupter(
								LOG,
								invokable,
								executingThread,
								taskNameWithSubtask,
								taskCancellationInterval);

						Thread interruptingThread = new Thread(
								executingThread.getThreadGroup(),
								interrupter,
								String.format("Canceler/Interrupts for %s (%s).", taskNameWithSubtask, executionId));
						interruptingThread.setDaemon(true);
						interruptingThread.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE);
						interruptingThread.start();
					}

					// if a cancellation timeout is set, the watchdog thread kills the process
					// if graceful cancellation does not succeed
					if (taskCancellationTimeout > 0) {
						Runnable cancelWatchdog = new TaskCancelerWatchDog(
								executingThread,
								taskManagerActions,
								taskCancellationTimeout);

						Thread watchDogThread = new Thread(
								executingThread.getThreadGroup(),
								cancelWatchdog,
								String.format("Cancellation Watchdog for %s (%s).",
										taskNameWithSubtask, executionId));
						watchDogThread.setDaemon(true);
						watchDogThread.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE);
						watchDogThread.start();
					}
				}
				return;
			}
		}
		else {
			throw new IllegalStateException(String.format("Unexpected state: %s of task %s (%s).",
				current, taskNameWithSubtask, executionId));
		}
	}
}
 
Example 15
Source File: RemoteChannelStateChecker.java    From flink with Apache License 2.0 4 votes vote down vote up
private static boolean isConsumerStateValidForConsumption(
		ExecutionState consumerExecutionState) {
	return consumerExecutionState == ExecutionState.RUNNING ||
		consumerExecutionState == ExecutionState.DEPLOYING;
}
 
Example 16
Source File: ShuffleDescriptorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the deployment descriptors for local, remote, and unknown partition
 * locations (with lazy deployment allowed and all execution states for the
 * producers).
 */
@Test
public void testMixedLocalRemoteUnknownDeployment() throws Exception {
	ResourceID consumerResourceID = ResourceID.generate();

	// Local and remote channel are only allowed for certain execution
	// states.
	for (ExecutionState state : ExecutionState.values()) {
		ResultPartitionID localPartitionId = new ResultPartitionID();
		ResultPartitionDeploymentDescriptor localPartition =
			createResultPartitionDeploymentDescriptor(localPartitionId, consumerResourceID);

		ResultPartitionID remotePartitionId = new ResultPartitionID();
		ResultPartitionDeploymentDescriptor remotePartition =
			createResultPartitionDeploymentDescriptor(remotePartitionId, ResourceID.generate());

		ResultPartitionID unknownPartitionId = new ResultPartitionID();

		ShuffleDescriptor localShuffleDescriptor =
			getConsumedPartitionShuffleDescriptor(localPartitionId, state, localPartition, true);
		ShuffleDescriptor remoteShuffleDescriptor =
			getConsumedPartitionShuffleDescriptor(remotePartitionId, state, remotePartition, true);
		ShuffleDescriptor unknownShuffleDescriptor =
			getConsumedPartitionShuffleDescriptor(unknownPartitionId, state, null, true);

		// These states are allowed
		if (state == ExecutionState.RUNNING ||
			state == ExecutionState.FINISHED ||
			state == ExecutionState.SCHEDULED ||
			state == ExecutionState.DEPLOYING) {
			NettyShuffleDescriptor nettyShuffleDescriptor;

			// Create local or remote channels
			verifyShuffleDescriptor(localShuffleDescriptor, NettyShuffleDescriptor.class, false, localPartitionId);
			nettyShuffleDescriptor = (NettyShuffleDescriptor) localShuffleDescriptor;
			assertThat(nettyShuffleDescriptor.isLocalTo(consumerResourceID), is(true));

			verifyShuffleDescriptor(remoteShuffleDescriptor, NettyShuffleDescriptor.class, false, remotePartitionId);
			nettyShuffleDescriptor = (NettyShuffleDescriptor) remoteShuffleDescriptor;
			assertThat(nettyShuffleDescriptor.isLocalTo(consumerResourceID), is(false));
			assertThat(nettyShuffleDescriptor.getConnectionId(), is(STUB_CONNECTION_ID));
		} else {
			// Unknown (lazy deployment allowed)
			verifyShuffleDescriptor(localShuffleDescriptor, UnknownShuffleDescriptor.class, true, localPartitionId);
			verifyShuffleDescriptor(remoteShuffleDescriptor, UnknownShuffleDescriptor.class, true, remotePartitionId);
		}

		verifyShuffleDescriptor(unknownShuffleDescriptor, UnknownShuffleDescriptor.class, true, unknownPartitionId);
	}
}