Search in sources :

Example 1 with StorageClusterStatusModel

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();
    }
}
Also used : ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName) StorageClusterStatusModel(org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel) IOException(java.io.IOException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with StorageClusterStatusModel

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);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) StorageClusterStatusModel(org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel) Test(org.junit.Test)

Example 3 with StorageClusterStatusModel

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");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) StorageClusterStatusModel(org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 4 with StorageClusterStatusModel

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);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) StorageClusterStatusModel(org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel) Test(org.junit.Test)

Aggregations

StorageClusterStatusModel (org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel)4 IOException (java.io.IOException)2 Response (org.apache.hadoop.hbase.rest.client.Response)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InterruptedIOException (java.io.InterruptedIOException)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 ClusterStatus (org.apache.hadoop.hbase.ClusterStatus)1 RegionLoad (org.apache.hadoop.hbase.RegionLoad)1 ServerLoad (org.apache.hadoop.hbase.ServerLoad)1 ServerName (org.apache.hadoop.hbase.ServerName)1