use of org.apache.flink.api.common.JobStatus in project flink by apache.
the class JobResult method createFrom.
/**
* Creates the {@link JobResult} from the given {@link AccessExecutionGraph} which must be in a
* globally terminal state.
*
* @param accessExecutionGraph to create the JobResult from
* @return JobResult of the given AccessExecutionGraph
*/
public static JobResult createFrom(AccessExecutionGraph accessExecutionGraph) {
final JobID jobId = accessExecutionGraph.getJobID();
final JobStatus jobStatus = accessExecutionGraph.getState();
checkArgument(jobStatus.isTerminalState(), "The job " + accessExecutionGraph.getJobName() + '(' + jobId + ") is not in a " + "terminal state. It is in state " + jobStatus + '.');
final JobResult.Builder builder = new JobResult.Builder();
builder.jobId(jobId);
builder.applicationStatus(ApplicationStatus.fromJobStatus(accessExecutionGraph.getState()));
final long netRuntime = accessExecutionGraph.getStatusTimestamp(jobStatus) - accessExecutionGraph.getStatusTimestamp(JobStatus.INITIALIZING);
// guard against clock changes
final long guardedNetRuntime = Math.max(netRuntime, 0L);
builder.netRuntime(guardedNetRuntime);
builder.accumulatorResults(accessExecutionGraph.getAccumulatorsSerialized());
if (jobStatus == JobStatus.FAILED) {
final ErrorInfo errorInfo = accessExecutionGraph.getFailureInfo();
checkNotNull(errorInfo, "No root cause is found for the job failure.");
builder.serializedThrowable(errorInfo.getException());
}
return builder.build();
}
use of org.apache.flink.api.common.JobStatus in project flink by apache.
the class JobStatusMetricsTest method testStatusSelection.
@Test
void testStatusSelection() {
final InterceptingOperatorMetricGroup metricGroup = new InterceptingOperatorMetricGroup();
final JobStatusMetrics jobStatusMetrics = new JobStatusMetrics(0L, enable(MetricOptions.JobStatusMetrics.STATE));
jobStatusMetrics.registerMetrics(metricGroup);
final Map<JobStatus, StateTimeMetricTest.StatusMetricSet> registeredMetrics = extractMetrics(metricGroup);
for (JobStatus value : JobStatus.values()) {
if (value.isTerminalState() || value == JobStatus.RECONCILING) {
assertThat(registeredMetrics).doesNotContainKey(value);
} else {
assertThat(registeredMetrics).containsKey(value);
}
}
}
use of org.apache.flink.api.common.JobStatus in project flink by apache.
the class StateTimeMetricTest method testMetricSelection.
private static void testMetricSelection(MetricOptions.JobStatusMetrics... selectedMetrics) {
final EnumSet<MetricOptions.JobStatusMetrics> selectedMetricsSet = EnumSet.noneOf(MetricOptions.JobStatusMetrics.class);
Arrays.stream(selectedMetrics).forEach(selectedMetricsSet::add);
final InterceptingOperatorMetricGroup metricGroup = new InterceptingOperatorMetricGroup();
StateTimeMetric.register(enable(selectedMetrics), metricGroup, new TestStateTimeMetric(), "test");
final Map<JobStatus, StatusMetricSet> registeredMetrics = extractMetrics(metricGroup);
for (StatusMetricSet metrics : registeredMetrics.values()) {
assertThat(metrics.getState().isPresent()).isEqualTo(selectedMetricsSet.contains(MetricOptions.JobStatusMetrics.STATE));
assertThat(metrics.getCurrentTime().isPresent()).isEqualTo(selectedMetricsSet.contains(MetricOptions.JobStatusMetrics.CURRENT_TIME));
assertThat(metrics.getTotalTime().isPresent()).isEqualTo(selectedMetricsSet.contains(MetricOptions.JobStatusMetrics.TOTAL_TIME));
}
}
use of org.apache.flink.api.common.JobStatus in project flink by apache.
the class StateTimeMetricTest method extractMetrics.
static Map<JobStatus, StatusMetricSet> extractMetrics(InterceptingOperatorMetricGroup metrics) {
final Map<JobStatus, StatusMetricSet> extractedMetrics = new EnumMap<>(JobStatus.class);
for (JobStatus jobStatus : JobStatus.values()) {
final String baseMetricName = JobStatusMetrics.getBaseMetricName(jobStatus);
final StatusMetricSet statusMetricSet = new StatusMetricSet((Gauge<Long>) metrics.get(StateTimeMetric.getStateMetricName(baseMetricName)), (Gauge<Long>) metrics.get(StateTimeMetric.getCurrentTimeMetricName(baseMetricName)), (Gauge<Long>) metrics.get(StateTimeMetric.getTotalTimeMetricName(baseMetricName)));
if (statusMetricSet.getState().isPresent() || statusMetricSet.getCurrentTime().isPresent() || statusMetricSet.getTotalTime().isPresent()) {
extractedMetrics.put(jobStatus, statusMetricSet);
}
}
return extractedMetrics;
}
use of org.apache.flink.api.common.JobStatus in project flink by apache.
the class JobMasterTriggerSavepointITCase method testStopJobAfterSavepointWithDeactivatedPeriodicCheckpointing.
@Test
public void testStopJobAfterSavepointWithDeactivatedPeriodicCheckpointing() throws Exception {
// set checkpointInterval to Long.MAX_VALUE, which means deactivated checkpointing
setUpWithCheckpointInterval(Long.MAX_VALUE);
final String savepointLocation = cancelWithSavepoint();
final JobStatus jobStatus = clusterClient.getJobStatus(jobGraph.getJobID()).get(60, TimeUnit.SECONDS);
assertThat(jobStatus, isOneOf(JobStatus.CANCELED, JobStatus.CANCELLING));
final List<Path> savepoints;
try (Stream<Path> savepointFiles = Files.list(savepointDirectory)) {
savepoints = savepointFiles.map(Path::getFileName).collect(Collectors.toList());
}
assertThat(savepoints, hasItem(Paths.get(savepointLocation).getFileName()));
}
Aggregations