use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.
the class TestProtobufUtil method getCellWithTags.
private Cell getCellWithTags() {
Tag tag = new ArrayBackedTag(TAG_TYPE, TAG_STR);
ExtendedCellBuilder cellBuilder = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY);
cellBuilder.setRow(Bytes.toBytes("row1"));
cellBuilder.setFamily(Bytes.toBytes("f1"));
cellBuilder.setQualifier(Bytes.toBytes("q1"));
cellBuilder.setValue(Bytes.toBytes("value1"));
cellBuilder.setType(Cell.Type.Delete);
cellBuilder.setTags(Collections.singletonList(tag));
return cellBuilder.build();
}
use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.
the class ProtobufUtil method toResult.
/**
* Convert a protocol buffer Result to a client Result
*
* @param proto the protocol buffer Result to convert
* @param decodeTags whether to decode tags into converted client Result
* When @decodeTags is set to true, it will decode all the tags from the
* response. These tags may contain some sensitive data like acl permissions,
* etc. Only the tools like Export, Import which needs to take backup needs to
* set it to true so that cell tags are persisted in backup.
* Refer to HBASE-25246 for more context.
* @return the converted client Result
*/
public static Result toResult(final ClientProtos.Result proto, boolean decodeTags) {
if (proto.hasExists()) {
if (proto.getStale()) {
return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE_STALE : EMPTY_RESULT_EXISTS_FALSE_STALE;
}
return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE : EMPTY_RESULT_EXISTS_FALSE;
}
List<CellProtos.Cell> values = proto.getCellList();
if (values.isEmpty()) {
return proto.getStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT;
}
List<Cell> cells = new ArrayList<>(values.size());
ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
for (CellProtos.Cell c : values) {
cells.add(toCell(builder, c, decodeTags));
}
return Result.create(cells, null, proto.getStale(), proto.getPartial());
}
use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.
the class ThriftUtilities method resultFromThrift.
public static Result resultFromThrift(TResult in) {
if (in == null) {
return null;
}
if (!in.isSetColumnValues() || in.getColumnValues().isEmpty()) {
return in.isStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT;
}
List<Cell> cells = new ArrayList<>(in.getColumnValues().size());
ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
for (TColumnValue columnValue : in.getColumnValues()) {
cells.add(toCell(builder, in.getRow(), columnValue));
}
return Result.create(cells, null, in.isStale(), in.isPartial());
}
use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.
the class DefaultVisibilityLabelServiceImpl method setAuths.
@Override
public OperationStatus[] setAuths(byte[] user, List<byte[]> authLabels) throws IOException {
assert labelsRegion != null;
OperationStatus[] finalOpStatus = new OperationStatus[authLabels.size()];
List<Mutation> puts = new ArrayList<>(authLabels.size());
int i = 0;
ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
for (byte[] auth : authLabels) {
String authStr = Bytes.toString(auth);
int labelOrdinal = this.labelsCache.getLabelOrdinal(authStr);
if (labelOrdinal == 0) {
// This label is not yet added. 1st this should be added to the system
finalOpStatus[i] = new OperationStatus(OperationStatusCode.FAILURE, new InvalidLabelException("Label '" + authStr + "' doesn't exists"));
} else {
byte[] row = Bytes.toBytes(labelOrdinal);
Put p = new Put(row);
p.add(builder.clear().setRow(row).setFamily(LABELS_TABLE_FAMILY).setQualifier(user).setTimestamp(p.getTimestamp()).setType(Cell.Type.Put).setValue(DUMMY_VALUE).setTags(TagUtil.fromList(Arrays.asList(LABELS_TABLE_TAGS))).build());
puts.add(p);
}
i++;
}
if (mutateLabelsRegion(puts, finalOpStatus)) {
updateZk(false);
}
return finalOpStatus;
}
use of org.apache.hadoop.hbase.ExtendedCellBuilder in project hbase by apache.
the class DefaultVisibilityLabelServiceImpl method addLabels.
@Override
public OperationStatus[] addLabels(List<byte[]> labels) throws IOException {
assert labelsRegion != null;
OperationStatus[] finalOpStatus = new OperationStatus[labels.size()];
List<Mutation> puts = new ArrayList<>(labels.size());
int i = 0;
ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
for (byte[] label : labels) {
String labelStr = Bytes.toString(label);
if (this.labelsCache.getLabelOrdinal(labelStr) > 0) {
finalOpStatus[i] = new OperationStatus(OperationStatusCode.FAILURE, new LabelAlreadyExistsException("Label '" + labelStr + "' already exists"));
} else {
byte[] row = Bytes.toBytes(ordinalCounter.get());
Put p = new Put(row);
p.add(builder.clear().setRow(row).setFamily(LABELS_TABLE_FAMILY).setQualifier(LABEL_QUALIFIER).setTimestamp(p.getTimestamp()).setType(Type.Put).setValue(label).setTags(TagUtil.fromList(Arrays.asList(LABELS_TABLE_TAGS))).build());
if (LOG.isDebugEnabled()) {
LOG.debug("Adding the label " + labelStr);
}
puts.add(p);
ordinalCounter.incrementAndGet();
}
i++;
}
if (mutateLabelsRegion(puts, finalOpStatus)) {
updateZk(true);
}
return finalOpStatus;
}
Aggregations