Search in sources :

Example 6 with CellVisibility

use of org.apache.hadoop.hbase.security.visibility.CellVisibility in project hbase by apache.

the class TestImportTSVWithVisibilityLabels method issueDeleteAndVerifyData.

private void issueDeleteAndVerifyData(TableName tableName) throws IOException {
    LOG.debug("Validating table after delete.");
    Table table = util.getConnection().getTable(tableName);
    boolean verified = false;
    long pause = conf.getLong("hbase.client.pause", 5 * 1000);
    int numRetries = conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 5);
    for (int i = 0; i < numRetries; i++) {
        try {
            Delete d = new Delete(Bytes.toBytes("KEY"));
            d.addFamily(Bytes.toBytes(FAMILY));
            d.setCellVisibility(new CellVisibility("private&secret"));
            table.delete(d);
            Scan scan = new Scan();
            // Scan entire family.
            scan.addFamily(Bytes.toBytes(FAMILY));
            scan.setAuthorizations(new Authorizations("secret", "private"));
            ResultScanner resScanner = table.getScanner(scan);
            Result[] next = resScanner.next(5);
            assertEquals(0, next.length);
            verified = true;
            break;
        } catch (NullPointerException e) {
        // If here, a cell was empty. Presume its because updates came in
        // after the scanner had been opened. Wait a while and retry.
        }
        try {
            Thread.sleep(pause);
        } catch (InterruptedException e) {
        // continue
        }
    }
    table.close();
    assertTrue(verified);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Authorizations(org.apache.hadoop.hbase.security.visibility.Authorizations) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) CellVisibility(org.apache.hadoop.hbase.security.visibility.CellVisibility) Result(org.apache.hadoop.hbase.client.Result) Scan(org.apache.hadoop.hbase.client.Scan)

Example 7 with CellVisibility

use of org.apache.hadoop.hbase.security.visibility.CellVisibility in project hbase by apache.

the class ThriftUtilities method appendFromHBase.

public static TAppend appendFromHBase(Append in) throws IOException {
    TAppend out = new TAppend();
    out.setRow(in.getRow());
    if (in.getDurability() != Durability.USE_DEFAULT) {
        out.setDurability(durabilityFromHBase(in.getDurability()));
    }
    for (Map.Entry<byte[], List<Cell>> entry : in.getFamilyCellMap().entrySet()) {
        byte[] family = entry.getKey();
        for (Cell cell : entry.getValue()) {
            TColumnValue columnValue = new TColumnValue();
            columnValue.setFamily(family).setQualifier(CellUtil.cloneQualifier(cell)).setType(cell.getType().getCode()).setTimestamp(cell.getTimestamp()).setValue(CellUtil.cloneValue(cell));
            if (cell.getTagsLength() != 0) {
                columnValue.setTags(PrivateCellUtil.cloneTags(cell));
            }
            out.addToColumns(columnValue);
        }
    }
    for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) {
        out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())), ByteBuffer.wrap(attribute.getValue()));
    }
    try {
        CellVisibility cellVisibility = in.getCellVisibility();
        if (cellVisibility != null) {
            TCellVisibility tCellVisibility = new TCellVisibility();
            tCellVisibility.setExpression(cellVisibility.getExpression());
            out.setCellVisibility(tCellVisibility);
        }
    } catch (DeserializationException e) {
        throw new RuntimeException(e);
    }
    out.setReturnResults(in.isReturnResults());
    return out;
}
Also used : TCellVisibility(org.apache.hadoop.hbase.thrift2.generated.TCellVisibility) CellVisibility(org.apache.hadoop.hbase.security.visibility.CellVisibility) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) TCellVisibility(org.apache.hadoop.hbase.thrift2.generated.TCellVisibility) List(java.util.List) ArrayList(java.util.ArrayList) TAppend(org.apache.hadoop.hbase.thrift2.generated.TAppend) Map(java.util.Map) Cell(org.apache.hadoop.hbase.Cell)

Example 8 with CellVisibility

use of org.apache.hadoop.hbase.security.visibility.CellVisibility in project Gaffer by gchq.

the class ElementSerialisation method getPuts.

public Pair<Put, Put> getPuts(final Element element, final Pair<byte[], byte[]> row, final byte[] cq) throws SerialisationException {
    final long ts = getTimestamp(element);
    final byte[] value = getValue(element);
    final String visibilityStr = Bytes.toString(getColumnVisibility(element));
    final CellVisibility cellVisibility = visibilityStr.isEmpty() ? null : new CellVisibility(visibilityStr);
    final Put put = new Put(row.getFirst());
    put.addColumn(HBaseStoreConstants.getColFam(), cq, ts, value);
    if (null != cellVisibility) {
        put.setCellVisibility(cellVisibility);
    }
    final Pair<Put, Put> puts = new Pair<>(put);
    if (null != row.getSecond()) {
        final Put put2 = new Put(row.getSecond());
        put2.addColumn(HBaseStoreConstants.getColFam(), cq, value);
        if (null != cellVisibility) {
            put2.setCellVisibility(cellVisibility);
        }
        puts.setSecond(put2);
    }
    return puts;
}
Also used : CellVisibility(org.apache.hadoop.hbase.security.visibility.CellVisibility) Put(org.apache.hadoop.hbase.client.Put) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair)

Example 9 with CellVisibility

use of org.apache.hadoop.hbase.security.visibility.CellVisibility in project hbase by apache.

the class PutSortReducer method reduce.

@Override
protected void reduce(ImmutableBytesWritable row, java.lang.Iterable<Put> puts, Reducer<ImmutableBytesWritable, Put, ImmutableBytesWritable, KeyValue>.Context<ImmutableBytesWritable, Put, ImmutableBytesWritable, KeyValue> context) throws java.io.IOException, InterruptedException {
    // although reduce() is called per-row, handle pathological case
    long threshold = context.getConfiguration().getLong("putsortreducer.row.threshold", 1L * (1 << 30));
    Iterator<Put> iter = puts.iterator();
    while (iter.hasNext()) {
        TreeSet<KeyValue> map = new TreeSet<>(CellComparator.COMPARATOR);
        long curSize = 0;
        // stop at the end or the RAM threshold
        List<Tag> tags = new ArrayList<>();
        while (iter.hasNext() && curSize < threshold) {
            // clear the tags
            tags.clear();
            Put p = iter.next();
            long t = p.getTTL();
            if (t != Long.MAX_VALUE) {
                // add TTL tag if found
                tags.add(new ArrayBackedTag(TagType.TTL_TAG_TYPE, Bytes.toBytes(t)));
            }
            byte[] acl = p.getACL();
            if (acl != null) {
                // add ACL tag if found
                tags.add(new ArrayBackedTag(TagType.ACL_TAG_TYPE, acl));
            }
            try {
                CellVisibility cellVisibility = p.getCellVisibility();
                if (cellVisibility != null) {
                    // add the visibility labels if any
                    tags.addAll(kvCreator.getVisibilityExpressionResolver().createVisibilityExpTags(cellVisibility.getExpression()));
                }
            } catch (DeserializationException e) {
                // just ignoring the bad one?
                throw new IOException("Invalid visibility expression found in mutation " + p, e);
            }
            for (List<Cell> cells : p.getFamilyCellMap().values()) {
                for (Cell cell : cells) {
                    // Creating the KV which needs to be directly written to HFiles. Using the Facade
                    // KVCreator for creation of kvs.
                    KeyValue kv = null;
                    TagUtil.carryForwardTags(tags, cell);
                    if (!tags.isEmpty()) {
                        kv = (KeyValue) kvCreator.create(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(), cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(), cell.getTimestamp(), cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), tags);
                    } else {
                        kv = KeyValueUtil.ensureKeyValue(cell);
                    }
                    if (map.add(kv)) {
                        // don't count duplicated kv into size
                        curSize += kv.heapSize();
                    }
                }
            }
        }
        context.setStatus("Read " + map.size() + " entries of " + map.getClass() + "(" + StringUtils.humanReadableInt(curSize) + ")");
        int index = 0;
        for (KeyValue kv : map) {
            context.write(row, kv);
            if (++index % 100 == 0)
                context.setStatus("Wrote " + index);
        }
        // if we have more entries to process
        if (iter.hasNext()) {
            // force flush because we cannot guarantee intra-row sorted order
            context.write(null, null);
        }
    }
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) CellVisibility(org.apache.hadoop.hbase.security.visibility.CellVisibility) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) Put(org.apache.hadoop.hbase.client.Put) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) TreeSet(java.util.TreeSet) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) Tag(org.apache.hadoop.hbase.Tag) Cell(org.apache.hadoop.hbase.Cell)

Example 10 with CellVisibility

use of org.apache.hadoop.hbase.security.visibility.CellVisibility in project hbase by apache.

the class TsvImporterMapper method populatePut.

protected void populatePut(byte[] lineBytes, ImportTsv.TsvParser.ParsedLine parsed, Put put, int i) throws BadTsvLineException, IOException {
    Cell cell = null;
    if (hfileOutPath == null) {
        cell = new KeyValue(lineBytes, parsed.getRowKeyOffset(), parsed.getRowKeyLength(), parser.getFamily(i), 0, parser.getFamily(i).length, parser.getQualifier(i), 0, parser.getQualifier(i).length, ts, KeyValue.Type.Put, lineBytes, parsed.getColumnOffset(i), parsed.getColumnLength(i));
        if (cellVisibilityExpr != null) {
            // We won't be validating the expression here. The Visibility CP will do
            // the validation
            put.setCellVisibility(new CellVisibility(cellVisibilityExpr));
        }
        if (ttl > 0) {
            put.setTTL(ttl);
        }
    } else {
        // Creating the KV which needs to be directly written to HFiles. Using the Facade
        // KVCreator for creation of kvs.
        cell = this.kvCreator.create(lineBytes, parsed.getRowKeyOffset(), parsed.getRowKeyLength(), parser.getFamily(i), 0, parser.getFamily(i).length, parser.getQualifier(i), 0, parser.getQualifier(i).length, ts, lineBytes, parsed.getColumnOffset(i), parsed.getColumnLength(i), tags);
    }
    put.add(cell);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) CellVisibility(org.apache.hadoop.hbase.security.visibility.CellVisibility) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

CellVisibility (org.apache.hadoop.hbase.security.visibility.CellVisibility)12 DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)7 ArrayList (java.util.ArrayList)6 Cell (org.apache.hadoop.hbase.Cell)6 IOException (java.io.IOException)5 Put (org.apache.hadoop.hbase.client.Put)5 List (java.util.List)4 Map (java.util.Map)4 KeyValue (org.apache.hadoop.hbase.KeyValue)3 Table (org.apache.hadoop.hbase.client.Table)3 TreeSet (java.util.TreeSet)2 ArrayBackedTag (org.apache.hadoop.hbase.ArrayBackedTag)2 Tag (org.apache.hadoop.hbase.Tag)2 Result (org.apache.hadoop.hbase.client.Result)2 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 Scan (org.apache.hadoop.hbase.client.Scan)2 Authorizations (org.apache.hadoop.hbase.security.visibility.Authorizations)2 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)2 TCellVisibility (org.apache.hadoop.hbase.thrift2.generated.TCellVisibility)2 File (java.io.File)1