/** * 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 { try (Table 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<>(); @Override 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); return result.values().iterator().next(); // There will be exactly one region for labels // table and so one entry in result Map. } }
/** * 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(); BlockingRpcCallback<ListLabelsResponse> rpcCallback = new BlockingRpcCallback<ListLabelsResponse>(); 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); return result.values().iterator().next(); // There will be exactly one region for labels // table and so one entry in result Map. } finally { if (table != null) { table.close(); } if (connection != null) { connection.close(); } } }
/** * Retrieve the list of visibility labels defined in the system. * @param conf * @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(Configuration conf, final String regex) throws Throwable { Connection connection = null; Table table = null; try { connection = ConnectionFactory.createConnection(conf); table = connection.getTable(LABELS_TABLE_NAME); Batch.Call<VisibilityLabelsService, ListLabelsResponse> callable = new Batch.Call<VisibilityLabelsService, ListLabelsResponse>() { ServerRpcController controller = new ServerRpcController(); BlockingRpcCallback<ListLabelsResponse> rpcCallback = new BlockingRpcCallback<ListLabelsResponse>(); 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); return result.values().iterator().next(); // There will be exactly one region for labels // table and so one entry in result Map. } finally { if (table != null) { table.close(); } if (connection != null) { connection.close(); } } }
@Override public void listLabels(RpcController controller, ListLabelsRequest request, RpcCallback<ListLabelsResponse> done) { }