Search in sources :

Example 11 with RemoteInterpreter

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

the class FileSystemRecoveryStorageTest method testSingleInterpreterProcess.

@Test
public void testSingleInterpreterProcess() throws InterpreterException, IOException {
    InterpreterSetting interpreterSetting = interpreterSettingManager.getByName("test");
    interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED);
    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());
    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)

Example 12 with RemoteInterpreter

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

the class NotebookTest method testAutoRestartInterpreterAfterSchedule.

// @Test
public void testAutoRestartInterpreterAfterSchedule() throws InterruptedException, IOException, InterpreterNotFoundException {
    // create a note and a paragraph
    String noteId = notebook.createNote("note1", anonymous);
    // use write lock, because we are overwrite the note configuration
    notebook.processNote(noteId, note -> {
        Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
        Map<String, Object> config = new HashMap<>();
        p.setConfig(config);
        p.setText("%mock1 sleep 1000");
        Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
        p2.setConfig(config);
        p2.setText("%mock2 sleep 500");
        // set cron scheduler, once a second
        config = note.getConfig();
        config.put("enabled", true);
        config.put("cron", "1/3 * * * * ?");
        config.put("releaseresource", true);
        note.setConfig(config);
        return null;
    });
    schedulerService.refreshCron(noteId);
    ExecutionContext executionContext = new ExecutionContext(anonymous.getUser(), noteId, "test");
    RemoteInterpreter mock1 = (RemoteInterpreter) interpreterFactory.getInterpreter("mock1", executionContext);
    RemoteInterpreter mock2 = (RemoteInterpreter) interpreterFactory.getInterpreter("mock2", executionContext);
    // wait until interpreters are started
    while (!mock1.isOpened() || !mock2.isOpened()) {
        Thread.yield();
    }
    // wait until interpreters are closed
    while (mock1.isOpened() || mock2.isOpened()) {
        Thread.yield();
    }
    // remove cron scheduler.
    // use write lock because config is overwritten
    notebook.processNote(noteId, note -> {
        Map<String, Object> config = note.getConfig();
        config.put("cron", null);
        note.setConfig(config);
        return null;
    });
    schedulerService.refreshCron(noteId);
    // make sure all paragraph has been executed
    notebook.processNote(noteId, note -> {
        for (Paragraph p : note.getParagraphs()) {
            assertNotNull(p);
        }
        return null;
    });
    notebook.removeNote(noteId, anonymous);
}
Also used : ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) HashMap(java.util.HashMap) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter)

Example 13 with RemoteInterpreter

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

the class InterpreterFactoryTest method testGetFactory.

@Test
public void testGetFactory() throws InterpreterException {
    assertTrue(interpreterFactory.getInterpreter("", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
    RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("", new ExecutionContext("user1", "note1", "test"));
    // EchoInterpreter is the default interpreter because test is the default interpreter group
    assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
    assertTrue(interpreterFactory.getInterpreter("double_echo", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
    remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("double_echo", new ExecutionContext("user1", "note1", "test"));
    assertEquals(DoubleEchoInterpreter.class.getName(), remoteInterpreter.getClassName());
    assertTrue(interpreterFactory.getInterpreter("test", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
    remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test", new ExecutionContext("user1", "note1", "test"));
    assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
    assertTrue(interpreterFactory.getInterpreter("test2", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
    remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test2", new ExecutionContext("user1", "note1", "test"));
    assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName());
    assertTrue(interpreterFactory.getInterpreter("test2.double_echo", new ExecutionContext("user1", "note1", "test")) instanceof RemoteInterpreter);
    remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test2.double_echo", new ExecutionContext("user1", "note1", "test"));
    assertEquals(DoubleEchoInterpreter.class.getName(), remoteInterpreter.getClassName());
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) Test(org.junit.Test)

Example 14 with RemoteInterpreter

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

the class RemoteSchedulerTest method test.

@Test
public void test() throws Exception {
    final RemoteInterpreter intpA = (RemoteInterpreter) interpreterSetting.getInterpreter("user1", note1Id, "mock");
    intpA.open();
    Scheduler scheduler = intpA.getScheduler();
    Job<Object> job = new Job<Object>("jobId", "jobName", null) {

        Object results;

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

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

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

        @Override
        protected Object jobRun() throws Throwable {
            intpA.interpret("1000", InterpreterContext.builder().setNoteId("noteId").setParagraphId("jobId").setResourcePool(new LocalResourcePool("pool1")).build());
            return "1000";
        }

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

        @Override
        public void setResult(Object results) {
            this.results = results;
        }
    };
    scheduler.submit(job);
    int cycles = 0;
    while (!job.isRunning() && cycles < MAX_WAIT_CYCLES) {
        LOGGER.info("Status:" + job.getStatus());
        Thread.sleep(TICK_WAIT);
        cycles++;
    }
    assertTrue(job.isRunning());
    Thread.sleep(5 * TICK_WAIT);
    cycles = 0;
    while (!job.isTerminated() && cycles < MAX_WAIT_CYCLES) {
        Thread.sleep(TICK_WAIT);
        cycles++;
    }
    assertTrue(job.isTerminated());
    intpA.close();
    schedulerSvc.removeScheduler("test");
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) AbstractInterpreterTest(org.apache.zeppelin.interpreter.AbstractInterpreterTest) Test(org.junit.Test)

Example 15 with RemoteInterpreter

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

the class ConfInterpreterTest method testRunningAfterOtherInterpreter.

@Test
public void testRunningAfterOtherInterpreter() throws InterpreterException {
    assertTrue(interpreterFactory.getInterpreter("test.conf", executionContext) instanceof ConfInterpreter);
    ConfInterpreter confInterpreter = (ConfInterpreter) interpreterFactory.getInterpreter("test.conf", executionContext);
    InterpreterContext context = InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build();
    RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test", executionContext);
    InterpreterResult result = remoteInterpreter.interpret("hello world", context);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code);
    result = confInterpreter.interpret("property_1\tnew_value\nnew_property\tdummy_value", context);
    assertEquals(InterpreterResult.Code.ERROR, result.code);
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) 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