Search in sources :

Example 21 with Note

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

the class NotebookServer method cancelParagraph.

private void cancelParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    final String paragraphId = (String) fromMessage.get("id");
    if (paragraphId == null) {
        return;
    }
    String noteId = getOpenNoteId(conn);
    if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
        return;
    }
    final Note note = notebook.getNote(noteId);
    Paragraph p = note.getParagraph(paragraphId);
    p.abort();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 22 with Note

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

the class NotebookServer method runAllParagraphs.

private void runAllParagraphs(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    final String noteId = (String) fromMessage.get("noteId");
    if (StringUtils.isBlank(noteId)) {
        return;
    }
    if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "run all paragraphs")) {
        return;
    }
    List<Map<String, Object>> paragraphs = gson.fromJson(String.valueOf(fromMessage.data.get("paragraphs")), new TypeToken<List<Map<String, Object>>>() {
    }.getType());
    for (Map<String, Object> raw : paragraphs) {
        String paragraphId = (String) raw.get("id");
        if (paragraphId == null) {
            continue;
        }
        String text = (String) raw.get("paragraph");
        String title = (String) raw.get("title");
        Map<String, Object> params = (Map<String, Object>) raw.get("params");
        Map<String, Object> config = (Map<String, Object>) raw.get("config");
        Note note = notebook.getNote(noteId);
        Paragraph p = setParagraphUsingMessage(note, fromMessage, paragraphId, text, title, params, config);
        persistAndExecuteSingleParagraph(conn, note, p);
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) 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) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 23 with Note

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

the class NotebookServer method onUpdate.

@Override
public void onUpdate(String interpreterGroupId, AngularObject object) {
    Notebook notebook = notebook();
    if (notebook == null) {
        return;
    }
    List<Note> notes = notebook.getAllNotes();
    for (Note note : notes) {
        if (object.getNoteId() != null && !note.getId().equals(object.getNoteId())) {
            continue;
        }
        List<InterpreterSetting> intpSettings = notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId());
        if (intpSettings.isEmpty()) {
            continue;
        }
        broadcast(note.getId(), new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", object).put("interpreterGroupId", interpreterGroupId).put("noteId", note.getId()).put("paragraphId", object.getParagraphId()));
    }
}
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) Note(org.apache.zeppelin.notebook.Note) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting)

Example 24 with Note

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

the class NotebookServer method sendHomeNote.

private void sendHomeNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    String noteId = notebook.getConf().getString(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN);
    String user = fromMessage.principal;
    Note note = null;
    if (noteId != null) {
        note = notebook.getNote(noteId);
    }
    if (note != null) {
        if (!hasParagraphReaderPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "read")) {
            return;
        }
        addConnectionToNote(note.getId(), conn);
        conn.send(serializeMessage(new Message(OP.NOTE).put("note", note)));
        sendAllAngularObjects(note, user, conn);
    } else {
        removeConnectionFromAllNote(conn);
        conn.send(serializeMessage(new Message(OP.NOTE).put("note", null)));
    }
}
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)

Example 25 with Note

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

the class MongoNotebookRepo method documentToNote.

/**
   * Convert document to note
   */
private Note documentToNote(Document doc) {
    // document to JSON
    String json = doc.toJson();
    // JSON to note
    Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new NotebookImportDeserializer()).create();
    Note note = gson.fromJson(json, Note.class);
    for (Paragraph p : note.getParagraphs()) {
        if (p.getStatus() == Job.Status.PENDING || p.getStatus() == Job.Status.RUNNING) {
            p.setStatus(Job.Status.ABORT);
        }
        List<ApplicationState> appStates = p.getAllApplicationStates();
        if (appStates != null) {
            for (ApplicationState app : appStates) {
                if (app.getStatus() != ApplicationState.Status.ERROR) {
                    app.setStatus(ApplicationState.Status.UNLOADED);
                }
            }
        }
    }
    return note;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Note(org.apache.zeppelin.notebook.Note) ApplicationState(org.apache.zeppelin.notebook.ApplicationState) Gson(com.google.gson.Gson) NotebookImportDeserializer(org.apache.zeppelin.notebook.NotebookImportDeserializer) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Aggregations

Note (org.apache.zeppelin.notebook.Note)142 Paragraph (org.apache.zeppelin.notebook.Paragraph)63 Test (org.junit.Test)63 Map (java.util.Map)35 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)31 IOException (java.io.IOException)24 Notebook (org.apache.zeppelin.notebook.Notebook)20 HashMap (java.util.HashMap)17 Message (org.apache.zeppelin.notebook.socket.Message)17 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)15 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)15 Path (javax.ws.rs.Path)13 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)13 NoteInfo (org.apache.zeppelin.notebook.NoteInfo)12 Gson (com.google.gson.Gson)11 TypeToken (com.google.gson.reflect.TypeToken)11 AngularObject (org.apache.zeppelin.display.AngularObject)11 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)9 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)9