Search in sources :

Example 16 with LocalResourcePool

use of org.apache.zeppelin.resource.LocalResourcePool in project zeppelin by apache.

the class RemoteInterpreterTest method testRemoteSchedulerSharing.

@Test
public void testRemoteSchedulerSharing() throws TTransportException, IOException {
    Properties p = new Properties();
    intpGroup.put("note", new LinkedList<Interpreter>());
    RemoteInterpreter intpA = new RemoteInterpreter(p, "note", MockInterpreterA.class.getName(), new File(INTERPRETER_SCRIPT).getAbsolutePath(), "fake", "fakeRepo", env, 10 * 1000, null, null, "anonymous", false);
    intpGroup.get("note").add(intpA);
    intpA.setInterpreterGroup(intpGroup);
    RemoteInterpreter intpB = new RemoteInterpreter(p, "note", MockInterpreterB.class.getName(), new File(INTERPRETER_SCRIPT).getAbsolutePath(), "fake", "fakeRepo", env, 10 * 1000, null, null, "anonymous", false);
    intpGroup.get("note").add(intpB);
    intpB.setInterpreterGroup(intpGroup);
    intpA.open();
    intpB.open();
    long start = System.currentTimeMillis();
    InterpreterResult ret = intpA.interpret("500", new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null));
    assertEquals("500", ret.message().get(0).getData());
    ret = intpB.interpret("500", new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null));
    assertEquals("1000", ret.message().get(0).getData());
    long end = System.currentTimeMillis();
    assertTrue(end - start >= 1000);
    intpA.close();
    intpB.close();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) HashMap(java.util.HashMap) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList) GUI(org.apache.zeppelin.display.GUI) AngularObject(org.apache.zeppelin.display.AngularObject) MockInterpreterA(org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA) File(java.io.File) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) MockInterpreterB(org.apache.zeppelin.interpreter.remote.mock.MockInterpreterB) Test(org.junit.Test)

Example 17 with LocalResourcePool

use of org.apache.zeppelin.resource.LocalResourcePool in project zeppelin by apache.

the class RemoteInterpreterTest method testEnvronmentAndPropertySet.

@Test
public void testEnvronmentAndPropertySet() {
    Properties p = new Properties();
    p.setProperty("MY_ENV1", "env value 1");
    p.setProperty("my.property.1", "property value 1");
    RemoteInterpreter intp = new RemoteInterpreter(p, "note", MockInterpreterEnv.class.getName(), new File(INTERPRETER_SCRIPT).getAbsolutePath(), "fake", "fakeRepo", env, 10 * 1000, null, null, "anonymous", false);
    intpGroup.put("note", new LinkedList<Interpreter>());
    intpGroup.get("note").add(intp);
    intp.setInterpreterGroup(intpGroup);
    intp.open();
    InterpreterContext context = new InterpreterContext("noteId", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null);
    assertEquals("env value 1", intp.interpret("getEnv MY_ENV1", context).message().get(0).getData());
    assertEquals(Code.ERROR, intp.interpret("getProperty MY_ENV1", context).code());
    assertEquals(Code.ERROR, intp.interpret("getEnv my.property.1", context).code());
    assertEquals("property value 1", intp.interpret("getProperty my.property.1", context).message().get(0).getData());
    intp.close();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) AngularObject(org.apache.zeppelin.display.AngularObject) GUI(org.apache.zeppelin.display.GUI) MockInterpreterEnv(org.apache.zeppelin.interpreter.remote.mock.MockInterpreterEnv) File(java.io.File) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 18 with LocalResourcePool

use of org.apache.zeppelin.resource.LocalResourcePool in project zeppelin by apache.

the class RemoteInterpreterTest method testRemoteSchedulerSharingSubmit.

@Test
public void testRemoteSchedulerSharingSubmit() throws TTransportException, IOException, InterruptedException {
    Properties p = new Properties();
    intpGroup.put("note", new LinkedList<Interpreter>());
    final RemoteInterpreter intpA = createMockInterpreterA(p);
    intpGroup.get("note").add(intpA);
    intpA.setInterpreterGroup(intpGroup);
    final RemoteInterpreter intpB = createMockInterpreterB(p);
    intpGroup.get("note").add(intpB);
    intpB.setInterpreterGroup(intpGroup);
    intpA.open();
    intpB.open();
    long start = System.currentTimeMillis();
    Job jobA = new Job("jobA", null) {

        private Object r;

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

        @Override
        public void setResult(Object results) {
            this.r = results;
        }

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

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

        @Override
        protected Object jobRun() throws Throwable {
            return intpA.interpret("500", new InterpreterContext("note", "jobA", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null));
        }

        @Override
        protected boolean jobAbort() {
            return false;
        }
    };
    intpA.getScheduler().submit(jobA);
    Job jobB = new Job("jobB", null) {

        private Object r;

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

        @Override
        public void setResult(Object results) {
            this.r = results;
        }

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

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

        @Override
        protected Object jobRun() throws Throwable {
            return intpB.interpret("500", new InterpreterContext("note", "jobB", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null));
        }

        @Override
        protected boolean jobAbort() {
            return false;
        }
    };
    intpB.getScheduler().submit(jobB);
    // wait until both job finished
    while (jobA.getStatus() != Status.FINISHED || jobB.getStatus() != Status.FINISHED) {
        Thread.sleep(100);
    }
    long end = System.currentTimeMillis();
    assertTrue(end - start >= 1000);
    assertEquals("1000", ((InterpreterResult) jobB.getReturn()).message().get(0).getData());
    intpA.close();
    intpB.close();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) HashMap(java.util.HashMap) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList) AngularObject(org.apache.zeppelin.display.AngularObject) GUI(org.apache.zeppelin.display.GUI) Job(org.apache.zeppelin.scheduler.Job) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 19 with LocalResourcePool

use of org.apache.zeppelin.resource.LocalResourcePool in project zeppelin by apache.

the class NotebookTest method testResourceRemovealOnParagraphNoteRemove.

@Test
public void testResourceRemovealOnParagraphNoteRemove() throws IOException {
    Note note = notebook.createNote(anonymous);
    interpreterSettingManager.setInterpreters(anonymous.getUser(), note.getId(), interpreterSettingManager.getDefaultInterpreterSettingList());
    for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) {
        intpGroup.setResourcePool(new LocalResourcePool(intpGroup.getId()));
    }
    Paragraph p1 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    p1.setText("hello");
    Paragraph p2 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    p2.setText("%mock2 world");
    note.runAll();
    while (p1.isTerminated() == false || p1.getResult() == null) Thread.yield();
    while (p2.isTerminated() == false || p2.getResult() == null) Thread.yield();
    assertEquals(2, ResourcePoolUtils.getAllResources().size());
    // remove a paragraph
    note.removeParagraph(anonymous.getUser(), p1.getId());
    assertEquals(1, ResourcePoolUtils.getAllResources().size());
    // remove note
    notebook.removeNote(note.getId(), anonymous);
    assertEquals(0, ResourcePoolUtils.getAllResources().size());
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) Test(org.junit.Test)

Aggregations

LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)19 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)17 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)16 GUI (org.apache.zeppelin.display.GUI)16 HashMap (java.util.HashMap)15 LinkedList (java.util.LinkedList)15 Properties (java.util.Properties)14 Test (org.junit.Test)12 AngularObject (org.apache.zeppelin.display.AngularObject)6 File (java.io.File)5 Job (org.apache.zeppelin.scheduler.Job)4 Before (org.junit.Before)4 Map (java.util.Map)3 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)3 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)3 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)3 MockInterpreterA (org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA)3 Interpreter (org.apache.zeppelin.interpreter.Interpreter)2 RemoteInterpreter (org.apache.zeppelin.interpreter.remote.RemoteInterpreter)2 RemoteInterpreterResultMessage (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage)2