Search in sources :

Example 1 with DelegationToken

use of org.apache.hadoop.hbase.protobuf.generated.ClientProtos.DelegationToken in project hbase by apache.

the class SecureBulkLoadEndpointClient method bulkLoadHFiles.

public boolean bulkLoadHFiles(final List<Pair<byte[], String>> familyPaths, final Token<?> userToken, final String bulkToken, final byte[] startRow) throws IOException {
    // HTable#coprocessorService methods that take start and end rowkeys; see HBASE-9639
    try {
        CoprocessorRpcChannel channel = table.coprocessorService(startRow);
        SecureBulkLoadProtos.SecureBulkLoadService instance = ProtobufUtil.newServiceStub(SecureBulkLoadProtos.SecureBulkLoadService.class, channel);
        DelegationToken protoDT = DelegationToken.newBuilder().build();
        if (userToken != null) {
            protoDT = DelegationToken.newBuilder().setIdentifier(ByteStringer.wrap(userToken.getIdentifier())).setPassword(ByteStringer.wrap(userToken.getPassword())).setKind(userToken.getKind().toString()).setService(userToken.getService().toString()).build();
        }
        List<ClientProtos.BulkLoadHFileRequest.FamilyPath> protoFamilyPaths = new ArrayList<>(familyPaths.size());
        for (Pair<byte[], String> el : familyPaths) {
            protoFamilyPaths.add(ClientProtos.BulkLoadHFileRequest.FamilyPath.newBuilder().setFamily(ByteStringer.wrap(el.getFirst())).setPath(el.getSecond()).build());
        }
        SecureBulkLoadProtos.SecureBulkLoadHFilesRequest request = SecureBulkLoadProtos.SecureBulkLoadHFilesRequest.newBuilder().setFsToken(protoDT).addAllFamilyPath(protoFamilyPaths).setBulkToken(bulkToken).build();
        ServerRpcController controller = new ServerRpcController();
        CoprocessorRpcUtils.BlockingRpcCallback<SecureBulkLoadProtos.SecureBulkLoadHFilesResponse> rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
        instance.secureBulkLoadHFiles(controller, request, rpcCallback);
        SecureBulkLoadProtos.SecureBulkLoadHFilesResponse response = rpcCallback.get();
        if (controller.failedOnException()) {
            throw controller.getFailedOn();
        }
        return response.getLoaded();
    } catch (Throwable throwable) {
        throw new IOException(throwable);
    }
}
Also used : CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) DelegationToken(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.DelegationToken) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) SecureBulkLoadProtos(org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos) CoprocessorRpcUtils(org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils) ClientProtos(org.apache.hadoop.hbase.protobuf.generated.ClientProtos)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)1 CoprocessorRpcUtils (org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils)1 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)1 ClientProtos (org.apache.hadoop.hbase.protobuf.generated.ClientProtos)1 DelegationToken (org.apache.hadoop.hbase.protobuf.generated.ClientProtos.DelegationToken)1 SecureBulkLoadProtos (org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos)1