org.apache.hadoop.hbase.security.visibility.Authorizations Java Examples

The following examples show how to use org.apache.hadoop.hbase.security.visibility.Authorizations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HBase_2_ClientService.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected ResultScanner getResults(final Table table, final byte[] startRow, final byte[] endRow, final Collection<Column> columns, List<String> authorizations) throws IOException {
    final Scan scan = new Scan();
    scan.setStartRow(startRow);
    scan.setStopRow(endRow);

    if (authorizations != null && authorizations.size() > 0) {
        scan.setAuthorizations(new Authorizations(authorizations));
    }

    if (columns != null && columns.size() > 0) {
        for (Column col : columns) {
            if (col.getQualifier() == null) {
                scan.addFamily(col.getFamily());
            } else {
                scan.addColumn(col.getFamily(), col.getQualifier());
            }
        }
    }

    return table.getScanner(scan);
}
 
Example #2
Source File: IntegrationTestWithCellVisibilityLoadAndVerify.java    From hbase with Apache License 2.0 6 votes vote down vote up
private Job doVerify(Configuration conf, TableDescriptor tableDescriptor, String... auths)
    throws IOException, InterruptedException, ClassNotFoundException {
  Path outputDir = getTestDir(TEST_NAME, "verify-output");
  Job job = new Job(conf);
  job.setJarByClass(this.getClass());
  job.setJobName(TEST_NAME + " Verification for " + tableDescriptor.getTableName());
  setJobScannerConf(job);
  Scan scan = new Scan();
  scan.setAuthorizations(new Authorizations(auths));
  TableMapReduceUtil.initTableMapperJob(tableDescriptor.getTableName().getNameAsString(), scan,
      VerifyMapper.class, NullWritable.class, NullWritable.class, job);
  TableMapReduceUtil.addDependencyJarsForClasses(job.getConfiguration(), AbstractHBaseTool.class);
  int scannerCaching = conf.getInt("verify.scannercaching", SCANNER_CACHING);
  TableMapReduceUtil.setScannerCaching(job, scannerCaching);
  job.setNumReduceTasks(0);
  FileOutputFormat.setOutputPath(job, outputDir);
  assertTrue(job.waitForCompletion(true));
  return job;
}
 
Example #3
Source File: HBase_1_1_2_ClientService.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected ResultScanner getResults(final Table table, final byte[] startRow, final byte[] endRow, final Collection<Column> columns, List<String> authorizations) throws IOException {
    final Scan scan = new Scan();
    scan.setStartRow(startRow);
    scan.setStopRow(endRow);

    if (authorizations != null && authorizations.size() > 0) {
        scan.setAuthorizations(new Authorizations(authorizations));
    }

    if (columns != null && columns.size() > 0) {
        for (Column col : columns) {
            if (col.getQualifier() == null) {
                scan.addFamily(col.getFamily());
            } else {
                scan.addColumn(col.getFamily(), col.getQualifier());
            }
        }
    }

    return table.getScanner(scan);
}
 
Example #4
Source File: TestScan.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetAuthorizations() {
  Scan scan = new Scan();
  try {
    scan.setAuthorizations(new Authorizations("\u002b|\u0029"));
    scan.setAuthorizations(new Authorizations("A", "B", "0123", "A0", "1A1", "_a"));
    scan.setAuthorizations(new Authorizations("A|B"));
    scan.setAuthorizations(new Authorizations("A&B"));
    scan.setAuthorizations(new Authorizations("!B"));
    scan.setAuthorizations(new Authorizations("A", "(A)"));
    scan.setAuthorizations(new Authorizations("A", "{A"));
    scan.setAuthorizations(new Authorizations(" "));
    scan.setAuthorizations(new Authorizations(":B"));
    scan.setAuthorizations(new Authorizations("-B"));
    scan.setAuthorizations(new Authorizations(".B"));
    scan.setAuthorizations(new Authorizations("/B"));
  } catch (IllegalArgumentException e) {
    fail("should not throw exception");
  }
}
 
Example #5
Source File: HBase_2_ClientService.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected ResultScanner getResults(final Table table, final Collection<Column> columns, final Filter filter, final long minTime, List<String> authorizations) throws IOException {
    // Create a new scan. We will set the min timerange as the latest timestamp that
    // we have seen so far. The minimum timestamp is inclusive, so we will get duplicates.
    // We will record any cells that have the latest timestamp, so that when we scan again,
    // we know to throw away those duplicates.
    final Scan scan = new Scan();
    scan.setTimeRange(minTime, Long.MAX_VALUE);

    if (authorizations != null && authorizations.size() > 0) {
        scan.setAuthorizations(new Authorizations(authorizations));
    }

    if (filter != null) {
        scan.setFilter(filter);
    }

    if (columns != null) {
        for (Column col : columns) {
            if (col.getQualifier() == null) {
                scan.addFamily(col.getFamily());
            } else {
                scan.addColumn(col.getFamily(), col.getQualifier());
            }
        }
    }

    return table.getScanner(scan);
}
 
Example #6
Source File: HBase_1_1_2_ClientService.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected ResultScanner getResults(final Table table, final Collection<Column> columns, final Filter filter, final long minTime, List<String> authorizations) throws IOException {
    // Create a new scan. We will set the min timerange as the latest timestamp that
    // we have seen so far. The minimum timestamp is inclusive, so we will get duplicates.
    // We will record any cells that have the latest timestamp, so that when we scan again,
    // we know to throw away those duplicates.
    final Scan scan = new Scan();
    scan.setTimeRange(minTime, Long.MAX_VALUE);

    if (authorizations != null && authorizations.size() > 0) {
        scan.setAuthorizations(new Authorizations(authorizations));
    }

    if (filter != null) {
        scan.setFilter(filter);
    }

    if (columns != null) {
        for (Column col : columns) {
            if (col.getQualifier() == null) {
                scan.addFamily(col.getFamily());
            } else {
                scan.addColumn(col.getFamily(), col.getQualifier());
            }
        }
    }

    return table.getScanner(scan);
}
 
Example #7
Source File: HBaseOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
public Iterator<GeoWaveRow> getDataIndexResults(
    final byte[][] rows,
    final short adapterId,
    final String... additionalAuthorizations) {
  Result[] results = null;
  final byte[] family = StringUtils.stringToBinary(ByteArrayUtils.shortToString(adapterId));
  try (final Table table = conn.getTable(getTableName(DataIndexUtils.DATA_ID_INDEX.getName()))) {
    results = table.get(Arrays.stream(rows).map(r -> {
      final Get g = new Get(r);
      g.addFamily(family);
      if ((additionalAuthorizations != null) && (additionalAuthorizations.length > 0)) {
        g.setAuthorizations(new Authorizations(additionalAuthorizations));
      }
      return g;
    }).collect(Collectors.toList()));
  } catch (final IOException e) {
    LOGGER.error("Unable to close HBase table", e);
  }
  if (results != null) {
    return Arrays.stream(results).filter(r -> r.containsColumn(family, new byte[0])).map(
        r -> DataIndexUtils.deserializeDataIndexRow(
            r.getRow(),
            adapterId,
            r.getValue(family, new byte[0]),
            false)).iterator();
  }
  return Collections.emptyIterator();
}
 
Example #8
Source File: HBaseOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
public Iterator<GeoWaveRow> getDataIndexResults(
    final byte[] startRow,
    final byte[] endRow,
    final short adapterId,
    final String... additionalAuthorizations) {
  Result[] results = null;
  final byte[] family = StringUtils.stringToBinary(ByteArrayUtils.shortToString(adapterId));
  final Scan scan = new Scan();
  if (startRow != null) {
    scan.setStartRow(startRow);
  }
  if (endRow != null) {
    scan.setStopRow(HBaseUtils.getInclusiveEndKey(endRow));
  }
  if ((additionalAuthorizations != null) && (additionalAuthorizations.length > 0)) {
    scan.setAuthorizations(new Authorizations(additionalAuthorizations));
  }
  Iterable<Result> s = null;
  try {
    s = getScannedResults(scan, DataIndexUtils.DATA_ID_INDEX.getName());
    results = Iterators.toArray(s.iterator(), Result.class);
  } catch (final IOException e) {
    LOGGER.error("Unable to close HBase table", e);
  } finally {
    if (s instanceof ResultScanner) {
      ((ResultScanner) s).close();
    }
  }
  if (results != null) {
    return Arrays.stream(results).filter(r -> r.containsColumn(family, new byte[0])).map(
        r -> DataIndexUtils.deserializeDataIndexRow(
            r.getRow(),
            adapterId,
            r.getValue(family, new byte[0]),
            false)).iterator();
  }
  return Collections.emptyIterator();
}
 
Example #9
Source File: TestGet.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void TestGetRowFromGetCopyConstructor() throws Exception {
  Get get = new Get(ROW);
  get.setFilter(null);
  get.setAuthorizations(new Authorizations("foo"));
  get.setACL("u", new Permission(Permission.Action.READ));
  get.setConsistency(Consistency.TIMELINE);
  get.setReplicaId(2);
  get.setIsolationLevel(IsolationLevel.READ_UNCOMMITTED);
  get.setCheckExistenceOnly(true);
  get.setTimeRange(3, 4);
  get.readVersions(11);
  get.setMaxResultsPerColumnFamily(10);
  get.setRowOffsetPerColumnFamily(11);
  get.setCacheBlocks(true);

  Get copyGet = new Get(get);
  assertEquals(0, Bytes.compareTo(get.getRow(), copyGet.getRow()));

  // from OperationWithAttributes
  assertEquals(get.getId(), copyGet.getId());

  // from Query class
  assertEquals(get.getFilter(), copyGet.getFilter());
  assertTrue(get.getAuthorizations().toString().equals(copyGet.getAuthorizations().toString()));
  assertTrue(Bytes.equals(get.getACL(), copyGet.getACL()));
  assertEquals(get.getConsistency(), copyGet.getConsistency());
  assertEquals(get.getReplicaId(), copyGet.getReplicaId());
  assertEquals(get.getIsolationLevel(), copyGet.getIsolationLevel());

  // from Get class
  assertEquals(get.isCheckExistenceOnly(), copyGet.isCheckExistenceOnly());
  assertTrue(get.getTimeRange().equals(copyGet.getTimeRange()));
  assertEquals(get.getMaxVersions(), copyGet.getMaxVersions());
  assertEquals(get.getMaxResultsPerColumnFamily(), copyGet.getMaxResultsPerColumnFamily());
  assertEquals(get.getRowOffsetPerColumnFamily(), copyGet.getRowOffsetPerColumnFamily());
  assertEquals(get.getCacheBlocks(), copyGet.getCacheBlocks());
  assertEquals(get.getId(), copyGet.getId());
}
 
Example #10
Source File: IntegrationTestBigLinkedListWithVisibility.java    From hbase with Apache License 2.0 5 votes vote down vote up
private int doVerify(Path outputDir, int numReducers) throws IOException, InterruptedException,
    ClassNotFoundException {
  job = new Job(getConf());

  job.setJobName("Link Verifier");
  job.setNumReduceTasks(numReducers);
  job.setJarByClass(getClass());

  setJobScannerConf(job);

  Scan scan = new Scan();
  scan.addColumn(FAMILY_NAME, COLUMN_PREV);
  scan.setCaching(10000);
  scan.setCacheBlocks(false);
  String[] split = labels.split(COMMA);

  scan.setAuthorizations(new Authorizations(split[this.labelIndex * 2],
      split[(this.labelIndex * 2) + 1]));

  TableMapReduceUtil.initTableMapperJob(tableName.getName(), scan, VerifyMapper.class,
      BytesWritable.class, BytesWritable.class, job);
  TableMapReduceUtil.addDependencyJars(job.getConfiguration(), AbstractHBaseTool.class);

  job.getConfiguration().setBoolean("mapreduce.map.speculative", false);

  job.setReducerClass(VerifyReducer.class);
  job.setOutputFormatClass(TextOutputFormat.class);
  TextOutputFormat.setOutputPath(job, outputDir);
  boolean success = job.waitForCompletion(true);

  return success ? 0 : 1;
}
 
Example #11
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a protocol buffer Authorizations bytes to a client Authorizations
 *
 * @param protoBytes
 * @return the converted client Authorizations
 * @throws DeserializationException
 */
public static Authorizations toAuthorizations(byte[] protoBytes) throws DeserializationException {
  if (protoBytes == null) return null;
  ClientProtos.Authorizations.Builder builder = ClientProtos.Authorizations.newBuilder();
  ClientProtos.Authorizations proto = null;
  try {
    ProtobufUtil.mergeFrom(builder, protoBytes);
    proto = builder.build();
  } catch (IOException e) {
    throw new DeserializationException(e);
  }
  return toAuthorizations(proto);
}
 
Example #12
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Create a protocol buffer Authorizations based on a client Authorizations.
 *
 * @param authorizations
 * @return a protocol buffer Authorizations
 */
public static ClientProtos.Authorizations toAuthorizations(Authorizations authorizations) {
  ClientProtos.Authorizations.Builder builder = ClientProtos.Authorizations.newBuilder();
  for (String label : authorizations.getLabels()) {
    builder.addLabel(label);
  }
  return builder.build();
}
 
Example #13
Source File: ScannerResultGenerator.java    From hbase with Apache License 2.0 4 votes vote down vote up
public ScannerResultGenerator(final String tableName, final RowSpec rowspec,
  final Filter filter, final int caching ,final boolean cacheBlocks, int limit) throws IOException {
  Table table = RESTServlet.getInstance().getTable(tableName);
  try {
    Scan scan;
    if (rowspec.hasEndRow()) {
      scan = new Scan().withStartRow(rowspec.getStartRow()).withStopRow(rowspec.getEndRow());
    } else {
      scan = new Scan().withStartRow(rowspec.getStartRow());
    }
    if (rowspec.hasColumns()) {
      byte[][] columns = rowspec.getColumns();
      for (byte[] column: columns) {
        byte[][] split = CellUtil.parseColumn(column);
        if (split.length == 1) {
          scan.addFamily(split[0]);
        } else if (split.length == 2) {
          scan.addColumn(split[0], split[1]);
        } else {
          throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
        }
      }
    }
    scan.setTimeRange(rowspec.getStartTime(), rowspec.getEndTime());
    scan.readVersions(rowspec.getMaxVersions());
    if (filter != null) {
      scan.setFilter(filter);
    }
    if (caching > 0 ) {
      scan.setCaching(caching);
    }
    if (limit > 0) {
      scan.setLimit(limit);
    }
    scan.setCacheBlocks(cacheBlocks);
    if (rowspec.hasLabels()) {
      scan.setAuthorizations(new Authorizations(rowspec.getLabels()));
    }
    scanner = table.getScanner(scan);
    cached = null;
    id = Long.toString(System.currentTimeMillis()) +
           Integer.toHexString(scanner.hashCode());
  } finally {
    table.close();
  }
}
 
Example #14
Source File: ThriftUtilities.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a {@link Get} (HBase) from a {@link TGet} (Thrift).
 *
 * This ignores any timestamps set on {@link TColumn} objects.
 *
 * @param in the <code>TGet</code> to convert
 *
 * @return <code>Get</code> object
 *
 * @throws IOException if an invalid time range or max version parameter is given
 */
public static Get getFromThrift(TGet in) throws IOException {
  Get out = new Get(in.getRow());

  // Timestamp overwrites time range if both are set
  if (in.isSetTimestamp()) {
    out.setTimestamp(in.getTimestamp());
  } else if (in.isSetTimeRange()) {
    out.setTimeRange(in.getTimeRange().getMinStamp(), in.getTimeRange().getMaxStamp());
  }

  if (in.isSetMaxVersions()) {
    out.readVersions(in.getMaxVersions());
  }

  if (in.isSetFilterString()) {
    ParseFilter parseFilter = new ParseFilter();
    out.setFilter(parseFilter.parseFilterString(in.getFilterString()));
  }

  if (in.isSetAttributes()) {
    addAttributes(out,in.getAttributes());
  }

  if (in.isSetAuthorizations()) {
    out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels()));
  }

  if (in.isSetConsistency()) {
    out.setConsistency(consistencyFromThrift(in.getConsistency()));
  }

  if (in.isSetTargetReplicaId()) {
    out.setReplicaId(in.getTargetReplicaId());
  }

  if (in.isSetCacheBlocks()) {
    out.setCacheBlocks(in.isCacheBlocks());
  }
  if (in.isSetStoreLimit()) {
    out.setMaxResultsPerColumnFamily(in.getStoreLimit());
  }
  if (in.isSetStoreOffset()) {
    out.setRowOffsetPerColumnFamily(in.getStoreOffset());
  }
  if (in.isSetExistence_only()) {
    out.setCheckExistenceOnly(in.isExistence_only());
  }

  if (in.isSetColumns()) {
    for (TColumn column : in.getColumns()) {
      if (column.isSetQualifier()) {
        out.addColumn(column.getFamily(), column.getQualifier());
      } else {
        out.addFamily(column.getFamily());
      }
    }
  }

  if (in.isSetFilterBytes()) {
    out.setFilter(filterFromThrift(in.getFilterBytes()));
  }
  return out;
}
 
Example #15
Source File: ThriftUtilities.java    From hbase with Apache License 2.0 4 votes vote down vote up
public static Scan scanFromThrift(TScan in) throws IOException {
  Scan out = new Scan();

  if (in.isSetStartRow()) {
    out.withStartRow(in.getStartRow());
  }
  if (in.isSetStopRow()) {
    out.withStopRow(in.getStopRow());
  }
  if (in.isSetCaching()) {
    out.setCaching(in.getCaching());
  }
  if (in.isSetMaxVersions()) {
    out.readVersions(in.getMaxVersions());
  }

  if (in.isSetColumns()) {
    for (TColumn column : in.getColumns()) {
      if (column.isSetQualifier()) {
        out.addColumn(column.getFamily(), column.getQualifier());
      } else {
        out.addFamily(column.getFamily());
      }
    }
  }

  TTimeRange timeRange = in.getTimeRange();
  if (timeRange != null &&
      timeRange.isSetMinStamp() && timeRange.isSetMaxStamp()) {
    out.setTimeRange(timeRange.getMinStamp(), timeRange.getMaxStamp());
  }

  if (in.isSetBatchSize()) {
    out.setBatch(in.getBatchSize());
  }

  if (in.isSetFilterString()) {
    ParseFilter parseFilter = new ParseFilter();
    out.setFilter(parseFilter.parseFilterString(in.getFilterString()));
  }

  if (in.isSetAttributes()) {
    addAttributes(out,in.getAttributes());
  }

  if (in.isSetAuthorizations()) {
    out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels()));
  }

  if (in.isSetReversed()) {
    out.setReversed(in.isReversed());
  }

  if (in.isSetCacheBlocks()) {
    out.setCacheBlocks(in.isCacheBlocks());
  }

  if (in.isSetColFamTimeRangeMap()) {
    Map<ByteBuffer, TTimeRange> colFamTimeRangeMap = in.getColFamTimeRangeMap();
    if (MapUtils.isNotEmpty(colFamTimeRangeMap)) {
      for (Map.Entry<ByteBuffer, TTimeRange> entry : colFamTimeRangeMap.entrySet()) {
        out.setColumnFamilyTimeRange(Bytes.toBytes(entry.getKey()),
            entry.getValue().getMinStamp(), entry.getValue().getMaxStamp());
      }
    }
  }

  if (in.isSetReadType()) {
    out.setReadType(readTypeFromThrift(in.getReadType()));
  }

  if (in.isSetLimit()) {
    out.setLimit(in.getLimit());
  }

  if (in.isSetConsistency()) {
    out.setConsistency(consistencyFromThrift(in.getConsistency()));
  }

  if (in.isSetTargetReplicaId()) {
    out.setReplicaId(in.getTargetReplicaId());
  }

  if (in.isSetFilterBytes()) {
    out.setFilter(filterFromThrift(in.getFilterBytes()));
  }

  return out;
}
 
Example #16
Source File: HBase_2_ClientService.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected ResultScanner getResults(final Table table, final String startRow, final String endRow, final String filterExpression, final Long timerangeMin, final Long timerangeMax,
        final Integer limitRows, final Boolean isReversed, final Boolean blockCache, final Collection<Column> columns, List<String> authorizations)  throws IOException {
    final Scan scan = new Scan();
    if (!StringUtils.isBlank(startRow)){
        scan.setStartRow(startRow.getBytes(StandardCharsets.UTF_8));
    }
    if (!StringUtils.isBlank(endRow)){
        scan.setStopRow(   endRow.getBytes(StandardCharsets.UTF_8));
    }

    if (authorizations != null && authorizations.size() > 0) {
        scan.setAuthorizations(new Authorizations(authorizations));
    }

    Filter filter = null;
    if (columns != null) {
        for (Column col : columns) {
            if (col.getQualifier() == null) {
                scan.addFamily(col.getFamily());
            } else {
                scan.addColumn(col.getFamily(), col.getQualifier());
            }
        }
    }
    if (!StringUtils.isBlank(filterExpression)) {
        ParseFilter parseFilter = new ParseFilter();
        filter = parseFilter.parseFilterString(filterExpression);
    }
    if (filter != null){
        scan.setFilter(filter);
    }

    if (timerangeMin != null && timerangeMax != null){
        scan.setTimeRange(timerangeMin, timerangeMax);
    }

    // ->>> reserved for HBase v 2 or later
    //if (limitRows != null && limitRows > 0){
    //    scan.setLimit(limitRows)
    //}

    if (isReversed != null){
        scan.setReversed(isReversed);
    }

    scan.setCacheBlocks(blockCache);

    return table.getScanner(scan);
}
 
Example #17
Source File: HBase_1_1_2_ClientService.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected ResultScanner getResults(final Table table, final String startRow, final String endRow, final String filterExpression, final Long timerangeMin, final Long timerangeMax,
        final Integer limitRows, final Boolean isReversed, final Boolean blockCache, final Collection<Column> columns, List<String> authorizations)  throws IOException {
    final Scan scan = new Scan();
    if (!StringUtils.isBlank(startRow)){
        scan.setStartRow(startRow.getBytes(StandardCharsets.UTF_8));
    }
    if (!StringUtils.isBlank(endRow)){
        scan.setStopRow(   endRow.getBytes(StandardCharsets.UTF_8));
    }

    if (authorizations != null && authorizations.size() > 0) {
        scan.setAuthorizations(new Authorizations(authorizations));
    }

    Filter filter = null;
    if (columns != null) {
        for (Column col : columns) {
            if (col.getQualifier() == null) {
                scan.addFamily(col.getFamily());
            } else {
                scan.addColumn(col.getFamily(), col.getQualifier());
            }
        }
    }
    if (!StringUtils.isBlank(filterExpression)) {
        ParseFilter parseFilter = new ParseFilter();
        filter = parseFilter.parseFilterString(filterExpression);
    }
    if (filter != null){
        scan.setFilter(filter);
    }

    if (timerangeMin != null && timerangeMax != null){
        scan.setTimeRange(timerangeMin, timerangeMax);
    }

    // ->>> reserved for HBase v 2 or later
    //if (limitRows != null && limitRows > 0){
    //    scan.setLimit(limitRows)
    //}

    if (isReversed != null){
        scan.setReversed(isReversed);
    }

    scan.setCacheBlocks(blockCache);

    return table.getScanner(scan);
}
 
Example #18
Source File: AggregationEndpoint.java    From geowave with Apache License 2.0 4 votes vote down vote up
private Object getValue(
    final Aggregation aggregation,
    final Filter filter,
    final DataTypeAdapter dataAdapter,
    final Short internalAdapterId,
    final HBaseDistributableFilter hdFilter,
    final boolean blockCaching,
    final int scanCacheSize,
    final String[] authorizations) throws IOException {
  final Scan scan = new Scan();
  scan.setMaxVersions(1);
  scan.setCacheBlocks(blockCaching);

  if (scanCacheSize != HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING) {
    scan.setCaching(scanCacheSize);
  }

  if (filter != null) {
    scan.setFilter(filter);
  }

  if (internalAdapterId != null) {
    scan.addFamily(StringUtils.stringToBinary(ByteArrayUtils.shortToString(internalAdapterId)));
  }

  if (authorizations != null) {
    scan.setAuthorizations(new Authorizations(authorizations));
  }
  env.getRegion().getCoprocessorHost().preScannerOpen(scan);
  try (InternalScanner scanner = env.getRegion().getScanner(scan)) {
    final List<Cell> results = new ArrayList<>();
    boolean hasNext;
    do {
      hasNext = scanner.next(results);
      if (!results.isEmpty()) {
        if (hdFilter != null) {
          if (dataAdapter != null) {
            final Object row = hdFilter.decodeRow(dataAdapter);

            if (row != null) {
              aggregation.aggregate(row);
            } else {
              LOGGER.error("DataAdapter failed to decode row");
            }
          } else {
            aggregation.aggregate(hdFilter.getPersistenceEncoding());
          }
        } else {
          aggregation.aggregate(null);
        }
        results.clear();
      }
    } while (hasNext);
  }
  return aggregation.getResult();
}
 
Example #19
Source File: Scan.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public Scan setAuthorizations(Authorizations authorizations) {
  return (Scan) super.setAuthorizations(authorizations);
}
 
Example #20
Source File: ScannerModel.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * @param scan the scan specification
 * @throws Exception
 */
public static ScannerModel fromScan(Scan scan) throws Exception {
  ScannerModel model = new ScannerModel();
  model.setStartRow(scan.getStartRow());
  model.setEndRow(scan.getStopRow());
  Map<byte [], NavigableSet<byte []>> families = scan.getFamilyMap();
  if (families != null) {
    for (Map.Entry<byte [], NavigableSet<byte []>> entry : families.entrySet()) {
      if (entry.getValue() != null) {
        for (byte[] qualifier: entry.getValue()) {
          model.addColumn(Bytes.add(entry.getKey(), COLUMN_DIVIDER, qualifier));
        }
      } else {
        model.addColumn(entry.getKey());
      }
    }
  }
  model.setStartTime(scan.getTimeRange().getMin());
  model.setEndTime(scan.getTimeRange().getMax());
  int caching = scan.getCaching();
  if (caching > 0) {
    model.setCaching(caching);
  }
  int batch = scan.getBatch();
  if (batch > 0) {
    model.setBatch(batch);
  }
  int maxVersions = scan.getMaxVersions();
  if (maxVersions > 0) {
    model.setMaxVersions(maxVersions);
  }
  if (scan.getLimit() > 0) {
    model.setLimit(scan.getLimit());
  }
  Filter filter = scan.getFilter();
  if (filter != null) {
    model.setFilter(stringifyFilter(filter));
  }
  // Add the visbility labels if found in the attributes
  Authorizations authorizations = scan.getAuthorizations();
  if (authorizations != null) {
    List<String> labels = authorizations.getLabels();
    for (String label : labels) {
      model.addLabel(label);
    }
  }
  return model;
}
 
Example #21
Source File: TestImmutableScan.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testScanCopyConstructor() throws Exception {
  Scan scan = new Scan();

  scan.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("q"))
    .setACL("test_user2", new Permission(Permission.Action.READ))
    .setAllowPartialResults(true)
    .setAsyncPrefetch(false)
    .setAttribute("test_key", Bytes.toBytes("test_value"))
    .setAuthorizations(new Authorizations("test_label"))
    .setBatch(10)
    .setCacheBlocks(false)
    .setCaching(10)
    .setConsistency(Consistency.TIMELINE)
    .setFilter(new FilterList())
    .setId("scan_copy_constructor")
    .setIsolationLevel(IsolationLevel.READ_COMMITTED)
    .setLimit(100)
    .setLoadColumnFamiliesOnDemand(false)
    .setMaxResultSize(100)
    .setMaxResultsPerColumnFamily(1000)
    .readVersions(9999)
    .setMvccReadPoint(5)
    .setNeedCursorResult(true)
    .setPriority(1)
    .setRaw(true)
    .setReplicaId(3)
    .setReversed(true)
    .setRowOffsetPerColumnFamily(5)
    .setRowPrefixFilter(Bytes.toBytes("row_"))
    .setScanMetricsEnabled(true)
    .setSmall(true)
    .setReadType(Scan.ReadType.STREAM)
    .withStartRow(Bytes.toBytes("row_1"))
    .withStopRow(Bytes.toBytes("row_2"))
    .setTimeRange(0, 13);

  // create a copy of existing scan object
  Scan scanCopy = new ImmutableScan(scan);

  // validate fields of copied scan object match with the original scan object
  assertArrayEquals(scan.getACL(), scanCopy.getACL());
  assertEquals(scan.getAllowPartialResults(), scanCopy.getAllowPartialResults());
  assertArrayEquals(scan.getAttribute("test_key"), scanCopy.getAttribute("test_key"));
  assertEquals(scan.getAttributeSize(), scanCopy.getAttributeSize());
  assertEquals(scan.getAttributesMap(), scanCopy.getAttributesMap());
  assertEquals(scan.getAuthorizations().getLabels(), scanCopy.getAuthorizations().getLabels());
  assertEquals(scan.getBatch(), scanCopy.getBatch());
  assertEquals(scan.getCacheBlocks(), scanCopy.getCacheBlocks());
  assertEquals(scan.getCaching(), scanCopy.getCaching());
  assertEquals(scan.getConsistency(), scanCopy.getConsistency());
  assertEquals(scan.getFamilies().length, scanCopy.getFamilies().length);
  assertArrayEquals(scan.getFamilies()[0], scanCopy.getFamilies()[0]);
  assertEquals(scan.getFamilyMap(), scanCopy.getFamilyMap());
  assertEquals(scan.getFilter(), scanCopy.getFilter());
  assertEquals(scan.getId(), scanCopy.getId());
  assertEquals(scan.getIsolationLevel(), scanCopy.getIsolationLevel());
  assertEquals(scan.getLimit(), scanCopy.getLimit());
  assertEquals(scan.getLoadColumnFamiliesOnDemandValue(),
    scanCopy.getLoadColumnFamiliesOnDemandValue());
  assertEquals(scan.getMaxResultSize(), scanCopy.getMaxResultSize());
  assertEquals(scan.getMaxResultsPerColumnFamily(), scanCopy.getMaxResultsPerColumnFamily());
  assertEquals(scan.getMaxVersions(), scanCopy.getMaxVersions());
  assertEquals(scan.getMvccReadPoint(), scanCopy.getMvccReadPoint());
  assertEquals(scan.getPriority(), scanCopy.getPriority());
  assertEquals(scan.getReadType(), scanCopy.getReadType());
  assertEquals(scan.getReplicaId(), scanCopy.getReplicaId());
  assertEquals(scan.getRowOffsetPerColumnFamily(), scanCopy.getRowOffsetPerColumnFamily());
  assertArrayEquals(scan.getStartRow(), scanCopy.getStartRow());
  assertArrayEquals(scan.getStopRow(), scanCopy.getStopRow());
  assertEquals(scan.getTimeRange(), scanCopy.getTimeRange());
  assertEquals(scan.getFingerprint(), scanCopy.getFingerprint());
  assertEquals(scan.toMap(1), scanCopy.toMap(1));
  assertEquals(scan.toString(2), scanCopy.toString(2));
  assertEquals(scan.toJSON(2), scanCopy.toJSON(2));

  LOG.debug("Compare all getters of scan and scanCopy.");
  compareGetters(scan, scanCopy);

  testUnmodifiableSetters(scanCopy);
}
 
Example #22
Source File: Query.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the authorizations to be used by this Query
 * @param authorizations
 */
public Query setAuthorizations(Authorizations authorizations) {
  this.setAttribute(VisibilityConstants.VISIBILITY_LABELS_ATTR_KEY, ProtobufUtil
      .toAuthorizations(authorizations).toByteArray());
  return this;
}
 
Example #23
Source File: TestScan.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testScanCopyConstructor() throws Exception {
  Scan scan = new Scan();

  scan.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("q"))
      .setACL("test_user", new Permission(Permission.Action.READ))
      .setAllowPartialResults(true)
      .setAsyncPrefetch(false)
      .setAttribute("test_key", Bytes.toBytes("test_value"))
      .setAuthorizations(new Authorizations("test_label"))
      .setBatch(10)
      .setCacheBlocks(false)
      .setCaching(10)
      .setConsistency(Consistency.TIMELINE)
      .setFilter(new FilterList())
      .setId("scan_copy_constructor")
      .setIsolationLevel(IsolationLevel.READ_COMMITTED)
      .setLimit(100)
      .setLoadColumnFamiliesOnDemand(false)
      .setMaxResultSize(100)
      .setMaxResultsPerColumnFamily(1000)
      .readVersions(9999)
      .setMvccReadPoint(5)
      .setNeedCursorResult(true)
      .setPriority(1)
      .setRaw(true)
      .setReplicaId(3)
      .setReversed(true)
      .setRowOffsetPerColumnFamily(5)
      .setRowPrefixFilter(Bytes.toBytes("row_"))
      .setScanMetricsEnabled(true)
      .setSmall(true)
      .setReadType(ReadType.STREAM)
      .withStartRow(Bytes.toBytes("row_1"))
      .withStopRow(Bytes.toBytes("row_2"))
      .setTimeRange(0, 13);

  // create a copy of existing scan object
  Scan scanCopy = new Scan(scan);

  // validate fields of copied scan object match with the original scan object
  assertEquals(scan.getACL(), scanCopy.getACL());
  assertEquals(scan.getAllowPartialResults(), scanCopy.getAllowPartialResults());
  assertEquals(scan.getAttribute("test_key"), scanCopy.getAttribute("test_key"));
  assertEquals(scan.getAttributeSize(), scanCopy.getAttributeSize());
  assertEquals(scan.getAttributesMap(), scanCopy.getAttributesMap());
  assertEquals(scan.getAuthorizations().getLabels(), scanCopy.getAuthorizations().getLabels());
  assertEquals(scan.getBatch(), scanCopy.getBatch());
  assertEquals(scan.getCacheBlocks(), scanCopy.getCacheBlocks());
  assertEquals(scan.getCaching(), scanCopy.getCaching());
  assertEquals(scan.getConsistency(), scanCopy.getConsistency());
  assertEquals(scan.getFamilies().length, scanCopy.getFamilies().length);
  assertEquals(scan.getFamilies()[0], scanCopy.getFamilies()[0]);
  assertEquals(scan.getFamilyMap(), scanCopy.getFamilyMap());
  assertEquals(scan.getFilter(), scanCopy.getFilter());
  assertEquals(scan.getId(), scanCopy.getId());
  assertEquals(scan.getIsolationLevel(), scanCopy.getIsolationLevel());
  assertEquals(scan.getLimit(), scanCopy.getLimit());
  assertEquals(scan.getLoadColumnFamiliesOnDemandValue(),
    scanCopy.getLoadColumnFamiliesOnDemandValue());
  assertEquals(scan.getMaxResultSize(), scanCopy.getMaxResultSize());
  assertEquals(scan.getMaxResultsPerColumnFamily(), scanCopy.getMaxResultsPerColumnFamily());
  assertEquals(scan.getMaxVersions(), scanCopy.getMaxVersions());
  assertEquals(scan.getMvccReadPoint(), scanCopy.getMvccReadPoint());
  assertEquals(scan.getPriority(), scanCopy.getPriority());
  assertEquals(scan.getReadType(), scanCopy.getReadType());
  assertEquals(scan.getReplicaId(), scanCopy.getReplicaId());
  assertEquals(scan.getRowOffsetPerColumnFamily(), scanCopy.getRowOffsetPerColumnFamily());
  assertEquals(scan.getStartRow(), scanCopy.getStartRow());
  assertEquals(scan.getStopRow(), scanCopy.getStopRow());
  assertEquals(scan.getTimeRange(), scanCopy.getTimeRange());

  assertTrue("Make sure copy constructor adds all the fields in the copied object",
    EqualsBuilder.reflectionEquals(scan, scanCopy));
}
 
Example #24
Source File: Query.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * @return The authorizations this Query is associated with.
 * @throws DeserializationException
 */
public Authorizations getAuthorizations() throws DeserializationException {
  byte[] authorizationsBytes = this.getAttribute(VisibilityConstants.VISIBILITY_LABELS_ATTR_KEY);
  if (authorizationsBytes == null) return null;
  return ProtobufUtil.toAuthorizations(authorizationsBytes);
}
 
Example #25
Source File: TestScan.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetToScan() throws Exception {
  Get get = new Get(Bytes.toBytes(1));
  get.setCacheBlocks(true)
          .setConsistency(Consistency.TIMELINE)
          .setFilter(new FilterList())
          .setId("get")
          .setIsolationLevel(IsolationLevel.READ_COMMITTED)
          .setLoadColumnFamiliesOnDemand(false)
          .setMaxResultsPerColumnFamily(1000)
          .readVersions(9999)
          .setRowOffsetPerColumnFamily(5)
          .setTimeRange(0, 13)
          .setAttribute("att_v0", Bytes.toBytes("att_v0"))
          .setColumnFamilyTimeRange(Bytes.toBytes("cf"), 0, 123)
          .setReplicaId(3)
          .setACL("test_user", new Permission(Permission.Action.READ))
          .setAuthorizations(new Authorizations("test_label"))
          .setPriority(3);

  Scan scan = new Scan(get);
  assertEquals(get.getCacheBlocks(), scan.getCacheBlocks());
  assertEquals(get.getConsistency(), scan.getConsistency());
  assertEquals(get.getFilter(), scan.getFilter());
  assertEquals(get.getId(), scan.getId());
  assertEquals(get.getIsolationLevel(), scan.getIsolationLevel());
  assertEquals(get.getLoadColumnFamiliesOnDemandValue(),
      scan.getLoadColumnFamiliesOnDemandValue());
  assertEquals(get.getMaxResultsPerColumnFamily(), scan.getMaxResultsPerColumnFamily());
  assertEquals(get.getMaxVersions(), scan.getMaxVersions());
  assertEquals(get.getRowOffsetPerColumnFamily(), scan.getRowOffsetPerColumnFamily());
  assertEquals(get.getTimeRange().getMin(), scan.getTimeRange().getMin());
  assertEquals(get.getTimeRange().getMax(), scan.getTimeRange().getMax());
  assertTrue(Bytes.equals(get.getAttribute("att_v0"), scan.getAttribute("att_v0")));
  assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin(),
          scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin());
  assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax(),
          scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMax());
  assertEquals(get.getReplicaId(), scan.getReplicaId());
  assertEquals(get.getACL(), scan.getACL());
  assertEquals(get.getAuthorizations().getLabels(), scan.getAuthorizations().getLabels());
  assertEquals(get.getPriority(), scan.getPriority());
}
 
Example #26
Source File: ImmutableScan.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public Authorizations getAuthorizations() throws DeserializationException {
  return this.delegateScan.getAuthorizations();
}
 
Example #27
Source File: ImmutableScan.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public Scan setAuthorizations(Authorizations authorizations) {
  throw new UnsupportedOperationException(
    "ImmutableScan does not allow access to setAuthorizations");
}
 
Example #28
Source File: Get.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public Get setAuthorizations(Authorizations authorizations) {
  return (Get) super.setAuthorizations(authorizations);
}
 
Example #29
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Convert a protocol buffer Authorizations to a client Authorizations
 *
 * @param proto
 * @return the converted client Authorizations
 */
public static Authorizations toAuthorizations(ClientProtos.Authorizations proto) {
  if (proto == null) return null;
  return new Authorizations(proto.getLabelList());
}