Search in sources :

Example 16 with AuthenticationInfo

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

the class NotebookRestApi method getJobListforNote.

/**
   * Get note jobs for job manager
   *
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@GET
@Path("jobmanager/")
@ZeppelinApi
public Response getJobListforNote() throws IOException, IllegalArgumentException {
    LOG.info("Get note jobs for job manager");
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    List<Map<String, Object>> noteJobs = notebook.getJobListByUnixTime(false, 0, 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 17 with AuthenticationInfo

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

the class NotebookRestApi method getNoteList.

@GET
@Path("/")
@ZeppelinApi
public Response getNoteList() throws IOException {
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    HashSet<String> userAndRoles = SecurityUtils.getRoles();
    userAndRoles.add(subject.getUser());
    List<Map<String, String>> notesInfo = notebookServer.generateNotesInfo(false, subject, userAndRoles);
    return new JsonResponse<>(Status.OK, "", notesInfo).build();
}
Also used : 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 18 with AuthenticationInfo

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

the class NotebookRestApi method runParagraph.

/**
   * Run asynchronously paragraph job REST API
   *
   * @param message - JSON with params if user wants to update dynamic form's value
   *                null, empty string, empty json if user doesn't want to update
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@POST
@Path("job/{noteId}/{paragraphId}")
@ZeppelinApi
public Response runParagraph(@PathParam("noteId") String noteId, @PathParam("paragraphId") String paragraphId, String message) throws IOException, IllegalArgumentException {
    LOG.info("run paragraph job asynchronously {} {} {}", noteId, paragraphId, message);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanWrite(noteId, "Insufficient privileges you cannot run job for this note");
    Paragraph paragraph = note.getParagraph(paragraphId);
    checkIfParagraphIsNotNull(paragraph);
    // handle params if presented
    handleParagraphParams(message, note, paragraph);
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    paragraph.setAuthenticationInfo(subject);
    note.persist(subject);
    note.run(paragraph.getId());
    return new JsonResponse<>(Status.OK).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 19 with AuthenticationInfo

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

the class NotebookRestApi method createNote.

/**
   * Create new note REST API
   *
   * @param message - JSON with new note name
   * @return JSON with new note ID
   * @throws IOException
   */
@POST
@Path("/")
@ZeppelinApi
public Response createNote(String message) throws IOException {
    LOG.info("Create new note by JSON {}", message);
    NewNoteRequest request = gson.fromJson(message, NewNoteRequest.class);
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    Note note = notebook.createNote(subject);
    List<NewParagraphRequest> initialParagraphs = request.getParagraphs();
    if (initialParagraphs != null) {
        for (NewParagraphRequest paragraphRequest : initialParagraphs) {
            Paragraph p = note.addParagraph(subject);
            p.setTitle(paragraphRequest.getTitle());
            p.setText(paragraphRequest.getText());
        }
    }
    // add one paragraph to the last
    note.addParagraph(subject);
    String noteName = request.getName();
    if (noteName.isEmpty()) {
        noteName = "Note " + note.getId();
    }
    note.setName(noteName);
    note.persist(subject);
    notebookServer.broadcastNote(note);
    notebookServer.broadcastNoteList(subject, SecurityUtils.getRoles());
    return new JsonResponse<>(Status.OK, "", note.getId()).build();
}
Also used : NewNoteRequest(org.apache.zeppelin.rest.message.NewNoteRequest) NewParagraphRequest(org.apache.zeppelin.rest.message.NewParagraphRequest) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 20 with AuthenticationInfo

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

the class NotebookRestApi method handleParagraphParams.

private void handleParagraphParams(String message, Note note, Paragraph paragraph) throws IOException {
    // handle params if presented
    if (!StringUtils.isEmpty(message)) {
        RunParagraphWithParametersRequest request = gson.fromJson(message, RunParagraphWithParametersRequest.class);
        Map<String, Object> paramsForUpdating = request.getParams();
        if (paramsForUpdating != null) {
            paragraph.settings.getParams().putAll(paramsForUpdating);
            AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
            note.persist(subject);
        }
    }
}
Also used : RunParagraphWithParametersRequest(org.apache.zeppelin.rest.message.RunParagraphWithParametersRequest) 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