Search in sources :

Example 16 with RowModel

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

the class RowResourceBase method checkValuePB.

protected static void checkValuePB(String table, String row, String column, String value) throws IOException {
    Response response = getValuePB(table, row, column);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
    CellSetModel cellSet = new CellSetModel();
    cellSet.getObjectFromMessage(response.getBody());
    RowModel rowModel = cellSet.getRows().get(0);
    CellModel cell = rowModel.getCells().get(0);
    assertEquals(Bytes.toString(cell.getColumn()), column);
    assertEquals(Bytes.toString(cell.getValue()), value);
}
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 17 with RowModel

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

the class RowResourceBase method checkValueJSON.

protected static void checkValueJSON(String table, String row, String column, String value) throws IOException, JAXBException {
    Response response = getValueJson(table, row, column);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
    CellSetModel cellSet = mapper.readValue(response.getBody(), CellSetModel.class);
    RowModel rowModel = cellSet.getRows().get(0);
    CellModel cell = rowModel.getCells().get(0);
    assertEquals(Bytes.toString(cell.getColumn()), column);
    assertEquals(Bytes.toString(cell.getValue()), value);
}
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) JacksonJaxbJsonProvider(org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 18 with RowModel

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

the class RowResourceBase method putValuePB.

static Response putValuePB(String url, String table, String row, String column, String value) throws IOException {
    RowModel rowModel = new RowModel(row);
    rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value)));
    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 19 with RowModel

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

the class RowResourceBase method checkValueXML.

protected static void checkValueXML(String url, String table, String row, String column, String value) throws IOException, JAXBException {
    Response response = getValueXML(url);
    assertEquals(response.getCode(), 200);
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
    RowModel rowModel = cellSet.getRows().get(0);
    CellModel cell = rowModel.getCells().get(0);
    assertEquals(Bytes.toString(cell.getColumn()), column);
    assertEquals(Bytes.toString(cell.getValue()), value);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) ByteArrayInputStream(java.io.ByteArrayInputStream) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel)

Example 20 with RowModel

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

the class TableScanResource method get.

@GET
@Produces({ Constants.MIMETYPE_XML, Constants.MIMETYPE_JSON })
public CellSetModelStream get(@Context final UriInfo uriInfo) {
    servlet.getMetrics().incrementRequests(1);
    final int rowsToSend = userRequestedLimit;
    servlet.getMetrics().incrementSucessfulScanRequests(1);
    final Iterator<Result> itr = results.iterator();
    return new CellSetModelStream(new ArrayList<RowModel>() {

        public Iterator<RowModel> iterator() {
            return new Iterator<RowModel>() {

                int count = rowsToSend;

                @Override
                public boolean hasNext() {
                    if (count > 0) {
                        return itr.hasNext();
                    } else {
                        return false;
                    }
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Remove method cannot be used in CellSetModelStream");
                }

                @Override
                public RowModel next() {
                    Result rs = itr.next();
                    if ((rs == null) || (count <= 0)) {
                        return null;
                    }
                    byte[] rowKey = rs.getRow();
                    RowModel rModel = new RowModel(rowKey);
                    List<Cell> kvs = rs.listCells();
                    for (Cell kv : kvs) {
                        rModel.addCell(new CellModel(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv), kv.getTimestamp(), CellUtil.cloneValue(kv)));
                    }
                    count--;
                    return rModel;
                }
            };
        }
    });
}
Also used : Result(org.apache.hadoop.hbase.client.Result) Iterator(java.util.Iterator) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) ArrayList(java.util.ArrayList) List(java.util.List) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) Cell(org.apache.hadoop.hbase.Cell) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

RowModel (org.apache.hadoop.hbase.rest.model.RowModel)44 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)37 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)35 Response (org.apache.hadoop.hbase.rest.client.Response)30 Test (org.junit.Test)15 StringWriter (java.io.StringWriter)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Cell (org.apache.hadoop.hbase.Cell)8 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)4 JAXBContext (javax.xml.bind.JAXBContext)3 Unmarshaller (javax.xml.bind.Unmarshaller)3 Put (org.apache.hadoop.hbase.client.Put)3 Result (org.apache.hadoop.hbase.client.Result)3 Table (org.apache.hadoop.hbase.client.Table)3 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)3 JacksonJaxbJsonProvider (org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider)3