Search in sources :

Example 1 with NamespacesModel

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

the class TestNamespacesResource method testNamespaceListXMLandJSON.

@Test
public void testNamespaceListXMLandJSON() throws IOException, JAXBException {
    String namespacePath = "/namespaces/";
    NamespacesModel model;
    Response response;
    // Check that namespace does not yet exist via non-REST call.
    Admin admin = TEST_UTIL.getAdmin();
    assertFalse(doesNamespaceExist(admin, NAMESPACE1));
    model = testNamespacesModel.buildTestModel();
    testNamespacesModel.checkModel(model);
    // Check that REST GET finds only default namespaces via XML and JSON responses.
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    model = fromXML(response.getBody());
    testNamespacesModel.checkModel(model, "hbase", "default");
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = testNamespacesModel.fromJSON(Bytes.toString(response.getBody()));
    testNamespacesModel.checkModel(model, "hbase", "default");
    // Create namespace and check that REST GET finds one additional namespace.
    createNamespaceViaAdmin(admin, NAMESPACE1);
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    model = fromXML(response.getBody());
    testNamespacesModel.checkModel(model, NAMESPACE1, "hbase", "default");
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = testNamespacesModel.fromJSON(Bytes.toString(response.getBody()));
    testNamespacesModel.checkModel(model, NAMESPACE1, "hbase", "default");
    // Create another namespace and check that REST GET finds one additional namespace.
    createNamespaceViaAdmin(admin, NAMESPACE2);
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    model = fromXML(response.getBody());
    testNamespacesModel.checkModel(model, NAMESPACE1, NAMESPACE2, "hbase", "default");
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = testNamespacesModel.fromJSON(Bytes.toString(response.getBody()));
    testNamespacesModel.checkModel(model, NAMESPACE1, NAMESPACE2, "hbase", "default");
    // Delete namespace and check that REST still finds correct namespaces.
    admin.deleteNamespace(NAMESPACE1);
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    model = fromXML(response.getBody());
    testNamespacesModel.checkModel(model, NAMESPACE2, "hbase", "default");
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = testNamespacesModel.fromJSON(Bytes.toString(response.getBody()));
    testNamespacesModel.checkModel(model, NAMESPACE2, "hbase", "default");
    admin.deleteNamespace(NAMESPACE2);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) NamespacesModel(org.apache.hadoop.hbase.rest.model.NamespacesModel) TestNamespacesModel(org.apache.hadoop.hbase.rest.model.TestNamespacesModel) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Example 2 with NamespacesModel

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

the class NamespacesResource method get.

/**
   * Build a response for a list of all namespaces 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);
    try {
        NamespacesModel rowModel = null;
        rowModel = new NamespacesModel(servlet.getAdmin());
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return Response.ok(rowModel).build();
    } catch (IOException e) {
        servlet.getMetrics().incrementFailedGetRequests(1);
        throw new RuntimeException("Cannot retrieve list of namespaces.");
    }
}
Also used : NamespacesModel(org.apache.hadoop.hbase.rest.model.NamespacesModel) IOException(java.io.IOException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with NamespacesModel

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

the class TestNamespacesResource method testNamespaceListPBandDefault.

@Test
public void testNamespaceListPBandDefault() throws IOException, JAXBException {
    String schemaPath = "/namespaces/";
    NamespacesModel model;
    Response response;
    // Check that namespace does not yet exist via non-REST call.
    Admin admin = TEST_UTIL.getAdmin();
    assertFalse(doesNamespaceExist(admin, NAMESPACE1));
    model = testNamespacesModel.buildTestModel();
    testNamespacesModel.checkModel(model);
    // Check that REST GET finds only default namespaces via PB and default Accept header.
    response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    model.getObjectFromMessage(response.getBody());
    testNamespacesModel.checkModel(model, "hbase", "default");
    response = client.get(schemaPath);
    assertEquals(200, response.getCode());
    // Create namespace and check that REST GET finds one additional namespace.
    createNamespaceViaAdmin(admin, NAMESPACE1);
    response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    model.getObjectFromMessage(response.getBody());
    testNamespacesModel.checkModel(model, NAMESPACE1, "hbase", "default");
    response = client.get(schemaPath);
    assertEquals(200, response.getCode());
    // Create another namespace and check that REST GET finds one additional namespace.
    createNamespaceViaAdmin(admin, NAMESPACE2);
    response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    model.getObjectFromMessage(response.getBody());
    testNamespacesModel.checkModel(model, NAMESPACE1, NAMESPACE2, "hbase", "default");
    response = client.get(schemaPath);
    assertEquals(200, response.getCode());
    // Delete namespace and check that REST GET still finds correct namespaces.
    admin.deleteNamespace(NAMESPACE1);
    response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    model.getObjectFromMessage(response.getBody());
    testNamespacesModel.checkModel(model, NAMESPACE2, "hbase", "default");
    response = client.get(schemaPath);
    assertEquals(200, response.getCode());
    admin.deleteNamespace(NAMESPACE2);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) NamespacesModel(org.apache.hadoop.hbase.rest.model.NamespacesModel) TestNamespacesModel(org.apache.hadoop.hbase.rest.model.TestNamespacesModel) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Aggregations

NamespacesModel (org.apache.hadoop.hbase.rest.model.NamespacesModel)3 Admin (org.apache.hadoop.hbase.client.Admin)2 Response (org.apache.hadoop.hbase.rest.client.Response)2 TestNamespacesModel (org.apache.hadoop.hbase.rest.model.TestNamespacesModel)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1