Search in sources :

Example 86 with Response

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

the class RowResourceBase method checkAndPutValueXML.

protected static Response checkAndPutValueXML(String url, String table, String row, String column, String valueToCheck, String valueToPut, HashMap<String, String> otherCells) throws IOException, JAXBException {
    RowModel rowModel = new RowModel(row);
    rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToPut)));
    if (otherCells != null) {
        for (Map.Entry<String, String> entry : otherCells.entrySet()) {
            rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
        }
    }
    // This Cell need to be added as last cell.
    rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck)));
    CellSetModel cellSetModel = new CellSetModel();
    cellSetModel.addRow(rowModel);
    StringWriter writer = new StringWriter();
    xmlMarshaller.marshal(cellSetModel, writer);
    Response response = client.put(url, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
    Thread.yield();
    return response;
}
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)

Example 87 with Response

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

the class RowResourceBase method checkAndDeleteValuePB.

protected static Response checkAndDeleteValuePB(String url, String table, String row, String column, String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException {
    RowModel rowModel = new RowModel(row);
    if (cellsToDelete != null) {
        for (Map.Entry<String, String> entry : cellsToDelete.entrySet()) {
            rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
        }
    }
    // Add this at the end
    rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck)));
    CellSetModel cellSetModel = new CellSetModel();
    cellSetModel.addRow(rowModel);
    Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput());
    Thread.yield();
    return response;
}
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 88 with Response

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

the class TestScannersWithFilters method verifyScanNoEarlyOut.

private static void verifyScanNoEarlyOut(Scan s, long expectedRows, long expectedKeys) throws Exception {
    ScannerModel model = ScannerModel.fromScan(s);
    // fetch it all at once
    model.setBatch(Integer.MAX_VALUE);
    StringWriter writer = new StringWriter();
    marshaller.marshal(model, writer);
    LOG.debug(writer.toString());
    byte[] body = Bytes.toBytes(writer.toString());
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    assertEquals(response.getCode(), 201);
    String 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()));
    // delete the scanner
    response = client.delete(scannerURI);
    assertEquals(response.getCode(), 200);
    Iterator<RowModel> i = cellSet.getRows().iterator();
    int j = 0;
    for (boolean done = true; done; j++) {
        done = i.hasNext();
        if (!done)
            break;
        RowModel rowModel = i.next();
        List<CellModel> cells = rowModel.getCells();
        if (cells.isEmpty())
            break;
        assertTrue("Scanned too many rows! Only expected " + expectedRows + " total but already scanned " + (j + 1), expectedRows > j);
        assertEquals("Expected " + expectedKeys + " keys per row but " + "returned " + cells.size(), expectedKeys, cells.size());
    }
    assertEquals("Expected " + expectedRows + " rows but scanned " + j + " rows", expectedRows, j);
}
Also used : CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) Response(org.apache.hadoop.hbase.rest.client.Response) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel)

Example 89 with Response

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

the class TestScannersWithFilters method verifyScan.

private static void verifyScan(Scan s, long expectedRows, long expectedKeys) throws Exception {
    ScannerModel model = ScannerModel.fromScan(s);
    // fetch it all at once
    model.setBatch(Integer.MAX_VALUE);
    StringWriter writer = new StringWriter();
    marshaller.marshal(model, writer);
    LOG.debug(writer.toString());
    byte[] body = Bytes.toBytes(writer.toString());
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    assertEquals(response.getCode(), 201);
    String 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 cells = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
    int rows = cells.getRows().size();
    assertTrue("Scanned too many rows! Only expected " + expectedRows + " total but scanned " + rows, expectedRows == rows);
    for (RowModel row : cells.getRows()) {
        int count = row.getCells().size();
        assertEquals("Expected " + expectedKeys + " keys per row but " + "returned " + count, expectedKeys, count);
    }
    // delete the scanner
    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) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel)

Example 90 with Response

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

the class TestScannersWithFilters method verifyScanFull.

private static void verifyScanFull(Scan s, KeyValue[] kvs) throws Exception {
    ScannerModel model = ScannerModel.fromScan(s);
    // fetch it all at once
    model.setBatch(Integer.MAX_VALUE);
    StringWriter writer = new StringWriter();
    marshaller.marshal(model, writer);
    LOG.debug(writer.toString());
    byte[] body = Bytes.toBytes(writer.toString());
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    assertEquals(response.getCode(), 201);
    String 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()));
    // delete the scanner
    response = client.delete(scannerURI);
    assertEquals(response.getCode(), 200);
    int row = 0;
    int idx = 0;
    Iterator<RowModel> i = cellSet.getRows().iterator();
    for (boolean done = true; done; row++) {
        done = i.hasNext();
        if (!done)
            break;
        RowModel rowModel = i.next();
        List<CellModel> cells = rowModel.getCells();
        if (cells.isEmpty())
            break;
        assertTrue("Scanned too many keys! Only expected " + kvs.length + " total but already scanned " + (cells.size() + idx), kvs.length >= idx + cells.size());
        for (CellModel cell : cells) {
            assertTrue("Row mismatch", Bytes.equals(rowModel.getKey(), CellUtil.cloneRow(kvs[idx])));
            byte[][] split = KeyValue.parseColumn(cell.getColumn());
            assertTrue("Family mismatch", Bytes.equals(split[0], CellUtil.cloneFamily(kvs[idx])));
            assertTrue("Qualifier mismatch", Bytes.equals(split[1], CellUtil.cloneQualifier(kvs[idx])));
            assertTrue("Value mismatch", Bytes.equals(cell.getValue(), CellUtil.cloneValue(kvs[idx])));
            idx++;
        }
    }
    assertEquals("Expected " + kvs.length + " total keys but scanned " + idx, kvs.length, idx);
}
Also used : CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) Response(org.apache.hadoop.hbase.rest.client.Response) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel)

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