Search in sources :

Example 11 with JobStatus

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();
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) ErrorInfo(org.apache.flink.runtime.executiongraph.ErrorInfo) JobID(org.apache.flink.api.common.JobID)

Example 12 with JobStatus

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);
        }
    }
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) InterceptingOperatorMetricGroup(org.apache.flink.runtime.metrics.util.InterceptingOperatorMetricGroup) Test(org.junit.jupiter.api.Test)

Example 13 with JobStatus

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));
    }
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) InterceptingOperatorMetricGroup(org.apache.flink.runtime.metrics.util.InterceptingOperatorMetricGroup) MetricOptions(org.apache.flink.configuration.MetricOptions)

Example 14 with JobStatus

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;
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) EnumMap(java.util.EnumMap)

Example 15 with JobStatus

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()));
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) Path(java.nio.file.Path) Test(org.junit.Test)

Aggregations

JobStatus (org.apache.flink.api.common.JobStatus)62 Test (org.junit.Test)28 JobID (org.apache.flink.api.common.JobID)19 CompletableFuture (java.util.concurrent.CompletableFuture)15 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)14 FlinkException (org.apache.flink.util.FlinkException)8 ExecutionException (java.util.concurrent.ExecutionException)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Time (org.apache.flink.api.common.time.Time)6 ExecutionGraphInfo (org.apache.flink.runtime.scheduler.ExecutionGraphInfo)6 TaskExecutionState (org.apache.flink.runtime.taskmanager.TaskExecutionState)6 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5 ExecutionState (org.apache.flink.runtime.execution.ExecutionState)5 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)5 TimeUnit (java.util.concurrent.TimeUnit)4 Configuration (org.apache.flink.configuration.Configuration)4 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)4 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)4