Search in sources :

Example 16 with ByteString

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());
}
Also used : AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) OperationStatus(org.apache.hadoop.hbase.regionserver.OperationStatus) VisibilityLabelsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse)

Example 17 with ByteString

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;
}
Also used : Scanner(org.apache.hadoop.hbase.shaded.rest.protobuf.generated.ScannerMessage.Scanner) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString)

Example 18 with ByteString

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();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerConfigBuilder(org.apache.hadoop.hbase.replication.ReplicationPeerConfigBuilder) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) List(java.util.List) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)

Example 19 with ByteString

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);
    }
}
Also used : ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with ByteString

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);
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) AggregateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)36 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)18 Test (org.junit.Test)11 AggregateResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse)9 Connection (org.apache.hadoop.hbase.client.Connection)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 List (java.util.List)7 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)7 Scan (org.apache.hadoop.hbase.client.Scan)7 Cell (org.apache.hadoop.hbase.Cell)6 CoprocessorRpcUtils (org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils)6 AggregateRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest)6 AggregateService (org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateService)6 GetAuthsResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse)6 VisibilityLabelsResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse)6 RpcCallback (org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback)6 RpcController (org.apache.hbase.thirdparty.com.google.protobuf.RpcController)6 ByteBuffer (java.nio.ByteBuffer)4 CellScanner (org.apache.hadoop.hbase.CellScanner)4