Search in sources :

Example 16 with Paragraph

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

the class NotebookServer method addNewParagraphIfLastParagraphIsExecuted.

private void addNewParagraphIfLastParagraphIsExecuted(Note note, Paragraph p) {
    // if it's the last paragraph and empty, let's add a new one
    boolean isTheLastParagraph = note.isLastParagraph(p.getId());
    if (!(p.getText().trim().equals(p.getMagic()) || Strings.isNullOrEmpty(p.getText())) && isTheLastParagraph) {
        Paragraph newPara = note.addParagraph(p.getAuthenticationInfo());
        broadcastNewParagraph(note, newPara);
    }
}
Also used : Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 17 with Paragraph

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

the class NotebookServer method onParaInfosReceived.

@Override
public void onParaInfosReceived(String noteId, String paragraphId, String interpreterSettingId, Map<String, String> metaInfos) {
    Note note = notebook().getNote(noteId);
    if (note != null) {
        Paragraph paragraph = note.getParagraph(paragraphId);
        if (paragraph != null) {
            InterpreterSetting setting = notebook().getInterpreterSettingManager().get(interpreterSettingId);
            setting.addNoteToPara(noteId, paragraphId);
            String label = metaInfos.get("label");
            String tooltip = metaInfos.get("tooltip");
            List<String> keysToRemove = Arrays.asList("noteId", "paraId", "label", "tooltip");
            for (String removeKey : keysToRemove) {
                metaInfos.remove(removeKey);
            }
            paragraph.updateRuntimeInfos(label, tooltip, metaInfos, setting.getGroup(), setting.getId());
            broadcast(note.getId(), new Message(OP.PARAS_INFO).put("id", paragraphId).put("infos", paragraph.getRuntimeInfos()));
        }
    }
}
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) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 18 with Paragraph

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

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

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

Paragraph (org.apache.zeppelin.notebook.Paragraph)75 Note (org.apache.zeppelin.notebook.Note)69 Test (org.junit.Test)40 Map (java.util.Map)30 TypeToken (com.google.gson.reflect.TypeToken)12 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)12 Path (javax.ws.rs.Path)11 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)11 PostMethod (org.apache.commons.httpclient.methods.PostMethod)9 Message (org.apache.zeppelin.notebook.socket.Message)9 Notebook (org.apache.zeppelin.notebook.Notebook)7 GetMethod (org.apache.commons.httpclient.methods.GetMethod)6 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)6 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 JsonObject (com.google.gson.JsonObject)4 IOException (java.io.IOException)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4