Search in sources :

Example 6 with RemoteInterpreter

use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.

the class SessionConfInterpreter method interpret.

@Override
public InterpreterResult interpret(String st, InterpreterContext context) throws InterpreterException {
    try {
        Properties finalProperties = new Properties();
        finalProperties.putAll(this.properties);
        Properties updatedProperties = new Properties();
        updatedProperties.load(new StringReader(st));
        finalProperties.putAll(updatedProperties);
        LOGGER.debug("Properties for Session: {}:{}", sessionId, finalProperties);
        List<Interpreter> interpreters = interpreterSetting.getInterpreterGroup(interpreterGroupId).get(sessionId);
        for (Interpreter intp : interpreters) {
            // only check the RemoteInterpreter, ConfInterpreter itself will be ignored here.
            if (intp instanceof RemoteInterpreter) {
                RemoteInterpreter remoteInterpreter = (RemoteInterpreter) intp;
                if (remoteInterpreter.isOpened()) {
                    return new InterpreterResult(InterpreterResult.Code.ERROR, "Can not change interpreter session properties after this session is started");
                }
                remoteInterpreter.setProperties(finalProperties);
            }
        }
        return new InterpreterResult(InterpreterResult.Code.SUCCESS);
    } catch (IOException e) {
        LOGGER.error("Fail to update interpreter setting", e);
        return new InterpreterResult(InterpreterResult.Code.ERROR, ExceptionUtils.getStackTrace(e));
    }
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) StringReader(java.io.StringReader) IOException(java.io.IOException) Properties(java.util.Properties) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter)

Example 7 with RemoteInterpreter

use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.

the class NotebookTest method testCronWithReleaseResourceClosesOnlySpecificInterpreters.

// @Test
public void testCronWithReleaseResourceClosesOnlySpecificInterpreters() throws IOException, InterruptedException, InterpreterNotFoundException {
    // create a cron scheduled note.
    String cronNoteId = notebook.createNote("note1", anonymous);
    // use write lock, because we overwrite the note configuration
    notebook.processNote(cronNoteId, cronNote -> {
        Map<String, Object> config = new HashMap<>();
        config.put("cron", "1/5 * * * * ?");
        config.put("cronExecutingUser", anonymous.getUser());
        config.put("releaseresource", true);
        cronNote.setConfig(config);
        return null;
    });
    RemoteInterpreter cronNoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("mock1", new ExecutionContext(anonymous.getUser(), cronNoteId, "test"));
    // create a paragraph of the cron scheduled note.
    notebook.processNote(cronNoteId, cronNote -> {
        Paragraph cronNoteParagraph = cronNote.addNewParagraph(AuthenticationInfo.ANONYMOUS);
        Map<String, Object> config = new HashMap<>();
        config.put("enabled", true);
        cronNoteParagraph.setConfig(config);
        cronNoteParagraph.setText("%mock1 sleep 1000");
        return null;
    });
    // create another note
    String anotherNoteId = notebook.createNote("note1", anonymous);
    RemoteInterpreter anotherNoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("mock2", new ExecutionContext(anonymous.getUser(), anotherNoteId, "test"));
    // create a paragraph of another note
    notebook.processNote(anotherNoteId, anotherNote -> {
        Paragraph anotherNoteParagraph = anotherNote.addNewParagraph(AuthenticationInfo.ANONYMOUS);
        Map<String, Object> config = new HashMap<>();
        config.put("enabled", true);
        anotherNoteParagraph.setConfig(config);
        anotherNoteParagraph.setText("%mock2 echo 1");
        // run the paragraph of another note
        anotherNote.run(anotherNoteParagraph.getId());
        return null;
    });
    // wait until anotherNoteInterpreter is opened
    while (!anotherNoteInterpreter.isOpened()) {
        Thread.yield();
    }
    // refresh the cron schedule
    schedulerService.refreshCron(cronNoteId);
    // wait until cronNoteInterpreter is opened
    while (!cronNoteInterpreter.isOpened()) {
        Thread.yield();
    }
    // wait until cronNoteInterpreter is closed
    while (cronNoteInterpreter.isOpened()) {
        Thread.yield();
    }
    // wait for a few seconds
    Thread.sleep(5 * 1000);
    // test that anotherNoteInterpreter is still opened
    assertTrue(anotherNoteInterpreter.isOpened());
    // remove cron scheduler
    // use write lock because config is overwritten
    notebook.processNote(cronNoteId, cronNote -> {
        Map<String, Object> config = new HashMap<>();
        config.put("cron", null);
        config.put("cronExecutingUser", null);
        config.put("releaseresource", null);
        cronNote.setConfig(config);
        return null;
    });
    schedulerService.refreshCron(cronNoteId);
    // remove notebooks
    notebook.removeNote(cronNoteId, anonymous);
    notebook.removeNote(anotherNoteId, anonymous);
}
Also used : ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) HashMap(java.util.HashMap) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter)

Example 8 with RemoteInterpreter

use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.

the class TimeoutLifecycleManagerTest method testTimeout_1.

@Test
public void testTimeout_1() throws InterpreterException, InterruptedException, IOException {
    assertTrue(interpreterFactory.getInterpreter("test.echo", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
    RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test.echo", new ExecutionContext("user1", "note1", "test"));
    assertFalse(remoteInterpreter.isOpened());
    InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("test");
    assertEquals(1, interpreterSetting.getAllInterpreterGroups().size());
    Thread.sleep(15 * 1000);
    // InterpreterGroup is not removed after 15 seconds, as TimeoutLifecycleManager only manage it after it is started
    assertEquals(1, interpreterSetting.getAllInterpreterGroups().size());
    InterpreterContext context = InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build();
    remoteInterpreter.interpret("hello world", context);
    assertTrue(remoteInterpreter.isOpened());
    Thread.sleep(15 * 1000);
    // interpreterGroup is timeout, so is removed.
    assertEquals(0, interpreterSetting.getAllInterpreterGroups().size());
}
Also used : ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) AbstractInterpreterTest(org.apache.zeppelin.interpreter.AbstractInterpreterTest) Test(org.junit.Test)

Example 9 with RemoteInterpreter

use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.

the class TimeoutLifecycleManagerTest method testTimeout_2.

@Test
public void testTimeout_2() throws InterpreterException, InterruptedException, IOException {
    assertTrue(interpreterFactory.getInterpreter("test.sleep", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
    final RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test.sleep", new ExecutionContext("user1", "note1", "test"));
    // simulate how zeppelin submit paragraph
    remoteInterpreter.getScheduler().submit(new Job<Object>("test-job", null) {

        @Override
        public Object getReturn() {
            return null;
        }

        @Override
        public int progress() {
            return 0;
        }

        @Override
        public Map<String, Object> info() {
            return null;
        }

        @Override
        protected Object jobRun() throws Throwable {
            InterpreterContext context = InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build();
            return remoteInterpreter.interpret("100000", context);
        }

        @Override
        protected boolean jobAbort() {
            return false;
        }

        @Override
        public void setResult(Object results) {
        }
    });
    while (!remoteInterpreter.isOpened()) {
        Thread.sleep(1000);
        LOGGER.info("Wait for interpreter to be started");
    }
    InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("test");
    assertEquals(1, interpreterSetting.getAllInterpreterGroups().size());
    Thread.sleep(15 * 1000);
    // interpreterGroup is not timeout because getStatus is called periodically.
    assertEquals(1, interpreterSetting.getAllInterpreterGroups().size());
    assertTrue(remoteInterpreter.isOpened());
}
Also used : ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) Map(java.util.Map) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) AbstractInterpreterTest(org.apache.zeppelin.interpreter.AbstractInterpreterTest) Test(org.junit.Test)

Example 10 with RemoteInterpreter

use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project zeppelin by apache.

the class LocalRecoveryStorageTest method testMultipleInterpreterProcess.

@Test
public void testMultipleInterpreterProcess() throws InterpreterException, IOException {
    InterpreterSetting interpreterSetting = interpreterSettingManager.getByName("test");
    interpreterSetting.getOption().setPerUser(InterpreterOption.ISOLATED);
    Interpreter interpreter1 = interpreterSetting.getDefaultInterpreter("user1", note1Id);
    RemoteInterpreter remoteInterpreter1 = (RemoteInterpreter) interpreter1;
    InterpreterContext context1 = InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build();
    remoteInterpreter1.interpret("hello", context1);
    assertEquals(1, interpreterSettingManager.getRecoveryStorage().restore().size());
    Interpreter interpreter2 = interpreterSetting.getDefaultInterpreter("user2", note2Id);
    RemoteInterpreter remoteInterpreter2 = (RemoteInterpreter) interpreter2;
    InterpreterContext context2 = InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build();
    remoteInterpreter2.interpret("hello", context2);
    assertEquals(2, interpreterSettingManager.getRecoveryStorage().restore().size());
    interpreterSettingManager.restart(interpreterSetting.getId(), "user1", note1Id);
    assertEquals(1, interpreterSettingManager.getRecoveryStorage().restore().size());
    interpreterSetting.close();
    assertEquals(0, interpreterSettingManager.getRecoveryStorage().restore().size());
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) AbstractInterpreterTest(org.apache.zeppelin.interpreter.AbstractInterpreterTest) Test(org.junit.Test)

Aggregations

RemoteInterpreter (org.apache.zeppelin.interpreter.remote.RemoteInterpreter)27 Test (org.junit.Test)17 Properties (java.util.Properties)8 AbstractInterpreterTest (org.apache.zeppelin.interpreter.AbstractInterpreterTest)8 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)7 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)7 HashMap (java.util.HashMap)6 Interpreter (org.apache.zeppelin.interpreter.Interpreter)5 ExecutionContext (org.apache.zeppelin.interpreter.ExecutionContext)4 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 GUI (org.apache.zeppelin.display.GUI)3 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)3 Path (java.nio.file.Path)2 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)2 MockInterpreterA (org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1