Search in sources :

Example 1 with VisibilityLabelsService

use of org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService in project hbase by apache.

the class VisibilityClient method setOrClearAuths.

private static VisibilityLabelsResponse setOrClearAuths(Connection connection, final String[] auths, final String user, final boolean setOrClear) throws IOException, ServiceException, Throwable {
    try (Table table = connection.getTable(LABELS_TABLE_NAME)) {
        Batch.Call<VisibilityLabelsService, VisibilityLabelsResponse> callable = new Batch.Call<VisibilityLabelsService, VisibilityLabelsResponse>() {

            ServerRpcController controller = new ServerRpcController();

            CoprocessorRpcUtils.BlockingRpcCallback<VisibilityLabelsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();

            public VisibilityLabelsResponse call(VisibilityLabelsService service) throws IOException {
                SetAuthsRequest.Builder setAuthReqBuilder = SetAuthsRequest.newBuilder();
                setAuthReqBuilder.setUser(ByteStringer.wrap(Bytes.toBytes(user)));
                for (String auth : auths) {
                    if (auth.length() > 0) {
                        setAuthReqBuilder.addAuth((ByteString.copyFromUtf8(auth)));
                    }
                }
                if (setOrClear) {
                    service.setAuths(controller, setAuthReqBuilder.build(), rpcCallback);
                } else {
                    service.clearAuths(controller, setAuthReqBuilder.build(), rpcCallback);
                }
                VisibilityLabelsResponse response = rpcCallback.get();
                if (controller.failedOnException()) {
                    throw controller.getFailedOn();
                }
                return response;
            }
        };
        Map<byte[], VisibilityLabelsResponse> result = table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable);
        // There will be exactly one region for labels
        return result.values().iterator().next();
    // table and so one entry in result Map.
    }
}
Also used : SetAuthsRequest(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.SetAuthsRequest) VisibilityLabelsService(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService) Table(org.apache.hadoop.hbase.client.Table) ByteString(com.google.protobuf.ByteString) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) Batch(org.apache.hadoop.hbase.client.coprocessor.Batch) VisibilityLabelsResponse(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse)

Example 2 with VisibilityLabelsService

use of org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService in project hbase by apache.

the class VisibilityClient method addLabels.

/**
   * Utility method for adding labels to the system.
   *
   * @param connection
   * @param labels
   * @return VisibilityLabelsResponse
   * @throws Throwable
   */
public static VisibilityLabelsResponse addLabels(Connection connection, final String[] labels) throws Throwable {
    try (Table table = connection.getTable(LABELS_TABLE_NAME)) {
        Batch.Call<VisibilityLabelsService, VisibilityLabelsResponse> callable = new Batch.Call<VisibilityLabelsService, VisibilityLabelsResponse>() {

            ServerRpcController controller = new ServerRpcController();

            CoprocessorRpcUtils.BlockingRpcCallback<VisibilityLabelsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();

            public VisibilityLabelsResponse call(VisibilityLabelsService service) throws IOException {
                VisibilityLabelsRequest.Builder builder = VisibilityLabelsRequest.newBuilder();
                for (String label : labels) {
                    if (label.length() > 0) {
                        VisibilityLabel.Builder newBuilder = VisibilityLabel.newBuilder();
                        newBuilder.setLabel(ByteStringer.wrap(Bytes.toBytes(label)));
                        builder.addVisLabel(newBuilder.build());
                    }
                }
                service.addLabels(controller, builder.build(), rpcCallback);
                VisibilityLabelsResponse response = rpcCallback.get();
                if (controller.failedOnException()) {
                    throw controller.getFailedOn();
                }
                return response;
            }
        };
        Map<byte[], VisibilityLabelsResponse> result = table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable);
        // There will be exactly one region for labels
        return result.values().iterator().next();
    // table and so one entry in result Map.
    }
}
Also used : VisibilityLabelsService(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService) Table(org.apache.hadoop.hbase.client.Table) ByteString(com.google.protobuf.ByteString) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) VisibilityLabelsRequest(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsRequest) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) Batch(org.apache.hadoop.hbase.client.coprocessor.Batch) VisibilityLabel(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabel) VisibilityLabelsResponse(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse)

Example 3 with VisibilityLabelsService

use of org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService in project hbase by apache.

the class VisibilityClient method listLabels.

/**
   * Retrieve the list of visibility labels defined in the system.
   * @param connection The Connection instance to use.
   * @param regex  The regular expression to filter which labels are returned.
   * @return labels The list of visibility labels defined in the system.
   * @throws Throwable
   */
public static ListLabelsResponse listLabels(Connection connection, final String regex) throws Throwable {
    Table table = null;
    try {
        table = connection.getTable(LABELS_TABLE_NAME);
        Batch.Call<VisibilityLabelsService, ListLabelsResponse> callable = new Batch.Call<VisibilityLabelsService, ListLabelsResponse>() {

            ServerRpcController controller = new ServerRpcController();

            CoprocessorRpcUtils.BlockingRpcCallback<ListLabelsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();

            public ListLabelsResponse call(VisibilityLabelsService service) throws IOException {
                ListLabelsRequest.Builder listAuthLabelsReqBuilder = ListLabelsRequest.newBuilder();
                if (regex != null) {
                    // Compile the regex here to catch any regex exception earlier.
                    Pattern pattern = Pattern.compile(regex);
                    listAuthLabelsReqBuilder.setRegex(pattern.toString());
                }
                service.listLabels(controller, listAuthLabelsReqBuilder.build(), rpcCallback);
                ListLabelsResponse response = rpcCallback.get();
                if (controller.failedOnException()) {
                    throw controller.getFailedOn();
                }
                return response;
            }
        };
        Map<byte[], ListLabelsResponse> result = table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable);
        // There will be exactly one region for labels
        return result.values().iterator().next();
    // table and so one entry in result Map.
    } finally {
        if (table != null) {
            table.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : VisibilityLabelsService(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService) Pattern(java.util.regex.Pattern) Table(org.apache.hadoop.hbase.client.Table) ListLabelsRequest(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest) ListLabelsResponse(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) Batch(org.apache.hadoop.hbase.client.coprocessor.Batch)

Example 4 with VisibilityLabelsService

use of org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService in project hbase by apache.

the class VisibilityClient method getAuths.

/**
   * @param connection the Connection instance to use.
   * @param user
   * @return labels, the given user is globally authorized for.
   * @throws Throwable
   */
public static GetAuthsResponse getAuths(Connection connection, final String user) throws Throwable {
    try (Table table = connection.getTable(LABELS_TABLE_NAME)) {
        Batch.Call<VisibilityLabelsService, GetAuthsResponse> callable = new Batch.Call<VisibilityLabelsService, GetAuthsResponse>() {

            ServerRpcController controller = new ServerRpcController();

            CoprocessorRpcUtils.BlockingRpcCallback<GetAuthsResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();

            public GetAuthsResponse call(VisibilityLabelsService service) throws IOException {
                GetAuthsRequest.Builder getAuthReqBuilder = GetAuthsRequest.newBuilder();
                getAuthReqBuilder.setUser(ByteStringer.wrap(Bytes.toBytes(user)));
                service.getAuths(controller, getAuthReqBuilder.build(), rpcCallback);
                GetAuthsResponse response = rpcCallback.get();
                if (controller.failedOnException()) {
                    throw controller.getFailedOn();
                }
                return response;
            }
        };
        Map<byte[], GetAuthsResponse> result = table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable);
        // There will be exactly one region for labels
        return result.values().iterator().next();
    // table and so one entry in result Map.
    }
}
Also used : VisibilityLabelsService(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService) Table(org.apache.hadoop.hbase.client.Table) GetAuthsRequest(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) Batch(org.apache.hadoop.hbase.client.coprocessor.Batch) GetAuthsResponse(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse)

Aggregations

Table (org.apache.hadoop.hbase.client.Table)4 Batch (org.apache.hadoop.hbase.client.coprocessor.Batch)4 CoprocessorRpcUtils (org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils)4 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)4 VisibilityLabelsService (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService)4 ByteString (com.google.protobuf.ByteString)2 VisibilityLabelsResponse (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse)2 Pattern (java.util.regex.Pattern)1 GetAuthsRequest (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest)1 GetAuthsResponse (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse)1 ListLabelsRequest (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest)1 ListLabelsResponse (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse)1 SetAuthsRequest (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.SetAuthsRequest)1 VisibilityLabel (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabel)1 VisibilityLabelsRequest (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsRequest)1