Search in sources :

Example 16 with InterpreterContext

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);
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) ArrayList(java.util.ArrayList) Properties(java.util.Properties) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) Before(org.junit.Before)

Example 17 with InterpreterContext

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;
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) IOException(java.io.IOException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 18 with InterpreterContext

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();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) Interpreter(org.apache.zeppelin.interpreter.Interpreter) HashMap(java.util.HashMap) Properties(java.util.Properties) LinkedList(java.util.LinkedList) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) InterpreterOutput(org.apache.zeppelin.interpreter.InterpreterOutput) GUI(org.apache.zeppelin.display.GUI) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Before(org.junit.Before)

Example 19 with InterpreterContext

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();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) Interpreter(org.apache.zeppelin.interpreter.Interpreter) HashMap(java.util.HashMap) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) InterpreterOutput(org.apache.zeppelin.interpreter.InterpreterOutput) GUI(org.apache.zeppelin.display.GUI) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 20 with InterpreterContext

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);
}
Also used : AngularObjectWatcher(org.apache.zeppelin.display.AngularObjectWatcher) AngularObject(org.apache.zeppelin.display.AngularObject) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext)

Aggregations

InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)21 Properties (java.util.Properties)9 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)7 Before (org.junit.Before)7 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)6 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)5 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 GUI (org.apache.zeppelin.display.GUI)4 Theory (org.junit.experimental.theories.Theory)4 AngularObjectWatcher (org.apache.zeppelin.display.AngularObjectWatcher)3 Interpreter (org.apache.zeppelin.interpreter.Interpreter)3 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)3 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)3 AngularObject (org.apache.zeppelin.display.AngularObject)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1