Search in sources :

Example 6 with CellSetModel

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

the class TestScannersWithLabels method testSimpleScannerXMLWithLabelsThatReceivesData.

@Test
public void testSimpleScannerXMLWithLabelsThatReceivesData() throws IOException, JAXBException {
    // new scanner
    ScannerModel model = new ScannerModel();
    model.setBatch(5);
    model.addColumn(Bytes.toBytes(COLUMN_1));
    model.addLabel(SECRET);
    StringWriter writer = new StringWriter();
    marshaller.marshal(model, writer);
    byte[] body = Bytes.toBytes(writer.toString());
    // recall previous put operation with read-only off
    conf.set("hbase.rest.readonly", "false");
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    assertEquals(201, response.getCode());
    String scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    // get a cell set
    response = client.get(scannerURI, Constants.MIMETYPE_XML);
    // Respond with 204 as there are no cells to be retrieved
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
    assertEquals(5, countCellSet(cellSet));
}
Also used : VisibilityLabelsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse) 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 7 with CellSetModel

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

the class TestScannerResource method testSimpleScannerPB.

@Test
public void testSimpleScannerPB() throws IOException {
    final int BATCH_SIZE = 10;
    // new scanner
    ScannerModel model = new ScannerModel();
    model.setBatch(BATCH_SIZE);
    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(403, response.getCode());
    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(201, response.getCode());
    scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    // get a cell set
    response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
    CellSetModel cellSet = new CellSetModel();
    cellSet.getObjectFromMessage(response.getBody());
    // confirm batch size conformance
    assertEquals(BATCH_SIZE, countCellSet(cellSet));
    // test delete scanner operation is forbidden in read-only mode
    conf.set("hbase.rest.readonly", "true");
    response = client.delete(scannerURI);
    assertEquals(403, response.getCode());
    // recall previous delete scanner operation with read-only off
    conf.set("hbase.rest.readonly", "false");
    response = client.delete(scannerURI);
    assertEquals(200, response.getCode());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Example 8 with CellSetModel

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

the class TestScannerResource method fullTableScan.

private static int fullTableScan(ScannerModel model) throws IOException {
    model.setBatch(100);
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
    assertEquals(201, response.getCode());
    String scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    int count = 0;
    while (true) {
        response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
        assertTrue(response.getCode() == 200 || response.getCode() == 204);
        if (response.getCode() == 200) {
            assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
            CellSetModel cellSet = new CellSetModel();
            cellSet.getObjectFromMessage(response.getBody());
            Iterator<RowModel> rows = cellSet.getRows().iterator();
            while (rows.hasNext()) {
                RowModel row = rows.next();
                Iterator<CellModel> cells = row.getCells().iterator();
                while (cells.hasNext()) {
                    cells.next();
                    count++;
                }
            }
        } else {
            break;
        }
    }
    // delete the scanner
    response = client.delete(scannerURI);
    assertEquals(200, response.getCode());
    return count;
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel)

Example 9 with CellSetModel

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

the class TestGetAndPutResource method testMultiCellGetPutXML.

@Test
public void testMultiCellGetPutXML() throws IOException, JAXBException {
    // deliberate nonexistent row
    String path = "/" + TABLE + "/fakerow";
    CellSetModel cellSetModel = new CellSetModel();
    RowModel rowModel = new RowModel(ROW_1);
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
    cellSetModel.addRow(rowModel);
    rowModel = new RowModel(ROW_2);
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3)));
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4)));
    cellSetModel.addRow(rowModel);
    StringWriter writer = new StringWriter();
    xmlMarshaller.marshal(cellSetModel, writer);
    Response response = client.put(path, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
    Thread.yield();
    // make sure the fake row was not actually created
    response = client.get(path, Constants.MIMETYPE_XML);
    assertEquals(404, response.getCode());
    // check that all of the values were created
    checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1);
    checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2);
    checkValueXML(TABLE, ROW_2, COLUMN_1, VALUE_3);
    checkValueXML(TABLE, ROW_2, COLUMN_2, VALUE_4);
    response = deleteRow(TABLE, ROW_1);
    assertEquals(200, response.getCode());
    response = deleteRow(TABLE, ROW_2);
    assertEquals(200, response.getCode());
}
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 10 with CellSetModel

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

the class TestGetAndPutResource method testMultiCellGetJson.

@Test
public void testMultiCellGetJson() throws IOException, JAXBException {
    // deliberate nonexistent row
    String path = "/" + TABLE + "/fakerow";
    CellSetModel cellSetModel = new CellSetModel();
    RowModel rowModel = new RowModel(ROW_1);
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
    cellSetModel.addRow(rowModel);
    rowModel = new RowModel(ROW_2);
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3)));
    rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4)));
    cellSetModel.addRow(rowModel);
    String jsonString = jsonMapper.writeValueAsString(cellSetModel);
    Response response = client.put(path, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
    Thread.yield();
    // make sure the fake row was not actually created
    response = client.get(path, Constants.MIMETYPE_JSON);
    assertEquals(404, response.getCode());
    // check that all of the values were created
    checkValueJSON(TABLE, ROW_1, COLUMN_1, VALUE_1);
    checkValueJSON(TABLE, ROW_1, COLUMN_2, VALUE_2);
    checkValueJSON(TABLE, ROW_2, COLUMN_1, VALUE_3);
    checkValueJSON(TABLE, ROW_2, COLUMN_2, VALUE_4);
    response = deleteRow(TABLE, ROW_1);
    assertEquals(200, response.getCode());
    response = deleteRow(TABLE, ROW_2);
    assertEquals(200, response.getCode());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) Test(org.junit.Test)

Aggregations

CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)61 Response (org.apache.hadoop.hbase.rest.client.Response)44 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)42 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)37 Test (org.junit.Test)26 StringWriter (java.io.StringWriter)14 IOException (java.io.IOException)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 Cell (org.apache.hadoop.hbase.Cell)9 JacksonJaxbJsonProvider (org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)9 InterruptedIOException (java.io.InterruptedIOException)7 JAXBContext (javax.xml.bind.JAXBContext)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 Map (java.util.Map)6 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)6 HashMap (java.util.HashMap)5 Result (org.apache.hadoop.hbase.client.Result)5 KeyValue (org.apache.hadoop.hbase.KeyValue)4 Put (org.apache.hadoop.hbase.client.Put)3