Search in sources :

Example 1 with InterpreterResultMessageOutput

use of org.apache.zeppelin.interpreter.InterpreterResultMessageOutput in project zeppelin by apache.

the class SparkInterpreterTest method getInterpreterContext.

private InterpreterContext getInterpreterContext() {
    output = "";
    InterpreterContext context = InterpreterContext.builder().setInterpreterOut(new InterpreterOutput()).setIntpEventClient(mockRemoteEventClient).setAngularObjectRegistry(new AngularObjectRegistry("spark", null)).build();
    context.out = new InterpreterOutput(new InterpreterOutputListener() {

        @Override
        public void onUpdateAll(InterpreterOutput out) {
        }

        @Override
        public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) {
            try {
                output = out.toInterpreterResultMessage().getData();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onUpdate(int index, InterpreterResultMessageOutput out) {
            messageOutput = out;
        }
    });
    return context;
}
Also used : InterpreterOutputListener(org.apache.zeppelin.interpreter.InterpreterOutputListener) InterpreterResultMessageOutput(org.apache.zeppelin.interpreter.InterpreterResultMessageOutput) InterpreterOutput(org.apache.zeppelin.interpreter.InterpreterOutput) IOException(java.io.IOException) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 2 with InterpreterResultMessageOutput

use of org.apache.zeppelin.interpreter.InterpreterResultMessageOutput in project zeppelin by apache.

the class TerminalInterpreter method createTerminalDashboard.

public void createTerminalDashboard(String noteId, String paragraphId, int port) {
    String hostName = "", hostIp = "";
    URL urlTemplate = Resources.getResource("ui_templates/terminal-dashboard.jinja");
    String template = null;
    try {
        template = Resources.toString(urlTemplate, Charsets.UTF_8);
        InetAddress addr = InetAddress.getLocalHost();
        hostName = addr.getHostName().toString();
        hostIp = RemoteInterpreterUtils.findAvailableHostAddress();
        // Internal and external IP mapping of zeppelin server
        if (mapIpMapping.containsKey(hostIp)) {
            LOGGER.info("Internal IP: {}", hostIp);
            hostIp = mapIpMapping.get(hostIp);
            LOGGER.info("External IP: {}", hostIp);
        }
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    Jinjava jinjava = new Jinjava();
    HashMap<String, Object> jinjaParams = new HashMap();
    Date now = new Date();
    String terminalServerUrl = "http://" + hostIp + ":" + port + "?noteId=" + noteId + "&paragraphId=" + paragraphId + "&t=" + now.getTime();
    jinjaParams.put("HOST_NAME", hostName);
    jinjaParams.put("HOST_IP", hostIp);
    jinjaParams.put("TERMINAL_SERVER_URL", terminalServerUrl);
    String terminalDashboardTemplate = jinjava.render(template, jinjaParams);
    LOGGER.info(terminalDashboardTemplate);
    try {
        intpContext.out.setType(InterpreterResult.Type.ANGULAR);
        InterpreterResultMessageOutput outputUI = intpContext.out.getOutputAt(0);
        outputUI.clear();
        outputUI.write(terminalDashboardTemplate);
        outputUI.flush();
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) Jinjava(com.hubspot.jinjava.Jinjava) InterpreterResultMessageOutput(org.apache.zeppelin.interpreter.InterpreterResultMessageOutput) IOException(java.io.IOException) InetAddress(java.net.InetAddress) URL(java.net.URL) Date(java.util.Date)

Example 3 with InterpreterResultMessageOutput

use of org.apache.zeppelin.interpreter.InterpreterResultMessageOutput in project zeppelin by apache.

the class SubmarineUI method createSubmarineUI.

public void createSubmarineUI(SubmarineCommand submarineCmd) {
    try {
        HashMap<String, Object> mapParams = new HashMap();
        mapParams.put(unifyKey(SubmarineConstants.PARAGRAPH_ID), intpContext.getParagraphId());
        mapParams.put(unifyKey(SubmarineConstants.COMMAND_TYPE), submarineCmd.getCommand());
        String templateName = "";
        switch(submarineCmd) {
            case USAGE:
                templateName = SUBMARINE_USAGE_JINJA;
                List<CommandlineOption> commandlineOptions = getCommandlineOptions();
                mapParams.put(SubmarineConstants.COMMANDLINE_OPTIONS, commandlineOptions);
                break;
            default:
                templateName = SUBMARINE_DASHBOARD_JINJA;
                break;
        }
        URL urlTemplate = Resources.getResource(templateName);
        String template = Resources.toString(urlTemplate, Charsets.UTF_8);
        Jinjava jinjava = new Jinjava();
        String submarineUsage = jinjava.render(template, mapParams);
        // UI
        InterpreterResultMessageOutput outputUI = intpContext.out.getOutputAt(0);
        outputUI.clear();
        outputUI.write(submarineUsage);
        outputUI.flush();
        // UI update, log needs to be cleaned at the same time
        InterpreterResultMessageOutput outputLOG = intpContext.out.getOutputAt(1);
        outputLOG.clear();
        outputLOG.flush();
    } catch (IOException e) {
        LOGGER.error("Can't print usage", e);
    }
}
Also used : HashMap(java.util.HashMap) Jinjava(com.hubspot.jinjava.Jinjava) InterpreterResultMessageOutput(org.apache.zeppelin.interpreter.InterpreterResultMessageOutput) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with InterpreterResultMessageOutput

use of org.apache.zeppelin.interpreter.InterpreterResultMessageOutput in project zeppelin by apache.

the class SubmarineUI method printCommnadUI.

public void printCommnadUI(SubmarineCommand submarineCmd) {
    try {
        HashMap<String, Object> mapParams = new HashMap();
        mapParams.put(unifyKey(SubmarineConstants.PARAGRAPH_ID), intpContext.getParagraphId());
        URL urlTemplate = Resources.getResource(SUBMARINE_DASHBOARD_JINJA);
        String template = Resources.toString(urlTemplate, Charsets.UTF_8);
        Jinjava jinjava = new Jinjava();
        String submarineUsage = jinjava.render(template, mapParams);
        InterpreterResultMessageOutput outputUI = intpContext.out.getOutputAt(0);
        outputUI.clear();
        outputUI.write(submarineUsage);
        outputUI.flush();
        // UI update, log needs to be cleaned at the same time
        InterpreterResultMessageOutput outputLOG = intpContext.out.getOutputAt(1);
        outputLOG.clear();
        outputLOG.flush();
    } catch (IOException e) {
        LOGGER.error("Can't print usage", e);
    }
}
Also used : HashMap(java.util.HashMap) Jinjava(com.hubspot.jinjava.Jinjava) InterpreterResultMessageOutput(org.apache.zeppelin.interpreter.InterpreterResultMessageOutput) IOException(java.io.IOException) URL(java.net.URL)

Example 5 with InterpreterResultMessageOutput

use of org.apache.zeppelin.interpreter.InterpreterResultMessageOutput in project zeppelin by apache.

the class SubmarineUI method createLogHeadUI.

public void createLogHeadUI() {
    try {
        HashMap<String, Object> mapParams = new HashMap();
        URL urlTemplate = Resources.getResource(SUBMARINE_LOG_HEAD_JINJA);
        String template = Resources.toString(urlTemplate, Charsets.UTF_8);
        Jinjava jinjava = new Jinjava();
        String submarineUsage = jinjava.render(template, mapParams);
        InterpreterResultMessageOutput outputUI = intpContext.out.getOutputAt(1);
        outputUI.clear();
        outputUI.write(submarineUsage);
        outputUI.flush();
    } catch (IOException e) {
        LOGGER.error("Can't print usage", e);
    }
}
Also used : HashMap(java.util.HashMap) Jinjava(com.hubspot.jinjava.Jinjava) InterpreterResultMessageOutput(org.apache.zeppelin.interpreter.InterpreterResultMessageOutput) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)11 InterpreterResultMessageOutput (org.apache.zeppelin.interpreter.InterpreterResultMessageOutput)11 Jinjava (com.hubspot.jinjava.Jinjava)5 URL (java.net.URL)5 HashMap (java.util.HashMap)5 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)3 InterpreterOutputListener (org.apache.zeppelin.interpreter.InterpreterOutputListener)3 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)2 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)2 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 Properties (java.util.Properties)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ApplicationContext (org.apache.zeppelin.helium.ApplicationContext)1 ApplicationException (org.apache.zeppelin.helium.ApplicationException)1 Interpreter (org.apache.zeppelin.interpreter.Interpreter)1 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)1 ExecuteResponse (org.apache.zeppelin.interpreter.jupyter.proto.ExecuteResponse)1 OutputType (org.apache.zeppelin.interpreter.jupyter.proto.OutputType)1 RemoteInterpreterEventClient (org.apache.zeppelin.interpreter.remote.RemoteInterpreterEventClient)1