use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.
the class PigQueryInterpreterTest method setUp.
@Before
public void setUp() {
Properties properties = new Properties();
properties.put("zeppelin.pig.execType", "local");
properties.put("zeppelin.pig.maxResult", "20");
pigInterpreter = new PigInterpreter(properties);
pigQueryInterpreter = new PigQueryInterpreter(properties);
List<Interpreter> interpreters = new ArrayList();
interpreters.add(pigInterpreter);
interpreters.add(pigQueryInterpreter);
InterpreterGroup group = new InterpreterGroup();
group.put("note_id", interpreters);
pigInterpreter.setInterpreterGroup(group);
pigQueryInterpreter.setInterpreterGroup(group);
pigInterpreter.open();
pigQueryInterpreter.open();
context = new InterpreterContext(null, "paragraph_id", null, null, null, null, null, null, null, null, null, null);
}
use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.
the class ScaldingInterpreter method interpret.
@Override
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) {
String user = contextInterpreter.getAuthenticationInfo().getUser();
logger.info("Running Scalding command: user: {} cmd: '{}'", user, cmd);
if (interpreter == null) {
logger.error("interpreter == null, open may not have been called because max.open.instances reached");
return new InterpreterResult(Code.ERROR, "interpreter == null\n" + "open may not have been called because max.open.instances reached");
}
if (cmd == null || cmd.trim().length() == 0) {
return new InterpreterResult(Code.SUCCESS);
}
InterpreterResult interpreterResult = new InterpreterResult(Code.ERROR);
if (property.getProperty(ARGS_STRING).contains("hdfs")) {
UserGroupInformation ugi = null;
try {
ugi = UserGroupInformation.createProxyUser(user, UserGroupInformation.getLoginUser());
} catch (IOException e) {
logger.error("Error creating UserGroupInformation", e);
return new InterpreterResult(Code.ERROR, e.getMessage());
}
try {
// Make variables final to avoid "local variable is accessed from within inner class;
// needs to be declared final" exception in JDK7
final String cmd1 = cmd;
final InterpreterContext contextInterpreter1 = contextInterpreter;
PrivilegedExceptionAction<InterpreterResult> action = new PrivilegedExceptionAction<InterpreterResult>() {
public InterpreterResult run() throws Exception {
return interpret(cmd1.split("\n"), contextInterpreter1);
}
};
interpreterResult = ugi.doAs(action);
} catch (Exception e) {
logger.error("Error running command with ugi.doAs", e);
return new InterpreterResult(Code.ERROR, e.getMessage());
}
} else {
interpreterResult = interpret(cmd.split("\n"), contextInterpreter);
}
return interpreterResult;
}
use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.
the class PythonInterpreterMatplotlibTest method setUp.
@Before
public void setUp() throws Exception {
Properties p = new Properties();
p.setProperty("zeppelin.python", "python");
p.setProperty("zeppelin.python.maxResult", "100");
intpGroup = new InterpreterGroup();
python = new PythonInterpreter(p);
python.setInterpreterGroup(intpGroup);
List<Interpreter> interpreters = new LinkedList<>();
interpreters.add(python);
intpGroup.put("note", interpreters);
out = new InterpreterOutput(this);
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>(), out);
python.open();
}
use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.
the class PythonInterpreterTest method beforeTest.
@Before
public void beforeTest() throws IOException {
cmdHistory = "";
// python interpreter
pythonInterpreter = new PythonInterpreter(getPythonTestProperties());
// create interpreter group
InterpreterGroup group = new InterpreterGroup();
group.put("note", new LinkedList<Interpreter>());
group.get("note").add(pythonInterpreter);
pythonInterpreter.setInterpreterGroup(group);
out = new InterpreterOutput(this);
context = new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(group.getId(), null), new LocalResourcePool("id"), new LinkedList<InterpreterContextRunner>(), out);
pythonInterpreter.open();
}
use of org.apache.zeppelin.interpreter.InterpreterContext in project zeppelin by apache.
the class ZeppelinContext method angularWatch.
private void angularWatch(String name, String noteId, final scala.Function2<Object, Object, Unit> func) {
AngularObjectWatcher w = new AngularObjectWatcher(getInterpreterContext()) {
@Override
public void watch(Object oldObject, Object newObject, InterpreterContext context) {
func.apply(newObject, newObject);
}
};
angularWatch(name, noteId, w);
}
Aggregations