Search in sources :

Example 6 with AngularObjectRegistry

use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.

the class SparkInterpreterTest method testParagraphUrls.

@Test
public void testParagraphUrls() {
    String paraId = "test_para_job_url";
    InterpreterContext intpCtx = new InterpreterContext("note", paraId, 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));
    repl.interpret("sc.parallelize(1 to 10).map(x => {x}).collect", intpCtx);
    Map<String, String> paraInfos = paraIdToInfosMap.get(intpCtx.getParagraphId());
    String jobUrl = null;
    if (paraInfos != null) {
        jobUrl = paraInfos.get("jobUrl");
    }
    String sparkUIUrl = repl.getSparkUIUrl();
    assertNotNull(jobUrl);
    assertTrue(jobUrl.startsWith(sparkUIUrl + "/jobs/job?id="));
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) GUI(org.apache.zeppelin.display.GUI) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 7 with AngularObjectRegistry

use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.

the class RemoteInterpreter method pushAngularObjectRegistryToRemote.

/**
   * Push local angular object registry to
   * remote interpreter. This method should be
   * call ONLY inside the init() method
   */
void pushAngularObjectRegistryToRemote(Client client) throws TException {
    final AngularObjectRegistry angularObjectRegistry = this.getInterpreterGroup().getAngularObjectRegistry();
    if (angularObjectRegistry != null && angularObjectRegistry.getRegistry() != null) {
        final Map<String, Map<String, AngularObject>> registry = angularObjectRegistry.getRegistry();
        logger.info("Push local angular object registry from ZeppelinServer to" + " remote interpreter group {}", this.getInterpreterGroup().getId());
        final java.lang.reflect.Type registryType = new TypeToken<Map<String, Map<String, AngularObject>>>() {
        }.getType();
        Gson gson = new Gson();
        client.angularRegistryPush(gson.toJson(registry, registryType));
    }
}
Also used : Gson(com.google.gson.Gson) AngularObject(org.apache.zeppelin.display.AngularObject) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 8 with AngularObjectRegistry

use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.

the class RemoteInterpreterTest method testRemoteInterperterCall.

@Test
public void testRemoteInterperterCall() throws TTransportException, IOException {
    Properties p = new Properties();
    intpGroup.put("note", new LinkedList<Interpreter>());
    RemoteInterpreter intpA = createMockInterpreterA(p);
    intpGroup.get("note").add(intpA);
    intpA.setInterpreterGroup(intpGroup);
    RemoteInterpreter intpB = createMockInterpreterB(p);
    intpGroup.get("note").add(intpB);
    intpB.setInterpreterGroup(intpGroup);
    RemoteInterpreterProcess process = intpA.getInterpreterProcess();
    process.equals(intpB.getInterpreterProcess());
    assertFalse(process.isRunning());
    assertEquals(0, process.getNumIdleClient());
    assertEquals(0, process.referenceCount());
    // initializa all interpreters in the same group
    intpA.open();
    assertTrue(process.isRunning());
    assertEquals(1, process.getNumIdleClient());
    assertEquals(2, process.referenceCount());
    intpA.interpret("1", 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));
    intpB.open();
    assertEquals(2, process.referenceCount());
    intpA.close();
    assertEquals(1, process.referenceCount());
    intpB.close();
    assertEquals(0, process.referenceCount());
    assertFalse(process.isRunning());
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) HashMap(java.util.HashMap) GUI(org.apache.zeppelin.display.GUI) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 9 with AngularObjectRegistry

use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.

the class RemoteInterpreterTest method testInterpreterGroupResetDuringProcessRunning.

@Test
public void testInterpreterGroupResetDuringProcessRunning() 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();
    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("2000", 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);
    // wait for job started
    while (intpA.getScheduler().getJobsRunning().size() == 0) {
        Thread.sleep(100);
    }
    // restart interpreter
    RemoteInterpreterProcess processA = intpA.getInterpreterProcess();
    intpA.close();
    InterpreterGroup newInterpreterGroup = new InterpreterGroup(intpA.getInterpreterGroup().getId());
    newInterpreterGroup.put("note", new LinkedList<Interpreter>());
    intpA.setInterpreterGroup(newInterpreterGroup);
    intpA.open();
    RemoteInterpreterProcess processB = intpA.getInterpreterProcess();
    assertNotSame(processA.hashCode(), processB.hashCode());
}
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 10 with AngularObjectRegistry

use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.

the class RemoteInterpreterTest method should_push_local_angular_repo_to_remote.

@Test
public void should_push_local_angular_repo_to_remote() throws Exception {
    //Given
    final Client client = Mockito.mock(Client.class);
    final RemoteInterpreter intr = new RemoteInterpreter(new Properties(), "noteId", MockInterpreterA.class.getName(), "runner", "path", "localRepo", env, 10 * 1000, null, null, "anonymous", false);
    final AngularObjectRegistry registry = new AngularObjectRegistry("spark", null);
    registry.add("name", "DuyHai DOAN", "nodeId", "paragraphId");
    final InterpreterGroup interpreterGroup = new InterpreterGroup("groupId");
    interpreterGroup.setAngularObjectRegistry(registry);
    intr.setInterpreterGroup(interpreterGroup);
    final java.lang.reflect.Type registryType = new TypeToken<Map<String, Map<String, AngularObject>>>() {
    }.getType();
    final Gson gson = new Gson();
    final String expected = gson.toJson(registry.getRegistry(), registryType);
    //When
    intr.pushAngularObjectRegistryToRemote(client);
    //Then
    Mockito.verify(client).angularRegistryPush(expected);
}
Also used : Gson(com.google.gson.Gson) AngularObject(org.apache.zeppelin.display.AngularObject) Properties(java.util.Properties) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) MockInterpreterA(org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA) HashMap(java.util.HashMap) Map(java.util.Map) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Aggregations

AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)48 Test (org.junit.Test)20 HashMap (java.util.HashMap)19 LinkedList (java.util.LinkedList)18 GUI (org.apache.zeppelin.display.GUI)18 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)18 Properties (java.util.Properties)16 AngularObject (org.apache.zeppelin.display.AngularObject)16 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)16 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)11 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)8 File (java.io.File)5 Map (java.util.Map)5 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)5 Note (org.apache.zeppelin.notebook.Note)5 Before (org.junit.Before)5 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)4 MockInterpreterA (org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA)4 Message (org.apache.zeppelin.notebook.socket.Message)4 Job (org.apache.zeppelin.scheduler.Job)4