ScannerModel model = new ScannerModel(); model.setStartRow(scan.getStartRow()); model.setEndRow(scan.getStopRow()); Map<byte [], NavigableSet<byte []>> families = scan.getFamilyMap(); if (families != null) { if (entry.getValue() != null) { for (byte[] qualifier: entry.getValue()) { model.addColumn(Bytes.add(entry.getKey(), COLUMN_DIVIDER, qualifier)); model.addColumn(entry.getKey()); model.setStartTime(scan.getTimeRange().getMin()); model.setEndTime(scan.getTimeRange().getMax()); int caching = scan.getCaching(); if (caching > 0) { model.setCaching(caching); model.setBatch(batch); model.setMaxVersions(maxVersions); model.setFilter(stringifyFilter(filter)); List<String> labels = authorizations.getLabels(); for (String label : labels) { model.addLabel(label);
@Test public void testSimpleScannerBinary() throws IOException { ScannerModel model = new ScannerModel(); model.setBatch(1); model.addColumn(Bytes.toBytes(COLUMN_1)); Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); assertEquals(403, response.getCode()); String scannerURI = response.getLocation(); Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); assertEquals(201, response.getCode()); scannerURI = response.getLocation();
@Override protected ScannerModel buildTestModel() { ScannerModel model = new ScannerModel(); model.setStartRow(START_ROW); model.setEndRow(END_ROW); model.addColumn(COLUMN1); model.addColumn(COLUMN2); model.setStartTime(START_TIME); model.setEndTime(END_TIME); model.setBatch(BATCH); model.setCaching(CACHING); model.addLabel(PRIVATE); model.addLabel(PUBLIC); model.setCacheBlocks(CACHE_BLOCKS); return model; }
private void verifyException(final String FILTER) throws Exception { ScannerModel model = new ScannerModel(); model.setFilter(FILTER); ScannerResultGenerator.buildFilterFromModel(model); } }
public Scanner(Scan scan) throws IOException { ScannerModel model; try { model = ScannerModel.fromScan(scan); } catch (Exception e) { throw new IOException(e); for (int i = 0; i < maxRetries; i++) { Response response = client.post(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); int code = response.getCode(); switch (code) {
.build(); byte[] endRow = model.hasEndRow() ? model.getEndRow() : null; RowSpec spec = null; if (model.getLabels() != null) { spec = new RowSpec(model.getStartRow(), endRow, model.getColumns(), model.getStartTime(), model.getEndTime(), model.getMaxVersions(), model.getLabels()); } else { spec = new RowSpec(model.getStartRow(), endRow, model.getColumns(), model.getStartTime(), model.getEndTime(), model.getMaxVersions()); String tableName = tableResource.getName(); ScannerResultGenerator gen = new ScannerResultGenerator(tableName, spec, filter, model.getCaching(), model.getCacheBlocks()); String id = gen.getID(); ScannerInstanceResource instance = new ScannerInstanceResource(tableName, id, gen, model.getBatch()); scanners.put(id, instance); if (LOG.isTraceEnabled()) {
@Test public void testSimpleScannerXMLWithLabelsThatReceivesNoData() throws IOException, JAXBException { final int BATCH_SIZE = 5; // new scanner ScannerModel model = new ScannerModel(); model.setBatch(BATCH_SIZE); model.addColumn(Bytes.toBytes(COLUMN_1)); model.addLabel(PUBLIC); 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(204, response.getCode()); // With no content in the payload, the 'Content-Type' header is not echo back }
.build(); byte[] endRow = model.hasEndRow() ? model.getEndRow() : null; RowSpec spec = new RowSpec(model.getStartRow(), endRow, model.getColumns(), model.getStartTime(), model.getEndTime(), model.getMaxVersions()); try { Filter filter = ScannerResultGenerator.buildFilterFromModel(model); String id = gen.getID(); ScannerInstanceResource instance = new ScannerInstanceResource(tableName, id, gen, model.getBatch()); scanners.put(id, instance); if (LOG.isDebugEnabled()) {
@Test public void testTableScanWithTableDisable() throws IOException { ScannerModel model = new ScannerModel(); model.addColumn(Bytes.toBytes(COLUMN_1)); model.setCaching(1); Response response = client.put("/" + TABLE_TO_BE_DISABLED + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput()); assertEquals(201, response.getCode()); String scannerURI = response.getLocation(); assertNotNull(scannerURI); TEST_UTIL.getAdmin().disableTable(TABLE_TO_BE_DISABLED); response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF); assertTrue("got " + response.getCode(), response.getCode() == 410); }
final int BATCH_SIZE = 5; ScannerModel model = new ScannerModel(); model.setBatch(BATCH_SIZE); model.addColumn(Bytes.toBytes(COLUMN_1)); StringWriter writer = new StringWriter(); marshaller.marshal(model, writer);
@Test public void testFullTableScan() throws IOException { ScannerModel model = new ScannerModel(); model.addColumn(Bytes.toBytes(COLUMN_1)); assertEquals(expectedRows1, fullTableScan(model)); model = new ScannerModel(); model.addColumn(Bytes.toBytes(COLUMN_2)); assertEquals(expectedRows2, fullTableScan(model)); }
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();
builder.setEndTime(endTime); builder.setBatch(getBatch()); if (caching > 0) { builder.setCaching(caching);
@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(404, response.getCode()); }
/** * @param routingContext * @return the scanner * @throws IOException */ private ScannerModel getScannerModel(RoutingContext routingContext) throws IOException { final ScannerModel scannerModel = new ScannerModel(); final byte[] rawMessage = routingContext.getBody().getBytes(); // deserialise from protobuf scannerModel.getObjectFromMessage(rawMessage); return scannerModel; }
addColumn(column.toByteArray());
@Override protected void checkModel(ScannerModel model) { assertTrue(Bytes.equals(model.getStartRow(), START_ROW)); assertTrue(Bytes.equals(model.getEndRow(), END_ROW)); boolean foundCol1 = false, foundCol2 = false; for (byte[] column : model.getColumns()) { if (Bytes.equals(column, COLUMN1)) { foundCol1 = true; assertEquals(START_TIME, model.getStartTime()); assertEquals(END_TIME, model.getEndTime()); assertEquals(BATCH, model.getBatch()); assertEquals(CACHING, model.getCaching()); assertEquals(CACHE_BLOCKS, model.getCacheBlocks()); boolean foundLabel1 = false; boolean foundLabel2 = false; if (model.getLabels() != null && model.getLabels().size() > 0) { for (String label : model.getLabels()) { if (label.equals(PRIVATE)) { foundLabel1 = true;
@Override protected ScannerModel buildTestModel() { ScannerModel model = new ScannerModel(); model.setStartRow(START_ROW); model.setEndRow(END_ROW); model.addColumn(COLUMN1); model.addColumn(COLUMN2); model.setStartTime(START_TIME); model.setEndTime(END_TIME); model.setBatch(BATCH); model.setCaching(CACHING); model.addLabel(PRIVATE); model.addLabel(PUBLIC); model.setCacheBlocks(CACHE_BLOCKS); return model; }