Search in sources :

Example 6 with JobSubmissionResult

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

the class SavepointMigrationTestBase method executeAndSavepoint.

@SafeVarargs
protected final void executeAndSavepoint(StreamExecutionEnvironment env, String savepointPath, Tuple2<String, Integer>... expectedAccumulators) throws Exception {
    // Retrieve the job manager
    ActorGateway jobManager = Await.result(cluster.leaderGateway().future(), DEADLINE.timeLeft());
    // Submit the job
    JobGraph jobGraph = env.getStreamGraph().getJobGraph();
    JobSubmissionResult jobSubmissionResult = cluster.submitJobDetached(jobGraph);
    LOG.info("Submitted job {} and waiting...", jobSubmissionResult.getJobID());
    StandaloneClusterClient clusterClient = new StandaloneClusterClient(cluster.configuration());
    boolean done = false;
    while (DEADLINE.hasTimeLeft()) {
        Thread.sleep(100);
        Map<String, Object> accumulators = clusterClient.getAccumulators(jobSubmissionResult.getJobID());
        boolean allDone = true;
        for (Tuple2<String, Integer> acc : expectedAccumulators) {
            Integer numFinished = (Integer) accumulators.get(acc.f0);
            if (numFinished == null) {
                allDone = false;
                break;
            }
            if (!numFinished.equals(acc.f1)) {
                allDone = false;
                break;
            }
        }
        if (allDone) {
            done = true;
            break;
        }
    }
    if (!done) {
        fail("Did not see the expected accumulator results within time limit.");
    }
    LOG.info("Triggering savepoint.");
    // Flink 1.2
    final Future<Object> savepointResultFuture = jobManager.ask(new JobManagerMessages.TriggerSavepoint(jobSubmissionResult.getJobID(), Option.<String>empty()), DEADLINE.timeLeft());
    // Flink 1.1
    //		final Future<Object> savepointResultFuture =
    //				jobManager.ask(new JobManagerMessages.TriggerSavepoint(jobSubmissionResult.getJobID()), DEADLINE.timeLeft());
    Object savepointResult = Await.result(savepointResultFuture, DEADLINE.timeLeft());
    if (savepointResult instanceof JobManagerMessages.TriggerSavepointFailure) {
        fail("Error drawing savepoint: " + ((JobManagerMessages.TriggerSavepointFailure) savepointResult).cause());
    }
    // jobmanager will store savepoint in heap, we have to retrieve it
    final String jobmanagerSavepointPath = ((JobManagerMessages.TriggerSavepointSuccess) savepointResult).savepointPath();
    LOG.info("Saved savepoint: " + jobmanagerSavepointPath);
    // Flink 1.2
    FileUtils.moveFile(new File(new URI(jobmanagerSavepointPath).getPath()), new File(savepointPath));
// Flink 1.1
// Retrieve the savepoint from the testing job manager
//		LOG.info("Requesting the savepoint.");
//		Future<Object> savepointFuture = jobManager.ask(new TestingJobManagerMessages.RequestSavepoint(jobmanagerSavepointPath), DEADLINE.timeLeft());
//
//		Savepoint savepoint = ((TestingJobManagerMessages.ResponseSavepoint) Await.result(savepointFuture, DEADLINE.timeLeft())).savepoint();
//		LOG.info("Retrieved savepoint: " + jobmanagerSavepointPath + ".");
//
//		LOG.info("Storing savepoint to file.");
//		Configuration config = new Configuration();
//		config.setString(org.apache.flink.runtime.checkpoint.savepoint.SavepointStoreFactory.SAVEPOINT_BACKEND_KEY, "filesystem");
//		config.setString(org.apache.flink.runtime.checkpoint.savepoint.SavepointStoreFactory.SAVEPOINT_DIRECTORY_KEY, "file:///Users/aljoscha/Downloads");
//		String path = org.apache.flink.runtime.checkpoint.savepoint.SavepointStoreFactory.createFromConfig(config).storeSavepoint(savepoint);
//
//		FileUtils.moveFile(new File(new URI(path).getPath()), new File(savepointPath));
}
Also used : JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) StandaloneClusterClient(org.apache.flink.client.program.StandaloneClusterClient) URI(java.net.URI) JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) File(java.io.File)

Example 7 with JobSubmissionResult

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

the class YarnClusterClientV2 method submitJob.

@Override
protected JobSubmissionResult submitJob(JobGraph jobGraph, ClassLoader classLoader) throws ProgramInvocationException {
    try {
        // Create application via yarnClient
        final YarnClientApplication yarnApplication = yarnClient.createApplication();
        ApplicationReport report = this.clusterDescriptor.startAppMaster(jobGraph, yarnClient, yarnApplication);
        if (report.getYarnApplicationState().equals(YarnApplicationState.RUNNING)) {
            appId = report.getApplicationId();
            trackingURL = report.getTrackingUrl();
            logAndSysout("Please refer to " + getWebInterfaceURL() + " for the running status of job " + jobGraph.getJobID().toString());
            //TODO: not support attach mode now
            return new JobSubmissionResult(jobGraph.getJobID());
        } else {
            throw new ProgramInvocationException("Fail to submit the job.");
        }
    } catch (Exception e) {
        throw new ProgramInvocationException("Fail to submit the job", e.getCause());
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) YarnClientApplication(org.apache.hadoop.yarn.client.api.YarnClientApplication) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) IOException(java.io.IOException)

Aggregations

JobSubmissionResult (org.apache.flink.api.common.JobSubmissionResult)7 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)3 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)3 File (java.io.File)2 IOException (java.io.IOException)2 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)2 StandaloneClusterClient (org.apache.flink.client.program.StandaloneClusterClient)2 JobExecutionException (org.apache.flink.runtime.client.JobExecutionException)2 Test (org.junit.Test)2 FileNotFoundException (java.io.FileNotFoundException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)1 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)1 JobID (org.apache.flink.api.common.JobID)1 MapFunction (org.apache.flink.api.common.functions.MapFunction)1 RichFlatMapFunction (org.apache.flink.api.common.functions.RichFlatMapFunction)1 RichMapFunction (org.apache.flink.api.common.functions.RichMapFunction)1 ProgramMissingJobException (org.apache.flink.client.program.ProgramMissingJobException)1 ProgramParametrizationException (org.apache.flink.client.program.ProgramParametrizationException)1