Search in sources :

Example 71 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class SparkInterpreterTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    intpGroup = new InterpreterGroup();
    intpGroup.put("note", new LinkedList<Interpreter>());
    repl = new SparkInterpreter(getSparkTestProperties(tmpDir));
    repl.setInterpreterGroup(intpGroup);
    intpGroup.get("note").add(repl);
    repl.open();
    final RemoteEventClientWrapper remoteEventClientWrapper = new RemoteEventClientWrapper() {

        @Override
        public void onParaInfosReceived(String noteId, String paragraphId, Map<String, String> infos) {
            if (infos != null) {
                paraIdToInfosMap.put(paragraphId, infos);
            }
        }

        @Override
        public void onMetaInfosReceived(Map<String, String> infos) {
        }
    };
    context = new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("id"), new LinkedList<InterpreterContextRunner>(), new InterpreterOutput(null)) {

        @Override
        public RemoteEventClientWrapper getClient() {
            return remoteEventClientWrapper;
        }
    };
    // The first para interpretdr will set the Eventclient wrapper
    //SparkInterpreter.interpret(String, InterpreterContext) ->
    //SparkInterpreter.populateSparkWebUrl(InterpreterContext) ->
    //ZeppelinContext.setEventClient(RemoteEventClientWrapper)
    //running a dummy to ensure that we dont have any race conditions among tests
    repl.interpret("sc", context);
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) HashMap(java.util.HashMap) RemoteEventClientWrapper(org.apache.zeppelin.interpreter.remote.RemoteEventClientWrapper) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList) GUI(org.apache.zeppelin.display.GUI) HashMap(java.util.HashMap) Map(java.util.Map) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 72 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class PythonInterpreterTest method beforeTest.

@Before
public void beforeTest() throws IOException {
    cmdHistory = "";
    // python interpreter
    pythonInterpreter = new PythonInterpreter(getPythonTestProperties());
    // create interpreter group
    InterpreterGroup group = new InterpreterGroup();
    group.put("note", new LinkedList<Interpreter>());
    group.get("note").add(pythonInterpreter);
    pythonInterpreter.setInterpreterGroup(group);
    out = new InterpreterOutput(this);
    context = new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(group.getId(), null), new LocalResourcePool("id"), new LinkedList<InterpreterContextRunner>(), out);
    pythonInterpreter.open();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) Interpreter(org.apache.zeppelin.interpreter.Interpreter) HashMap(java.util.HashMap) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) InterpreterOutput(org.apache.zeppelin.interpreter.InterpreterOutput) GUI(org.apache.zeppelin.display.GUI) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 73 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class RemoteInterpreterTest method testRunOrderPreserved.

@Test
public void testRunOrderPreserved() throws InterruptedException {
    Properties p = new Properties();
    intpGroup.put("note", new LinkedList<Interpreter>());
    final RemoteInterpreter intpA = createMockInterpreterA(p);
    intpGroup.get("note").add(intpA);
    intpA.setInterpreterGroup(intpGroup);
    intpA.open();
    int concurrency = 3;
    final List<InterpreterResultMessage> results = new LinkedList<>();
    Scheduler scheduler = intpA.getScheduler();
    for (int i = 0; i < concurrency; i++) {
        final String jobId = Integer.toString(i);
        scheduler.submit(new Job(jobId, Integer.toString(i), null, 200) {

            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 {
                InterpreterResult ret = intpA.interpret(getJobName(), new InterpreterContext("note", jobId, null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null));
                synchronized (results) {
                    results.addAll(ret.message());
                    results.notify();
                }
                return null;
            }

            @Override
            protected boolean jobAbort() {
                return false;
            }
        });
    }
    // wait for job finished
    synchronized (results) {
        while (results.size() != concurrency) {
            results.wait(300);
        }
    }
    int i = 0;
    for (InterpreterResultMessage result : results) {
        assertEquals(Integer.toString(i++), result.getData());
    }
    assertEquals(concurrency, i);
    intpA.close();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) Scheduler(org.apache.zeppelin.scheduler.Scheduler) Properties(java.util.Properties) RemoteInterpreterResultMessage(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage) LinkedList(java.util.LinkedList) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) AngularObject(org.apache.zeppelin.display.AngularObject) GUI(org.apache.zeppelin.display.GUI) Job(org.apache.zeppelin.scheduler.Job) HashMap(java.util.HashMap) Map(java.util.Map) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 74 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo 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 75 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo 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)

Aggregations

AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)128 Test (org.junit.Test)44 HashMap (java.util.HashMap)40 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)29 Properties (java.util.Properties)28 Note (org.apache.zeppelin.notebook.Note)27 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)23 LinkedList (java.util.LinkedList)22 GUI (org.apache.zeppelin.display.GUI)22 Map (java.util.Map)21 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)20 AngularObject (org.apache.zeppelin.display.AngularObject)19 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)19 IOException (java.io.IOException)18 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)18 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)18 Paragraph (org.apache.zeppelin.notebook.Paragraph)18 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)16 Path (javax.ws.rs.Path)15 HashSet (java.util.HashSet)13