Search in sources :

Example 16 with RemoteInterpreter

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

the class ConfInterpreterTest method testEmptyConf.

@Test
public void testEmptyConf() 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();
    InterpreterResult result = confInterpreter.interpret("", context);
    assertEquals(InterpreterResult.Code.SUCCESS, result.code);
    assertTrue(interpreterFactory.getInterpreter("test", executionContext) instanceof RemoteInterpreter);
    RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("test", executionContext);
    assertEquals(6, remoteInterpreter.getProperties().size());
    assertEquals("value_1", remoteInterpreter.getProperty("property_1"));
    assertEquals("value_3", remoteInterpreter.getProperty("property_3"));
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) Test(org.junit.Test)

Example 17 with RemoteInterpreter

use of org.apache.zeppelin.interpreter.remote.RemoteInterpreter in project SSM by Intel-bigdata.

the class InterpreterFactory method createRemoteRepl.

Interpreter createRemoteRepl(String interpreterPath, String interpreterSessionKey, String className, Properties property, String interpreterSettingId, String userName, Boolean isUserImpersonate, InterpreterRunner interpreterRunner) {
    int connectTimeout = conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT);
    String localRepoPath = conf.getInterpreterLocalRepoPath() + "/" + interpreterSettingId;
    int maxPoolSize = conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_MAX_POOL_SIZE);
    String interpreterRunnerPath;
    if (null != interpreterRunner) {
        interpreterRunnerPath = interpreterRunner.getPath();
        Path p = Paths.get(interpreterRunnerPath);
        if (!p.isAbsolute()) {
            interpreterRunnerPath = Joiner.on(File.separator).join(interpreterPath, interpreterRunnerPath);
        }
    } else {
        interpreterRunnerPath = conf.getInterpreterRemoteRunnerPath();
    }
    RemoteInterpreter remoteInterpreter = new RemoteInterpreter(property, interpreterSessionKey, className, interpreterRunnerPath, interpreterPath, localRepoPath, connectTimeout, maxPoolSize, remoteInterpreterProcessListener, appEventListener, userName, isUserImpersonate, conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_OUTPUT_LIMIT));
    remoteInterpreter.addEnv(env);
    return new LazyOpenInterpreter(remoteInterpreter);
}
Also used : Path(java.nio.file.Path) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter)

Example 18 with RemoteInterpreter

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

the class Paragraph method recover.

public void recover() {
    try {
        LOGGER.info("Recovering paragraph: {}", getId());
        this.interpreter = getBindedInterpreter();
        InterpreterSetting interpreterSetting = ((ManagedInterpreterGroup) interpreter.getInterpreterGroup()).getInterpreterSetting();
        Map<String, Object> config = interpreterSetting.getConfig(interpreter.getClassName());
        mergeConfig(config);
        if (shouldSkipRunParagraph()) {
            LOGGER.info("Skip to run blank paragraph. {}", getId());
            setStatus(Job.Status.FINISHED);
            return;
        }
        setStatus(Status.READY);
        localProperties.put("isRecover", "true");
        for (List<Interpreter> sessions : this.interpreter.getInterpreterGroup().values()) {
            for (Interpreter intp : sessions) {
                // exclude ConfInterpreter
                if (intp instanceof RemoteInterpreter) {
                    ((RemoteInterpreter) intp).setOpened(true);
                }
            }
        }
        if (getConfig().get("enabled") == null || (Boolean) getConfig().get("enabled")) {
            setAuthenticationInfo(getAuthenticationInfo());
            interpreter.getScheduler().submit(this);
        }
    } catch (InterpreterNotFoundException e) {
        InterpreterResult intpResult = new InterpreterResult(InterpreterResult.Code.ERROR, String.format("Interpreter %s not found", this.intpText));
        setReturn(intpResult, e);
        setStatus(Job.Status.ERROR);
    } catch (Throwable e) {
        InterpreterResult intpResult = new InterpreterResult(InterpreterResult.Code.ERROR, "Unexpected exception: " + ExceptionUtils.getStackTrace(e));
        setReturn(intpResult, e);
        setStatus(Job.Status.ERROR);
    }
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) AngularObject(org.apache.zeppelin.display.AngularObject) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter)

Example 19 with RemoteInterpreter

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

the class RemoteSchedulerTest method testAbortOnPending.

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

        Object results;

        InterpreterContext context = InterpreterContext.builder().setNoteId("noteId").setParagraphId("jobId1").setResourcePool(new LocalResourcePool("pool1")).build();

        @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", context);
            return "1000";
        }

        @Override
        protected boolean jobAbort() {
            if (isRunning()) {
                try {
                    intpA.cancel(context);
                } catch (InterpreterException e) {
                    e.printStackTrace();
                }
            }
            return true;
        }

        @Override
        public void setResult(Object results) {
            this.results = results;
        }
    };
    Job<Object> job2 = new Job<Object>("jobId2", "jobName2", null) {

        public Object results;

        InterpreterContext context = InterpreterContext.builder().setNoteId("noteId").setParagraphId("jobId2").setResourcePool(new LocalResourcePool("pool1")).build();

        @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", context);
            return "1000";
        }

        @Override
        protected boolean jobAbort() {
            if (isRunning()) {
                try {
                    intpA.cancel(context);
                } catch (InterpreterException e) {
                    e.printStackTrace();
                }
            }
            return true;
        }

        @Override
        public void setResult(Object results) {
            this.results = results;
        }
    };
    job2.setResult("result2");
    scheduler.submit(job1);
    scheduler.submit(job2);
    int cycles = 0;
    while (!job1.isRunning() && cycles < MAX_WAIT_CYCLES) {
        Thread.sleep(TICK_WAIT);
        cycles++;
    }
    assertTrue(job1.isRunning());
    assertEquals(Status.PENDING, job2.getStatus());
    job2.abort();
    cycles = 0;
    while (!job1.isTerminated() && cycles < MAX_WAIT_CYCLES) {
        Thread.sleep(TICK_WAIT);
        cycles++;
    }
    assertNotNull(job1.getDateFinished());
    assertTrue(job1.isTerminated());
    assertNull(job2.getDateFinished());
    assertTrue(job2.isTerminated());
    assertEquals("result2", job2.getReturn());
    intpA.close();
    schedulerSvc.removeScheduler("test");
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) AbstractInterpreterTest(org.apache.zeppelin.interpreter.AbstractInterpreterTest) Test(org.junit.Test)

Example 20 with RemoteInterpreter

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

the class FileSystemRecoveryStorageTest 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