Search in sources :

Example 46 with Interpreter

use of org.apache.zeppelin.interpreter.Interpreter 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 47 with Interpreter

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

the class NoteInterpreterLoaderTest method testNoteInterpreterCloseForAll.

@Test
public void testNoteInterpreterCloseForAll() throws IOException {
    interpreterSettingManager.setInterpreters("user", "FitstNote", interpreterSettingManager.getDefaultInterpreterSettingList());
    interpreterSettingManager.getInterpreterSettings("FitstNote").get(0).getOption().setPerNote(InterpreterOption.SCOPED);
    interpreterSettingManager.setInterpreters("user", "yourFirstNote", interpreterSettingManager.getDefaultInterpreterSettingList());
    interpreterSettingManager.getInterpreterSettings("yourFirstNote").get(0).getOption().setPerNote(InterpreterOption.ISOLATED);
    // interpreters are not created before accessing it
    assertNull(interpreterSettingManager.getInterpreterSettings("FitstNote").get(0).getInterpreterGroup("user", "FitstNote").get("FitstNote"));
    assertNull(interpreterSettingManager.getInterpreterSettings("yourFirstNote").get(0).getInterpreterGroup("user", "yourFirstNote").get("yourFirstNote"));
    Interpreter firstNoteIntp = factory.getInterpreter("user", "FitstNote", "group1.mock1");
    Interpreter yourFirstNoteIntp = factory.getInterpreter("user", "yourFirstNote", "group1.mock1");
    firstNoteIntp.open();
    yourFirstNoteIntp.open();
    assertTrue(((LazyOpenInterpreter) firstNoteIntp).isOpen());
    assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
    interpreterSettingManager.closeNote("user", "FitstNote");
    assertFalse(((LazyOpenInterpreter) firstNoteIntp).isOpen());
    assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
    //reopen
    firstNoteIntp.open();
    assertTrue(((LazyOpenInterpreter) firstNoteIntp).isOpen());
    assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
    // invalid check
    interpreterSettingManager.closeNote("invalid", "Note");
    assertTrue(((LazyOpenInterpreter) firstNoteIntp).isOpen());
    assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
    // invalid contains value check
    interpreterSettingManager.closeNote("u", "Note");
    assertTrue(((LazyOpenInterpreter) firstNoteIntp).isOpen());
    assertTrue(((LazyOpenInterpreter) yourFirstNoteIntp).isOpen());
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) Test(org.junit.Test)

Example 48 with Interpreter

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

the class PigQueryInterpreterTest method setUp.

@Before
public void setUp() throws InterpreterException {
    Properties properties = new Properties();
    properties.put("zeppelin.pig.execType", "local");
    properties.put("zeppelin.pig.maxResult", "20");
    pigInterpreter = new LazyOpenInterpreter(new PigInterpreter(properties));
    pigQueryInterpreter = new LazyOpenInterpreter(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 = InterpreterContext.builder().setParagraphId("paragraphId").build();
}
Also used : LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Before(org.junit.Before)

Example 49 with Interpreter

use of org.apache.zeppelin.interpreter.Interpreter 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");
    p.setProperty("zeppelin.python.useIPython", "false");
    p.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");
    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 = InterpreterContext.builder().setInterpreterOut(out).setAngularObjectRegistry(new AngularObjectRegistry(intpGroup.getId(), null)).build();
    InterpreterContext.set(context);
    python.open();
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) InterpreterOutput(org.apache.zeppelin.interpreter.InterpreterOutput) Properties(java.util.Properties) LinkedList(java.util.LinkedList) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Before(org.junit.Before)

Example 50 with Interpreter

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

the class PythonInterpreterTest method testFailtoLaunchPythonProcess.

@Test
public void testFailtoLaunchPythonProcess() throws InterpreterException {
    tearDown();
    intpGroup = new InterpreterGroup();
    Properties properties = new Properties();
    properties.setProperty("zeppelin.python", "invalid_python");
    properties.setProperty("zeppelin.python.useIPython", "false");
    properties.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");
    interpreter = new LazyOpenInterpreter(new PythonInterpreter(properties));
    intpGroup.put("note", new LinkedList<Interpreter>());
    intpGroup.get("note").add(interpreter);
    interpreter.setInterpreterGroup(intpGroup);
    InterpreterContext.set(getInterpreterContext());
    try {
        interpreter.interpret("1+1", getInterpreterContext());
        fail("Should fail to open PythonInterpreter");
    } catch (InterpreterException e) {
        String stacktrace = ExceptionUtils.getStackTrace(e);
        assertTrue(stacktrace, stacktrace.contains("No such file or directory"));
    }
}
Also used : LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Interpreter (org.apache.zeppelin.interpreter.Interpreter)85 Test (org.junit.Test)46 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)42 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)30 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)27 LazyOpenInterpreter (org.apache.zeppelin.interpreter.LazyOpenInterpreter)26 AbstractInterpreterTest (org.apache.zeppelin.interpreter.AbstractInterpreterTest)21 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)21 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)20 Properties (java.util.Properties)19 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)11 ExecutionContext (org.apache.zeppelin.interpreter.ExecutionContext)11 IOException (java.io.IOException)10 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)10 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)9 WrappedInterpreter (org.apache.zeppelin.interpreter.WrappedInterpreter)7 ArrayList (java.util.ArrayList)6 InterpreterNotFoundException (org.apache.zeppelin.interpreter.InterpreterNotFoundException)6 ManagedInterpreterGroup (org.apache.zeppelin.interpreter.ManagedInterpreterGroup)6 Before (org.junit.Before)6