HBASE-27444 Add tool commands list_enabled_tables and list_disabled_tables (#4849)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
1bebf8699f
commit
186679f5a6
|
@ -158,6 +158,13 @@ public interface Admin extends Abortable, Closeable {
|
||||||
List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables)
|
List<TableDescriptor> listTableDescriptors(Pattern pattern, boolean includeSysTables)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all enabled or disabled tables
|
||||||
|
* @param isEnabled is true means return enabled tables, false means return disabled tables
|
||||||
|
* @return a list of enabled or disabled tables
|
||||||
|
*/
|
||||||
|
List<TableDescriptor> listTableDescriptorsByState(boolean isEnabled) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all of the names of userspace tables.
|
* List all of the names of userspace tables.
|
||||||
* @return TableName[] table names
|
* @return TableName[] table names
|
||||||
|
@ -184,6 +191,14 @@ public interface Admin extends Abortable, Closeable {
|
||||||
*/
|
*/
|
||||||
TableName[] listTableNames(Pattern pattern, boolean includeSysTables) throws IOException;
|
TableName[] listTableNames(Pattern pattern, boolean includeSysTables) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all enabled or disabled table names
|
||||||
|
* @param isEnabled is true means return enabled table names, false means return disabled table
|
||||||
|
* names
|
||||||
|
* @return a list of enabled or disabled table names
|
||||||
|
*/
|
||||||
|
List<TableName> listTableNamesByState(boolean isEnabled) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a table descriptor.
|
* Get a table descriptor.
|
||||||
* @param tableName as a {@link TableName}
|
* @param tableName as a {@link TableName}
|
||||||
|
|
|
@ -146,6 +146,11 @@ class AdminOverAsyncAdmin implements Admin {
|
||||||
return get(admin.listTableDescriptors(pattern, includeSysTables));
|
return get(admin.listTableDescriptors(pattern, includeSysTables));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TableDescriptor> listTableDescriptorsByState(boolean isEnabled) throws IOException {
|
||||||
|
return get(admin.listTableDescriptorsByState(isEnabled));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableName[] listTableNames() throws IOException {
|
public TableName[] listTableNames() throws IOException {
|
||||||
return get(admin.listTableNames()).toArray(new TableName[0]);
|
return get(admin.listTableNames()).toArray(new TableName[0]);
|
||||||
|
@ -156,6 +161,11 @@ class AdminOverAsyncAdmin implements Admin {
|
||||||
return get(admin.listTableNames(pattern, includeSysTables)).toArray(new TableName[0]);
|
return get(admin.listTableNames(pattern, includeSysTables)).toArray(new TableName[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TableName> listTableNamesByState(boolean isEnabled) throws IOException {
|
||||||
|
return get(admin.listTableNamesByState(isEnabled));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableDescriptor getDescriptor(TableName tableName)
|
public TableDescriptor getDescriptor(TableName tableName)
|
||||||
throws TableNotFoundException, IOException {
|
throws TableNotFoundException, IOException {
|
||||||
|
|
|
@ -111,6 +111,14 @@ public interface AsyncAdmin {
|
||||||
*/
|
*/
|
||||||
CompletableFuture<List<TableDescriptor>> listTableDescriptorsByNamespace(String name);
|
CompletableFuture<List<TableDescriptor>> listTableDescriptorsByNamespace(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all enabled or disabled table descriptors
|
||||||
|
* @param isEnabled is true means return enabled table descriptors, false means return disabled
|
||||||
|
* table descriptors
|
||||||
|
* @return a list of table names wrapped by a {@link CompletableFuture}.
|
||||||
|
*/
|
||||||
|
CompletableFuture<List<TableDescriptor>> listTableDescriptorsByState(boolean isEnabled);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all of the names of userspace tables.
|
* List all of the names of userspace tables.
|
||||||
* @return a list of table names wrapped by a {@link CompletableFuture}.
|
* @return a list of table names wrapped by a {@link CompletableFuture}.
|
||||||
|
@ -135,6 +143,14 @@ public interface AsyncAdmin {
|
||||||
*/
|
*/
|
||||||
CompletableFuture<List<TableName>> listTableNames(Pattern pattern, boolean includeSysTables);
|
CompletableFuture<List<TableName>> listTableNames(Pattern pattern, boolean includeSysTables);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all enabled or disabled table names
|
||||||
|
* @param isEnabled is true means return enabled table names, false means return disabled table
|
||||||
|
* names
|
||||||
|
* @return a list of table names wrapped by a {@link CompletableFuture}.
|
||||||
|
*/
|
||||||
|
CompletableFuture<List<TableName>> listTableNamesByState(boolean isEnabled);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of table names by namespace.
|
* Get list of table names by namespace.
|
||||||
* @param name namespace name
|
* @param name namespace name
|
||||||
|
|
|
@ -104,6 +104,11 @@ class AsyncHBaseAdmin implements AsyncAdmin {
|
||||||
return wrap(rawAdmin.listTableDescriptorsByNamespace(name));
|
return wrap(rawAdmin.listTableDescriptorsByNamespace(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<TableDescriptor>> listTableDescriptorsByState(boolean isEnabled) {
|
||||||
|
return wrap(rawAdmin.listTableDescriptorsByState(isEnabled));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<TableName>> listTableNames(boolean includeSysTables) {
|
public CompletableFuture<List<TableName>> listTableNames(boolean includeSysTables) {
|
||||||
return wrap(rawAdmin.listTableNames(includeSysTables));
|
return wrap(rawAdmin.listTableNames(includeSysTables));
|
||||||
|
@ -115,6 +120,11 @@ class AsyncHBaseAdmin implements AsyncAdmin {
|
||||||
return wrap(rawAdmin.listTableNames(pattern, includeSysTables));
|
return wrap(rawAdmin.listTableNames(pattern, includeSysTables));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<TableName>> listTableNamesByState(boolean isEnabled) {
|
||||||
|
return wrap(rawAdmin.listTableNamesByState(isEnabled));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<TableName>> listTableNamesByNamespace(String name) {
|
public CompletableFuture<List<TableName>> listTableNamesByNamespace(String name) {
|
||||||
return wrap(rawAdmin.listTableNamesByNamespace(name));
|
return wrap(rawAdmin.listTableNamesByNamespace(name));
|
||||||
|
|
|
@ -223,8 +223,12 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamesp
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespacesResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespacesResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceRequest;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceRequest;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceResponse;
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateRequest;
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceResponse;
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByStateRequest;
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByStateResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampForRegionRequest;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampForRegionRequest;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampRequest;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampRequest;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
|
||||||
|
@ -563,6 +567,17 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
return getTableNames(RequestConverter.buildGetTableNamesRequest(pattern, includeSysTables));
|
return getTableNames(RequestConverter.buildGetTableNamesRequest(pattern, includeSysTables));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<TableName>> listTableNamesByState(boolean isEnabled) {
|
||||||
|
return this.<List<TableName>> newMasterCaller()
|
||||||
|
.action((controller, stub) -> this.<ListTableNamesByStateRequest,
|
||||||
|
ListTableNamesByStateResponse, List<TableName>> call(controller, stub,
|
||||||
|
ListTableNamesByStateRequest.newBuilder().setIsEnabled(isEnabled).build(),
|
||||||
|
(s, c, req, done) -> s.listTableNamesByState(c, req, done),
|
||||||
|
(resp) -> ProtobufUtil.toTableNameList(resp.getTableNamesList())))
|
||||||
|
.call();
|
||||||
|
}
|
||||||
|
|
||||||
private CompletableFuture<List<TableName>> getTableNames(GetTableNamesRequest request) {
|
private CompletableFuture<List<TableName>> getTableNames(GetTableNamesRequest request) {
|
||||||
return this.<List<TableName>> newMasterCaller()
|
return this.<List<TableName>> newMasterCaller()
|
||||||
.action((controller, stub) -> this.<GetTableNamesRequest, GetTableNamesResponse,
|
.action((controller, stub) -> this.<GetTableNamesRequest, GetTableNamesResponse,
|
||||||
|
@ -583,6 +598,17 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
.call();
|
.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<TableDescriptor>> listTableDescriptorsByState(boolean isEnabled) {
|
||||||
|
return this.<List<TableDescriptor>> newMasterCaller()
|
||||||
|
.action((controller, stub) -> this.<ListTableDescriptorsByStateRequest,
|
||||||
|
ListTableDescriptorsByStateResponse, List<TableDescriptor>> call(controller, stub,
|
||||||
|
ListTableDescriptorsByStateRequest.newBuilder().setIsEnabled(isEnabled).build(),
|
||||||
|
(s, c, req, done) -> s.listTableDescriptorsByState(c, req, done),
|
||||||
|
(resp) -> ProtobufUtil.toTableDescriptorList(resp)))
|
||||||
|
.call();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<TableName>> listTableNamesByNamespace(String name) {
|
public CompletableFuture<List<TableName>> listTableNamesByNamespace(String name) {
|
||||||
return this.<List<TableName>> newMasterCaller()
|
return this.<List<TableName>> newMasterCaller()
|
||||||
|
|
|
@ -198,6 +198,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetComplet
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceResponse;
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos;
|
||||||
|
@ -506,6 +507,18 @@ public final class ProtobufUtil {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of TableDescriptor from ListTableDescriptorsByNamespaceResponse protobuf
|
||||||
|
* @param proto the ListTableDescriptorsByNamespaceResponse
|
||||||
|
* @return a list of TableDescriptor
|
||||||
|
*/
|
||||||
|
public static List<TableDescriptor>
|
||||||
|
toTableDescriptorList(ListTableDescriptorsByStateResponse proto) {
|
||||||
|
if (proto == null) return new ArrayList<>();
|
||||||
|
return proto.getTableSchemaList().stream().map(ProtobufUtil::toTableDescriptor)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the split keys in form "byte [][]" from a CreateTableRequest proto
|
* get the split keys in form "byte [][]" from a CreateTableRequest proto
|
||||||
* @param proto the CreateTableRequest
|
* @param proto the CreateTableRequest
|
||||||
|
|
|
@ -512,6 +512,14 @@ message GetTableDescriptorsResponse {
|
||||||
repeated TableSchema table_schema = 1;
|
repeated TableSchema table_schema = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ListTableDescriptorsByStateRequest {
|
||||||
|
required bool is_enabled = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ListTableDescriptorsByStateResponse {
|
||||||
|
repeated TableSchema table_schema = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message GetTableNamesRequest {
|
message GetTableNamesRequest {
|
||||||
optional string regex = 1;
|
optional string regex = 1;
|
||||||
optional bool include_sys_tables = 2 [default=false];
|
optional bool include_sys_tables = 2 [default=false];
|
||||||
|
@ -522,6 +530,14 @@ message GetTableNamesResponse {
|
||||||
repeated TableName table_names = 1;
|
repeated TableName table_names = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ListTableNamesByStateRequest {
|
||||||
|
required bool is_enabled = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ListTableNamesByStateResponse {
|
||||||
|
repeated TableName table_names = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message GetTableStateRequest {
|
message GetTableStateRequest {
|
||||||
required TableName table_name = 1;
|
required TableName table_name = 1;
|
||||||
}
|
}
|
||||||
|
@ -770,10 +786,18 @@ service MasterService {
|
||||||
rpc GetTableDescriptors(GetTableDescriptorsRequest)
|
rpc GetTableDescriptors(GetTableDescriptorsRequest)
|
||||||
returns(GetTableDescriptorsResponse);
|
returns(GetTableDescriptorsResponse);
|
||||||
|
|
||||||
|
/** List all enabled or disabled table descriptors. */
|
||||||
|
rpc ListTableDescriptorsByState(ListTableDescriptorsByStateRequest)
|
||||||
|
returns(ListTableDescriptorsByStateResponse);
|
||||||
|
|
||||||
/** Get the list of table names. */
|
/** Get the list of table names. */
|
||||||
rpc GetTableNames(GetTableNamesRequest)
|
rpc GetTableNames(GetTableNamesRequest)
|
||||||
returns(GetTableNamesResponse);
|
returns(GetTableNamesResponse);
|
||||||
|
|
||||||
|
/** List all enabled or disabled table names. */
|
||||||
|
rpc ListTableNamesByState(ListTableNamesByStateRequest)
|
||||||
|
returns(ListTableNamesByStateResponse);
|
||||||
|
|
||||||
/** Return cluster status. */
|
/** Return cluster status. */
|
||||||
rpc GetClusterStatus(GetClusterStatusRequest)
|
rpc GetClusterStatus(GetClusterStatusRequest)
|
||||||
returns(GetClusterStatusResponse);
|
returns(GetClusterStatusResponse);
|
||||||
|
|
|
@ -283,8 +283,12 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamesp
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespacesResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespacesResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceRequest;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceRequest;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByNamespaceResponse;
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateRequest;
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableDescriptorsByStateResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceResponse;
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByStateRequest;
|
||||||
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByStateResponse;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampForRegionRequest;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampForRegionRequest;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampRequest;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampRequest;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
|
||||||
|
@ -1173,6 +1177,31 @@ public class MasterRpcServices extends HBaseRpcServicesBase<HMaster>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListTableDescriptorsByStateResponse listTableDescriptorsByState(RpcController controller,
|
||||||
|
ListTableDescriptorsByStateRequest request) throws ServiceException {
|
||||||
|
try {
|
||||||
|
server.checkInitialized();
|
||||||
|
List<TableDescriptor> descriptors = server.listTableDescriptors(null, null, null, false);
|
||||||
|
|
||||||
|
ListTableDescriptorsByStateResponse.Builder builder =
|
||||||
|
ListTableDescriptorsByStateResponse.newBuilder();
|
||||||
|
if (descriptors != null && descriptors.size() > 0) {
|
||||||
|
// Add the table descriptors to the response
|
||||||
|
TableState.State state =
|
||||||
|
request.getIsEnabled() ? TableState.State.ENABLED : TableState.State.DISABLED;
|
||||||
|
for (TableDescriptor htd : descriptors) {
|
||||||
|
if (server.getTableStateManager().isTableState(htd.getTableName(), state)) {
|
||||||
|
builder.addTableSchema(ProtobufUtil.toTableSchema(htd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new ServiceException(ioe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of userspace table names
|
* Get list of userspace table names
|
||||||
* @param controller Unused (set to null).
|
* @param controller Unused (set to null).
|
||||||
|
@ -1202,6 +1231,29 @@ public class MasterRpcServices extends HBaseRpcServicesBase<HMaster>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListTableNamesByStateResponse listTableNamesByState(RpcController controller,
|
||||||
|
ListTableNamesByStateRequest request) throws ServiceException {
|
||||||
|
try {
|
||||||
|
server.checkServiceStarted();
|
||||||
|
List<TableName> tableNames = server.listTableNames(null, null, false);
|
||||||
|
ListTableNamesByStateResponse.Builder builder = ListTableNamesByStateResponse.newBuilder();
|
||||||
|
if (tableNames != null && tableNames.size() > 0) {
|
||||||
|
// Add the disabled table names to the response
|
||||||
|
TableState.State state =
|
||||||
|
request.getIsEnabled() ? TableState.State.ENABLED : TableState.State.DISABLED;
|
||||||
|
for (TableName table : tableNames) {
|
||||||
|
if (server.getTableStateManager().isTableState(table, state)) {
|
||||||
|
builder.addTableNames(ProtobufUtil.toProtoTableName(table));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ServiceException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GetTableStateResponse getTableState(RpcController controller, GetTableStateRequest request)
|
public GetTableStateResponse getTableState(RpcController controller, GetTableStateRequest request)
|
||||||
throws ServiceException {
|
throws ServiceException {
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.hbase.master;
|
||||||
|
|
||||||
|
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||||
|
import org.apache.hadoop.hbase.HBaseTestingUtil;
|
||||||
|
import org.apache.hadoop.hbase.TableName;
|
||||||
|
import org.apache.hadoop.hbase.client.Admin;
|
||||||
|
import org.apache.hadoop.hbase.client.TableDescriptor;
|
||||||
|
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
|
||||||
|
import org.apache.hadoop.hbase.testclassification.MasterTests;
|
||||||
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
@Category({ MasterTests.class, MediumTests.class })
|
||||||
|
public class TestListTablesByState {
|
||||||
|
@ClassRule
|
||||||
|
public static final HBaseClassTestRule CLASS_RULE =
|
||||||
|
HBaseClassTestRule.forClass(TestListTablesByState.class);
|
||||||
|
|
||||||
|
private static HBaseTestingUtil UTIL;
|
||||||
|
private static Admin ADMIN;
|
||||||
|
private final static int SLAVES = 1;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
UTIL = new HBaseTestingUtil();
|
||||||
|
UTIL.startMiniCluster(SLAVES);
|
||||||
|
ADMIN = UTIL.getAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListTableNamesByState() throws Exception {
|
||||||
|
TableName testTableName = TableName.valueOf("test");
|
||||||
|
TableDescriptor testTableDesc = TableDescriptorBuilder.newBuilder(testTableName).build();
|
||||||
|
ADMIN.createTable(testTableDesc);
|
||||||
|
ADMIN.disableTable(testTableName);
|
||||||
|
Assert.assertEquals(ADMIN.listTableNamesByState(false).get(0), testTableName);
|
||||||
|
ADMIN.enableTable(testTableName);
|
||||||
|
Assert.assertEquals(ADMIN.listTableNamesByState(true).get(0), testTableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListTableDescriptorByState() throws Exception {
|
||||||
|
TableName testTableName = TableName.valueOf("test");
|
||||||
|
TableDescriptor testTableDesc = TableDescriptorBuilder.newBuilder(testTableName).build();
|
||||||
|
ADMIN.createTable(testTableDesc);
|
||||||
|
ADMIN.disableTable(testTableName);
|
||||||
|
Assert.assertEquals(ADMIN.listTableDescriptorsByState(false).get(0), testTableDesc);
|
||||||
|
ADMIN.enableTable(testTableName);
|
||||||
|
Assert.assertEquals(ADMIN.listTableDescriptorsByState(true).get(0), testTableDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void tearDownAfterClass() throws Exception {
|
||||||
|
if (ADMIN != null) {
|
||||||
|
ADMIN.close();
|
||||||
|
}
|
||||||
|
if (UTIL != null) {
|
||||||
|
UTIL.shutdownMiniCluster();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -144,6 +144,11 @@ public class VerifyingRSGroupAdmin implements Admin, Closeable {
|
||||||
return admin.listTableDescriptors(pattern, includeSysTables);
|
return admin.listTableDescriptors(pattern, includeSysTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TableDescriptor> listTableDescriptorsByState(boolean isEnabled) throws IOException {
|
||||||
|
return admin.listTableDescriptorsByState(isEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
public TableName[] listTableNames() throws IOException {
|
public TableName[] listTableNames() throws IOException {
|
||||||
return admin.listTableNames();
|
return admin.listTableNames();
|
||||||
}
|
}
|
||||||
|
@ -152,6 +157,11 @@ public class VerifyingRSGroupAdmin implements Admin, Closeable {
|
||||||
return admin.listTableNames(pattern, includeSysTables);
|
return admin.listTableNames(pattern, includeSysTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TableName> listTableNamesByState(boolean isEnabled) throws IOException {
|
||||||
|
return admin.listTableNamesByState(isEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
public TableDescriptor getDescriptor(TableName tableName)
|
public TableDescriptor getDescriptor(TableName tableName)
|
||||||
throws TableNotFoundException, IOException {
|
throws TableNotFoundException, IOException {
|
||||||
return admin.getDescriptor(tableName);
|
return admin.getDescriptor(tableName);
|
||||||
|
|
|
@ -1885,6 +1885,12 @@ module Hbase
|
||||||
def flush_master_store()
|
def flush_master_store()
|
||||||
@admin.flushMasterStore()
|
@admin.flushMasterStore()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Returns a list of enable or disabled tables in hbase
|
||||||
|
def list_tables_by_state(isEnabled)
|
||||||
|
@admin.listTableNamesByState(isEnabled).map(&:getNameAsString)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/ClassLength
|
# rubocop:enable Metrics/ClassLength
|
||||||
end
|
end
|
||||||
|
|
|
@ -390,6 +390,8 @@ Shell.load_command_group(
|
||||||
locate_region
|
locate_region
|
||||||
list_regions
|
list_regions
|
||||||
clone_table_schema
|
clone_table_schema
|
||||||
|
list_enabled_tables
|
||||||
|
list_disabled_tables
|
||||||
],
|
],
|
||||||
aliases: {
|
aliases: {
|
||||||
'describe' => ['desc']
|
'describe' => ['desc']
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
# distributed with this work for additional information
|
||||||
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
|
# to you under the Apache License, Version 2.0 (the
|
||||||
|
# "License"); you may not use this file except in compliance
|
||||||
|
# with the License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
module Shell
|
||||||
|
module Commands
|
||||||
|
class ListDisabledTables < Command
|
||||||
|
def help
|
||||||
|
<<~EOF
|
||||||
|
List all disabled tables
|
||||||
|
Examples:
|
||||||
|
hbase> list_disabled_tables
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command()
|
||||||
|
formatter.header(['TABLE'])
|
||||||
|
|
||||||
|
list = admin.list_tables_by_state(false)
|
||||||
|
list.each do |table|
|
||||||
|
formatter.row([table])
|
||||||
|
end
|
||||||
|
|
||||||
|
formatter.footer(list.size)
|
||||||
|
list
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,44 @@
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
# distributed with this work for additional information
|
||||||
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
|
# to you under the Apache License, Version 2.0 (the
|
||||||
|
# "License"); you may not use this file except in compliance
|
||||||
|
# with the License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
module Shell
|
||||||
|
module Commands
|
||||||
|
class ListEnabledTables < Command
|
||||||
|
def help
|
||||||
|
<<~EOF
|
||||||
|
List all enabled tables
|
||||||
|
Examples:
|
||||||
|
hbase> list_enabled_tables
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command()
|
||||||
|
formatter.header(['TABLE'])
|
||||||
|
|
||||||
|
list = admin.list_tables_by_state(true)
|
||||||
|
list.each do |table|
|
||||||
|
formatter.row([table])
|
||||||
|
end
|
||||||
|
|
||||||
|
formatter.footer(list.size)
|
||||||
|
list
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.hbase.client;
|
||||||
|
|
||||||
|
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||||
|
import org.apache.hadoop.hbase.testclassification.ClientTests;
|
||||||
|
import org.apache.hadoop.hbase.testclassification.LargeTests;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
@Category({ ClientTests.class, LargeTests.class })
|
||||||
|
public class TestListTablesShell extends AbstractTestShell {
|
||||||
|
@ClassRule
|
||||||
|
public static final HBaseClassTestRule CLASS_RULE =
|
||||||
|
HBaseClassTestRule.forClass(TestListTablesShell.class);
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
setUpConfig();
|
||||||
|
|
||||||
|
TEST_UTIL.startMiniCluster(3);
|
||||||
|
|
||||||
|
setUpJRubyRuntime();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getIncludeList() {
|
||||||
|
return "list_tables_test.rb";
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,6 +32,6 @@ public class TestShell extends AbstractTestShell {
|
||||||
@Override
|
@Override
|
||||||
protected String getExcludeList() {
|
protected String getExcludeList() {
|
||||||
return "replication_admin_test.rb,rsgroup_shell_test.rb,admin_test.rb,table_test.rb,"
|
return "replication_admin_test.rb,rsgroup_shell_test.rb,admin_test.rb,table_test.rb,"
|
||||||
+ "quotas_test.rb,admin2_test.rb";
|
+ "quotas_test.rb,admin2_test.rb,list_tables_test.rb";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
# distributed with this work for additional information
|
||||||
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
|
# to you under the Apache License, Version 2.0 (the
|
||||||
|
# "License"); you may not use this file except in compliance
|
||||||
|
# with the License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'hbase_constants'
|
||||||
|
require 'hbase_shell'
|
||||||
|
|
||||||
|
class ListTablesTest < Test::Unit::TestCase
|
||||||
|
def setup
|
||||||
|
@hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
|
||||||
|
@shell = Shell::Shell.new(@hbase)
|
||||||
|
connection = $TEST_CLUSTER.getConnection
|
||||||
|
@admin = connection.getAdmin
|
||||||
|
end
|
||||||
|
|
||||||
|
define_test "List enabled tables" do
|
||||||
|
table = 'test_table1'
|
||||||
|
family = 'f1'
|
||||||
|
@shell.command('create', table, family)
|
||||||
|
assert_equal [table], @shell.command('list_enabled_tables')
|
||||||
|
@shell.command(:disable, table)
|
||||||
|
@shell.command(:drop, table)
|
||||||
|
end
|
||||||
|
|
||||||
|
define_test "List disabled tables" do
|
||||||
|
table = 'test_table2'
|
||||||
|
family = 'f1'
|
||||||
|
@shell.command('create', table, family)
|
||||||
|
@shell.command(:disable, table)
|
||||||
|
assert_equal [table], @shell.command('list_disabled_tables')
|
||||||
|
@shell.command(:drop, table)
|
||||||
|
end
|
||||||
|
end
|
|
@ -174,6 +174,11 @@ public class ThriftAdmin implements Admin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TableDescriptor> listTableDescriptorsByState(boolean isEnabled) throws IOException {
|
||||||
|
throw new NotImplementedException("listTableDescriptorsByState not supported in ThriftAdmin");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableName[] listTableNames() throws IOException {
|
public TableName[] listTableNames() throws IOException {
|
||||||
return listTableNames(null);
|
return listTableNames(null);
|
||||||
|
@ -195,6 +200,11 @@ public class ThriftAdmin implements Admin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TableName> listTableNamesByState(boolean isEnabled) throws IOException {
|
||||||
|
throw new NotImplementedException("listTableNamesByState not supported in ThriftAdmin");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableDescriptor getDescriptor(TableName tableName)
|
public TableDescriptor getDescriptor(TableName tableName)
|
||||||
throws TableNotFoundException, IOException {
|
throws TableNotFoundException, IOException {
|
||||||
|
|
Loading…
Reference in New Issue