HBASE-22065 Add listTableDescriptors(List<TableName>) method in AsyncAdmin
Signed-off-by: zhangduo <zhangduo@apache.org>
This commit is contained in:
parent
556b98101c
commit
cbd9c9b2e1
|
@ -87,6 +87,13 @@ public interface AsyncAdmin {
|
|||
CompletableFuture<List<TableDescriptor>> 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<List<TableDescriptor>> listTableDescriptors(List<TableName> tableNames);
|
||||
|
||||
/**
|
||||
* Get list of table descriptors by namespace.
|
||||
* @param name namespace name
|
||||
|
|
|
@ -88,6 +88,11 @@ class AsyncHBaseAdmin implements AsyncAdmin {
|
|||
return wrap(rawAdmin.listTableDescriptors(pattern, includeSysTables));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<TableDescriptor>> listTableDescriptors(List<TableName> tableNames) {
|
||||
return wrap(rawAdmin.listTableDescriptors(tableNames));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<TableDescriptor>> listTableDescriptorsByNamespace(String name) {
|
||||
return wrap(rawAdmin.listTableDescriptorsByNamespace(name));
|
||||
|
|
|
@ -473,6 +473,16 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
|||
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>>
|
||||
getTableDescriptors(GetTableDescriptorsRequest request) {
|
||||
return this.<List<TableDescriptor>> newMasterCaller()
|
||||
|
|
|
@ -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<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++) {
|
||||
admin.disableTable(tables[i]).join();
|
||||
admin.deleteTable(tables[i]).join();
|
||||
|
|
Loading…
Reference in New Issue