Search in sources :

Example 46 with AuthenticationInfo

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

the class AbstractRestApi method getServiceContext.

protected ServiceContext getServiceContext() {
    AuthenticationInfo authInfo = new AuthenticationInfo(authenticationService.getPrincipal());
    Set<String> userAndRoles = new HashSet<>();
    userAndRoles.add(authenticationService.getPrincipal());
    userAndRoles.addAll(authenticationService.getAssociatedRoles());
    return new ServiceContext(authInfo, userAndRoles);
}
Also used : ServiceContext(org.apache.zeppelin.service.ServiceContext) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) HashSet(java.util.HashSet)

Example 47 with AuthenticationInfo

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

the class NotebookRepoRestApi method updateRepoSetting.

/**
 * Update a specific note repo.
 *
 * @param payload
 * @return
 */
@PUT
@ZeppelinApi
public Response updateRepoSetting(String payload) {
    if (StringUtils.isBlank(payload)) {
        return new JsonResponse<>(Status.NOT_FOUND, "", Collections.emptyMap()).build();
    }
    AuthenticationInfo subject = new AuthenticationInfo(authenticationService.getPrincipal());
    NotebookRepoSettingsRequest newSettings;
    try {
        newSettings = NotebookRepoSettingsRequest.fromJson(payload);
    } catch (JsonSyntaxException e) {
        LOG.error("Cannot update notebook repo settings", e);
        return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload structure")).build();
    }
    if (NotebookRepoSettingsRequest.isEmpty(newSettings)) {
        LOG.error("Invalid property");
        return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload")).build();
    }
    LOG.info("User {} is going to change repo setting", subject.getUser());
    NotebookRepoWithSettings updatedSettings = noteRepos.updateNotebookRepo(newSettings.name, newSettings.settings, subject);
    if (!updatedSettings.isEmpty()) {
        LOG.info("Broadcasting note list to user {}", subject.getUser());
        try {
            notebookWsServer.broadcastReloadedNoteList(getServiceContext());
        } catch (IOException e) {
            LOG.error("Fail to refresh repo.", e);
        }
    }
    return new JsonResponse<>(Status.OK, "", updatedSettings).build();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) NotebookRepoWithSettings(org.apache.zeppelin.notebook.repo.NotebookRepoWithSettings) NotebookRepoSettingsRequest(org.apache.zeppelin.rest.message.NotebookRepoSettingsRequest) IOException(java.io.IOException) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) JsonResponse(org.apache.zeppelin.server.JsonResponse) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) PUT(javax.ws.rs.PUT)

Example 48 with AuthenticationInfo

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

the class NotebookRepoRestApi method getServiceContext.

private ServiceContext getServiceContext() {
    AuthenticationInfo authInfo = new AuthenticationInfo(authenticationService.getPrincipal());
    Set<String> userAndRoles = new HashSet<>();
    userAndRoles.add(authenticationService.getPrincipal());
    userAndRoles.addAll(authenticationService.getAssociatedRoles());
    return new ServiceContext(authInfo, userAndRoles);
}
Also used : ServiceContext(org.apache.zeppelin.service.ServiceContext) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) HashSet(java.util.HashSet)

Example 49 with AuthenticationInfo

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

the class NotebookRestApi method runNoteJobs.

/**
 * Run note jobs REST API.
 *
 * @param noteId ID of Note
 * @param blocking blocking until jobs are done
 * @param isolated use isolated interpreter for running this note
 * @param message any parameters passed to note
 * @return JSON with status.OK
 * @throws IOException
 * @throws IllegalArgumentException
 */
@POST
@Path("job/{noteId}")
@ZeppelinApi
public Response runNoteJobs(@PathParam("noteId") String noteId, @DefaultValue("false") @QueryParam("blocking") boolean blocking, @DefaultValue("false") @QueryParam("isolated") boolean isolated, String message) throws Exception, IllegalArgumentException {
    Map<String, Object> params = new HashMap<>();
    if (!StringUtils.isEmpty(message)) {
        ParametersRequest request = ParametersRequest.fromJson(message);
        params.putAll(request.getParams());
    }
    LOGGER.info("Run note jobs, noteId: {}, blocking: {}, isolated: {}, params: {}", noteId, blocking, isolated, params);
    return notebook.processNote(noteId, note -> {
        AuthenticationInfo subject = new AuthenticationInfo(authenticationService.getPrincipal());
        subject.setRoles(authenticationService.getAssociatedRoles());
        checkIfNoteIsNotNull(note, noteId);
        checkIfUserCanRun(noteId, "Insufficient privileges you cannot run job for this note");
        // TODO(zjffdu), can we run a note via rest api when cron is enabled ?
        try {
            note.runAll(subject, blocking, isolated, params);
            return new JsonResponse<>(Status.OK).build();
        } catch (Exception e) {
            return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, "Fail to run note").build();
        }
    });
}
Also used : HashMap(java.util.HashMap) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) ParagraphNotFoundException(org.apache.zeppelin.rest.exception.ParagraphNotFoundException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) IOException(java.io.IOException) BadRequestException(org.apache.zeppelin.rest.exception.BadRequestException) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Example 50 with AuthenticationInfo

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

the class NotebookRestApi method createNote.

/**
 * Create new note REST API with note json.
 *
 * @param message - JSON with new note name
 * @return JSON with new note ID
 * @throws IOException
 */
@POST
@ZeppelinApi
public Response createNote(String message) throws IOException {
    String user = authenticationService.getPrincipal();
    LOGGER.info("Creating new note by JSON {}", message);
    NewNoteRequest request = NewNoteRequest.fromJson(message);
    String defaultInterpreterGroup = request.getDefaultInterpreterGroup();
    if (StringUtils.isBlank(defaultInterpreterGroup)) {
        defaultInterpreterGroup = zConf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_GROUP_DEFAULT);
    }
    String noteId = notebookService.createNote(request.getName(), defaultInterpreterGroup, request.getAddingEmptyParagraph(), getServiceContext(), new RestServiceCallback<>());
    return notebook.processNote(noteId, note -> {
        AuthenticationInfo subject = new AuthenticationInfo(authenticationService.getPrincipal());
        if (request.getParagraphs() != null) {
            for (NewParagraphRequest paragraphRequest : request.getParagraphs()) {
                Paragraph p = note.addNewParagraph(subject);
                initParagraph(p, paragraphRequest, user);
            }
        }
        return new JsonResponse<>(Status.OK, "", note.getId()).build();
    });
}
Also used : AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Aggregations

AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)128 Test (org.junit.Test)44 HashMap (java.util.HashMap)40 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)29 Properties (java.util.Properties)28 Note (org.apache.zeppelin.notebook.Note)27 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)23 LinkedList (java.util.LinkedList)22 GUI (org.apache.zeppelin.display.GUI)22 Map (java.util.Map)21 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)20 AngularObject (org.apache.zeppelin.display.AngularObject)19 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)19 IOException (java.io.IOException)18 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)18 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)18 Paragraph (org.apache.zeppelin.notebook.Paragraph)18 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)16 Path (javax.ws.rs.Path)15 HashSet (java.util.HashSet)13