Search in sources :

Example 26 with AngularObjectRegistry

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

the class CassandraInterpreterTest method should_extract_variable_from_statement.

@Test
public void should_extract_variable_from_statement() throws Exception {
    //Given
    AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
    when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
    when(intrContext.getGui().input("login", "hsue")).thenReturn("hsue");
    when(intrContext.getGui().input("age", "27")).thenReturn("27");
    String queries = "@prepare[test_insert_with_variable]=" + "INSERT INTO zeppelin.users(login,firstname,lastname,age) VALUES(?,?,?,?)\n" + "@bind[test_insert_with_variable]='{{login=hsue}}','Helen','SUE',{{age=27}}\n" + "SELECT firstname,lastname,age FROM zeppelin.users WHERE login='hsue';";
    //When
    final InterpreterResult actual = interpreter.interpret(queries, intrContext);
    //Then
    assertThat(actual.code()).isEqualTo(Code.SUCCESS);
    assertThat(actual.message().get(0).getData()).isEqualTo("firstname\tlastname\tage\n" + "Helen\tSUE\t27\n");
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 27 with AngularObjectRegistry

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

the class InterpreterFactory method createInterpreterGroup.

/**
   * @param id interpreterGroup id. Combination of interpreterSettingId + noteId/userId/shared
   * depends on interpreter mode
   */
@Override
public InterpreterGroup createInterpreterGroup(String id, InterpreterOption option) throws InterpreterException, NullArgumentException {
    //When called from REST API without option we receive NPE
    if (option == null) {
        throw new NullArgumentException("option");
    }
    AngularObjectRegistry angularObjectRegistry;
    InterpreterGroup interpreterGroup = new InterpreterGroup(id);
    if (option.isRemote()) {
        angularObjectRegistry = new RemoteAngularObjectRegistry(id, angularObjectRegistryListener, interpreterGroup);
    } else {
        angularObjectRegistry = new AngularObjectRegistry(id, angularObjectRegistryListener);
    // TODO(moon) : create distributed resource pool for local interpreters and set
    }
    interpreterGroup.setAngularObjectRegistry(angularObjectRegistry);
    return interpreterGroup;
}
Also used : RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) NullArgumentException(org.apache.commons.lang.NullArgumentException) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 28 with AngularObjectRegistry

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

the class NotebookServerTest method unbindAngularObjectFromLocalForParagraphs.

@Test
public void unbindAngularObjectFromLocalForParagraphs() throws Exception {
    //Given
    final String varName = "name";
    final String value = "val";
    final Message messageReceived = new Message(OP.ANGULAR_OBJECT_CLIENT_UNBIND).put("noteId", "noteId").put("name", varName).put("paragraphId", "paragraphId");
    final NotebookServer server = new NotebookServer();
    final Notebook notebook = mock(Notebook.class);
    final Note note = mock(Note.class, RETURNS_DEEP_STUBS);
    when(notebook.getNote("noteId")).thenReturn(note);
    final Paragraph paragraph = mock(Paragraph.class, RETURNS_DEEP_STUBS);
    when(note.getParagraph("paragraphId")).thenReturn(paragraph);
    final AngularObjectRegistry mdRegistry = mock(AngularObjectRegistry.class);
    final InterpreterGroup mdGroup = new InterpreterGroup("mdGroup");
    mdGroup.setAngularObjectRegistry(mdRegistry);
    when(paragraph.getCurrentRepl().getInterpreterGroup()).thenReturn(mdGroup);
    final AngularObject<String> ao1 = AngularObjectBuilder.build(varName, value, "noteId", "paragraphId");
    when(mdRegistry.remove(varName, "noteId", "paragraphId")).thenReturn(ao1);
    NotebookSocket conn = mock(NotebookSocket.class);
    NotebookSocket otherConn = mock(NotebookSocket.class);
    final String mdMsg1 = server.serializeMessage(new Message(OP.ANGULAR_OBJECT_REMOVE).put("angularObject", ao1).put("interpreterGroupId", "mdGroup").put("noteId", "noteId").put("paragraphId", "paragraphId"));
    server.noteSocketMap.put("noteId", asList(conn, otherConn));
    // When
    server.angularObjectClientUnbind(conn, new HashSet<String>(), notebook, messageReceived);
    // Then
    verify(otherConn).send(mdMsg1);
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Note(org.apache.zeppelin.notebook.Note) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 29 with AngularObjectRegistry

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

the class NotebookServerTest method bindAngularObjectToLocalForParagraphs.

@Test
public void bindAngularObjectToLocalForParagraphs() throws Exception {
    //Given
    final String varName = "name";
    final String value = "DuyHai DOAN";
    final Message messageReceived = new Message(OP.ANGULAR_OBJECT_CLIENT_BIND).put("noteId", "noteId").put("name", varName).put("value", value).put("paragraphId", "paragraphId");
    final NotebookServer server = new NotebookServer();
    final Notebook notebook = mock(Notebook.class);
    final Note note = mock(Note.class, RETURNS_DEEP_STUBS);
    when(notebook.getNote("noteId")).thenReturn(note);
    final Paragraph paragraph = mock(Paragraph.class, RETURNS_DEEP_STUBS);
    when(note.getParagraph("paragraphId")).thenReturn(paragraph);
    final AngularObjectRegistry mdRegistry = mock(AngularObjectRegistry.class);
    final InterpreterGroup mdGroup = new InterpreterGroup("mdGroup");
    mdGroup.setAngularObjectRegistry(mdRegistry);
    when(paragraph.getCurrentRepl().getInterpreterGroup()).thenReturn(mdGroup);
    final AngularObject<String> ao1 = AngularObjectBuilder.build(varName, value, "noteId", "paragraphId");
    when(mdRegistry.add(varName, value, "noteId", "paragraphId")).thenReturn(ao1);
    NotebookSocket conn = mock(NotebookSocket.class);
    NotebookSocket otherConn = mock(NotebookSocket.class);
    final String mdMsg1 = server.serializeMessage(new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao1).put("interpreterGroupId", "mdGroup").put("noteId", "noteId").put("paragraphId", "paragraphId"));
    server.noteSocketMap.put("noteId", asList(conn, otherConn));
    // When
    server.angularObjectClientBind(conn, new HashSet<String>(), notebook, messageReceived);
    // Then
    verify(otherConn).send(mdMsg1);
}
Also used : Message(org.apache.zeppelin.notebook.socket.Message) Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Note(org.apache.zeppelin.notebook.Note) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 30 with AngularObjectRegistry

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

the class Note method snapshotAngularObjectRegistry.

private void snapshotAngularObjectRegistry(String user) {
    angularObjects = new HashMap<>();
    List<InterpreterSetting> settings = interpreterSettingManager.getInterpreterSettings(getId());
    if (settings == null || settings.size() == 0) {
        return;
    }
    for (InterpreterSetting setting : settings) {
        InterpreterGroup intpGroup = setting.getInterpreterGroup(user, id);
        AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
        angularObjects.put(intpGroup.getId(), registry.getAllWithGlobal(id));
    }
}
Also used : AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)

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