Search in sources :

Example 31 with AuthenticationInfo

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

the class NotebookServer method updateNote.

private void updateNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
    String noteId = (String) fromMessage.get("id");
    String name = (String) fromMessage.get("name");
    Map<String, Object> config = (Map<String, Object>) fromMessage.get("config");
    if (noteId == null) {
        return;
    }
    if (config == null) {
        return;
    }
    if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "update")) {
        return;
    }
    Note note = notebook.getNote(noteId);
    if (note != null) {
        boolean cronUpdated = isCronUpdated(config, note.getConfig());
        note.setName(name);
        note.setConfig(config);
        if (cronUpdated) {
            notebook.refreshCron(note.getId());
        }
        AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
        note.persist(subject);
        broadcast(note.getId(), new Message(OP.NOTE_UPDATED).put("name", name).put("config", config).put("info", note.getInfo()));
        broadcastNoteList(subject, userAndRoles);
    }
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Note(org.apache.zeppelin.notebook.Note) JsonObject(com.google.gson.JsonObject) AngularObject(org.apache.zeppelin.display.AngularObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 32 with AuthenticationInfo

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

the class NotebookServer method updatePersonalizedMode.

private void updatePersonalizedMode(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
    String noteId = (String) fromMessage.get("id");
    String personalized = (String) fromMessage.get("personalized");
    boolean isPersonalized = personalized.equals("true") ? true : false;
    if (noteId == null) {
        return;
    }
    if (!hasParagraphOwnerPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "persoanlized")) {
        return;
    }
    Note note = notebook.getNote(noteId);
    if (note != null) {
        note.setPersonalizedMode(isPersonalized);
        AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
        note.persist(subject);
        broadcastNote(note);
    }
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 33 with AuthenticationInfo

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

the class NotebookServer method broadcastNoteList.

public void broadcastNoteList(AuthenticationInfo subject, HashSet userAndRoles) {
    if (subject == null) {
        subject = new AuthenticationInfo(StringUtils.EMPTY);
    }
    //send first to requesting user
    List<Map<String, String>> notesInfo = generateNotesInfo(false, subject, userAndRoles);
    multicastToUser(subject.getUser(), new Message(OP.NOTES_INFO).put("notes", notesInfo));
    //to others afterwards
    broadcastNoteListExcept(notesInfo, subject);
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 34 with AuthenticationInfo

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

the class NotebookServer method moveParagraph.

private void moveParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    final String paragraphId = (String) fromMessage.get("id");
    if (paragraphId == null) {
        return;
    }
    final int newIndex = (int) Double.parseDouble(fromMessage.get("index").toString());
    String noteId = getOpenNoteId(conn);
    final Note note = notebook.getNote(noteId);
    if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
        return;
    }
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    note.moveParagraph(paragraphId, newIndex);
    note.persist(subject);
    broadcast(note.getId(), new Message(OP.PARAGRAPH_MOVED).put("id", paragraphId).put("index", newIndex));
}
Also used : InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 35 with AuthenticationInfo

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

the class Note method runAll.

/**
   * Run all paragraphs sequentially.
   */
public synchronized void runAll() {
    String cronExecutingUser = (String) getConfig().get("cronExecutingUser");
    if (null == cronExecutingUser) {
        cronExecutingUser = "anonymous";
    }
    for (Paragraph p : getParagraphs()) {
        if (!p.isEnabled()) {
            continue;
        }
        AuthenticationInfo authenticationInfo = new AuthenticationInfo();
        authenticationInfo.setUser(cronExecutingUser);
        p.setAuthenticationInfo(authenticationInfo);
        run(p.getId());
    }
}
Also used : AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Aggregations

AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)88 HashMap (java.util.HashMap)27 Note (org.apache.zeppelin.notebook.Note)27 Test (org.junit.Test)22 LinkedList (java.util.LinkedList)19 Properties (java.util.Properties)19 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)19 GUI (org.apache.zeppelin.display.GUI)19 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)17 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)16 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)15 Path (javax.ws.rs.Path)14 Message (org.apache.zeppelin.notebook.socket.Message)14 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)14 Paragraph (org.apache.zeppelin.notebook.Paragraph)12 Before (org.junit.Before)12 Map (java.util.Map)11 File (java.io.File)10 AngularObject (org.apache.zeppelin.display.AngularObject)9 POST (javax.ws.rs.POST)6