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();
}
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());
}
}
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());
}
}
Aggregations