Search in sources :

Example 26 with JobExecutionException

use of org.apache.flink.runtime.client.JobExecutionException in project flink by apache.

the class JarRunHandler method handleJsonRequest.

@Override
public String handleJsonRequest(Map<String, String> pathParams, Map<String, String> queryParams, ActorGateway jobManager) throws Exception {
    try {
        JarActionHandlerConfig config = JarActionHandlerConfig.fromParams(pathParams, queryParams);
        Tuple2<JobGraph, ClassLoader> graph = getJobGraphAndClassLoader(config);
        try {
            graph.f0.uploadUserJars(jobManager, timeout, clientConfig);
        } catch (IOException e) {
            throw new ProgramInvocationException("Failed to upload jar files to the job manager", e);
        }
        try {
            JobClient.submitJobDetached(jobManager, clientConfig, graph.f0, timeout, graph.f1);
        } catch (JobExecutionException e) {
            throw new ProgramInvocationException("Failed to submit the job to the job manager", e);
        }
        StringWriter writer = new StringWriter();
        JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
        gen.writeStartObject();
        gen.writeStringField("jobid", graph.f0.getJobID().toString());
        gen.writeEndObject();
        gen.close();
        return writer.toString();
    } catch (Exception e) {
        return sendError(e);
    }
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) StringWriter(java.io.StringWriter) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) IOException(java.io.IOException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException)

Example 27 with JobExecutionException

use of org.apache.flink.runtime.client.JobExecutionException in project flink by apache.

the class ClusterClient method runDetached.

/**
	 * Submits a JobGraph detached.
	 * @param jobGraph The JobGraph
	 * @param classLoader User code class loader to deserialize the results and errors (may contain custom classes).
	 * @return JobSubmissionResult
	 * @throws ProgramInvocationException
	 */
public JobSubmissionResult runDetached(JobGraph jobGraph, ClassLoader classLoader) throws ProgramInvocationException {
    waitForClusterToBeReady();
    final ActorGateway jobManagerGateway;
    try {
        jobManagerGateway = getJobManagerGateway();
    } catch (Exception e) {
        throw new ProgramInvocationException("Failed to retrieve the JobManager gateway.", e);
    }
    try {
        logAndSysout("Submitting Job with JobID: " + jobGraph.getJobID() + ". Returning after job submission.");
        JobClient.submitJobDetached(jobManagerGateway, flinkConfig, jobGraph, timeout, classLoader);
        return new JobSubmissionResult(jobGraph.getJobID());
    } catch (JobExecutionException e) {
        throw new ProgramInvocationException("The program execution failed: " + e.getMessage(), e);
    }
}
Also used : JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) JobRetrievalException(org.apache.flink.runtime.client.JobRetrievalException) URISyntaxException(java.net.URISyntaxException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) IOException(java.io.IOException) CompilerException(org.apache.flink.optimizer.CompilerException)

Example 28 with JobExecutionException

use of org.apache.flink.runtime.client.JobExecutionException in project flink by apache.

the class ClusterClient method run.

/**
	 * Submits a JobGraph blocking.
	 * @param jobGraph The JobGraph
	 * @param classLoader User code class loader to deserialize the results and errors (may contain custom classes).
	 * @return JobExecutionResult
	 * @throws ProgramInvocationException
	 */
public JobExecutionResult run(JobGraph jobGraph, ClassLoader classLoader) throws ProgramInvocationException {
    waitForClusterToBeReady();
    final LeaderRetrievalService leaderRetrievalService;
    try {
        leaderRetrievalService = LeaderRetrievalUtils.createLeaderRetrievalService(flinkConfig, true);
    } catch (Exception e) {
        throw new ProgramInvocationException("Could not create the leader retrieval service", e);
    }
    try {
        logAndSysout("Submitting job with JobID: " + jobGraph.getJobID() + ". Waiting for job completion.");
        this.lastJobExecutionResult = JobClient.submitJobAndWait(actorSystemLoader.get(), flinkConfig, leaderRetrievalService, jobGraph, timeout, printStatusDuringExecution, classLoader);
        return this.lastJobExecutionResult;
    } catch (JobExecutionException e) {
        throw new ProgramInvocationException("The program execution failed: " + e.getMessage(), e);
    }
}
Also used : JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) JobRetrievalException(org.apache.flink.runtime.client.JobRetrievalException) URISyntaxException(java.net.URISyntaxException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) IOException(java.io.IOException) CompilerException(org.apache.flink.optimizer.CompilerException)

Example 29 with JobExecutionException

use of org.apache.flink.runtime.client.JobExecutionException in project flink by apache.

the class ElasticsearchSinkTestBase method runTransportClientFailsTest.

/**
	 * Tests whether the Elasticsearch sink fails when there is no cluster to connect to.
	 */
public void runTransportClientFailsTest() throws Exception {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStreamSource<Tuple2<Integer, String>> source = env.addSource(new SourceSinkDataTestKit.TestDataSourceFunction());
    Map<String, String> userConfig = new HashMap<>();
    userConfig.put(ElasticsearchSinkBase.CONFIG_KEY_BULK_FLUSH_MAX_ACTIONS, "1");
    userConfig.put("cluster.name", "my-transport-client-cluster");
    source.addSink(createElasticsearchSinkForEmbeddedNode(userConfig, new SourceSinkDataTestKit.TestElasticsearchSinkFunction("test")));
    try {
        env.execute("Elasticsearch Transport Client Test");
    } catch (JobExecutionException expectedException) {
        assertTrue(expectedException.getCause().getMessage().contains("not connected to any Elasticsearch nodes"));
        return;
    }
    fail();
}
Also used : JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) HashMap(java.util.HashMap) Tuple2(org.apache.flink.api.java.tuple.Tuple2) SourceSinkDataTestKit(org.apache.flink.streaming.connectors.elasticsearch.testutils.SourceSinkDataTestKit) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)

Example 30 with JobExecutionException

use of org.apache.flink.runtime.client.JobExecutionException in project flink by apache.

the class JobMaster method jobStatusChanged.

private void jobStatusChanged(final JobStatus newJobStatus, long timestamp, final Throwable error) {
    validateRunsInMainThread();
    final JobID jobID = executionGraph.getJobID();
    final String jobName = executionGraph.getJobName();
    log.info("Status of job {} ({}) changed to {}.", jobID, jobName, newJobStatus, error);
    if (newJobStatus.isGloballyTerminalState()) {
        switch(newJobStatus) {
            case FINISHED:
                try {
                    // TODO get correct job duration
                    // job done, let's get the accumulators
                    Map<String, Object> accumulatorResults = executionGraph.getAccumulators();
                    JobExecutionResult result = new JobExecutionResult(jobID, 0L, accumulatorResults);
                    jobCompletionActions.jobFinished(result);
                } catch (Exception e) {
                    log.error("Cannot fetch final accumulators for job {} ({})", jobName, jobID, e);
                    final JobExecutionException exception = new JobExecutionException(jobID, "Failed to retrieve accumulator results. " + "The job is registered as 'FINISHED (successful), but this notification describes " + "a failure, since the resulting accumulators could not be fetched.", e);
                    jobCompletionActions.jobFailed(exception);
                }
                break;
            case CANCELED:
                {
                    final JobExecutionException exception = new JobExecutionException(jobID, "Job was cancelled.", new Exception("The job was cancelled"));
                    jobCompletionActions.jobFailed(exception);
                    break;
                }
            case FAILED:
                {
                    final Throwable unpackedError = SerializedThrowable.get(error, userCodeLoader);
                    final JobExecutionException exception = new JobExecutionException(jobID, "Job execution failed.", unpackedError);
                    jobCompletionActions.jobFailed(exception);
                    break;
                }
            default:
                // this can happen only if the enum is buggy
                throw new IllegalStateException(newJobStatus.toString());
        }
    }
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) SerializedThrowable(org.apache.flink.runtime.util.SerializedThrowable) JobID(org.apache.flink.api.common.JobID) TimeoutException(java.util.concurrent.TimeoutException) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) LeaderIdMismatchException(org.apache.flink.runtime.highavailability.LeaderIdMismatchException) PartitionProducerDisposedException(org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) IOException(java.io.IOException)

Aggregations

JobExecutionException (org.apache.flink.runtime.client.JobExecutionException)43 Test (org.junit.Test)27 IOException (java.io.IOException)19 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)17 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)15 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)9 ExecutionException (java.util.concurrent.ExecutionException)8 Optional (java.util.Optional)6 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)6 JobID (org.apache.flink.api.common.JobID)5 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)5 NoResourceAvailableException (org.apache.flink.runtime.jobmanager.scheduler.NoResourceAvailableException)5 JobException (org.apache.flink.runtime.JobException)4 URISyntaxException (java.net.URISyntaxException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)3 JobSubmissionResult (org.apache.flink.api.common.JobSubmissionResult)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 JobSubmissionException (org.apache.flink.runtime.client.JobSubmissionException)3