HBASE-22065 Add listTableDescriptors(List<TableName>) method in AsyncAdmin

Signed-off-by: zhangduo <zhangduo@apache.org>
This commit is contained in:
niuyulin 2019-03-20 15:27:59 +08:00 committed by zhangduo
parent 556b98101c
commit cbd9c9b2e1
4 changed files with 40 additions and 0 deletions

View File

@ -87,6 +87,13 @@ public interface AsyncAdmin {
CompletableFuture<List<TableDescriptor>> listTableDescriptors(Pattern pattern, CompletableFuture<List<TableDescriptor>> listTableDescriptors(Pattern pattern,
boolean includeSysTables); 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<List<TableDescriptor>> listTableDescriptors(List<TableName> tableNames);
/** /**
* Get list of table descriptors by namespace. * Get list of table descriptors by namespace.
* @param name namespace name * @param name namespace name

View File

@ -88,6 +88,11 @@ class AsyncHBaseAdmin implements AsyncAdmin {
return wrap(rawAdmin.listTableDescriptors(pattern, includeSysTables)); return wrap(rawAdmin.listTableDescriptors(pattern, includeSysTables));
} }
@Override
public CompletableFuture<List<TableDescriptor>> listTableDescriptors(List<TableName> tableNames) {
return wrap(rawAdmin.listTableDescriptors(tableNames));
}
@Override @Override
public CompletableFuture<List<TableDescriptor>> listTableDescriptorsByNamespace(String name) { public CompletableFuture<List<TableDescriptor>> listTableDescriptorsByNamespace(String name) {
return wrap(rawAdmin.listTableDescriptorsByNamespace(name)); return wrap(rawAdmin.listTableDescriptorsByNamespace(name));

View File

@ -473,6 +473,16 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
includeSysTables)); includeSysTables));
} }
@Override
public CompletableFuture<List<TableDescriptor>> listTableDescriptors(List<TableName> 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<List<TableDescriptor>> private CompletableFuture<List<TableDescriptor>>
getTableDescriptors(GetTableDescriptorsRequest request) { getTableDescriptors(GetTableDescriptorsRequest request) {
return this.<List<TableDescriptor>> newMasterCaller() return this.<List<TableDescriptor>> newMasterCaller()

View File

@ -25,6 +25,8 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -110,6 +112,22 @@ public class TestAsyncTableAdminApi3 extends TestAsyncAdminBase {
assertTrue("Not found: " + tables[i], found); assertTrue("Not found: " + tables[i], found);
} }
tableNames = new ArrayList<TableName>(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++) { for (int i = 0; i < tables.length; i++) {
admin.disableTable(tables[i]).join(); admin.disableTable(tables[i]).join();
admin.deleteTable(tables[i]).join(); admin.deleteTable(tables[i]).join();