Search in sources :

Example 16 with Produces

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

the class NamespacesInstanceResource method get.

/**
 * Build a response for GET namespace description or GET list of namespace tables.
 * @param context servlet context
 * @param uriInfo (JAX-RS context variable) request URL
 * @return A response containing NamespacesInstanceModel for a namespace descriptions and
 * TableListModel for a list of namespace tables.
 */
@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);
    // Respond to list of namespace tables requests.
    if (queryTables) {
        TableListModel tableModel = new TableListModel();
        try {
            List<TableDescriptor> tables = servlet.getAdmin().listTableDescriptorsByNamespace(Bytes.toBytes(namespace));
            for (TableDescriptor table : tables) {
                tableModel.add(new TableModel(table.getTableName().getQualifierAsString()));
            }
            servlet.getMetrics().incrementSucessfulGetRequests(1);
            return Response.ok(tableModel).build();
        } catch (IOException e) {
            servlet.getMetrics().incrementFailedGetRequests(1);
            throw new RuntimeException("Cannot retrieve table list for '" + namespace + "'.");
        }
    }
    // Respond to namespace description requests.
    try {
        NamespacesInstanceModel rowModel = new NamespacesInstanceModel(servlet.getAdmin(), namespace);
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return Response.ok(rowModel).build();
    } catch (IOException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        throw new RuntimeException("Cannot retrieve info for '" + namespace + "'.");
    }
}
Also used : TableListModel(org.apache.hadoop.hbase.rest.model.TableListModel) NamespacesInstanceModel(org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel) IOException(java.io.IOException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) TableModel(org.apache.hadoop.hbase.rest.model.TableModel) 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