Search in sources :

Example 1 with StorageClusterVersionModel

use of org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel in project hbase by apache.

the class RemoteAdmin method getClusterVersion.

/**
   * @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 StorageClusterVersionModel getClusterVersion() throws IOException {
    StringBuilder path = new StringBuilder();
    path.append('/');
    if (accessToken != null) {
        path.append(accessToken);
        path.append('/');
    }
    path.append("version/cluster");
    int code = 0;
    for (int i = 0; i < maxRetries; i++) {
        Response response = client.get(path.toString(), Constants.MIMETYPE_XML);
        code = response.getCode();
        switch(code) {
            case 200:
                try {
                    return (StorageClusterVersionModel) getUnmarsheller().unmarshal(getInputStream(response));
                } catch (JAXBException jaxbe) {
                    throw new IOException("Issue parsing StorageClusterVersionModel object in XML form: " + jaxbe.getLocalizedMessage(), jaxbe);
                }
            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(path.toString() + " request returned " + code);
        }
    }
    throw new IOException("get request to " + path.toString() + " request timed out");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)

Example 2 with StorageClusterVersionModel

use of org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel in project hbase by apache.

the class StorageClusterVersionResource method get.

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON })
public Response get(@Context final UriInfo uriInfo) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("GET " + uriInfo.getAbsolutePath());
    }
    servlet.getMetrics().incrementRequests(1);
    try {
        StorageClusterVersionModel model = new StorageClusterVersionModel();
        model.setVersion(servlet.getAdmin().getClusterStatus().getHBaseVersion());
        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 : IOException(java.io.IOException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with StorageClusterVersionModel

use of org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel in project hbase by apache.

the class TestXmlParsing method testParsingClusterVersion.

@Test
public void testParsingClusterVersion() throws Exception {
    final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<ClusterVersion>2.0.0</ClusterVersion>";
    Client client = mock(Client.class);
    RemoteAdmin admin = new RemoteAdmin(client, HBaseConfiguration.create(), null);
    Response resp = new Response(200, null, xml.getBytes());
    when(client.get("/version/cluster", Constants.MIMETYPE_XML)).thenReturn(resp);
    StorageClusterVersionModel cv = admin.getClusterVersion();
    assertEquals("2.0.0", cv.getVersion());
}
Also used : StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel) Test(org.junit.Test)

Example 4 with StorageClusterVersionModel

use of org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel in project hbase by apache.

the class TestVersionResource method testGetStorageClusterVersionXML.

@Test
public void testGetStorageClusterVersionXML() throws IOException, JAXBException {
    Response response = client.get("/version/cluster", Constants.MIMETYPE_XML);
    assertTrue(response.getCode() == 200);
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    StorageClusterVersionModel clusterVersionModel = (StorageClusterVersionModel) context.createUnmarshaller().unmarshal(new ByteArrayInputStream(response.getBody()));
    assertNotNull(clusterVersionModel);
    assertNotNull(clusterVersionModel.getVersion());
    LOG.info("success retrieving storage cluster version as XML");
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel) Test(org.junit.Test)

Aggregations

StorageClusterVersionModel (org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)4 IOException (java.io.IOException)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 JAXBException (javax.xml.bind.JAXBException)1 Response (org.apache.hadoop.hbase.rest.client.Response)1