Search in sources :

Example 26 with JobStatus

use of org.apache.flink.api.common.JobStatus in project flink by apache.

the class AbstractQueryableStateTestBase method testWrongJobIdAndWrongQueryableStateName.

/**
 * Tests that the correct exception is thrown if the query contains a wrong jobId or wrong
 * queryable state name.
 */
@Test
@Ignore
public void testWrongJobIdAndWrongQueryableStateName() throws Exception {
    final Deadline deadline = Deadline.now().plus(TEST_TIMEOUT);
    final long numElements = 1024L;
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setStateBackend(stateBackend);
    env.setParallelism(maxParallelism);
    env.setRestartStrategy(RestartStrategies.fixedDelayRestart(Integer.MAX_VALUE, 1000L));
    DataStream<Tuple2<Integer, Long>> source = env.addSource(new TestAscendingValueSource(numElements));
    ValueStateDescriptor<Tuple2<Integer, Long>> valueState = new ValueStateDescriptor<>("any", source.getType());
    source.keyBy(new KeySelector<Tuple2<Integer, Long>, Integer>() {

        private static final long serialVersionUID = 7662520075515707428L;

        @Override
        public Integer getKey(Tuple2<Integer, Long> value) {
            return value.f0;
        }
    }).asQueryableState("hakuna", valueState);
    try (AutoCancellableJob closableJobGraph = new AutoCancellableJob(deadline, clusterClient, env)) {
        clusterClient.submitJob(closableJobGraph.getJobGraph()).get();
        CompletableFuture<JobStatus> jobStatusFuture = clusterClient.getJobStatus(closableJobGraph.getJobId());
        while (deadline.hasTimeLeft() && !jobStatusFuture.get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS).equals(JobStatus.RUNNING)) {
            Thread.sleep(50);
            jobStatusFuture = clusterClient.getJobStatus(closableJobGraph.getJobId());
        }
        assertEquals(JobStatus.RUNNING, jobStatusFuture.get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS));
        final JobID wrongJobId = new JobID();
        CompletableFuture<ValueState<Tuple2<Integer, Long>>> unknownJobFuture = client.getKvState(// this is the wrong job id
        wrongJobId, "hakuna", 0, BasicTypeInfo.INT_TYPE_INFO, valueState);
        try {
            unknownJobFuture.get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
            // by now the request must have failed.
            fail();
        } catch (ExecutionException e) {
            Assert.assertTrue("GOT: " + e.getCause().getMessage(), e.getCause() instanceof RuntimeException);
            Assert.assertTrue("GOT: " + e.getCause().getMessage(), e.getCause().getMessage().contains("FlinkJobNotFoundException: Could not find Flink job (" + wrongJobId + ")"));
        } catch (Exception f) {
            fail("Unexpected type of exception: " + f.getMessage());
        }
        CompletableFuture<ValueState<Tuple2<Integer, Long>>> unknownQSName = client.getKvState(closableJobGraph.getJobId(), // this is the wrong name.
        "wrong-hakuna", 0, BasicTypeInfo.INT_TYPE_INFO, valueState);
        try {
            unknownQSName.get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
            // by now the request must have failed.
            fail();
        } catch (ExecutionException e) {
            Assert.assertTrue("GOT: " + e.getCause().getMessage(), e.getCause() instanceof RuntimeException);
            Assert.assertTrue("GOT: " + e.getCause().getMessage(), e.getCause().getMessage().contains("UnknownKvStateLocation: No KvStateLocation found for KvState instance with name 'wrong-hakuna'."));
        } catch (Exception f) {
            fail("Unexpected type of exception: " + f.getMessage());
        }
    }
}
Also used : Deadline(org.apache.flink.api.common.time.Deadline) KeySelector(org.apache.flink.api.java.functions.KeySelector) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) IOException(java.io.IOException) UnknownKeyOrNamespaceException(org.apache.flink.queryablestate.exceptions.UnknownKeyOrNamespaceException) ExecutionException(java.util.concurrent.ExecutionException) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) JobStatus(org.apache.flink.api.common.JobStatus) ValueState(org.apache.flink.api.common.state.ValueState) Tuple2(org.apache.flink.api.java.tuple.Tuple2) AtomicLong(java.util.concurrent.atomic.AtomicLong) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) ExecutionException(java.util.concurrent.ExecutionException) JobID(org.apache.flink.api.common.JobID) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with JobStatus

use of org.apache.flink.api.common.JobStatus in project flink by apache.

the class HistoryServerArchiveFetcher method convertLegacyJobOverview.

private static String convertLegacyJobOverview(String legacyOverview) throws IOException {
    JsonNode root = mapper.readTree(legacyOverview);
    JsonNode finishedJobs = root.get("finished");
    JsonNode job = finishedJobs.get(0);
    JobID jobId = JobID.fromHexString(job.get("jid").asText());
    String name = job.get("name").asText();
    JobStatus state = JobStatus.valueOf(job.get("state").asText());
    long startTime = job.get("start-time").asLong();
    long endTime = job.get("end-time").asLong();
    long duration = job.get("duration").asLong();
    long lastMod = job.get("last-modification").asLong();
    JsonNode tasks = job.get("tasks");
    int numTasks = tasks.get("total").asInt();
    JsonNode pendingNode = tasks.get("pending");
    // for flink version < 1.4 we have pending field,
    // when version >= 1.4 pending has been split into scheduled, deploying, and created.
    boolean versionLessThan14 = pendingNode != null;
    int created = 0;
    int scheduled;
    int deploying = 0;
    if (versionLessThan14) {
        // pending is a mix of CREATED/SCHEDULED/DEPLOYING
        // to maintain the correct number of task states we pick SCHEDULED
        scheduled = pendingNode.asInt();
    } else {
        created = tasks.get("created").asInt();
        scheduled = tasks.get("scheduled").asInt();
        deploying = tasks.get("deploying").asInt();
    }
    int running = tasks.get("running").asInt();
    int finished = tasks.get("finished").asInt();
    int canceling = tasks.get("canceling").asInt();
    int canceled = tasks.get("canceled").asInt();
    int failed = tasks.get("failed").asInt();
    int[] tasksPerState = new int[ExecutionState.values().length];
    tasksPerState[ExecutionState.CREATED.ordinal()] = created;
    tasksPerState[ExecutionState.SCHEDULED.ordinal()] = scheduled;
    tasksPerState[ExecutionState.DEPLOYING.ordinal()] = deploying;
    tasksPerState[ExecutionState.RUNNING.ordinal()] = running;
    tasksPerState[ExecutionState.FINISHED.ordinal()] = finished;
    tasksPerState[ExecutionState.CANCELING.ordinal()] = canceling;
    tasksPerState[ExecutionState.CANCELED.ordinal()] = canceled;
    tasksPerState[ExecutionState.FAILED.ordinal()] = failed;
    JobDetails jobDetails = new JobDetails(jobId, name, startTime, endTime, duration, state, lastMod, tasksPerState, numTasks);
    MultipleJobsDetails multipleJobsDetails = new MultipleJobsDetails(Collections.singleton(jobDetails));
    StringWriter sw = new StringWriter();
    mapper.writeValue(sw, multipleJobsDetails);
    return sw.toString();
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) StringWriter(java.io.StringWriter) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) MultipleJobsDetails(org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails) JobID(org.apache.flink.api.common.JobID) JobDetails(org.apache.flink.runtime.messages.webmonitor.JobDetails)

Example 28 with JobStatus

use of org.apache.flink.api.common.JobStatus in project flink by apache.

the class CliFrontend method printJobStatusMessages.

private static void printJobStatusMessages(List<JobStatusMessage> jobs) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    Comparator<JobStatusMessage> startTimeComparator = (o1, o2) -> (int) (o1.getStartTime() - o2.getStartTime());
    Comparator<Map.Entry<JobStatus, List<JobStatusMessage>>> statusComparator = (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey().toString(), o2.getKey().toString());
    Map<JobStatus, List<JobStatusMessage>> jobsByState = jobs.stream().collect(Collectors.groupingBy(JobStatusMessage::getJobState));
    jobsByState.entrySet().stream().sorted(statusComparator).map(Map.Entry::getValue).flatMap(List::stream).sorted(startTimeComparator).forEachOrdered(job -> System.out.println(dateFormat.format(new Date(job.getStartTime())) + " : " + job.getJobId() + " : " + job.getJobName() + " (" + job.getJobState() + ")"));
}
Also used : Arrays(java.util.Arrays) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ClientUtils(org.apache.flink.client.ClientUtils) URL(java.net.URL) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) ExceptionUtils(org.apache.flink.util.ExceptionUtils) ApplicationConfiguration(org.apache.flink.client.deployment.application.ApplicationConfiguration) ProgramMissingJobException(org.apache.flink.client.program.ProgramMissingJobException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Duration(java.time.Duration) Map(java.util.Map) SecurityUtils(org.apache.flink.runtime.security.SecurityUtils) URI(java.net.URI) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) DefaultExecutorServiceLoader(org.apache.flink.core.execution.DefaultExecutorServiceLoader) ClusterClientServiceLoader(org.apache.flink.client.deployment.ClusterClientServiceLoader) JobStatusMessage(org.apache.flink.runtime.client.JobStatusMessage) ProgramParametrizationException(org.apache.flink.client.program.ProgramParametrizationException) ClusterClientFactory(org.apache.flink.client.deployment.ClusterClientFactory) Collection(java.util.Collection) JobManagerOptions(org.apache.flink.configuration.JobManagerOptions) SecurityConfiguration(org.apache.flink.runtime.security.SecurityConfiguration) EnvironmentInformation(org.apache.flink.runtime.util.EnvironmentInformation) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) FileSystem(org.apache.flink.core.fs.FileSystem) ClusterClient(org.apache.flink.client.program.ClusterClient) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) PackagedProgram(org.apache.flink.client.program.PackagedProgram) DefaultClusterClientServiceLoader(org.apache.flink.client.deployment.DefaultClusterClientServiceLoader) FlinkException(org.apache.flink.util.FlinkException) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) Pipeline(org.apache.flink.api.dag.Pipeline) Options(org.apache.commons.cli.Options) SimpleDateFormat(java.text.SimpleDateFormat) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) ConfigConstants(org.apache.flink.configuration.ConfigConstants) CommandLine(org.apache.commons.cli.CommandLine) FlinkPipelineTranslationUtil(org.apache.flink.client.FlinkPipelineTranslationUtil) RestOptions(org.apache.flink.configuration.RestOptions) PackagedProgramUtils(org.apache.flink.client.program.PackagedProgramUtils) Logger(org.slf4j.Logger) Configuration(org.apache.flink.configuration.Configuration) ApplicationClusterDeployer(org.apache.flink.client.deployment.application.cli.ApplicationClusterDeployer) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) JobID(org.apache.flink.api.common.JobID) ClusterDescriptor(org.apache.flink.client.deployment.ClusterDescriptor) CoreOptions(org.apache.flink.configuration.CoreOptions) PluginUtils(org.apache.flink.core.plugin.PluginUtils) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) Comparator(java.util.Comparator) Collections(java.util.Collections) HELP_OPTION(org.apache.flink.client.cli.CliFrontendParser.HELP_OPTION) JobStatus(org.apache.flink.api.common.JobStatus) JobStatusMessage(org.apache.flink.runtime.client.JobStatusMessage) List(java.util.List) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map) Date(java.util.Date)

Example 29 with JobStatus

use of org.apache.flink.api.common.JobStatus in project flink by apache.

the class ApplicationDispatcherBootstrapTest method testShutdownDisabled.

@ParameterizedTest
@EnumSource(value = JobStatus.class, names = { "FINISHED", "CANCELED", "FAILED" })
public void testShutdownDisabled(JobStatus jobStatus) throws Exception {
    final Configuration configurationUnderTest = getConfiguration();
    configurationUnderTest.set(DeploymentOptions.SHUTDOWN_ON_APPLICATION_FINISH, false);
    final TestingDispatcherGateway dispatcherGateway = dispatcherGatewayBuilder(jobStatus).setClusterShutdownFunction(status -> {
        fail("Cluster shutdown should not be called");
        return CompletableFuture.completedFuture(Acknowledge.get());
    }).build();
    ApplicationDispatcherBootstrap bootstrap = createApplicationDispatcherBootstrap(configurationUnderTest, dispatcherGateway, scheduledExecutor);
    // Wait until bootstrap is finished to make sure cluster shutdown isn't called
    bootstrap.getBootstrapCompletionFuture().get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ScheduledFuture(java.util.concurrent.ScheduledFuture) ExceptionUtils(org.apache.flink.util.ExceptionUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Duration(java.time.Duration) Assertions(org.assertj.core.api.Assertions) FailingJob(org.apache.flink.client.testjar.FailingJob) ScheduledExecutor(org.apache.flink.util.concurrent.ScheduledExecutor) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) Test(org.junit.jupiter.api.Test) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Optional(java.util.Optional) PackagedProgram(org.apache.flink.client.program.PackagedProgram) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FlinkException(org.apache.flink.util.FlinkException) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EnumSource(org.junit.jupiter.params.provider.EnumSource) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Supplier(java.util.function.Supplier) EmbeddedExecutor(org.apache.flink.client.deployment.application.executors.EmbeddedExecutor) PipelineOptionsInternal(org.apache.flink.configuration.PipelineOptionsInternal) MultiExecuteJob(org.apache.flink.client.testjar.MultiExecuteJob) JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) HighAvailabilityMode(org.apache.flink.runtime.jobmanager.HighAvailabilityMode) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) Configuration(org.apache.flink.configuration.Configuration) JobCancellationException(org.apache.flink.runtime.client.JobCancellationException) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) JobID(org.apache.flink.api.common.JobID) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Collections(java.util.Collections) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Configuration(org.apache.flink.configuration.Configuration) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with JobStatus

use of org.apache.flink.api.common.JobStatus in project flink by apache.

the class DefaultExecutionGraph method allVerticesInTerminalState.

/**
 * This method is a callback during cancellation/failover and called when all tasks have reached
 * a terminal state (cancelled/failed/finished).
 */
private void allVerticesInTerminalState() {
    assertRunningInJobMasterMainThread();
    // we are done, transition to the final state
    JobStatus current;
    while (true) {
        current = this.state;
        if (current == JobStatus.RUNNING) {
            failGlobal(new Exception("ExecutionGraph went into allVerticesInTerminalState() from RUNNING"));
        } else if (current == JobStatus.CANCELLING) {
            if (transitionState(current, JobStatus.CANCELED)) {
                onTerminalState(JobStatus.CANCELED);
                break;
            }
        } else if (current == JobStatus.FAILING) {
            break;
        } else if (current.isGloballyTerminalState()) {
            LOG.warn("Job has entered globally terminal state without waiting for all " + "job vertices to reach final state.");
            break;
        } else {
            failGlobal(new Exception("ExecutionGraph went into final state from state " + current));
            break;
        }
    }
// done transitioning the state
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) FlinkException(org.apache.flink.util.FlinkException) JobException(org.apache.flink.runtime.JobException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

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