Search in sources :

Example 1 with HashMap

use of scala.collection.mutable.HashMap in project zeppelin by apache.

the class SparkInterpreter method getProgressFromStage_1_1x.

private int[] getProgressFromStage_1_1x(JobProgressListener sparkListener, Object stage) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    int numTasks = (int) stage.getClass().getMethod("numTasks").invoke(stage);
    int completedTasks = 0;
    int id = (int) stage.getClass().getMethod("id").invoke(stage);
    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.setAsJavaSetConverter(stageIdData.keySet()).asJava();
        for (Tuple2<Object, Object> k : keys) {
            if (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<Object> parents = JavaConversions.seqAsJavaList((Seq<Object>) stage.getClass().getMethod("parents").invoke(stage));
    if (parents != null) {
        for (Object s : parents) {
            int[] p = getProgressFromStage_1_1x(sparkListener, s);
            numTasks += p[0];
            completedTasks += p[1];
        }
    }
    return new int[] { numTasks, completedTasks };
}
Also used : HashMap(scala.collection.mutable.HashMap) Method(java.lang.reflect.Method) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)1 HashMap (scala.collection.mutable.HashMap)1