use of org.apache.hbase.thirdparty.com.google.protobuf.ByteString in project hbase by apache.
the class VisibilityController method setAuths.
@Override
public synchronized void setAuths(RpcController controller, SetAuthsRequest request, RpcCallback<VisibilityLabelsResponse> done) {
VisibilityLabelsResponse.Builder response = VisibilityLabelsResponse.newBuilder();
List<ByteString> auths = request.getAuthList();
if (!initialized) {
setExceptionResults(auths.size(), new VisibilityControllerNotReadyException("VisibilityController not yet initialized!"), response);
} else {
byte[] user = request.getUser().toByteArray();
List<byte[]> labelAuths = new ArrayList<>(auths.size());
try {
if (authorizationEnabled) {
checkCallingUserAuth();
}
for (ByteString authBS : auths) {
labelAuths.add(authBS.toByteArray());
}
OperationStatus[] opStatus = this.visibilityLabelService.setAuths(user, labelAuths);
logResult(true, "setAuths", "Setting authorization for labels allowed", user, labelAuths, null);
RegionActionResult successResult = RegionActionResult.newBuilder().build();
for (OperationStatus status : opStatus) {
if (status.getOperationStatusCode() == SUCCESS) {
response.addResult(successResult);
} else {
RegionActionResult.Builder failureResultBuilder = RegionActionResult.newBuilder();
failureResultBuilder.setException(buildException(new DoNotRetryIOException(status.getExceptionMsg())));
response.addResult(failureResultBuilder.build());
}
}
} catch (AccessDeniedException e) {
logResult(false, "setAuths", e.getMessage(), user, labelAuths, null);
LOG.error("User is not having required permissions to set authorization", e);
setExceptionResults(auths.size(), e, response);
} catch (IOException e) {
LOG.error(e.toString(), e);
setExceptionResults(auths.size(), e, response);
}
}
done.run(response.build());
}
use of org.apache.hbase.thirdparty.com.google.protobuf.ByteString in project hbase by apache.
the class ScannerModel method getObjectFromMessage.
@Override
public ProtobufMessageHandler getObjectFromMessage(byte[] message) throws IOException {
Scanner.Builder builder = Scanner.newBuilder();
ProtobufUtil.mergeFrom(builder, message);
if (builder.hasStartRow()) {
startRow = builder.getStartRow().toByteArray();
}
if (builder.hasEndRow()) {
endRow = builder.getEndRow().toByteArray();
}
for (ByteString column : builder.getColumnsList()) {
addColumn(column.toByteArray());
}
if (builder.hasBatch()) {
batch = builder.getBatch();
}
if (builder.hasCaching()) {
caching = builder.getCaching();
}
if (builder.hasLimit()) {
limit = builder.getLimit();
}
if (builder.hasStartTime()) {
startTime = builder.getStartTime();
}
if (builder.hasEndTime()) {
endTime = builder.getEndTime();
}
if (builder.hasMaxVersions()) {
maxVersions = builder.getMaxVersions();
}
if (builder.hasFilter()) {
filter = builder.getFilter();
}
if (builder.getLabelsList() != null) {
List<String> labels = builder.getLabelsList();
for (String label : labels) {
addLabel(label);
}
}
if (builder.hasCacheBlocks()) {
this.cacheBlocks = builder.getCacheBlocks();
}
return this;
}
use of org.apache.hbase.thirdparty.com.google.protobuf.ByteString in project hbase by apache.
the class ReplicationPeerConfigUtil method convert.
public static ReplicationPeerConfig convert(ReplicationProtos.ReplicationPeer peer) {
ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder();
if (peer.hasClusterkey()) {
builder.setClusterKey(peer.getClusterkey());
}
if (peer.hasReplicationEndpointImpl()) {
builder.setReplicationEndpointImpl(peer.getReplicationEndpointImpl());
}
for (HBaseProtos.BytesBytesPair pair : peer.getDataList()) {
builder.putPeerData(pair.getFirst().toByteArray(), pair.getSecond().toByteArray());
}
for (HBaseProtos.NameStringPair pair : peer.getConfigurationList()) {
builder.putConfiguration(pair.getName(), pair.getValue());
}
Map<TableName, List<String>> tableCFsMap = convert2Map(peer.getTableCfsList().toArray(new ReplicationProtos.TableCF[peer.getTableCfsCount()]));
if (tableCFsMap != null) {
builder.setTableCFsMap(tableCFsMap);
}
List<ByteString> namespacesList = peer.getNamespacesList();
if (namespacesList != null && namespacesList.size() != 0) {
builder.setNamespaces(namespacesList.stream().map(ByteString::toStringUtf8).collect(Collectors.toSet()));
}
if (peer.hasBandwidth()) {
builder.setBandwidth(peer.getBandwidth());
}
if (peer.hasReplicateAll()) {
builder.setReplicateAllUserTables(peer.getReplicateAll());
}
if (peer.hasSerial()) {
builder.setSerial(peer.getSerial());
}
Map<TableName, List<String>> excludeTableCFsMap = convert2Map(peer.getExcludeTableCfsList().toArray(new ReplicationProtos.TableCF[peer.getExcludeTableCfsCount()]));
if (excludeTableCFsMap != null) {
builder.setExcludeTableCFsMap(excludeTableCFsMap);
}
List<ByteString> excludeNamespacesList = peer.getExcludeNamespacesList();
if (excludeNamespacesList != null && excludeNamespacesList.size() != 0) {
builder.setExcludeNamespaces(excludeNamespacesList.stream().map(ByteString::toStringUtf8).collect(Collectors.toSet()));
}
if (peer.hasRemoteWALDir()) {
builder.setRemoteWALDir(peer.getRemoteWALDir());
}
return builder.build();
}
use of org.apache.hbase.thirdparty.com.google.protobuf.ByteString in project hbase by apache.
the class AggregateImplementation method constructColumnInterpreterFromRequest.
@SuppressWarnings("unchecked")
// Used server-side too by Aggregation Coprocesor Endpoint. Undo this interdependence. TODO.
ColumnInterpreter<T, S, P, Q, R> constructColumnInterpreterFromRequest(AggregateRequest request) throws IOException {
String className = request.getInterpreterClassName();
try {
ColumnInterpreter<T, S, P, Q, R> ci;
Class<?> cls = Class.forName(className);
ci = (ColumnInterpreter<T, S, P, Q, R>) cls.getDeclaredConstructor().newInstance();
if (request.hasInterpreterSpecificBytes()) {
ByteString b = request.getInterpreterSpecificBytes();
P initMsg = getParsedGenericInstance(ci.getClass(), 2, b);
ci.initialize(initMsg);
}
return ci;
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new IOException(e);
}
}
use of org.apache.hbase.thirdparty.com.google.protobuf.ByteString in project hbase by apache.
the class AggregateImplementation method getAvg.
/**
* Gives a Pair with first object as Sum and second object as row count,
* computed for a given combination of column qualifier and column family in
* the given row range as defined in the Scan object. In its current
* implementation, it takes one column family and one column qualifier (if
* provided). In case of null column qualifier, an aggregate sum over all the
* entire column family will be returned.
* <p>
* The average is computed in
* AggregationClient#avg(byte[], ColumnInterpreter, Scan) by
* processing results from all regions, so its "ok" to pass sum and a Long
* type.
*/
@Override
public void getAvg(RpcController controller, AggregateRequest request, RpcCallback<AggregateResponse> done) {
AggregateResponse response = null;
InternalScanner scanner = null;
try {
ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
S sumVal = null;
Long rowCountVal = 0L;
Scan scan = ProtobufUtil.toScan(request.getScan());
scanner = env.getRegion().getScanner(scan);
byte[] colFamily = scan.getFamilies()[0];
NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
byte[] qualifier = null;
if (qualifiers != null && !qualifiers.isEmpty()) {
qualifier = qualifiers.pollFirst();
}
List<Cell> results = new ArrayList<>();
boolean hasMoreRows = false;
do {
results.clear();
hasMoreRows = scanner.next(results);
int listSize = results.size();
for (int i = 0; i < listSize; i++) {
sumVal = ci.add(sumVal, ci.castToReturnType(ci.getValue(colFamily, qualifier, results.get(i))));
}
rowCountVal++;
} while (hasMoreRows);
if (sumVal != null) {
ByteString first = ci.getProtoForPromotedType(sumVal).toByteString();
AggregateResponse.Builder pair = AggregateResponse.newBuilder();
pair.addFirstPart(first);
ByteBuffer bb = ByteBuffer.allocate(8).putLong(rowCountVal);
bb.rewind();
pair.setSecondPart(ByteString.copyFrom(bb));
response = pair.build();
}
} catch (IOException e) {
CoprocessorRpcUtils.setControllerException(controller, e);
} finally {
if (scanner != null) {
try {
scanner.close();
} catch (IOException ignored) {
}
}
}
done.run(response);
}
Aggregations