use of org.apache.hbase.thirdparty.javax.ws.rs.GET 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;
}
};
}
});
}
use of org.apache.hbase.thirdparty.javax.ws.rs.GET 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);
}
}
use of org.apache.hbase.thirdparty.javax.ws.rs.GET 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);
}
}
use of org.apache.hbase.thirdparty.javax.ws.rs.GET 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);
}
}
use of org.apache.hbase.thirdparty.javax.ws.rs.GET 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.");
}
}
Aggregations