Search in sources :

Example 26 with RemoteInterpreter

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

the class RemoteSchedulerTest method testAbortOnPending.

@Test
public void testAbortOnPending() throws Exception {
    Properties p = new Properties();
    final InterpreterGroup intpGroup = new InterpreterGroup();
    Map<String, String> env = new HashMap<>();
    env.put("ZEPPELIN_CLASSPATH", new File("./target/test-classes").getAbsolutePath());
    final RemoteInterpreter intpA = new RemoteInterpreter(p, "note", MockInterpreterA.class.getName(), new File(INTERPRETER_SCRIPT).getAbsolutePath(), "fake", "fakeRepo", env, 10 * 1000, this, null, "anonymous", false);
    intpGroup.put("note", new LinkedList<Interpreter>());
    intpGroup.get("note").add(intpA);
    intpA.setInterpreterGroup(intpGroup);
    intpA.open();
    Scheduler scheduler = schedulerSvc.createOrGetRemoteScheduler("test", "note", intpA.getInterpreterProcess(), 10);
    Job job1 = new Job("jobId1", "jobName1", null, 200) {

        Object results;

        InterpreterContext context = new InterpreterContext("note", "jobId1", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null);

        @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()) {
                intpA.cancel(context);
            }
            return true;
        }

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

        public Object results;

        InterpreterContext context = new InterpreterContext("note", "jobId2", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null);

        @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()) {
                intpA.cancel(context);
            }
            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());
    assertTrue(job2.getStatus() == Status.PENDING);
    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) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) HashMap(java.util.HashMap) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) GUI(org.apache.zeppelin.display.GUI) MockInterpreterA(org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA) File(java.io.File) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 27 with RemoteInterpreter

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

the class InterpreterFactory method connectToRemoteRepl.

private Interpreter connectToRemoteRepl(String interpreterSessionKey, String className, String host, int port, Properties property, String interpreterSettingId, String userName, Boolean isUserImpersonate) {
    int connectTimeout = conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT);
    int maxPoolSize = conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_MAX_POOL_SIZE);
    String localRepoPath = conf.getInterpreterLocalRepoPath() + "/" + interpreterSettingId;
    LazyOpenInterpreter intp = new LazyOpenInterpreter(new RemoteInterpreter(property, interpreterSessionKey, className, host, port, localRepoPath, connectTimeout, maxPoolSize, remoteInterpreterProcessListener, appEventListener, userName, isUserImpersonate, conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_OUTPUT_LIMIT)));
    return intp;
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter)

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