From ffcc003f853303f321d3c8a3d0915dd3639feaa5 Mon Sep 17 00:00:00 2001 From: niuyulin Date: Wed, 20 Mar 2019 15:27:59 +0800 Subject: [PATCH] HBASE-22065 Add listTableDescriptors(List) method in AsyncAdmin Signed-off-by: zhangduo --- .../apache/hadoop/hbase/client/AsyncAdmin.java | 7 +++++++ .../hadoop/hbase/client/AsyncHBaseAdmin.java | 5 +++++ .../hbase/client/RawAsyncHBaseAdmin.java | 10 ++++++++++ .../hbase/client/TestAsyncTableAdminApi3.java | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java index 2df18fe98ef..682ae62c82a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java @@ -83,6 +83,13 @@ public interface AsyncAdmin { CompletableFuture> listTableDescriptors(Pattern pattern, boolean includeSysTables); + /** + * List specific tables including system tables. + * @param tableNames the table list to match against + * @return - returns a list of TableDescriptors wrapped by a {@link CompletableFuture}. + */ + CompletableFuture> listTableDescriptors(List tableNames); + /** * Get list of table descriptors by namespace. * @param name namespace name diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java index e62f3bb2604..f037b4e1b0c 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java @@ -87,6 +87,11 @@ class AsyncHBaseAdmin implements AsyncAdmin { return wrap(rawAdmin.listTableDescriptors(pattern, includeSysTables)); } + @Override + public CompletableFuture> listTableDescriptors(List tableNames) { + return wrap(rawAdmin.listTableDescriptors(tableNames)); + } + @Override public CompletableFuture> listTableDescriptorsByNamespace(String name) { return wrap(rawAdmin.listTableDescriptorsByNamespace(name)); diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java index 0eba0fdcd10..f00a38da9bd 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java @@ -470,6 +470,16 @@ class RawAsyncHBaseAdmin implements AsyncAdmin { includeSysTables)); } + @Override + public CompletableFuture> listTableDescriptors(List tableNames) { + Preconditions.checkNotNull(tableNames, + "tableNames is null. If you don't specify tableNames, " + "use listTables(boolean) instead"); + if (tableNames.isEmpty()) { + return CompletableFuture.completedFuture(Collections.emptyList()); + } + return getTableDescriptors(RequestConverter.buildGetTableDescriptorsRequest(tableNames)); + } + private CompletableFuture> getTableDescriptors(GetTableDescriptorsRequest request) { return this.> newMasterCaller() diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi3.java index 750749dc0e1..d4bb3be0204 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi3.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi3.java @@ -25,6 +25,8 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutionException; @@ -110,6 +112,22 @@ public class TestAsyncTableAdminApi3 extends TestAsyncAdminBase { assertTrue("Not found: " + tables[i], found); } + tableNames = new ArrayList(tables.length + 1); + tableDescs = admin.listTableDescriptors(tableNames).get(); + size = tableDescs.size(); + assertEquals(0, size); + + Collections.addAll(tableNames, tables); + tableNames.add(TableName.META_TABLE_NAME); + tableDescs = admin.listTableDescriptors(tableNames).get(); + size = tableDescs.size(); + assertEquals(tables.length + 1, size); + for (int i = 0, j = 0; i < tables.length && j < size; i++, j++) { + assertTrue("tableName should be equal in order", + tableDescs.get(j).getTableName().equals(tables[i])); + } + assertTrue(tableDescs.get(size - 1).getTableName().equals(TableName.META_TABLE_NAME)); + for (int i = 0; i < tables.length; i++) { admin.disableTable(tables[i]).join(); admin.deleteTable(tables[i]).join();