Search in sources :

Example 6 with Produces

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

the class StorageClusterStatusResource method get.

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    try {
        ClusterMetrics status = servlet.getAdmin().getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS, Option.DEAD_SERVERS));
        StorageClusterStatusModel model = new StorageClusterStatusModel();
        model.setRegions(status.getRegionCount());
        model.setRequests(status.getRequestCount());
        model.setAverageLoad(status.getAverageLoad());
        for (Map.Entry<ServerName, ServerMetrics> entry : status.getLiveServerMetrics().entrySet()) {
            ServerName sn = entry.getKey();
            ServerMetrics load = entry.getValue();
            StorageClusterStatusModel.Node node = model.addLiveNode(sn.getHostname() + ":" + Integer.toString(sn.getPort()), sn.getStartcode(), (int) load.getUsedHeapSize().get(Size.Unit.MEGABYTE), (int) load.getMaxHeapSize().get(Size.Unit.MEGABYTE));
            node.setRequests(load.getRequestCount());
            for (RegionMetrics region : load.getRegionMetrics().values()) {
                node.addRegion(region.getRegionName(), region.getStoreCount(), region.getStoreFileCount(), (int) region.getStoreFileSize().get(Size.Unit.MEGABYTE), (int) region.getMemStoreSize().get(Size.Unit.MEGABYTE), (long) region.getStoreFileIndexSize().get(Size.Unit.KILOBYTE), region.getReadRequestCount(), region.getCpRequestCount(), region.getWriteRequestCount(), (int) region.getStoreFileRootLevelIndexSize().get(Size.Unit.KILOBYTE), (int) region.getStoreFileUncompressedDataIndexSize().get(Size.Unit.KILOBYTE), (int) region.getBloomFilterSize().get(Size.Unit.KILOBYTE), region.getCompactingCellCount(), region.getCompactedCellCount());
            }
        }
        for (ServerName name : status.getDeadServerNames()) {
            model.addDeadNode(name.toString());
        }
        ResponseBuilder response = Response.ok(model);
        response.cacheControl(cacheControl);
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return response.build();
    } catch (IOException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
    }
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName) StorageClusterStatusModel(org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) IOException(java.io.IOException) ResponseBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder) Map(java.util.Map) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Example 7 with Produces

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

the class VersionResource method get.

/**
 * Build a response for a version request.
 * @param context servlet context
 * @param uriInfo (JAX-RS context variable) request URL
 * @return a response for a version request
 */
@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final ServletContext context, @Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    ResponseBuilder response = Response.ok(new VersionModel(context));
    response.cacheControl(cacheControl);
    servlet.getMetrics().incrementSucessfulGetRequests(1);
    return response.build();
}
Also used : ResponseBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder) VersionModel(org.apache.hadoop.hbase.rest.model.VersionModel) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Example 8 with Produces

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

the class ScannerInstanceResource method getBinary.

@GET
@Produces(MIMETYPE_BINARY)
public Response getBinary(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath() + " as " + MIMETYPE_BINARY);
    }
    servlet.getMetrics().incrementRequests(1);
    try {
        Cell value = generator.next();
        if (value == null) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("generator exhausted");
            }
            return Response.noContent().build();
        }
        ResponseBuilder response = Response.ok(CellUtil.cloneValue(value));
        response.cacheControl(cacheControl);
        response.header("X-Row", Bytes.toString(Base64.getEncoder().encode(CellUtil.cloneRow(value))));
        response.header("X-Column", Bytes.toString(Base64.getEncoder().encode(CellUtil.makeColumn(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value)))));
        response.header("X-Timestamp", value.getTimestamp());
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return response.build();
    } catch (IllegalStateException e) {
        if (ScannerResource.delete(id)) {
            servlet.getMetrics().incrementSucessfulDeleteRequests(1);
        } else {
            servlet.getMetrics().incrementFailedDeleteRequests(1);
        }
        servlet.getMetrics().incrementFailedGetRequests(1);
        return Response.status(Response.Status.GONE).type(MIMETYPE_TEXT).entity("Gone" + CRLF).build();
    }
}
Also used : ResponseBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder) Cell(org.apache.hadoop.hbase.Cell) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Example 9 with Produces

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

the class SchemaResource method get.

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    try {
        ResponseBuilder response = Response.ok(new TableSchemaModel(getTableSchema()));
        response.cacheControl(cacheControl);
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return response.build();
    } catch (Exception e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return processException(e);
    }
}
Also used : TableSchemaModel(org.apache.hadoop.hbase.rest.model.TableSchemaModel) ResponseBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) WebApplicationException(org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException) IOException(java.io.IOException) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Example 10 with Produces

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

the class StorageClusterVersionResource method get.

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON })
public Response get(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    try {
        StorageClusterVersionModel model = new StorageClusterVersionModel();
        model.setVersion(servlet.getAdmin().getClusterMetrics(EnumSet.of(Option.HBASE_VERSION)).getHBaseVersion());
        ResponseBuilder response = Response.ok(model);
        response.cacheControl(cacheControl);
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return response.build();
    } catch (IOException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF).build();
    }
}
Also used : IOException(java.io.IOException) ResponseBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder) StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Aggregations

GET (org.apache.hbase.thirdparty.javax.ws.rs.GET)16 Produces (org.apache.hbase.thirdparty.javax.ws.rs.Produces)16 IOException (java.io.IOException)12 ResponseBuilder (org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder)11 Cell (org.apache.hadoop.hbase.Cell)6 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)4 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)4 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)3 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)3 ServerName (org.apache.hadoop.hbase.ServerName)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 ClusterMetrics (org.apache.hadoop.hbase.ClusterMetrics)1 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)1 RegionMetrics (org.apache.hadoop.hbase.RegionMetrics)1 ServerMetrics (org.apache.hadoop.hbase.ServerMetrics)1 TableExistsException (org.apache.hadoop.hbase.TableExistsException)1 TableName (org.apache.hadoop.hbase.TableName)1