code: public static String optimizerPlanAsJSON(Plan plan) throws Exception {
  		final int parallelism = plan.getDefaultParallelism() == ExecutionConfig.PARALLELISM_DEFAULT ? 1 : plan.getDefaultParallelism();
  
  		Optimizer pc = new Optimizer(new DataStatistics(), new Configuration());
  		pc.setDefaultParallelism(parallelism);
  		OptimizedPlan op = pc.compile(plan);
  
  		return new PlanJSONDumpGenerator().getOptimizerPlanAsJSON(op);
  	}
docs: Creates a JSON representation of the given dataflow's execution plan.
  
  @param plan The dataflow plan.
  @return The dataflow's execution plan, as a JSON string.
  @throws Exception Thrown, if the optimization process that creates the execution plan failed.