org.apache.spark.ui.jobs.JobProgressListener Java Examples
The following examples show how to use
org.apache.spark.ui.jobs.JobProgressListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Spark1Shims.java From zeppelin with Apache License 2.0 | 5 votes |
public void setupSparkListener(final String master, final String sparkWebUrl, final InterpreterContext context) { SparkContext sc = SparkContext.getOrCreate(); sc.addSparkListener(new JobProgressListener(sc.getConf()) { @Override public void onJobStart(SparkListenerJobStart jobStart) { if (sc.getConf().getBoolean("spark.ui.enabled", true) && !Boolean.parseBoolean(properties.getProperty("zeppelin.spark.ui.hidden", "false"))) { buildSparkJobUrl(master, sparkWebUrl, jobStart.jobId(), jobStart.properties(), context); } } }); }
Example #2
Source File: SparkInterpreter.java From Explorer with Apache License 2.0 | 5 votes |
public synchronized SparkContext getSparkContext() { context.loadConfiguration(new PropertiesReader().readConfigFrom("spark_interpreter")); SparkContext sc =context.getConnector(); env = SparkEnv.get(); sparkListener = new JobProgressListener(context.getConnector().getConf()); sc.listenerBus().addListener(sparkListener); return sc; }
Example #3
Source File: SparkInterpreter.java From Explorer with Apache License 2.0 | 5 votes |
private int[] getProgressFromStage_1_1x(JobProgressListener sparkListener, Stage stage) { int numTasks = stage.numTasks(); int completedTasks = 0; try { Method stageIdToData = sparkListener.getClass().getMethod("stageIdToData"); HashMap<Tuple2<Object, Object>, Object> stageIdData = (HashMap<Tuple2<Object, Object>, Object>) stageIdToData .invoke(sparkListener); Class<?> stageUIDataClass = this.getClass().forName("org.apache.spark.ui.jobs.UIData$StageUIData"); Method numCompletedTasks = stageUIDataClass.getMethod("numCompleteTasks"); Set<Tuple2<Object, Object>> keys = JavaConverters.asJavaSetConverter(stageIdData.keySet()).asJava(); for (Tuple2<Object, Object> k : keys) { if (stage.id() == (int) k._1()) { Object uiData = stageIdData.get(k).get(); completedTasks += (int) numCompletedTasks.invoke(uiData); } } } catch (Exception e) { logger.error("Error on getting progress information", e); } List<Stage> parents = JavaConversions.asJavaList(stage.parents()); if (parents != null) { for (Stage s : parents) { int[] p = getProgressFromStage_1_1x(sparkListener, s); numTasks += p[0]; completedTasks += p[1]; } } return new int[] { numTasks, completedTasks }; }
Example #4
Source File: SparkSqlInterpreter.java From Explorer with Apache License 2.0 | 5 votes |
public int getProgress() { SQLContext sqlc = getSparkInterpreter().getSQLContext(); SparkContext sc = sqlc.sparkContext(); JobProgressListener sparkListener = getSparkInterpreter().getJobProgressListener(); int completedTasks = 0; int totalTasks = 0; DAGScheduler scheduler = sc.dagScheduler(); HashSet<ActiveJob> jobs = scheduler.activeJobs(); Iterator<ActiveJob> it = jobs.iterator(); while (it.hasNext()) { ActiveJob job = it.next(); String g = (String) job.properties().get("spark.jobGroup.id"); if (jobGroup.equals(g)) { int[] progressInfo = null; if (sc.version().startsWith("1.0")) { progressInfo = getProgressFromStage_1_0x(sparkListener, job.finalStage()); } else if (sc.version().startsWith("1.1") || sc.version().startsWith("1.2")) { progressInfo = getProgressFromStage_1_1x(sparkListener, job.finalStage()); } else { logger.warn("Spark {} getting progress information not supported" + sc.version()); continue; } totalTasks += progressInfo[0]; completedTasks += progressInfo[1]; } } if (totalTasks == 0) { return 0; } return completedTasks * 100 / totalTasks; }
Example #5
Source File: SparkSqlInterpreter.java From Explorer with Apache License 2.0 | 5 votes |
private int[] getProgressFromStage_1_1x(JobProgressListener sparkListener, Stage stage) { int numTasks = stage.numTasks(); int completedTasks = 0; try { Method stageIdToData = sparkListener.getClass().getMethod("stageIdToData"); HashMap<Tuple2<Object, Object>, Object> stageIdData = (HashMap<Tuple2<Object, Object>, Object>) stageIdToData .invoke(sparkListener); Class<?> stageUIDataClass = this.getClass().forName("org.apache.spark.ui.jobs.UIData$StageUIData"); Method numCompletedTasks = stageUIDataClass.getMethod("numCompleteTasks"); Set<Tuple2<Object, Object>> keys = JavaConverters.asJavaSetConverter(stageIdData.keySet()).asJava(); for (Tuple2<Object, Object> k : keys) { if (stage.id() == (int) k._1()) { Object uiData = stageIdData.get(k).get(); completedTasks += (int) numCompletedTasks.invoke(uiData); } } } catch (Exception e) { logger.error("Error on getting progress information", e); } List<Stage> parents = JavaConversions.asJavaList(stage.parents()); if (parents != null) { for (Stage s : parents) { int[] p = getProgressFromStage_1_1x(sparkListener, s); numTasks += p[0]; completedTasks += p[1]; } } return new int[] { numTasks, completedTasks }; }
Example #6
Source File: SparkInterpreter.java From Explorer with Apache License 2.0 | 4 votes |
public JobProgressListener getJobProgressListener() { return sparkListener; }