Search in sources :

Example 11 with Produces

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

the class TableScanResource method get.

@GET
@Produces({ Constants.MIMETYPE_XML, Constants.MIMETYPE_JSON })
public CellSetModelStream get(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    final int rowsToSend = userRequestedLimit;
    servlet.getMetrics().incrementSucessfulScanRequests(1);
    final Iterator<Result> itr = results.iterator();
    return new CellSetModelStream(new ArrayList<RowModel>() {

        @Override
        public Iterator<RowModel> iterator() {
            return new Iterator<RowModel>() {

                int count = rowsToSend;

                @Override
                public boolean hasNext() {
                    return count > 0 && itr.hasNext();
                }

                @Override
                public RowModel next() {
                    Result rs = itr.next();
                    if ((rs == null) || (count <= 0)) {
                        return null;
                    }
                    byte[] rowKey = rs.getRow();
                    RowModel rModel = new RowModel(rowKey);
                    List<Cell> kvs = rs.listCells();
                    for (Cell kv : kvs) {
                        rModel.addCell(new CellModel(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv), kv.getTimestamp(), CellUtil.cloneValue(kv)));
                    }
                    count--;
                    if (count == 0) {
                        results.close();
                    }
                    return rModel;
                }
            };
        }
    });
}
Also used : Iterator(java.util.Iterator) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) ArrayList(java.util.ArrayList) List(java.util.List) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Example 12 with Produces

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

the class RowResource 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);
    // return a single cell
    if (!rowspec.hasColumns() || rowspec.getColumns().length > 1) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT).entity("Bad request: Default 'GET' method only works if there is exactly 1 column " + "in the row. Using the 'Accept' header with one of these formats lets you " + "retrieve the entire row if it has multiple columns: " + // Same as the @Produces list for the get method.
        MIMETYPE_XML + ", " + MIMETYPE_JSON + ", " + MIMETYPE_PROTOBUF + ", " + MIMETYPE_PROTOBUF_IETF + CRLF).build();
    }
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    try {
        ResultGenerator generator = ResultGenerator.fromRowSpec(tableResource.getName(), rowspec, null, !params.containsKey(NOCACHE_PARAM_NAME));
        if (!generator.hasNext()) {
            servlet.getMetrics().incrementFailedGetRequests(1);
            return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
        }
        Cell value = generator.next();
        ResponseBuilder response = Response.ok(CellUtil.cloneValue(value));
        response.header("X-Timestamp", value.getTimestamp());
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return response.build();
    } catch (Exception e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return processException(e);
    }
}
Also used : ResponseBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder) Cell(org.apache.hadoop.hbase.Cell) IOException(java.io.IOException) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Example 13 with Produces

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

the class RootResource 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(getTableList());
        response.cacheControl(cacheControl);
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return response.build();
    } catch (Exception e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return processException(e);
    }
}
Also used : ResponseBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder) IOException(java.io.IOException) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Example 14 with Produces

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

the class MultiRowResource method get.

@GET
@Produces({ MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    servlet.getMetrics().incrementRequests(1);
    try {
        CellSetModel model = new CellSetModel();
        for (String rk : params.get(ROW_KEYS_PARAM_NAME)) {
            RowSpec rowSpec = new RowSpec(rk);
            if (this.versions != null) {
                rowSpec.setMaxVersions(this.versions);
            }
            if (this.columns != null) {
                for (int i = 0; i < this.columns.length; i++) {
                    rowSpec.addColumn(Bytes.toBytes(this.columns[i]));
                }
            }
            ResultGenerator generator = ResultGenerator.fromRowSpec(this.tableResource.getName(), rowSpec, null, !params.containsKey(NOCACHE_PARAM_NAME));
            Cell value = null;
            RowModel rowModel = new RowModel(rowSpec.getRow());
            if (generator.hasNext()) {
                while ((value = generator.next()) != null) {
                    rowModel.addCell(new CellModel(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value), value.getTimestamp(), CellUtil.cloneValue(value)));
                }
                model.addRow(rowModel);
            } else {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("The row : " + rk + " not found in the table.");
                }
            }
        }
        if (model.getRows().isEmpty()) {
            // If no rows found.
            servlet.getMetrics().incrementFailedGetRequests(1);
            return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("No rows found." + CRLF).build();
        } else {
            servlet.getMetrics().incrementSucessfulGetRequests(1);
            return Response.ok(model).build();
        }
    } catch (IOException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        return processException(e);
    }
}
Also used : CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) IOException(java.io.IOException) 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 15 with Produces

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

the class NamespacesResource method get.

/**
 * Build a response for a list of all namespaces 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);
    try {
        NamespacesModel rowModel = null;
        rowModel = new NamespacesModel(servlet.getAdmin());
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return Response.ok(rowModel).build();
    } catch (IOException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        throw new RuntimeException("Cannot retrieve list of namespaces.");
    }
}
Also used : NamespacesModel(org.apache.hadoop.hbase.rest.model.NamespacesModel) IOException(java.io.IOException) 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