Search in sources :

Example 11 with Response

use of org.apache.hadoop.hbase.rest.client.Response 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 12 with Response

use of org.apache.hadoop.hbase.rest.client.Response 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 13 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestVersionResource method testGetStargateVersionText.

@Test
public void testGetStargateVersionText() throws IOException {
    Response response = client.get("/version", Constants.MIMETYPE_TEXT);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
    String body = Bytes.toString(response.getBody());
    assertTrue(body.length() > 0);
    assertTrue(body.contains(RESTServlet.VERSION_STRING));
    assertTrue(body.contains(System.getProperty("java.vm.vendor")));
    assertTrue(body.contains(System.getProperty("java.version")));
    assertTrue(body.contains(System.getProperty("java.vm.version")));
    assertTrue(body.contains(System.getProperty("os.name")));
    assertTrue(body.contains(System.getProperty("os.version")));
    assertTrue(body.contains(System.getProperty("os.arch")));
// TODO: fix when we actually get a jersey version
// assertTrue(body.contains(ServletContainer.class.getPackage().getImplementationVersion()));
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Test(org.junit.Test)

Example 14 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestNamespacesInstanceResource method testCannotDeleteDefaultAndHbaseNamespaces.

@Test
public void testCannotDeleteDefaultAndHbaseNamespaces() throws IOException {
    String defaultPath = "/namespaces/default";
    String hbasePath = "/namespaces/hbase";
    Response response;
    // Check that doesn't exist via non-REST call.
    Admin admin = TEST_UTIL.getAdmin();
    assertNotNull(findNamespace(admin, "default"));
    assertNotNull(findNamespace(admin, "hbase"));
    // Try (but fail) to delete namespaces via REST.
    response = client.delete(defaultPath);
    assertEquals(503, response.getCode());
    response = client.delete(hbasePath);
    assertEquals(503, response.getCode());
    assertNotNull(findNamespace(admin, "default"));
    assertNotNull(findNamespace(admin, "hbase"));
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Example 15 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestNamespacesInstanceResource method testNamespaceCreateAndDeleteXMLAndJSON.

@Test
public void testNamespaceCreateAndDeleteXMLAndJSON() throws IOException, JAXBException {
    String namespacePath1 = "/namespaces/" + NAMESPACE1;
    String namespacePath2 = "/namespaces/" + NAMESPACE2;
    NamespacesInstanceModel model1;
    NamespacesInstanceModel model2;
    Response response;
    // Check that namespaces don't exist via non-REST call.
    Admin admin = TEST_UTIL.getAdmin();
    assertNull(findNamespace(admin, NAMESPACE1));
    assertNull(findNamespace(admin, NAMESPACE2));
    model1 = testNamespacesInstanceModel.buildTestModel(NAMESPACE1, NAMESPACE1_PROPS);
    testNamespacesInstanceModel.checkModel(model1, NAMESPACE1, NAMESPACE1_PROPS);
    model2 = testNamespacesInstanceModel.buildTestModel(NAMESPACE2, NAMESPACE2_PROPS);
    testNamespacesInstanceModel.checkModel(model2, NAMESPACE2, NAMESPACE2_PROPS);
    // Test cannot PUT (alter) non-existent namespace.
    response = client.put(namespacePath1, Constants.MIMETYPE_XML, toXML(model1));
    assertEquals(403, response.getCode());
    String jsonString = jsonMapper.writeValueAsString(model2);
    response = client.put(namespacePath2, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
    assertEquals(403, response.getCode());
    // Test cannot create tables when in read only mode.
    conf.set("hbase.rest.readonly", "true");
    response = client.post(namespacePath1, Constants.MIMETYPE_XML, toXML(model1));
    assertEquals(403, response.getCode());
    jsonString = jsonMapper.writeValueAsString(model2);
    response = client.post(namespacePath2, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
    assertEquals(403, response.getCode());
    NamespaceDescriptor nd1 = findNamespace(admin, NAMESPACE1);
    NamespaceDescriptor nd2 = findNamespace(admin, NAMESPACE2);
    assertNull(nd1);
    assertNull(nd2);
    conf.set("hbase.rest.readonly", "false");
    // Create namespace via XML and JSON.
    response = client.post(namespacePath1, Constants.MIMETYPE_XML, toXML(model1));
    assertEquals(201, response.getCode());
    jsonString = jsonMapper.writeValueAsString(model2);
    response = client.post(namespacePath2, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
    assertEquals(201, response.getCode());
    // check passing null content-type with a payload returns 415
    Header[] nullHeaders = null;
    response = client.post(namespacePath1, nullHeaders, toXML(model1));
    assertEquals(415, response.getCode());
    response = client.post(namespacePath1, nullHeaders, Bytes.toBytes(jsonString));
    assertEquals(415, response.getCode());
    // Check that created namespaces correctly.
    nd1 = findNamespace(admin, NAMESPACE1);
    nd2 = findNamespace(admin, NAMESPACE2);
    assertNotNull(nd1);
    assertNotNull(nd2);
    checkNamespaceProperties(nd1, NAMESPACE1_PROPS);
    checkNamespaceProperties(nd1, NAMESPACE1_PROPS);
    // Test cannot delete tables when in read only mode.
    conf.set("hbase.rest.readonly", "true");
    response = client.delete(namespacePath1);
    assertEquals(403, response.getCode());
    response = client.delete(namespacePath2);
    assertEquals(403, response.getCode());
    nd1 = findNamespace(admin, NAMESPACE1);
    nd2 = findNamespace(admin, NAMESPACE2);
    assertNotNull(nd1);
    assertNotNull(nd2);
    conf.set("hbase.rest.readonly", "false");
    // Delete namespaces via XML and JSON.
    response = client.delete(namespacePath1);
    assertEquals(200, response.getCode());
    response = client.delete(namespacePath2);
    assertEquals(200, response.getCode());
    nd1 = findNamespace(admin, NAMESPACE1);
    nd2 = findNamespace(admin, NAMESPACE2);
    assertNull(nd1);
    assertNull(nd2);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) TestNamespacesInstanceModel(org.apache.hadoop.hbase.rest.model.TestNamespacesInstanceModel) NamespacesInstanceModel(org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel) Header(org.apache.http.Header) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Aggregations

Response (org.apache.hadoop.hbase.rest.client.Response)111 Test (org.junit.Test)90 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)44 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)34 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)27 ByteArrayInputStream (java.io.ByteArrayInputStream)17 StringWriter (java.io.StringWriter)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 JacksonJaxbJsonProvider (org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)11 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)10 HashMap (java.util.HashMap)9 Admin (org.apache.hadoop.hbase.client.Admin)9 JAXBContext (javax.xml.bind.JAXBContext)8 Unmarshaller (javax.xml.bind.Unmarshaller)8 Header (org.apache.http.Header)6 Map (java.util.Map)5 StorageClusterVersionModel (org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)5 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)4 NamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel)4 TestNamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.TestNamespacesInstanceModel)4