Search in sources :

Example 61 with Response

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

the class TestGetAndPutResource method testInvalidColumnPut.

@Test
public void testInvalidColumnPut() throws IOException, JAXBException {
    String dummyColumn = "doesnot:exist";
    CellSetModel cellSetModel = new CellSetModel();
    RowModel rowModel = new RowModel(ROW_1);
    rowModel.addCell(new CellModel(Bytes.toBytes(dummyColumn), Bytes.toBytes(VALUE_1)));
    cellSetModel.addRow(rowModel);
    StringWriter writer = new StringWriter();
    xmlMarshaller.marshal(cellSetModel, writer);
    final String path = "/" + TABLE + "/" + ROW_1 + "/" + dummyColumn;
    Response response = client.put(path, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
    assertEquals(response.getCode(), 404);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) StringWriter(java.io.StringWriter) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) Test(org.junit.Test)

Example 62 with Response

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

Example 63 with Response

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

the class TestScannerResource method testSimpleScannerXML.

@Test
public void testSimpleScannerXML() throws IOException, JAXBException {
    final int BATCH_SIZE = 5;
    // new scanner
    ScannerModel model = new ScannerModel();
    model.setBatch(BATCH_SIZE);
    model.addColumn(Bytes.toBytes(COLUMN_1));
    StringWriter writer = new StringWriter();
    marshaller.marshal(model, writer);
    byte[] body = Bytes.toBytes(writer.toString());
    // test put operation is forbidden in read-only mode
    conf.set("hbase.rest.readonly", "true");
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    assertEquals(response.getCode(), 403);
    String scannerURI = response.getLocation();
    assertNull(scannerURI);
    // recall previous put operation with read-only off
    conf.set("hbase.rest.readonly", "false");
    response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    assertEquals(response.getCode(), 201);
    scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    // get a cell set
    response = client.get(scannerURI, Constants.MIMETYPE_XML);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
    // confirm batch size conformance
    assertEquals(countCellSet(cellSet), BATCH_SIZE);
    // test delete scanner operation is forbidden in read-only mode
    conf.set("hbase.rest.readonly", "true");
    response = client.delete(scannerURI);
    assertEquals(response.getCode(), 403);
    // recall previous delete scanner operation with read-only off
    conf.set("hbase.rest.readonly", "false");
    response = client.delete(scannerURI);
    assertEquals(response.getCode(), 200);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) StringWriter(java.io.StringWriter) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) ByteArrayInputStream(java.io.ByteArrayInputStream) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Example 64 with Response

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

the class TestScannerResource method testTableDoesNotExist.

@Test
public void testTableDoesNotExist() throws IOException, JAXBException {
    ScannerModel model = new ScannerModel();
    StringWriter writer = new StringWriter();
    marshaller.marshal(model, writer);
    byte[] body = Bytes.toBytes(writer.toString());
    Response response = client.put("/" + NONEXISTENT_TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    String scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    response = client.get(scannerURI, Constants.MIMETYPE_XML);
    assertEquals(response.getCode(), 404);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) StringWriter(java.io.StringWriter) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Example 65 with Response

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

the class TestScannerResource method testSimpleScannerBinary.

@Test
public void testSimpleScannerBinary() throws IOException {
    // new scanner
    ScannerModel model = new ScannerModel();
    model.setBatch(1);
    model.addColumn(Bytes.toBytes(COLUMN_1));
    // test put operation is forbidden in read-only mode
    conf.set("hbase.rest.readonly", "true");
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
    assertEquals(response.getCode(), 403);
    String scannerURI = response.getLocation();
    assertNull(scannerURI);
    // recall previous put operation with read-only off
    conf.set("hbase.rest.readonly", "false");
    response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
    assertEquals(response.getCode(), 201);
    scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    // get a cell
    response = client.get(scannerURI, Constants.MIMETYPE_BINARY);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
    // verify that data was returned
    assertTrue(response.getBody().length > 0);
    // verify that the expected X-headers are present
    boolean foundRowHeader = false, foundColumnHeader = false, foundTimestampHeader = false;
    for (Header header : response.getHeaders()) {
        if (header.getName().equals("X-Row")) {
            foundRowHeader = true;
        } else if (header.getName().equals("X-Column")) {
            foundColumnHeader = true;
        } else if (header.getName().equals("X-Timestamp")) {
            foundTimestampHeader = true;
        }
    }
    assertTrue(foundRowHeader);
    assertTrue(foundColumnHeader);
    assertTrue(foundTimestampHeader);
    // test delete scanner operation is forbidden in read-only mode
    conf.set("hbase.rest.readonly", "true");
    response = client.delete(scannerURI);
    assertEquals(response.getCode(), 403);
    // recall previous delete scanner operation with read-only off
    conf.set("hbase.rest.readonly", "false");
    response = client.delete(scannerURI);
    assertEquals(response.getCode(), 200);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Header(org.apache.http.Header) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Aggregations

Response (org.apache.hadoop.hbase.rest.client.Response)91 Test (org.junit.Test)73 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)39 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)30 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)24 ByteArrayInputStream (java.io.ByteArrayInputStream)16 StringWriter (java.io.StringWriter)16 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)10 Admin (org.apache.hadoop.hbase.client.Admin)9 JAXBContext (javax.xml.bind.JAXBContext)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 JacksonJaxbJsonProvider (org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 HashMap (java.util.HashMap)4 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 Header (org.apache.http.Header)4 StorageClusterVersionModel (org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)3 TableListModel (org.apache.hadoop.hbase.rest.model.TableListModel)3