use of org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder in project hbase by apache.
the class ScannerInstanceResource method get.
@GET
@Produces({ MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo, @QueryParam("n") int maxRows, @QueryParam("c") final int maxValues) {
if (LOG.isTraceEnabled()) {
LOG.trace("GET " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
if (generator == null) {
servlet.getMetrics().incrementFailedGetRequests(1);
return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
} else {
// Updated the connection access time for each client next() call
RESTServlet.getInstance().getConnectionCache().updateConnectionAccessTime();
}
CellSetModel model = new CellSetModel();
RowModel rowModel = null;
byte[] rowKey = null;
int limit = batch;
if (maxValues > 0) {
limit = maxValues;
}
int count = limit;
do {
Cell value = null;
try {
value = generator.next();
} 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();
} catch (IllegalArgumentException e) {
Throwable t = e.getCause();
if (t instanceof TableNotFoundException) {
return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF).build();
}
throw e;
}
if (value == null) {
if (LOG.isTraceEnabled()) {
LOG.trace("generator exhausted");
}
// returned
if (count == limit) {
return Response.noContent().build();
}
break;
}
if (rowKey == null) {
rowKey = CellUtil.cloneRow(value);
rowModel = new RowModel(rowKey);
}
if (!Bytes.equals(CellUtil.cloneRow(value), rowKey)) {
// specified number of rows
if (maxRows > 0) {
if (--maxRows == 0) {
generator.putBack(value);
break;
}
}
model.addRow(rowModel);
rowKey = CellUtil.cloneRow(value);
rowModel = new RowModel(rowKey);
}
rowModel.addCell(new CellModel(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value), value.getTimestamp(), CellUtil.cloneValue(value)));
} while (--count > 0);
model.addRow(rowModel);
ResponseBuilder response = Response.ok(model);
response.cacheControl(cacheControl);
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
}
use of org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder 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();
}
}
use of org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder 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();
}
use of org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder 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();
}
}
use of org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder 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);
}
}
Aggregations