Search in sources :

Example 1 with RemoteEventClientWrapper

use of org.apache.zeppelin.interpreter.remote.RemoteEventClientWrapper in project zeppelin by apache.

the class SparkInterpreter method setupListeners.

static JobProgressListener setupListeners(SparkContext context) {
    JobProgressListener pl = new JobProgressListener(context.getConf()) {

        @Override
        public synchronized void onJobStart(SparkListenerJobStart jobStart) {
            super.onJobStart(jobStart);
            int jobId = jobStart.jobId();
            String jobGroupId = jobStart.properties().getProperty("spark.jobGroup.id");
            String jobUrl = getJobUrl(jobId);
            String noteId = Utils.getNoteId(jobGroupId);
            String paragraphId = Utils.getParagraphId(jobGroupId);
            if (jobUrl != null && noteId != null && paragraphId != null) {
                RemoteEventClientWrapper eventClient = ZeppelinContext.getEventClient();
                Map<String, String> infos = new java.util.HashMap<>();
                infos.put("jobUrl", jobUrl);
                infos.put("label", "SPARK JOB");
                infos.put("tooltip", "View in Spark web UI");
                if (eventClient != null) {
                    eventClient.onParaInfosReceived(noteId, paragraphId, infos);
                }
            }
        }

        private String getJobUrl(int jobId) {
            String jobUrl = null;
            if (sparkUrl != null) {
                jobUrl = sparkUrl + "/jobs/job?id=" + jobId;
            }
            return jobUrl;
        }
    };
    try {
        Object listenerBus = context.getClass().getMethod("listenerBus").invoke(context);
        Method[] methods = listenerBus.getClass().getMethods();
        Method addListenerMethod = null;
        for (Method m : methods) {
            if (!m.getName().equals("addListener")) {
                continue;
            }
            Class<?>[] parameterTypes = m.getParameterTypes();
            if (parameterTypes.length != 1) {
                continue;
            }
            if (!parameterTypes[0].isAssignableFrom(JobProgressListener.class)) {
                continue;
            }
            addListenerMethod = m;
            break;
        }
        if (addListenerMethod != null) {
            addListenerMethod.invoke(listenerBus, pl);
        } else {
            return null;
        }
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        logger.error(e.toString(), e);
        return null;
    }
    return pl;
}
Also used : JobProgressListener(org.apache.spark.ui.jobs.JobProgressListener) SparkListenerJobStart(org.apache.spark.scheduler.SparkListenerJobStart) HashMap(scala.collection.mutable.HashMap) Method(java.lang.reflect.Method) RemoteEventClientWrapper(org.apache.zeppelin.interpreter.remote.RemoteEventClientWrapper) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with RemoteEventClientWrapper

use of org.apache.zeppelin.interpreter.remote.RemoteEventClientWrapper in project zeppelin by apache.

the class SparkInterpreterTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    intpGroup = new InterpreterGroup();
    intpGroup.put("note", new LinkedList<Interpreter>());
    repl = new SparkInterpreter(getSparkTestProperties(tmpDir));
    repl.setInterpreterGroup(intpGroup);
    intpGroup.get("note").add(repl);
    repl.open();
    final RemoteEventClientWrapper remoteEventClientWrapper = new RemoteEventClientWrapper() {

        @Override
        public void onParaInfosReceived(String noteId, String paragraphId, Map<String, String> infos) {
            if (infos != null) {
                paraIdToInfosMap.put(paragraphId, infos);
            }
        }

        @Override
        public void onMetaInfosReceived(Map<String, String> infos) {
        }
    };
    context = new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("id"), new LinkedList<InterpreterContextRunner>(), new InterpreterOutput(null)) {

        @Override
        public RemoteEventClientWrapper getClient() {
            return remoteEventClientWrapper;
        }
    };
    // The first para interpretdr will set the Eventclient wrapper
    //SparkInterpreter.interpret(String, InterpreterContext) ->
    //SparkInterpreter.populateSparkWebUrl(InterpreterContext) ->
    //ZeppelinContext.setEventClient(RemoteEventClientWrapper)
    //running a dummy to ensure that we dont have any race conditions among tests
    repl.interpret("sc", context);
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) HashMap(java.util.HashMap) RemoteEventClientWrapper(org.apache.zeppelin.interpreter.remote.RemoteEventClientWrapper) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList) GUI(org.apache.zeppelin.display.GUI) HashMap(java.util.HashMap) Map(java.util.Map) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Aggregations

RemoteEventClientWrapper (org.apache.zeppelin.interpreter.remote.RemoteEventClientWrapper)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 SparkListenerJobStart (org.apache.spark.scheduler.SparkListenerJobStart)1 JobProgressListener (org.apache.spark.ui.jobs.JobProgressListener)1 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)1 GUI (org.apache.zeppelin.display.GUI)1 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)1 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)1 HashMap (scala.collection.mutable.HashMap)1