Search in sources :

Example 1 with ApplicationState

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

Example 2 with ApplicationState

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

the class VFSNotebookRepo method getNote.

private Note getNote(FileObject noteDir) throws IOException {
    if (!isDirectory(noteDir)) {
        throw new IOException(noteDir.getName().toString() + " is not a directory");
    }
    FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD);
    if (!noteJson.exists()) {
        throw new IOException(noteJson.getName().toString() + " not found");
    }
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setPrettyPrinting();
    Gson gson = gsonBuilder.registerTypeAdapter(Date.class, new NotebookImportDeserializer()).create();
    FileContent content = noteJson.getContent();
    InputStream ins = content.getInputStream();
    String json = IOUtils.toString(ins, conf.getString(ConfVars.ZEPPELIN_ENCODING));
    ins.close();
    Note note = gson.fromJson(json, Note.class);
    for (Paragraph p : note.getParagraphs()) {
        if (p.getStatus() == Status.PENDING || p.getStatus() == Status.RUNNING) {
            p.setStatus(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) InputStream(java.io.InputStream) ApplicationState(org.apache.zeppelin.notebook.ApplicationState) Gson(com.google.gson.Gson) IOException(java.io.IOException) NotebookImportDeserializer(org.apache.zeppelin.notebook.NotebookImportDeserializer) Date(java.util.Date) Paragraph(org.apache.zeppelin.notebook.Paragraph) FileContent(org.apache.commons.vfs2.FileContent) Note(org.apache.zeppelin.notebook.Note) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 ApplicationState (org.apache.zeppelin.notebook.ApplicationState)2 Note (org.apache.zeppelin.notebook.Note)2 NotebookImportDeserializer (org.apache.zeppelin.notebook.NotebookImportDeserializer)2 Paragraph (org.apache.zeppelin.notebook.Paragraph)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 FileContent (org.apache.commons.vfs2.FileContent)1 FileObject (org.apache.commons.vfs2.FileObject)1