use of org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel 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 {
ClusterStatus status = servlet.getAdmin().getClusterStatus();
StorageClusterStatusModel model = new StorageClusterStatusModel();
model.setRegions(status.getRegionsCount());
model.setRequests(status.getRequestsCount());
model.setAverageLoad(status.getAverageLoad());
for (ServerName info : status.getServers()) {
ServerLoad load = status.getLoad(info);
StorageClusterStatusModel.Node node = model.addLiveNode(info.getHostname() + ":" + Integer.toString(info.getPort()), info.getStartcode(), load.getUsedHeapMB(), load.getMaxHeapMB());
node.setRequests(load.getNumberOfRequests());
for (RegionLoad region : load.getRegionsLoad().values()) {
node.addRegion(region.getName(), region.getStores(), region.getStorefiles(), region.getStorefileSizeMB(), region.getMemStoreSizeMB(), region.getStorefileIndexSizeMB(), region.getReadRequestsCount(), region.getWriteRequestsCount(), region.getRootIndexSizeKB(), region.getTotalStaticIndexSizeKB(), region.getTotalStaticBloomSizeKB(), region.getTotalCompactingKVs(), region.getCurrentCompactedKVs());
}
}
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.hadoop.hbase.rest.model.StorageClusterStatusModel in project hbase by apache.
the class TestStatusResource method testGetClusterStatusXML.
@Test
public void testGetClusterStatusXML() throws IOException, JAXBException {
Response response = client.get("/status/cluster", Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
StorageClusterStatusModel model = (StorageClusterStatusModel) context.createUnmarshaller().unmarshal(new ByteArrayInputStream(response.getBody()));
validate(model);
}
use of org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel in project hbase by apache.
the class RemoteAdmin method getClusterStatus.
/**
* @return string representing the cluster's version
* @throws IOException if the endpoint does not exist, there is a timeout, or some other general failure mode
*/
public StorageClusterStatusModel getClusterStatus() throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
if (accessToken != null) {
path.append(accessToken);
path.append('/');
}
path.append("status/cluster");
int code = 0;
for (int i = 0; i < maxRetries; i++) {
Response response = client.get(path.toString(), Constants.MIMETYPE_PROTOBUF);
code = response.getCode();
switch(code) {
case 200:
StorageClusterStatusModel s = new StorageClusterStatusModel();
return (StorageClusterStatusModel) s.getObjectFromMessage(response.getBody());
case 404:
throw new IOException("Cluster version not found");
case 509:
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
break;
default:
throw new IOException("get request to " + path + " returned " + code);
}
}
throw new IOException("get request to " + path + " timed out");
}
use of org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel in project hbase by apache.
the class TestStatusResource method testGetClusterStatusPB.
@Test
public void testGetClusterStatusPB() throws IOException {
Response response = client.get("/status/cluster", Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
StorageClusterStatusModel model = new StorageClusterStatusModel();
model.getObjectFromMessage(response.getBody());
validate(model);
response = client.get("/status/cluster", Constants.MIMETYPE_PROTOBUF_IETF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new StorageClusterStatusModel();
model.getObjectFromMessage(response.getBody());
validate(model);
}
Aggregations