Search in sources :

Example 1 with StreamingPlan

use of org.apache.flink.optimizer.plan.StreamingPlan in project flink by apache.

the class CliFrontend method info.

/**
	 * Executes the info action.
	 * 
	 * @param args Command line arguments for the info action.
	 */
protected int info(String[] args) {
    LOG.info("Running 'info' command.");
    // Parse command line options
    InfoOptions options;
    try {
        options = CliFrontendParser.parseInfoCommand(args);
    } catch (CliArgsException e) {
        return handleArgException(e);
    } catch (Throwable t) {
        return handleError(t);
    }
    // evaluate help flag
    if (options.isPrintHelp()) {
        CliFrontendParser.printHelpForInfo();
        return 0;
    }
    if (options.getJarFilePath() == null) {
        return handleArgException(new CliArgsException("The program JAR file was not specified."));
    }
    // -------- build the packaged program -------------
    PackagedProgram program;
    try {
        LOG.info("Building program from JAR file");
        program = buildProgram(options);
    } catch (Throwable t) {
        return handleError(t);
    }
    try {
        int parallelism = options.getParallelism();
        LOG.info("Creating program plan dump");
        Optimizer compiler = new Optimizer(new DataStatistics(), new DefaultCostEstimator(), config);
        FlinkPlan flinkPlan = ClusterClient.getOptimizedPlan(compiler, program, parallelism);
        String jsonPlan = null;
        if (flinkPlan instanceof OptimizedPlan) {
            jsonPlan = new PlanJSONDumpGenerator().getOptimizerPlanAsJSON((OptimizedPlan) flinkPlan);
        } else if (flinkPlan instanceof StreamingPlan) {
            jsonPlan = ((StreamingPlan) flinkPlan).getStreamingPlanAsJSON();
        }
        if (jsonPlan != null) {
            System.out.println("----------------------- Execution Plan -----------------------");
            System.out.println(jsonPlan);
            System.out.println("--------------------------------------------------------------");
        } else {
            System.out.println("JSON plan could not be generated.");
        }
        String description = program.getDescription();
        if (description != null) {
            System.out.println();
            System.out.println(description);
        } else {
            System.out.println();
            System.out.println("No description provided.");
        }
        return 0;
    } catch (Throwable t) {
        return handleError(t);
    } finally {
        program.deleteExtractedLibraries();
    }
}
Also used : PlanJSONDumpGenerator(org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator) StreamingPlan(org.apache.flink.optimizer.plan.StreamingPlan) Optimizer(org.apache.flink.optimizer.Optimizer) DataStatistics(org.apache.flink.optimizer.DataStatistics) CliArgsException(org.apache.flink.client.cli.CliArgsException) FlinkPlan(org.apache.flink.optimizer.plan.FlinkPlan) TriggerSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint) DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) CancelJobWithSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.CancelJobWithSavepoint) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) PackagedProgram(org.apache.flink.client.program.PackagedProgram) DefaultCostEstimator(org.apache.flink.optimizer.costs.DefaultCostEstimator) InfoOptions(org.apache.flink.client.cli.InfoOptions)

Example 2 with StreamingPlan

use of org.apache.flink.optimizer.plan.StreamingPlan in project flink by apache.

the class JarActionHandler method getJobGraphAndClassLoader.

protected Tuple2<JobGraph, ClassLoader> getJobGraphAndClassLoader(JarActionHandlerConfig config) throws Exception {
    // generate the graph
    JobGraph graph = null;
    PackagedProgram program = new PackagedProgram(new File(jarDir, config.getJarFile()), config.getEntryClass(), config.getProgramArgs());
    ClassLoader classLoader = program.getUserCodeClassLoader();
    Optimizer optimizer = new Optimizer(new DataStatistics(), new DefaultCostEstimator(), new Configuration());
    FlinkPlan plan = ClusterClient.getOptimizedPlan(optimizer, program, config.getParallelism());
    if (plan instanceof StreamingPlan) {
        graph = ((StreamingPlan) plan).getJobGraph();
    } else if (plan instanceof OptimizedPlan) {
        graph = new JobGraphGenerator().compileJobGraph((OptimizedPlan) plan);
    }
    if (graph == null) {
        throw new CompilerException("A valid job graph couldn't be generated for the jar.");
    }
    // Set the savepoint settings
    graph.setSavepointRestoreSettings(config.getSavepointRestoreSettings());
    for (URL jar : program.getAllLibraries()) {
        try {
            graph.addJar(new Path(jar.toURI()));
        } catch (URISyntaxException e) {
            throw new ProgramInvocationException("Invalid jar path. Unexpected error. :(");
        }
    }
    return Tuple2.of(graph, classLoader);
}
Also used : Path(org.apache.flink.core.fs.Path) Configuration(org.apache.flink.configuration.Configuration) StreamingPlan(org.apache.flink.optimizer.plan.StreamingPlan) Optimizer(org.apache.flink.optimizer.Optimizer) DataStatistics(org.apache.flink.optimizer.DataStatistics) FlinkPlan(org.apache.flink.optimizer.plan.FlinkPlan) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) PackagedProgram(org.apache.flink.client.program.PackagedProgram) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobGraphGenerator(org.apache.flink.optimizer.plantranslate.JobGraphGenerator) CompilerException(org.apache.flink.optimizer.CompilerException) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) DefaultCostEstimator(org.apache.flink.optimizer.costs.DefaultCostEstimator) File(java.io.File)

Example 3 with StreamingPlan

use of org.apache.flink.optimizer.plan.StreamingPlan in project flink by apache.

the class ClusterClient method getJobGraph.

private JobGraph getJobGraph(FlinkPlan optPlan, List<URL> jarFiles, List<URL> classpaths, SavepointRestoreSettings savepointSettings) {
    JobGraph job;
    if (optPlan instanceof StreamingPlan) {
        job = ((StreamingPlan) optPlan).getJobGraph();
        job.setSavepointRestoreSettings(savepointSettings);
    } else {
        JobGraphGenerator gen = new JobGraphGenerator(this.flinkConfig);
        job = gen.compileJobGraph((OptimizedPlan) optPlan);
    }
    for (URL jar : jarFiles) {
        try {
            job.addJar(new Path(jar.toURI()));
        } catch (URISyntaxException e) {
            throw new RuntimeException("URL is invalid. This should not happen.", e);
        }
    }
    job.setClasspaths(classpaths);
    return job;
}
Also used : Path(org.apache.flink.core.fs.Path) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) StreamingPlan(org.apache.flink.optimizer.plan.StreamingPlan) JobGraphGenerator(org.apache.flink.optimizer.plantranslate.JobGraphGenerator) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan)

Aggregations

OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)3 StreamingPlan (org.apache.flink.optimizer.plan.StreamingPlan)3 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 PackagedProgram (org.apache.flink.client.program.PackagedProgram)2 Path (org.apache.flink.core.fs.Path)2 DataStatistics (org.apache.flink.optimizer.DataStatistics)2 Optimizer (org.apache.flink.optimizer.Optimizer)2 DefaultCostEstimator (org.apache.flink.optimizer.costs.DefaultCostEstimator)2 FlinkPlan (org.apache.flink.optimizer.plan.FlinkPlan)2 JobGraphGenerator (org.apache.flink.optimizer.plantranslate.JobGraphGenerator)2 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)2 File (java.io.File)1 CliArgsException (org.apache.flink.client.cli.CliArgsException)1 InfoOptions (org.apache.flink.client.cli.InfoOptions)1 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)1 Configuration (org.apache.flink.configuration.Configuration)1 CompilerException (org.apache.flink.optimizer.CompilerException)1 PlanJSONDumpGenerator (org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator)1 CancelJobWithSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.CancelJobWithSavepoint)1