Search in sources :

Example 36 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi in project zeppelin by apache.

the class NotebookRestApi method getParagraph.

/**
   * Get paragraph REST API
   *
   * @param noteId ID of Note
   * @return JSON with information of the paragraph
   * @throws IOException
   */
@GET
@Path("{noteId}/paragraph/{paragraphId}")
@ZeppelinApi
public Response getParagraph(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId) throws IOException {
    LOG.info("get paragraph {} {}", noteId, paragraphId);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanRead(noteId, "Insufficient privileges you cannot get this paragraph");
    Paragraph p = note.getParagraph(paragraphId);
    checkIfParagraphIsNotNull(p);
    return new JsonResponse<>(Status.OK, "", p).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 37 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi in project zeppelin by apache.

the class NotebookRestApi method getUpdatedJobListforNote.

/**
   * Get updated note jobs for job manager
   *
   * Return the `Note` change information within the post unix timestamp.
   *
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@GET
@Path("jobmanager/{lastUpdateUnixtime}/")
@ZeppelinApi
public Response getUpdatedJobListforNote(@PathParam("lastUpdateUnixtime") long lastUpdateUnixTime) throws IOException, IllegalArgumentException {
    LOG.info("Get updated note jobs lastUpdateTime {}", lastUpdateUnixTime);
    List<Map<String, Object>> noteJobs;
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    noteJobs = notebook.getJobListByUnixTime(false, lastUpdateUnixTime, subject);
    Map<String, Object> response = new HashMap<>();
    response.put("lastResponseUnixTime", System.currentTimeMillis());
    response.put("jobs", noteJobs);
    return new JsonResponse<>(Status.OK, response).build();
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 38 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi in project zeppelin by apache.

the class NotebookRestApi method stopNoteJobs.

/**
   * Stop(delete) note jobs REST API
   *
   * @param noteId ID of Note
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@DELETE
@Path("job/{noteId}")
@ZeppelinApi
public Response stopNoteJobs(@PathParam("noteId") String noteId) throws IOException, IllegalArgumentException {
    LOG.info("stop note jobs {} ", noteId);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot stop this job for this note");
    for (Paragraph p : note.getParagraphs()) {
        if (!p.isTerminated()) {
            p.abort();
        }
    }
    return new JsonResponse<>(Status.OK).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Example 39 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi in project zeppelin by apache.

the class NotebookRestApi method getNoteParagraphJobStatus.

/**
   * Get note paragraph job status REST API
   *
   * @param noteId ID of Note
   * @param paragraphId ID of Paragraph
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@GET
@Path("job/{noteId}/{paragraphId}")
@ZeppelinApi
public Response getNoteParagraphJobStatus(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId) throws IOException, IllegalArgumentException {
    LOG.info("get note paragraph job status.");
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanRead(noteId, "Insufficient privileges you cannot get job status");
    Paragraph paragraph = note.getParagraph(paragraphId);
    checkIfParagraphIsNotNull(paragraph);
    return new JsonResponse<>(Status.OK, null, note.generateSingleParagraphInfo(paragraphId)).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 40 with ZeppelinApi

use of org.apache.zeppelin.annotation.ZeppelinApi in project zeppelin by apache.

the class ZeppelinContext method run.

/**
   * Run paragraphs
   * @param paragraphIdOrIdx list of paragraph id or idx
   */
@ZeppelinApi
public void run(List<Object> paragraphIdOrIdx, InterpreterContext context) {
    String noteId = context.getNoteId();
    for (Object idOrIdx : paragraphIdOrIdx) {
        if (idOrIdx instanceof String) {
            String paragraphId = (String) idOrIdx;
            run(noteId, paragraphId, context);
        } else if (idOrIdx instanceof Integer) {
            Integer idx = (Integer) idOrIdx;
            run(noteId, idx, context);
        } else {
            throw new InterpreterException("Paragraph " + idOrIdx + " not found");
        }
    }
}
Also used : InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) AngularObject(org.apache.zeppelin.display.AngularObject) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Aggregations

ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)45 Path (javax.ws.rs.Path)35 Note (org.apache.zeppelin.notebook.Note)22 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)16 JsonResponse (org.apache.zeppelin.server.JsonResponse)15 GET (javax.ws.rs.GET)13 POST (javax.ws.rs.POST)13 Paragraph (org.apache.zeppelin.notebook.Paragraph)11 DELETE (javax.ws.rs.DELETE)6 PUT (javax.ws.rs.PUT)6 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ResourcePool (org.apache.zeppelin.resource.ResourcePool)4 Map (java.util.Map)3 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)3 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)3 Properties (java.util.Properties)2 Subject (org.apache.shiro.subject.Subject)2 NotebookRepoWithSettings (org.apache.zeppelin.notebook.repo.NotebookRepoWithSettings)2