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;
}
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 + "¶graphId=" + 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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations