Search in sources :

Example 11 with PlanJSONDumpGenerator

use of org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator in project flink by apache.

the class PackagedProgram method getPreviewPlan.

/**
	 * Returns the analyzed plan without any optimizations.
	 *
	 * @return
	 *         the analyzed plan without any optimizations.
	 * @throws ProgramInvocationException Thrown if an error occurred in the
	 *  user-provided pact assembler. This may indicate
	 *         missing parameters for generation.
	 */
public String getPreviewPlan() throws ProgramInvocationException {
    Thread.currentThread().setContextClassLoader(this.getUserCodeClassLoader());
    List<DataSinkNode> previewPlan;
    if (isUsingProgramEntryPoint()) {
        previewPlan = Optimizer.createPreOptimizedPlan(getPlan());
    } else if (isUsingInteractiveMode()) {
        // temporary hack to support the web client
        PreviewPlanEnvironment env = new PreviewPlanEnvironment();
        env.setAsContext();
        try {
            invokeInteractiveModeForExecution();
        } catch (ProgramInvocationException e) {
            throw e;
        } catch (Throwable t) {
            // the invocation gets aborted with the preview plan
            if (env.previewPlan != null) {
                previewPlan = env.previewPlan;
            } else if (env.preview != null) {
                return env.preview;
            } else {
                throw new ProgramInvocationException("The program caused an error: ", t);
            }
        } finally {
            env.unsetAsContext();
        }
        if (env.previewPlan != null) {
            previewPlan = env.previewPlan;
        } else {
            throw new ProgramInvocationException("The program plan could not be fetched. The program silently swallowed the control flow exceptions.");
        }
    } else {
        throw new RuntimeException();
    }
    PlanJSONDumpGenerator jsonGen = new PlanJSONDumpGenerator();
    StringWriter string = new StringWriter(1024);
    try (PrintWriter pw = new PrintWriter(string)) {
        jsonGen.dumpPactPlanAsJSON(previewPlan, pw);
    }
    return string.toString();
}
Also used : PlanJSONDumpGenerator(org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator) StringWriter(java.io.StringWriter) DataSinkNode(org.apache.flink.optimizer.dag.DataSinkNode) PrintWriter(java.io.PrintWriter)

Example 12 with PlanJSONDumpGenerator

use of org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator in project flink by apache.

the class ExecutionPlanCreationTest method testGetExecutionPlan.

@Test
public void testGetExecutionPlan() {
    try {
        PackagedProgram prg = new PackagedProgram(TestOptimizerPlan.class, "/dev/random", "/tmp");
        assertNotNull(prg.getPreviewPlan());
        InetAddress mockAddress = InetAddress.getLocalHost();
        InetSocketAddress mockJmAddress = new InetSocketAddress(mockAddress, 12345);
        Configuration config = new Configuration();
        config.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, mockJmAddress.getHostName());
        config.setInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, mockJmAddress.getPort());
        Optimizer optimizer = new Optimizer(new DataStatistics(), new DefaultCostEstimator(), config);
        OptimizedPlan op = (OptimizedPlan) ClusterClient.getOptimizedPlan(optimizer, prg, -1);
        assertNotNull(op);
        PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator();
        assertNotNull(dumper.getOptimizerPlanAsJSON(op));
        // test HTML escaping
        PlanJSONDumpGenerator dumper2 = new PlanJSONDumpGenerator();
        dumper2.setEncodeForHTML(true);
        String htmlEscaped = dumper2.getOptimizerPlanAsJSON(op);
        assertEquals(-1, htmlEscaped.indexOf('\\'));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : PlanJSONDumpGenerator(org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator) Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) Optimizer(org.apache.flink.optimizer.Optimizer) DataStatistics(org.apache.flink.optimizer.DataStatistics) DefaultCostEstimator(org.apache.flink.optimizer.costs.DefaultCostEstimator) InetAddress(java.net.InetAddress) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) Test(org.junit.Test)

Example 13 with PlanJSONDumpGenerator

use of org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator in project flink by apache.

the class DumpCompiledPlanTest method dump.

private void dump(Plan p) {
    p.setExecutionConfig(new ExecutionConfig());
    try {
        OptimizedPlan op = compileNoStats(p);
        PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator();
        String json = dumper.getOptimizerPlanAsJSON(op);
        JsonParser parser = new JsonFactory().createJsonParser(json);
        while (parser.nextToken() != null) ;
    } catch (JsonParseException e) {
        e.printStackTrace();
        Assert.fail("JSON Generator produced malformatted output: " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("An error occurred in the test: " + e.getMessage());
    }
}
Also used : PlanJSONDumpGenerator(org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator) JsonFactory(org.codehaus.jackson.JsonFactory) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) JsonParseException(org.codehaus.jackson.JsonParseException) JsonParseException(org.codehaus.jackson.JsonParseException) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) JsonParser(org.codehaus.jackson.JsonParser)

Aggregations

PlanJSONDumpGenerator (org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator)13 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)11 DataStatistics (org.apache.flink.optimizer.DataStatistics)6 Optimizer (org.apache.flink.optimizer.Optimizer)6 DefaultCostEstimator (org.apache.flink.optimizer.costs.DefaultCostEstimator)4 Test (org.junit.Test)4 Configuration (org.apache.flink.configuration.Configuration)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 Plan (org.apache.flink.api.common.Plan)2 DataSinkNode (org.apache.flink.optimizer.dag.DataSinkNode)2 JobGraphGenerator (org.apache.flink.optimizer.plantranslate.JobGraphGenerator)2 JsonFactory (org.codehaus.jackson.JsonFactory)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonParser (org.codehaus.jackson.JsonParser)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)1 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1