Java Code Examples for org.apache.flink.runtime.jobgraph.JobStatus#isTerminalState()

The following examples show how to use org.apache.flink.runtime.jobgraph.JobStatus#isTerminalState() . 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: ExecutionGraph.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private boolean transitionState(JobStatus current, JobStatus newState, Throwable error) {
	assertRunningInJobMasterMainThread();
	// consistency check
	if (current.isTerminalState()) {
		String message = "Job is trying to leave terminal state " + current;
		LOG.error(message);
		throw new IllegalStateException(message);
	}

	// now do the actual state transition
	if (STATE_UPDATER.compareAndSet(this, current, newState)) {
		LOG.info("Job {} ({}) switched from state {} to {}.", getJobName(), getJobID(), current, newState, error);

		stateTimestamps[newState.ordinal()] = System.currentTimeMillis();
		notifyJobStatusChange(newState, error);
		return true;
	}
	else {
		return false;
	}
}
 
Example 2
Source File: UpTimeGauge.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public Long getValue() {
	final JobStatus status = eg.getState();

	if (status == JobStatus.RUNNING) {
		// running right now - report the uptime
		final long runningTimestamp = eg.getStatusTimestamp(JobStatus.RUNNING);
		// we use 'Math.max' here to avoid negative timestamps when clocks change
		return Math.max(System.currentTimeMillis() - runningTimestamp, 0);
	}
	else if (status.isTerminalState()) {
		// not running any more -> finished or not on leader
		return NO_LONGER_RUNNING;
	}
	else {
		// not yet running or not up at the moment
		return 0L;
	}
}
 
Example 3
Source File: DownTimeGauge.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public Long getValue() {
	final JobStatus status = eg.getState();

	if (status == JobStatus.RUNNING) {
		// running right now - no downtime
		return 0L;
	}
	else if (status.isTerminalState()) {
		// not running any more -> finished or not on leader
		return NO_LONGER_RUNNING;
	}
	else {
		final long runningTimestamp = eg.getStatusTimestamp(JobStatus.RUNNING);
		if (runningTimestamp > 0) {
			// job was running at some point and is not running now
			// we use 'Math.max' here to avoid negative timestamps when clocks change
			return Math.max(System.currentTimeMillis() - runningTimestamp, 0);
		}
		else {
			// job was never scheduled so far
			return NOT_YET_RUNNING;
		}
	}
}
 
Example 4
Source File: ExecutionGraph.java    From flink with Apache License 2.0 6 votes vote down vote up
private boolean transitionState(JobStatus current, JobStatus newState, Throwable error) {
	assertRunningInJobMasterMainThread();
	// consistency check
	if (current.isTerminalState()) {
		String message = "Job is trying to leave terminal state " + current;
		LOG.error(message);
		throw new IllegalStateException(message);
	}

	// now do the actual state transition
	if (STATE_UPDATER.compareAndSet(this, current, newState)) {
		LOG.info("Job {} ({}) switched from state {} to {}.", getJobName(), getJobID(), current, newState, error);

		stateTimestamps[newState.ordinal()] = System.currentTimeMillis();
		notifyJobStatusChange(newState, error);
		return true;
	}
	else {
		return false;
	}
}
 
Example 5
Source File: UpTimeGauge.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Long getValue() {
	final JobStatus status = eg.getState();

	if (status == JobStatus.RUNNING) {
		// running right now - report the uptime
		final long runningTimestamp = eg.getStatusTimestamp(JobStatus.RUNNING);
		// we use 'Math.max' here to avoid negative timestamps when clocks change
		return Math.max(System.currentTimeMillis() - runningTimestamp, 0);
	}
	else if (status.isTerminalState()) {
		// not running any more -> finished or not on leader
		return NO_LONGER_RUNNING;
	}
	else {
		// not yet running or not up at the moment
		return 0L;
	}
}
 
Example 6
Source File: DownTimeGauge.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Long getValue() {
	final JobStatus status = eg.getState();

	if (status == JobStatus.RUNNING) {
		// running right now - no downtime
		return 0L;
	}
	else if (status.isTerminalState()) {
		// not running any more -> finished or not on leader
		return NO_LONGER_RUNNING;
	}
	else {
		final long runningTimestamp = eg.getStatusTimestamp(JobStatus.RUNNING);
		if (runningTimestamp > 0) {
			// job was running at some point and is not running now
			// we use 'Math.max' here to avoid negative timestamps when clocks change
			return Math.max(System.currentTimeMillis() - runningTimestamp, 0);
		}
		else {
			// job was never scheduled so far
			return NOT_YET_RUNNING;
		}
	}
}
 
Example 7
Source File: RestartTimeGauge.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Long getValue() {
	final JobStatus status = eg.getState();

	final long restartingTimestamp = eg.getStatusTimestamp(JobStatus.RESTARTING);

	final long switchToRunningTimestamp;
	final long lastRestartTime;

	if (restartingTimestamp <= 0) {
		// we haven't yet restarted our job
		return 0L;
	}
	else if ((switchToRunningTimestamp = eg.getStatusTimestamp(JobStatus.RUNNING)) >= restartingTimestamp) {
		// we have transitioned to RUNNING since the last restart
		lastRestartTime = switchToRunningTimestamp - restartingTimestamp;
	}
	else if (status.isTerminalState()) {
		// since the last restart we've switched to a terminal state without touching
		// the RUNNING state (e.g. failing from RESTARTING)
		lastRestartTime = eg.getStatusTimestamp(status) - restartingTimestamp;
	}
	else {
		// we're still somewhere between RESTARTING and RUNNING
		lastRestartTime  = System.currentTimeMillis() - restartingTimestamp;
	}

	// we guard this with 'Math.max' to avoid negative timestamps when clocks re-sync 
	return Math.max(lastRestartTime, 0);
}
 
Example 8
Source File: RestartTimeGauge.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Long getValue() {
	final JobStatus status = eg.getState();

	final long restartingTimestamp = eg.getStatusTimestamp(JobStatus.RESTARTING);

	final long switchToRunningTimestamp;
	final long lastRestartTime;

	if (restartingTimestamp <= 0) {
		// we haven't yet restarted our job
		return 0L;
	}
	else if ((switchToRunningTimestamp = eg.getStatusTimestamp(JobStatus.RUNNING)) >= restartingTimestamp) {
		// we have transitioned to RUNNING since the last restart
		lastRestartTime = switchToRunningTimestamp - restartingTimestamp;
	}
	else if (status.isTerminalState()) {
		// since the last restart we've switched to a terminal state without touching
		// the RUNNING state (e.g. failing from RESTARTING)
		lastRestartTime = eg.getStatusTimestamp(status) - restartingTimestamp;
	}
	else {
		// we're still somewhere between RESTARTING and RUNNING
		lastRestartTime  = System.currentTimeMillis() - restartingTimestamp;
	}

	// we guard this with 'Math.max' to avoid negative timestamps when clocks re-sync 
	return Math.max(lastRestartTime, 0);
}