Search in sources :

Example 1 with Jinjava

use of com.hubspot.jinjava.Jinjava in project zeppelin by apache.

the class JinjaTemplatesTest method jobRunJinjaTemplateTest.

public String jobRunJinjaTemplateTest(Boolean dist, Boolean launchMode) throws IOException {
    URL urlTemplate = Resources.getResource(SubmarineJob.SUBMARINE_JOBRUN_TF_JINJA);
    String template = Resources.toString(urlTemplate, Charsets.UTF_8);
    Jinjava jinjava = new Jinjava();
    HashMap<String, Object> jinjaParams = initJinjaParams(dist, launchMode);
    String submarineCmd = jinjava.render(template, jinjaParams);
    int pos = submarineCmd.indexOf("\n");
    if (pos == 0) {
        submarineCmd = submarineCmd.replaceFirst("\n", "");
    }
    LOGGER.info("------------------------");
    LOGGER.info(submarineCmd);
    LOGGER.info("------------------------");
    return submarineCmd;
}
Also used : Jinjava(com.hubspot.jinjava.Jinjava) URL(java.net.URL)

Example 2 with Jinjava

use of com.hubspot.jinjava.Jinjava 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 Jinjava

use of com.hubspot.jinjava.Jinjava 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 Jinjava

use of com.hubspot.jinjava.Jinjava 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 Jinjava

use of com.hubspot.jinjava.Jinjava 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

Jinjava (com.hubspot.jinjava.Jinjava)19 URL (java.net.URL)9 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 InterpreterResultMessageOutput (org.apache.zeppelin.interpreter.InterpreterResultMessageOutput)5 File (java.io.File)2 UncheckedIOException (java.io.UncheckedIOException)2 Properties (java.util.Properties)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CommandLine (org.apache.commons.exec.CommandLine)2 DefaultExecuteResultHandler (org.apache.commons.exec.DefaultExecuteResultHandler)2 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)2 ExecuteException (org.apache.commons.exec.ExecuteException)2 ExecuteWatchdog (org.apache.commons.exec.ExecuteWatchdog)2 LogOutputStream (org.apache.commons.exec.LogOutputStream)2 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)2 SubmarineUI (org.apache.zeppelin.submarine.commons.SubmarineUI)2 TaskAction (org.gradle.api.tasks.TaskAction)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 JinjavaConfig (com.hubspot.jinjava.JinjavaConfig)1