Search in sources :

Example 1 with VersionModel

use of org.apache.hadoop.hbase.rest.model.VersionModel 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();
}
Also used : ResponseBuilder(org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder) VersionModel(org.apache.hadoop.hbase.rest.model.VersionModel) Produces(org.apache.hbase.thirdparty.javax.ws.rs.Produces) GET(org.apache.hbase.thirdparty.javax.ws.rs.GET)

Example 2 with VersionModel

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

the class TestVersionResource method testGetStargateVersionPB.

@Test
public void testGetStargateVersionPB() throws IOException {
    Response response = client.get("/version", Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
    VersionModel model = new VersionModel();
    model.getObjectFromMessage(response.getBody());
    validate(model);
    response = client.get("/version", Constants.MIMETYPE_PROTOBUF_IETF);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
    model = new VersionModel();
    model.getObjectFromMessage(response.getBody());
    validate(model);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel) VersionModel(org.apache.hadoop.hbase.rest.model.VersionModel) Test(org.junit.Test)

Example 3 with VersionModel

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

the class TestVersionResource method testGetStargateVersionJSON.

@Test
public void testGetStargateVersionJSON() throws IOException {
    Response response = client.get("/version", Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(VersionModel.class, MediaType.APPLICATION_JSON_TYPE);
    VersionModel model = mapper.readValue(response.getBody(), VersionModel.class);
    validate(model);
    LOG.info("success retrieving Stargate version as JSON");
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) JacksonJaxbJsonProvider(org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel) VersionModel(org.apache.hadoop.hbase.rest.model.VersionModel) Test(org.junit.Test)

Example 4 with VersionModel

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

the class TestVersionResource method testGetStargateVersionXML.

@Test
public void testGetStargateVersionXML() throws IOException, JAXBException {
    Response response = client.get("/version", Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    VersionModel model = (VersionModel) context.createUnmarshaller().unmarshal(new ByteArrayInputStream(response.getBody()));
    validate(model);
    LOG.info("success retrieving Stargate 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) VersionModel(org.apache.hadoop.hbase.rest.model.VersionModel) Test(org.junit.Test)

Example 5 with VersionModel

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

the class RemoteAdmin method getRestVersion.

/**
 * @return string representing the rest api's version
 * @throws IOException
 *           if the endpoint does not exist, there is a timeout, or some other
 *           general failure mode
 */
public VersionModel getRestVersion() throws IOException {
    StringBuilder path = new StringBuilder();
    path.append('/');
    if (accessToken != null) {
        path.append(accessToken);
        path.append('/');
    }
    path.append("version/rest");
    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:
                VersionModel v = new VersionModel();
                return (VersionModel) v.getObjectFromMessage(response.getBody());
            case 404:
                throw new IOException("REST 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.toString() + " returned " + code);
        }
    }
    throw new IOException("get request to " + path.toString() + " timed out");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel) VersionModel(org.apache.hadoop.hbase.rest.model.VersionModel)

Aggregations

VersionModel (org.apache.hadoop.hbase.rest.model.VersionModel)5 StorageClusterVersionModel (org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)4 Response (org.apache.hadoop.hbase.rest.client.Response)3 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 JacksonJaxbJsonProvider (org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1 GET (org.apache.hbase.thirdparty.javax.ws.rs.GET)1 Produces (org.apache.hbase.thirdparty.javax.ws.rs.Produces)1 ResponseBuilder (org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder)1