Search in sources :

Example 61 with Produces

use of javax.ws.rs.Produces in project hbase by apache.

the class ExistsResource method get.

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF, MIMETYPE_BINARY })
public Response get(@Context final UriInfo uriInfo) {
    try {
        if (!tableResource.exists()) {
            return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
        }
    } catch (IOException e) {
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
    }
    ResponseBuilder response = Response.ok();
    response.cacheControl(cacheControl);
    return response.build();
}
Also used : IOException(java.io.IOException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 62 with Produces

use of javax.ws.rs.Produces in project zookeeper by apache.

the class ZNodeResource method deleteZNode.

@DELETE
@Produces({ MediaType.APPLICATION_JSON, "application/javascript", MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
public void deleteZNode(@PathParam("path") String path, @DefaultValue("-1") @QueryParam("version") String versionParam, @Context UriInfo ui) throws InterruptedException, KeeperException {
    ensurePathNotNull(path);
    int version;
    try {
        version = Integer.parseInt(versionParam);
    } catch (NumberFormatException e) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build());
    }
    zk.delete(path, version);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ZError(org.apache.zookeeper.server.jersey.jaxb.ZError) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 63 with Produces

use of javax.ws.rs.Produces in project zookeeper by apache.

the class ZNodeResource method setZNodeAsOctet.

@PUT
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public void setZNodeAsOctet(@PathParam("path") String path, @DefaultValue("-1") @QueryParam("version") String versionParam, @DefaultValue("false") @QueryParam("null") String setNull, @Context UriInfo ui, byte[] data) throws InterruptedException, KeeperException {
    ensurePathNotNull(path);
    int version;
    try {
        version = Integer.parseInt(versionParam);
    } catch (NumberFormatException e) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build());
    }
    if (setNull.equals("true")) {
        data = null;
    }
    zk.setData(path, data, version);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ZError(org.apache.zookeeper.server.jersey.jaxb.ZError) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 64 with Produces

use of javax.ws.rs.Produces in project zookeeper by apache.

the class ZNodeResource method getZNodeListAsOctet.

@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getZNodeListAsOctet(@PathParam("path") String path) throws InterruptedException, KeeperException {
    ensurePathNotNull(path);
    Stat stat = new Stat();
    byte[] data = zk.getData(path, false, stat);
    if (data == null) {
        return Response.status(Response.Status.NO_CONTENT).build();
    } else {
        return Response.status(Response.Status.OK).entity(data).build();
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZStat(org.apache.zookeeper.server.jersey.jaxb.ZStat) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 65 with Produces

use of javax.ws.rs.Produces 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)

Aggregations

Produces (javax.ws.rs.Produces)1150 Path (javax.ws.rs.Path)844 GET (javax.ws.rs.GET)724 Consumes (javax.ws.rs.Consumes)306 POST (javax.ws.rs.POST)304 ApiOperation (io.swagger.annotations.ApiOperation)275 ApiResponses (io.swagger.annotations.ApiResponses)218 IOException (java.io.IOException)143 Response (javax.ws.rs.core.Response)139 WebApplicationException (javax.ws.rs.WebApplicationException)115 URI (java.net.URI)110 TimedResource (org.killbill.commons.metrics.TimedResource)109 Timed (com.codahale.metrics.annotation.Timed)103 ArrayList (java.util.ArrayList)91 PUT (javax.ws.rs.PUT)89 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)85 HashMap (java.util.HashMap)68 Map (java.util.Map)63 UUID (java.util.UUID)63 DELETE (javax.ws.rs.DELETE)62