Search in sources :

Example 6 with Notebook

use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.

the class InterpreterFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis());
    tmpDir.mkdirs();
    new File(tmpDir, "conf").mkdirs();
    FileUtils.copyDirectory(new File("src/test/resources/interpreter"), new File(tmpDir, "interpreter"));
    System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), tmpDir.getAbsolutePath());
    System.setProperty(ConfVars.ZEPPELIN_INTERPRETER_GROUP_ORDER.getVarName(), "mock1,mock2,mock11,dev");
    conf = new ZeppelinConfiguration();
    schedulerFactory = new SchedulerFactory();
    depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
    interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
    factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
    context = new InterpreterContext("note", "id", null, "title", "text", null, null, null, null, null, null, null);
    ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
    interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
    interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(), Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
    Properties intp1Properties = new Properties();
    intp1Properties.put("PROPERTY_1", "VALUE_1");
    intp1Properties.put("property_2", "value_2");
    interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(true), intp1Properties);
    ArrayList<InterpreterInfo> interpreterInfos2 = new ArrayList<>();
    interpreterInfos2.add(new InterpreterInfo(MockInterpreter2.class.getName(), "mock2", true, new HashMap<String, Object>()));
    interpreterSettingManager.add("mock2", interpreterInfos2, new ArrayList<Dependency>(), new InterpreterOption(), Maps.<String, InterpreterProperty>newHashMap(), "mock2", null);
    interpreterSettingManager.createNewSetting("mock2", "mock2", new ArrayList<Dependency>(), new InterpreterOption(), new Properties());
    SearchService search = mock(SearchService.class);
    notebookRepo = new VFSNotebookRepo(conf);
    notebookAuthorization = NotebookAuthorization.init(conf);
    notebook = new Notebook(conf, notebookRepo, schedulerFactory, factory, interpreterSettingManager, jobListenerFactory, search, notebookAuthorization, null);
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties) SchedulerFactory(org.apache.zeppelin.scheduler.SchedulerFactory) DependencyResolver(org.apache.zeppelin.dep.DependencyResolver) VFSNotebookRepo(org.apache.zeppelin.notebook.repo.VFSNotebookRepo) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) SearchService(org.apache.zeppelin.search.SearchService) Before(org.junit.Before)

Example 7 with Notebook

use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.

the class NotebookServer method onMessage.

@Override
public void onMessage(NotebookSocket conn, String msg) {
    Notebook notebook = notebook();
    try {
        Message messagereceived = deserializeMessage(msg);
        LOG.debug("RECEIVE << " + messagereceived.op);
        LOG.debug("RECEIVE PRINCIPAL << " + messagereceived.principal);
        LOG.debug("RECEIVE TICKET << " + messagereceived.ticket);
        LOG.debug("RECEIVE ROLES << " + messagereceived.roles);
        if (LOG.isTraceEnabled()) {
            LOG.trace("RECEIVE MSG = " + messagereceived);
        }
        String ticket = TicketContainer.instance.getTicket(messagereceived.principal);
        if (ticket != null && (messagereceived.ticket == null || !ticket.equals(messagereceived.ticket))) {
            /* not to pollute logs, log instead of exception */
            if (StringUtils.isEmpty(messagereceived.ticket)) {
                LOG.debug("{} message: invalid ticket {} != {}", messagereceived.op, messagereceived.ticket, ticket);
            } else {
                if (!messagereceived.op.equals(OP.PING)) {
                    conn.send(serializeMessage(new Message(OP.SESSION_LOGOUT).put("info", "Your ticket is invalid possibly due to server restart. " + "Please login again.")));
                }
            }
            return;
        }
        ZeppelinConfiguration conf = ZeppelinConfiguration.create();
        boolean allowAnonymous = conf.isAnonymousAllowed();
        if (!allowAnonymous && messagereceived.principal.equals("anonymous")) {
            throw new Exception("Anonymous access not allowed ");
        }
        HashSet<String> userAndRoles = new HashSet<>();
        userAndRoles.add(messagereceived.principal);
        if (!messagereceived.roles.equals("")) {
            HashSet<String> roles = gson.fromJson(messagereceived.roles, new TypeToken<HashSet<String>>() {
            }.getType());
            if (roles != null) {
                userAndRoles.addAll(roles);
            }
        }
        if (StringUtils.isEmpty(conn.getUser())) {
            addUserConnection(messagereceived.principal, conn);
        }
        AuthenticationInfo subject = new AuthenticationInfo(messagereceived.principal, messagereceived.ticket);
        /** Lets be elegant here */
        switch(messagereceived.op) {
            case LIST_NOTES:
                unicastNoteList(conn, subject, userAndRoles);
                break;
            case RELOAD_NOTES_FROM_REPO:
                broadcastReloadedNoteList(subject, userAndRoles);
                break;
            case GET_HOME_NOTE:
                sendHomeNote(conn, userAndRoles, notebook, messagereceived);
                break;
            case GET_NOTE:
                sendNote(conn, userAndRoles, notebook, messagereceived);
                break;
            case NEW_NOTE:
                createNote(conn, userAndRoles, notebook, messagereceived);
                break;
            case DEL_NOTE:
                removeNote(conn, userAndRoles, notebook, messagereceived);
                break;
            case REMOVE_FOLDER:
                removeFolder(conn, userAndRoles, notebook, messagereceived);
                break;
            case MOVE_NOTE_TO_TRASH:
                moveNoteToTrash(conn, userAndRoles, notebook, messagereceived);
                break;
            case MOVE_FOLDER_TO_TRASH:
                moveFolderToTrash(conn, userAndRoles, notebook, messagereceived);
                break;
            case EMPTY_TRASH:
                emptyTrash(conn, userAndRoles, notebook, messagereceived);
                break;
            case RESTORE_FOLDER:
                restoreFolder(conn, userAndRoles, notebook, messagereceived);
                break;
            case RESTORE_NOTE:
                restoreNote(conn, userAndRoles, notebook, messagereceived);
                break;
            case RESTORE_ALL:
                restoreAll(conn, userAndRoles, notebook, messagereceived);
                break;
            case CLONE_NOTE:
                cloneNote(conn, userAndRoles, notebook, messagereceived);
                break;
            case IMPORT_NOTE:
                importNote(conn, userAndRoles, notebook, messagereceived);
                break;
            case COMMIT_PARAGRAPH:
                updateParagraph(conn, userAndRoles, notebook, messagereceived);
                break;
            case RUN_PARAGRAPH:
                runParagraph(conn, userAndRoles, notebook, messagereceived);
                break;
            case PARAGRAPH_EXECUTED_BY_SPELL:
                broadcastSpellExecution(conn, userAndRoles, notebook, messagereceived);
                break;
            case RUN_ALL_PARAGRAPHS:
                runAllParagraphs(conn, userAndRoles, notebook, messagereceived);
                break;
            case CANCEL_PARAGRAPH:
                cancelParagraph(conn, userAndRoles, notebook, messagereceived);
                break;
            case MOVE_PARAGRAPH:
                moveParagraph(conn, userAndRoles, notebook, messagereceived);
                break;
            case INSERT_PARAGRAPH:
                insertParagraph(conn, userAndRoles, notebook, messagereceived);
                break;
            case COPY_PARAGRAPH:
                copyParagraph(conn, userAndRoles, notebook, messagereceived);
                break;
            case PARAGRAPH_REMOVE:
                removeParagraph(conn, userAndRoles, notebook, messagereceived);
                break;
            case PARAGRAPH_CLEAR_OUTPUT:
                clearParagraphOutput(conn, userAndRoles, notebook, messagereceived);
                break;
            case PARAGRAPH_CLEAR_ALL_OUTPUT:
                clearAllParagraphOutput(conn, userAndRoles, notebook, messagereceived);
                break;
            case NOTE_UPDATE:
                updateNote(conn, userAndRoles, notebook, messagereceived);
                break;
            case NOTE_RENAME:
                renameNote(conn, userAndRoles, notebook, messagereceived);
                break;
            case FOLDER_RENAME:
                renameFolder(conn, userAndRoles, notebook, messagereceived);
                break;
            case UPDATE_PERSONALIZED_MODE:
                updatePersonalizedMode(conn, userAndRoles, notebook, messagereceived);
                break;
            case COMPLETION:
                completion(conn, userAndRoles, notebook, messagereceived);
                break;
            case PING:
                //do nothing
                break;
            case ANGULAR_OBJECT_UPDATED:
                angularObjectUpdated(conn, userAndRoles, notebook, messagereceived);
                break;
            case ANGULAR_OBJECT_CLIENT_BIND:
                angularObjectClientBind(conn, userAndRoles, notebook, messagereceived);
                break;
            case ANGULAR_OBJECT_CLIENT_UNBIND:
                angularObjectClientUnbind(conn, userAndRoles, notebook, messagereceived);
                break;
            case LIST_CONFIGURATIONS:
                sendAllConfigurations(conn, userAndRoles, notebook);
                break;
            case CHECKPOINT_NOTE:
                checkpointNote(conn, notebook, messagereceived);
                break;
            case LIST_REVISION_HISTORY:
                listRevisionHistory(conn, notebook, messagereceived);
                break;
            case SET_NOTE_REVISION:
                setNoteRevision(conn, userAndRoles, notebook, messagereceived);
                break;
            case NOTE_REVISION:
                getNoteByRevision(conn, notebook, messagereceived);
                break;
            case LIST_NOTE_JOBS:
                unicastNoteJobInfo(conn, messagereceived);
                break;
            case UNSUBSCRIBE_UPDATE_NOTE_JOBS:
                unsubscribeNoteJobInfo(conn);
                break;
            case GET_INTERPRETER_BINDINGS:
                getInterpreterBindings(conn, messagereceived);
                break;
            case SAVE_INTERPRETER_BINDINGS:
                saveInterpreterBindings(conn, messagereceived);
                break;
            case EDITOR_SETTING:
                getEditorSetting(conn, messagereceived);
                break;
            case GET_INTERPRETER_SETTINGS:
                getInterpreterSettings(conn, subject);
                break;
            case WATCHER:
                switchConnectionToWatcher(conn, messagereceived);
                break;
            default:
                break;
        }
    } catch (Exception e) {
        LOG.error("Can't handle message", e);
    }
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) TypeToken(com.google.gson.reflect.TypeToken) URISyntaxException(java.net.URISyntaxException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) HashSet(java.util.HashSet)

Example 8 with Notebook

use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.

the class NotebookServer method broadcastToNoteBindedInterpreter.

private void broadcastToNoteBindedInterpreter(String interpreterGroupId, Message m) {
    Notebook notebook = notebook();
    List<Note> notes = notebook.getAllNotes();
    for (Note note : notes) {
        List<String> ids = notebook.getInterpreterSettingManager().getInterpreters(note.getId());
        for (String id : ids) {
            if (id.equals(interpreterGroupId)) {
                broadcast(note.getId(), m);
            }
        }
    }
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) Note(org.apache.zeppelin.notebook.Note)

Example 9 with Notebook

use of org.apache.zeppelin.notebook.Notebook 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 10 with Notebook

use of org.apache.zeppelin.notebook.Notebook 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)

Aggregations

Notebook (org.apache.zeppelin.notebook.Notebook)15 Note (org.apache.zeppelin.notebook.Note)11 Message (org.apache.zeppelin.notebook.socket.Message)8 Paragraph (org.apache.zeppelin.notebook.Paragraph)7 HashMap (java.util.HashMap)4 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)4 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)4 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)4 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)3 URISyntaxException (java.net.URISyntaxException)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Properties (java.util.Properties)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2