Search in sources :

Example 21 with GET

use of javax.ws.rs.GET in project zeppelin by apache.

the class NotebookRestApi method getCronJob.

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

Example 22 with GET

use of javax.ws.rs.GET in project zeppelin by apache.

the class InterpreterRestApi method getMetaInfo.

/**
   * get the metainfo property value
   */
@GET
@Path("getmetainfos/{settingId}")
public Response getMetaInfo(@Context HttpServletRequest req, @PathParam("settingId") String settingId) {
    String propName = req.getParameter("propName");
    if (propName == null) {
        return new JsonResponse<>(Status.BAD_REQUEST).build();
    }
    String propValue = null;
    InterpreterSetting interpreterSetting = interpreterSettingManager.get(settingId);
    Map<String, String> infos = interpreterSetting.getInfos();
    if (infos != null) {
        propValue = infos.get(propName);
    }
    Map<String, String> respMap = new HashMap<>();
    respMap.put(propName, propValue);
    logger.debug("Get meta info");
    logger.debug("Interpretersetting Id: {}, property Name:{}, property value: {}", settingId, propName, propValue);
    return new JsonResponse<>(Status.OK, respMap).build();
}
Also used : HashMap(java.util.HashMap) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 23 with GET

use of javax.ws.rs.GET in project Openfire by igniterealtime.

the class UserServiceLegacy method userSerivceRequest.

@GET
@Path("/userservice")
public Response userSerivceRequest() throws IOException {
    // Printwriter for writing out responses to browser
    PrintWriter out = response.getWriter();
    if (!plugin.getAllowedIPs().isEmpty()) {
        // Get client's IP address
        String ipAddress = request.getHeader("x-forwarded-for");
        if (ipAddress == null) {
            ipAddress = request.getHeader("X_FORWARDED_FOR");
            if (ipAddress == null) {
                ipAddress = request.getHeader("X-Forward-For");
                if (ipAddress == null) {
                    ipAddress = request.getRemoteAddr();
                }
            }
        }
        if (!plugin.getAllowedIPs().contains(ipAddress)) {
            Log.warn("User service rejected service to IP address: " + ipAddress);
            replyError("RequestNotAuthorised", response, out);
            return Response.status(200).build();
        }
    }
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String name = request.getParameter("name");
    String email = request.getParameter("email");
    String type = request.getParameter("type");
    String secret = request.getParameter("secret");
    String groupNames = request.getParameter("groups");
    String item_jid = request.getParameter("item_jid");
    String sub = request.getParameter("subscription");
    // Check that our plugin is enabled.
    if (!plugin.isEnabled()) {
        Log.warn("User service plugin is disabled: " + request.getQueryString());
        replyError("UserServiceDisabled", response, out);
        return Response.status(200).build();
    }
    // Check this request is authorised
    if (secret == null || !secret.equals(plugin.getSecret())) {
        Log.warn("An unauthorised user service request was received: " + request.getQueryString());
        replyError("RequestNotAuthorised", response, out);
        return Response.status(200).build();
    }
    // Some checking is required on the username
    if (username == null && !"grouplist".equals(type)) {
        replyError("IllegalArgumentException", response, out);
        return Response.status(200).build();
    }
    if ((type.equals("add_roster") || type.equals("update_roster") || type.equals("delete_roster")) && (item_jid == null || !(sub == null || sub.equals("-1") || sub.equals("0") || sub.equals("1") || sub.equals("2") || sub.equals("3")))) {
        replyError("IllegalArgumentException", response, out);
        return Response.status(200).build();
    }
    // Check the request type and process accordingly
    try {
        if ("grouplist".equals(type)) {
            String message = "";
            for (String groupname : userServiceController.getAllGroups()) {
                message += "<groupname>" + groupname + "</groupname>";
            }
            replyMessage(message, response, out);
        } else {
            username = username.trim().toLowerCase();
            username = JID.escapeNode(username);
            username = Stringprep.nodeprep(username);
            if ("add".equals(type)) {
                userServiceController.createUser(username, password, name, email, groupNames);
                replyMessage("ok", response, out);
            } else if ("delete".equals(type)) {
                userServiceController.deleteUser(username);
                replyMessage("ok", response, out);
            } else if ("enable".equals(type)) {
                userServiceController.enableUser(username);
                replyMessage("ok", response, out);
            } else if ("disable".equals(type)) {
                userServiceController.disableUser(username);
                replyMessage("ok", response, out);
            } else if ("update".equals(type)) {
                userServiceController.updateUser(username, password, name, email, groupNames);
                replyMessage("ok", response, out);
            } else if ("add_roster".equals(type)) {
                userServiceController.addRosterItem(username, item_jid, name, sub, groupNames);
                replyMessage("ok", response, out);
            } else if ("update_roster".equals(type)) {
                userServiceController.updateRosterItem(username, item_jid, name, sub, groupNames);
                replyMessage("ok", response, out);
            } else if ("delete_roster".equals(type)) {
                userServiceController.deleteRosterItem(username, item_jid);
                replyMessage("ok", response, out);
            } else if ("usergrouplist".equals(type)) {
                String message = "";
                for (String groupname : userServiceController.getUserGroups(username)) {
                    message += "<groupname>" + groupname + "</groupname>";
                }
                replyMessage(message, response, out);
            } else {
                Log.warn("The userService servlet received an invalid request of type: " + type);
            // TODO Do something
            }
        }
    } catch (UserAlreadyExistsException e) {
        replyError("UserAlreadyExistsException", response, out);
    } catch (UserNotFoundException e) {
        replyError("UserNotFoundException", response, out);
    } catch (IllegalArgumentException e) {
        replyError("IllegalArgumentException", response, out);
    } catch (SharedGroupException e) {
        replyError("SharedGroupException", response, out);
    } catch (Exception e) {
        Log.error("Error: ", e);
        replyError(e.toString(), response, out);
    }
    return Response.status(200).build();
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) IOException(java.io.IOException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException) PrintWriter(java.io.PrintWriter) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 24 with GET

use of javax.ws.rs.GET in project pinot by linkedin.

the class TableSizeResource method getTableSize.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/tables/{tableName}/size")
@ApiOperation(value = "Show table storage size", notes = "Lists size of all the segments of the table")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Internal server error"), @ApiResponse(code = 404, message = "Table not found") })
public TableSizeInfo getTableSize(@ApiParam(value = "Table Name with type", required = true) @PathParam("tableName") String tableName, @ApiParam(value = "Provide detailed information", required = false) @DefaultValue("true") @QueryParam("detailed") boolean detailed) throws WebApplicationException {
    InstanceDataManager dataManager = (InstanceDataManager) serverInstance.getInstanceDataManager();
    if (dataManager == null) {
        throw new WebApplicationException("Invalid server initialization", Response.Status.INTERNAL_SERVER_ERROR);
    }
    TableDataManager tableDataManager = dataManager.getTableDataManager(tableName);
    if (tableDataManager == null) {
        throw new WebApplicationException("Table: " + tableName + " is not found", Response.Status.NOT_FOUND);
    }
    TableSizeInfo tableSizeInfo = new TableSizeInfo();
    tableSizeInfo.tableName = tableDataManager.getTableName();
    tableSizeInfo.diskSizeInBytes = 0L;
    ImmutableList<SegmentDataManager> segmentDataManagers = tableDataManager.acquireAllSegments();
    try {
        for (SegmentDataManager segmentDataManager : segmentDataManagers) {
            IndexSegment segment = segmentDataManager.getSegment();
            long segmentSizeBytes = segment.getDiskSizeBytes();
            if (detailed) {
                SegmentSizeInfo segmentSizeInfo = new SegmentSizeInfo(segment.getSegmentName(), segmentSizeBytes);
                tableSizeInfo.segments.add(segmentSizeInfo);
            }
            tableSizeInfo.diskSizeInBytes += segmentSizeBytes;
        }
    } finally {
        // executes fast so duration of holding segments is not a concern
        for (SegmentDataManager segmentDataManager : segmentDataManagers) {
            tableDataManager.releaseSegment(segmentDataManager);
        }
    }
    //invalid to use the segmentDataManagers below
    return tableSizeInfo;
}
Also used : SegmentDataManager(com.linkedin.pinot.core.data.manager.offline.SegmentDataManager) WebApplicationException(javax.ws.rs.WebApplicationException) IndexSegment(com.linkedin.pinot.core.indexsegment.IndexSegment) TableDataManager(com.linkedin.pinot.core.data.manager.offline.TableDataManager) InstanceDataManager(com.linkedin.pinot.core.data.manager.offline.InstanceDataManager) SegmentSizeInfo(com.linkedin.pinot.common.restlet.resources.SegmentSizeInfo) TableSizeInfo(com.linkedin.pinot.common.restlet.resources.TableSizeInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 25 with GET

use of javax.ws.rs.GET in project pinot by linkedin.

the class TablesResource method listTableSegments.

@GET
@Path("/tables/{tableName}/segments")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List table segments", notes = "List segments of table hosted on this server")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = TableSegments.class), @ApiResponse(code = 500, message = "Server initialization error", response = ErrorInfo.class) })
public TableSegments listTableSegments(@ApiParam(value = "Table name including type", required = true, example = "myTable_OFFLINE") @PathParam("tableName") String tableName) {
    TableDataManager tableDataManager = checkGetTableDataManager(tableName);
    ImmutableList<SegmentDataManager> segmentDataManagers = tableDataManager.acquireAllSegments();
    List<String> segments = new ArrayList<>(segmentDataManagers.size());
    for (SegmentDataManager segmentDataManager : segmentDataManagers) {
        segments.add(segmentDataManager.getSegmentName());
        tableDataManager.releaseSegment(segmentDataManager);
    }
    return new TableSegments(segments);
}
Also used : TableSegments(com.linkedin.pinot.common.restlet.resources.TableSegments) SegmentDataManager(com.linkedin.pinot.core.data.manager.offline.SegmentDataManager) TableDataManager(com.linkedin.pinot.core.data.manager.offline.TableDataManager) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

GET (javax.ws.rs.GET)3467 Path (javax.ws.rs.Path)2921 Produces (javax.ws.rs.Produces)2414 ApiOperation (io.swagger.annotations.ApiOperation)709 ApiResponses (io.swagger.annotations.ApiResponses)558 ArrayList (java.util.ArrayList)468 IOException (java.io.IOException)344 Response (javax.ws.rs.core.Response)342 WebApplicationException (javax.ws.rs.WebApplicationException)335 Consumes (javax.ws.rs.Consumes)267 HashMap (java.util.HashMap)242 List (java.util.List)231 URI (java.net.URI)202 Map (java.util.Map)202 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)196 Timed (com.codahale.metrics.annotation.Timed)195 TimedResource (org.killbill.commons.metrics.TimedResource)121 TenantContext (org.killbill.billing.util.callcontext.TenantContext)117 MediaType (javax.ws.rs.core.MediaType)113 ApiResponse (io.swagger.annotations.ApiResponse)111