HBASE-22377 Provide API to check the existence of a namespace which does not require ADMIN permissions (#225)

Signed-off-by: Xu Cang <xucang@apache.org>
This commit is contained in:
Andrew Purtell 2019-05-14 11:56:16 -07:00 committed by GitHub
parent fde025112b
commit a9de9f5f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 1171 additions and 13 deletions

View File

@ -112,7 +112,7 @@ public interface Admin extends Abortable, Closeable {
/** /**
* @param tableName Table to check. * @param tableName Table to check.
* @return <code>true</code> if table exists already. * @return <code>true</code> if table exists already.
* @throws IOException * @throws IOException if a remote or network exception occurs
*/ */
boolean tableExists(TableName tableName) throws IOException; boolean tableExists(TableName tableName) throws IOException;
@ -486,7 +486,7 @@ public interface Admin extends Abortable, Closeable {
* Get all the online regions on a region server. * Get all the online regions on a region server.
* *
* @return List of {@link RegionInfo} * @return List of {@link RegionInfo}
* @throws java.io.IOException * @throws IOException if a remote or network exception occurs
*/ */
List<RegionInfo> getRegions(ServerName serverName) throws IOException; List<RegionInfo> getRegions(ServerName serverName) throws IOException;
@ -1130,8 +1130,18 @@ public interface Admin extends Abortable, Closeable {
throws NamespaceNotFoundException, IOException; throws NamespaceNotFoundException, IOException;
/** /**
* List available namespace descriptors. * List available namespaces
*
* @return List of namespace names
* @throws IOException if a remote or network exception occurs
*/
String[] listNamespaces() throws IOException;
/**
* List available namespace descriptors
*
* @return List of descriptors * @return List of descriptors
* @throws IOException if a remote or network exception occurs
*/ */
NamespaceDescriptor[] listNamespaceDescriptors() throws IOException; NamespaceDescriptor[] listNamespaceDescriptors() throws IOException;
@ -1139,6 +1149,7 @@ public interface Admin extends Abortable, Closeable {
* Get list of table descriptors by namespace. * Get list of table descriptors by namespace.
* @param name namespace name * @param name namespace name
* @return returns a list of TableDescriptors * @return returns a list of TableDescriptors
* @throws IOException if a remote or network exception occurs
*/ */
List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name) throws IOException; List<TableDescriptor> listTableDescriptorsByNamespace(byte[] name) throws IOException;
@ -1146,6 +1157,7 @@ public interface Admin extends Abortable, Closeable {
* Get list of table names by namespace. * Get list of table names by namespace.
* @param name namespace name * @param name namespace name
* @return The list of table names in the namespace * @return The list of table names in the namespace
* @throws IOException if a remote or network exception occurs
*/ */
TableName[] listTableNamesByNamespace(String name) throws IOException; TableName[] listTableNamesByNamespace(String name) throws IOException;
@ -1154,6 +1166,7 @@ public interface Admin extends Abortable, Closeable {
* *
* @param tableName the name of the table * @param tableName the name of the table
* @return List of {@link RegionInfo}. * @return List of {@link RegionInfo}.
* @throws IOException if a remote or network exception occurs
*/ */
List<RegionInfo> getRegions(TableName tableName) throws IOException; List<RegionInfo> getRegions(TableName tableName) throws IOException;
@ -1178,7 +1191,7 @@ public interface Admin extends Abortable, Closeable {
* @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
* @return <code>true</code> if aborted, <code>false</code> if procedure already completed or does * @return <code>true</code> if aborted, <code>false</code> if procedure already completed or does
* not exist * not exist
* @throws IOException * @throws IOException if a remote or network exception occurs
* @deprecated Since 2.1.1 -- to be removed. * @deprecated Since 2.1.1 -- to be removed.
*/ */
@Deprecated @Deprecated
@ -1198,7 +1211,7 @@ public interface Admin extends Abortable, Closeable {
* @param procId ID of the procedure to abort * @param procId ID of the procedure to abort
* @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
* @return <code>true</code> if aborted, <code>false</code> if procedure already completed or does not exist * @return <code>true</code> if aborted, <code>false</code> if procedure already completed or does not exist
* @throws IOException * @throws IOException if a remote or network exception occurs
* @deprecated Since 2.1.1 -- to be removed. * @deprecated Since 2.1.1 -- to be removed.
*/ */
@Deprecated @Deprecated
@ -1208,7 +1221,7 @@ public interface Admin extends Abortable, Closeable {
/** /**
* Get procedures. * Get procedures.
* @return procedure list in JSON * @return procedure list in JSON
* @throws IOException * @throws IOException if a remote or network exception occurs
*/ */
String getProcedures() throws IOException; String getProcedures() throws IOException;

View File

@ -270,6 +270,12 @@ public interface AsyncAdmin {
*/ */
CompletableFuture<NamespaceDescriptor> getNamespaceDescriptor(String name); CompletableFuture<NamespaceDescriptor> getNamespaceDescriptor(String name);
/**
* List available namespaces
* @return List of namespaces wrapped by a {@link CompletableFuture}.
*/
CompletableFuture<List<String>> listNamespaces();
/** /**
* List available namespace descriptors * List available namespace descriptors
* @return List of descriptors wrapped by a {@link CompletableFuture}. * @return List of descriptors wrapped by a {@link CompletableFuture}.

View File

@ -214,6 +214,11 @@ class AsyncHBaseAdmin implements AsyncAdmin {
return wrap(rawAdmin.getNamespaceDescriptor(name)); return wrap(rawAdmin.getNamespaceDescriptor(name));
} }
@Override
public CompletableFuture<List<String>> listNamespaces() {
return wrap(rawAdmin.listNamespaces());
}
@Override @Override
public CompletableFuture<List<NamespaceDescriptor>> listNamespaceDescriptors() { public CompletableFuture<List<NamespaceDescriptor>> listNamespaceDescriptors() {
return wrap(rawAdmin.listNamespaceDescriptors()); return wrap(rawAdmin.listNamespaceDescriptors());

View File

@ -1561,6 +1561,13 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
return stub.deleteNamespace(controller, request); return stub.deleteNamespace(controller, request);
} }
@Override
public MasterProtos.ListNamespacesResponse listNamespaces(
RpcController controller,
MasterProtos.ListNamespacesRequest request) throws ServiceException {
return stub.listNamespaces(controller, request);
}
@Override @Override
public MasterProtos.GetNamespaceDescriptorResponse getNamespaceDescriptor( public MasterProtos.GetNamespaceDescriptorResponse getNamespaceDescriptor(
RpcController controller, RpcController controller,

View File

@ -182,6 +182,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshot
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneResponse; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecommissionedRegionServersRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecommissionedRegionServersRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespacesRequest;
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.ListTableNamesByNamespaceRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampForRegionRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampForRegionRequest;
@ -1412,7 +1413,7 @@ public class HBaseAdmin implements Admin {
* @param nameOfRegionB encoded or full name of region b * @param nameOfRegionB encoded or full name of region b
* @param forcible true if do a compulsory merge, otherwise we will only merge * @param forcible true if do a compulsory merge, otherwise we will only merge
* two adjacent regions * two adjacent regions
* @throws IOException * @throws IOException if a remote or network exception occurs
*/ */
@VisibleForTesting @VisibleForTesting
public void mergeRegionsSync( public void mergeRegionsSync(
@ -1512,7 +1513,7 @@ public class HBaseAdmin implements Admin {
* Therefore, this is for internal testing only. * Therefore, this is for internal testing only.
* @param regionName encoded or full name of region * @param regionName encoded or full name of region
* @param splitPoint key where region splits * @param splitPoint key where region splits
* @throws IOException * @throws IOException if a remote or network exception occurs
*/ */
@VisibleForTesting @VisibleForTesting
public void splitRegionSync(byte[] regionName, byte[] splitPoint) throws IOException { public void splitRegionSync(byte[] regionName, byte[] splitPoint) throws IOException {
@ -1526,7 +1527,7 @@ public class HBaseAdmin implements Admin {
* @param splitPoint split point * @param splitPoint split point
* @param timeout how long to wait on split * @param timeout how long to wait on split
* @param units time units * @param units time units
* @throws IOException * @throws IOException if a remote or network exception occurs
*/ */
public void splitRegionSync(byte[] regionName, byte[] splitPoint, final long timeout, public void splitRegionSync(byte[] regionName, byte[] splitPoint, final long timeout,
final TimeUnit units) throws IOException { final TimeUnit units) throws IOException {
@ -1647,7 +1648,7 @@ public class HBaseAdmin implements Admin {
* MetaTableAccessor#getRegionLocation(Connection, byte[])} * MetaTableAccessor#getRegionLocation(Connection, byte[])}
* else null. * else null.
* Throw IllegalArgumentException if <code>regionName</code> is null. * Throw IllegalArgumentException if <code>regionName</code> is null.
* @throws IOException * @throws IOException if a remote or network exception occurs
*/ */
Pair<RegionInfo, ServerName> getRegion(final byte[] regionName) throws IOException { Pair<RegionInfo, ServerName> getRegion(final byte[] regionName) throws IOException {
if (regionName == null) { if (regionName == null) {
@ -1921,6 +1922,29 @@ public class HBaseAdmin implements Admin {
}); });
} }
/**
* List available namespaces
* @return List of namespace names
* @throws IOException if a remote or network exception occurs
*/
@Override
public String[] listNamespaces() throws IOException {
return executeCallable(new MasterCallable<String[]>(getConnection(),
getRpcControllerFactory()) {
@Override
protected String[] rpcCall() throws Exception {
List<String> list = master.listNamespaces(getRpcController(),
ListNamespacesRequest.newBuilder().build()).getNamespaceNameList();
return list.toArray(new String[list.size()]);
}
});
}
/**
* List available namespace descriptors
* @return List of descriptors
* @throws IOException if a remote or network exception occurs
*/
@Override @Override
public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException { public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException {
return executeCallable(new MasterCallable<NamespaceDescriptor[]>(getConnection(), return executeCallable(new MasterCallable<NamespaceDescriptor[]>(getConnection(),
@ -3594,7 +3618,7 @@ public class HBaseAdmin implements Admin {
* </ol> * </ol>
* @param tableName name of the table to sync to the peer * @param tableName name of the table to sync to the peer
* @param splits table split keys * @param splits table split keys
* @throws IOException * @throws IOException if a remote or network exception occurs
*/ */
private void checkAndSyncTableDescToPeers(final TableName tableName, final byte[][] splits) private void checkAndSyncTableDescToPeers(final TableName tableName, final byte[][] splits)
throws IOException { throws IOException {

View File

@ -214,6 +214,8 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecomm
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecommissionedRegionServersResponse; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecommissionedRegionServersResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest;
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.ListNamespacesRequest;
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.ListTableNamesByNamespaceRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
@ -828,6 +830,18 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
.toNamespaceDescriptor(resp.getNamespaceDescriptor()))).call(); .toNamespaceDescriptor(resp.getNamespaceDescriptor()))).call();
} }
@Override
public CompletableFuture<List<String>> listNamespaces() {
return this
.<List<String>> newMasterCaller()
.action(
(controller, stub) -> this
.<ListNamespacesRequest, ListNamespacesResponse, List<String>> call(
controller, stub, ListNamespacesRequest.newBuilder().build(), (s, c, req,
done) -> s.listNamespaces(c, req, done),
(resp) -> resp.getNamespaceNameList())).call();
}
@Override @Override
public CompletableFuture<List<NamespaceDescriptor>> listNamespaceDescriptors() { public CompletableFuture<List<NamespaceDescriptor>> listNamespaceDescriptors() {
return this return this

View File

@ -31,6 +31,7 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos.Rev
import org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos.RevokeResponse; import org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos.RevokeResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse; import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AbortProcedureRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AbortProcedureRequest;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AbortProcedureResponse; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AbortProcedureResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AddColumnRequest;
@ -107,6 +108,8 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecomm
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecommissionedRegionServersResponse; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecommissionedRegionServersResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest;
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.ListNamespacesRequest;
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.ListTableNamesByNamespaceRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
@ -446,6 +449,12 @@ public class ShortCircuitMasterConnection implements MasterKeepAliveConnection {
return stub.getNamespaceDescriptor(controller, request); return stub.getNamespaceDescriptor(controller, request);
} }
@Override
public ListNamespacesResponse listNamespaces(RpcController controller,
ListNamespacesRequest request) throws ServiceException {
return stub.listNamespaces(controller, request);
}
@Override @Override
public MajorCompactionTimestampResponse getLastMajorCompactionTimestampForRegion( public MajorCompactionTimestampResponse getLastMajorCompactionTimestampForRegion(
RpcController controller, MajorCompactionTimestampForRegionRequest request) RpcController controller, MajorCompactionTimestampForRegionRequest request)

View File

@ -237,6 +237,13 @@ message GetNamespaceDescriptorResponse {
required NamespaceDescriptor namespaceDescriptor = 1; required NamespaceDescriptor namespaceDescriptor = 1;
} }
message ListNamespacesRequest {
}
message ListNamespacesResponse {
repeated string namespaceName = 1;
}
message ListNamespaceDescriptorsRequest { message ListNamespaceDescriptorsRequest {
} }
@ -916,7 +923,7 @@ service MasterService {
rpc GetNamespaceDescriptor(GetNamespaceDescriptorRequest) rpc GetNamespaceDescriptor(GetNamespaceDescriptorRequest)
returns(GetNamespaceDescriptorResponse); returns(GetNamespaceDescriptorResponse);
/** returns a list of namespaces */ /** returns a list of namespace descriptors */
rpc ListNamespaceDescriptors(ListNamespaceDescriptorsRequest) rpc ListNamespaceDescriptors(ListNamespaceDescriptorsRequest)
returns(ListNamespaceDescriptorsResponse); returns(ListNamespaceDescriptorsResponse);
@ -1035,6 +1042,10 @@ service MasterService {
rpc GetUserPermissions (GetUserPermissionsRequest) returns (GetUserPermissionsResponse); rpc GetUserPermissions (GetUserPermissionsRequest) returns (GetUserPermissionsResponse);
rpc HasUserPermissions (HasUserPermissionsRequest) returns (HasUserPermissionsResponse); rpc HasUserPermissions (HasUserPermissionsRequest) returns (HasUserPermissionsResponse);
/** returns a list of namespace names */
rpc ListNamespaces(ListNamespacesRequest)
returns(ListNamespacesResponse);
} }
// HBCK Service definitions. // HBCK Service definitions.

View File

@ -963,6 +963,24 @@ public interface MasterObserver {
default void postGetNamespaceDescriptor(ObserverContext<MasterCoprocessorEnvironment> ctx, default void postGetNamespaceDescriptor(ObserverContext<MasterCoprocessorEnvironment> ctx,
NamespaceDescriptor ns) throws IOException {} NamespaceDescriptor ns) throws IOException {}
/**
* Called before a listNamespaces request has been processed.
* @param ctx the environment to interact with the framework and master
* @param namespaces an empty list, can be filled with what to return if bypassing
* @throws IOException if something went wrong
*/
default void preListNamespaces(ObserverContext<MasterCoprocessorEnvironment> ctx,
List<String> namespaces) throws IOException {}
/**
* Called after a listNamespaces request has been processed.
* @param ctx the environment to interact with the framework and master
* @param namespaces the list of namespaces about to be returned
* @throws IOException if something went wrong
*/
default void postListNamespaces(ObserverContext<MasterCoprocessorEnvironment> ctx,
List<String> namespaces) throws IOException {};
/** /**
* Called before a listNamespaceDescriptors request has been processed. * Called before a listNamespaceDescriptors request has been processed.
* @param ctx the environment to interact with the framework and master * @param ctx the environment to interact with the framework and master

View File

@ -3392,6 +3392,25 @@ public class HMaster extends HRegionServer implements MasterServices {
return nsds; return nsds;
} }
/**
* List namespace names
* @return All namespace names
*/
public List<String> listNamespaces() throws IOException {
checkInitialized();
List<String> namespaces = new ArrayList<>();
if (cpHost != null) {
cpHost.preListNamespaces(namespaces);
}
for (NamespaceDescriptor namespace : clusterSchemaService.getNamespaces()) {
namespaces.add(namespace.getName());
}
if (cpHost != null) {
cpHost.postListNamespaces(namespaces);
}
return namespaces;
}
@Override @Override
public List<TableName> listTableNamesByNamespace(String name) throws IOException { public List<TableName> listTableNamesByNamespace(String name) throws IOException {
checkInitialized(); checkInitialized();

View File

@ -297,6 +297,24 @@ public class MasterCoprocessorHost
}); });
} }
public void preListNamespaces(final List<String> namespaces) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver oserver) throws IOException {
oserver.preListNamespaces(this, namespaces);
}
});
}
public void postListNamespaces(final List<String> namespaces) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver oserver) throws IOException {
oserver.postListNamespaces(this, namespaces);
}
});
}
public void preListNamespaceDescriptors(final List<NamespaceDescriptor> descriptors) public void preListNamespaceDescriptors(final List<NamespaceDescriptor> descriptors)
throws IOException { throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {

View File

@ -233,6 +233,8 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecomm
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecommissionedRegionServersResponse; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListDecommissionedRegionServersResponse;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListNamespaceDescriptorsRequest;
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.ListNamespacesRequest;
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.ListTableNamesByNamespaceRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ListTableNamesByNamespaceRequest;
@ -994,6 +996,19 @@ public class MasterRpcServices extends RSRpcServices
} }
} }
@Override
public ListNamespacesResponse listNamespaces(
RpcController controller, ListNamespacesRequest request)
throws ServiceException {
try {
return ListNamespacesResponse.newBuilder()
.addAllNamespaceName(master.listNamespaces())
.build();
} catch (IOException e) {
throw new ServiceException(e);
}
}
@Override @Override
public GetNamespaceDescriptorResponse getNamespaceDescriptor( public GetNamespaceDescriptorResponse getNamespaceDescriptor(
RpcController controller, GetNamespaceDescriptorRequest request) RpcController controller, GetNamespaceDescriptorRequest request)

View File

@ -1175,6 +1175,12 @@ public class AccessController implements MasterCoprocessor, RegionCoprocessor,
requireNamespacePermission(ctx, "getNamespaceDescriptor", namespace, Action.ADMIN); requireNamespacePermission(ctx, "getNamespaceDescriptor", namespace, Action.ADMIN);
} }
@Override
public void postListNamespaces(ObserverContext<MasterCoprocessorEnvironment> ctx,
List<String> namespaces) throws IOException {
/* always allow namespace listing */
}
@Override @Override
public void postListNamespaceDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx, public void postListNamespaceDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx,
List<NamespaceDescriptor> descriptors) throws IOException { List<NamespaceDescriptor> descriptors) throws IOException {

View File

@ -110,6 +110,7 @@ public class TestNamespace {
assertNotNull(ns); assertNotNull(ns);
assertEquals(ns.getName(), NamespaceDescriptor.SYSTEM_NAMESPACE.getName()); assertEquals(ns.getName(), NamespaceDescriptor.SYSTEM_NAMESPACE.getName());
assertEquals(2, admin.listNamespaces().length);
assertEquals(2, admin.listNamespaceDescriptors().length); assertEquals(2, admin.listNamespaceDescriptors().length);
//verify existence of system tables //verify existence of system tables
@ -175,9 +176,11 @@ public class TestNamespace {
//create namespace and verify //create namespace and verify
admin.createNamespace(NamespaceDescriptor.create(nsName).build()); admin.createNamespace(NamespaceDescriptor.create(nsName).build());
assertEquals(3, admin.listNamespaces().length);
assertEquals(3, admin.listNamespaceDescriptors().length); assertEquals(3, admin.listNamespaceDescriptors().length);
//remove namespace and verify //remove namespace and verify
admin.deleteNamespace(nsName); admin.deleteNamespace(nsName);
assertEquals(2, admin.listNamespaces().length);
assertEquals(2, admin.listNamespaceDescriptors().length); assertEquals(2, admin.listNamespaceDescriptors().length);
} }

View File

@ -71,9 +71,11 @@ public class TestAsyncNamespaceAdminApi extends TestAsyncAdminBase {
// create namespace and verify // create namespace and verify
admin.createNamespace(NamespaceDescriptor.create(nsName).build()).join(); admin.createNamespace(NamespaceDescriptor.create(nsName).build()).join();
assertEquals(3, admin.listNamespaces().get().size());
assertEquals(3, admin.listNamespaceDescriptors().get().size()); assertEquals(3, admin.listNamespaceDescriptors().get().size());
// delete namespace and verify // delete namespace and verify
admin.deleteNamespace(nsName).join(); admin.deleteNamespace(nsName).join();
assertEquals(2, admin.listNamespaces().get().size());
assertEquals(2, admin.listNamespaceDescriptors().get().size()); assertEquals(2, admin.listNamespaceDescriptors().get().size());
} }

View File

@ -111,6 +111,8 @@ public class TestMasterObserver {
private boolean postModifyNamespaceCalled; private boolean postModifyNamespaceCalled;
private boolean preGetNamespaceDescriptorCalled; private boolean preGetNamespaceDescriptorCalled;
private boolean postGetNamespaceDescriptorCalled; private boolean postGetNamespaceDescriptorCalled;
private boolean preListNamespacesCalled;
private boolean postListNamespacesCalled;
private boolean preListNamespaceDescriptorsCalled; private boolean preListNamespaceDescriptorsCalled;
private boolean postListNamespaceDescriptorsCalled; private boolean postListNamespaceDescriptorsCalled;
private boolean preAddColumnCalled; private boolean preAddColumnCalled;
@ -204,6 +206,8 @@ public class TestMasterObserver {
postModifyNamespaceCalled = false; postModifyNamespaceCalled = false;
preGetNamespaceDescriptorCalled = false; preGetNamespaceDescriptorCalled = false;
postGetNamespaceDescriptorCalled = false; postGetNamespaceDescriptorCalled = false;
preListNamespacesCalled = false;
postListNamespacesCalled = false;
preListNamespaceDescriptorsCalled = false; preListNamespaceDescriptorsCalled = false;
postListNamespaceDescriptorsCalled = false; postListNamespaceDescriptorsCalled = false;
preAddColumnCalled = false; preAddColumnCalled = false;
@ -472,6 +476,18 @@ public class TestMasterObserver {
return preGetNamespaceDescriptorCalled && postGetNamespaceDescriptorCalled; return preGetNamespaceDescriptorCalled && postGetNamespaceDescriptorCalled;
} }
@Override
public void preListNamespaces(ObserverContext<MasterCoprocessorEnvironment> ctx,
List<String> namespaces) {
preListNamespacesCalled = true;
}
@Override
public void postListNamespaces(ObserverContext<MasterCoprocessorEnvironment> ctx,
List<String> namespaces) {
postListNamespacesCalled = true;
}
@Override @Override
public void preListNamespaceDescriptors(ObserverContext<MasterCoprocessorEnvironment> env, public void preListNamespaceDescriptors(ObserverContext<MasterCoprocessorEnvironment> env,
List<NamespaceDescriptor> descriptors) throws IOException { List<NamespaceDescriptor> descriptors) throws IOException {
@ -1253,6 +1269,7 @@ public class TestMasterObserver {
final ObserverContext<MasterCoprocessorEnvironment> ctx, final ObserverContext<MasterCoprocessorEnvironment> ctx,
final RegionInfo[] regionsToMerge) throws IOException { final RegionInfo[] regionsToMerge) throws IOException {
} }
} }
private static HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
@ -1495,6 +1512,11 @@ public class TestMasterObserver {
// create a table // create a table
Admin admin = UTIL.getAdmin(); Admin admin = UTIL.getAdmin();
admin.listNamespaces();
assertTrue("preListNamespaces should have been called", cp.preListNamespacesCalled);
assertTrue("postListNamespaces should have been called", cp.postListNamespacesCalled);
admin.createNamespace(NamespaceDescriptor.create(testNamespace).build()); admin.createNamespace(NamespaceDescriptor.create(testNamespace).build());
assertTrue("Test namespace should be created", cp.wasCreateNamespaceCalled()); assertTrue("Test namespace should be created", cp.wasCreateNamespaceCalled());

View File

@ -1244,7 +1244,7 @@ module Hbase
# Returns a list of namespaces in hbase # Returns a list of namespaces in hbase
def list_namespace(regex = '.*') def list_namespace(regex = '.*')
pattern = java.util.regex.Pattern.compile(regex) pattern = java.util.regex.Pattern.compile(regex)
list = @admin.listNamespaceDescriptors.map(&:getName) list = @admin.listNamespaces
list.select { |s| pattern.match(s) } list.select { |s| pattern.match(s) }
end end

View File

@ -793,6 +793,20 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements TH
} }
} }
@Override
public List<String> listNamespaces() throws TIOError, TException {
try {
String[] namespaces = connectionCache.getAdmin().listNamespaces();
List<String> result = new ArrayList<>(namespaces.length);
for (String ns: namespaces) {
result.add(ns);
}
return result;
} catch (IOException e) {
throw getTIOError(e);
}
}
@Override @Override
public List<TNamespaceDescriptor> listNamespaceDescriptors() throws TIOError, TException { public List<TNamespaceDescriptor> listNamespaceDescriptors() throws TIOError, TException {
try { try {

View File

@ -395,6 +395,16 @@ public class ThriftAdmin implements Admin {
} }
} }
@Override
public String[] listNamespaces() throws IOException {
try {
List<String> tNamespaces = client.listNamespaces();
return tNamespaces.toArray(new String[tNamespaces.size()]);
} catch (TException e) {
throw new IOException(e);
}
}
@Override @Override
public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException { public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException {
try { try {

View File

@ -494,6 +494,12 @@ public class THBaseService {
*/ */
public java.util.List<TNamespaceDescriptor> listNamespaceDescriptors() throws TIOError, org.apache.thrift.TException; public java.util.List<TNamespaceDescriptor> listNamespaceDescriptors() throws TIOError, org.apache.thrift.TException;
/**
* @return all namespace names
*
*/
public java.util.List<java.lang.String> listNamespaces() throws TIOError, org.apache.thrift.TException;
} }
public interface AsyncIface { public interface AsyncIface {
@ -588,6 +594,8 @@ public class THBaseService {
public void listNamespaceDescriptors(org.apache.thrift.async.AsyncMethodCallback<java.util.List<TNamespaceDescriptor>> resultHandler) throws org.apache.thrift.TException; public void listNamespaceDescriptors(org.apache.thrift.async.AsyncMethodCallback<java.util.List<TNamespaceDescriptor>> resultHandler) throws org.apache.thrift.TException;
public void listNamespaces(org.apache.thrift.async.AsyncMethodCallback<java.util.List<java.lang.String>> resultHandler) throws org.apache.thrift.TException;
} }
public static class Client extends org.apache.thrift.TServiceClient implements Iface { public static class Client extends org.apache.thrift.TServiceClient implements Iface {
@ -1775,6 +1783,31 @@ public class THBaseService {
throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "listNamespaceDescriptors failed: unknown result"); throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "listNamespaceDescriptors failed: unknown result");
} }
public java.util.List<java.lang.String> listNamespaces() throws TIOError, org.apache.thrift.TException
{
send_listNamespaces();
return recv_listNamespaces();
}
public void send_listNamespaces() throws org.apache.thrift.TException
{
listNamespaces_args args = new listNamespaces_args();
sendBase("listNamespaces", args);
}
public java.util.List<java.lang.String> recv_listNamespaces() throws TIOError, org.apache.thrift.TException
{
listNamespaces_result result = new listNamespaces_result();
receiveBase(result, "listNamespaces");
if (result.isSetSuccess()) {
return result.success;
}
if (result.io != null) {
throw result.io;
}
throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "listNamespaces failed: unknown result");
}
} }
public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface {
public static class Factory implements org.apache.thrift.async.TAsyncClientFactory<AsyncClient> { public static class Factory implements org.apache.thrift.async.TAsyncClientFactory<AsyncClient> {
@ -3353,6 +3386,35 @@ public class THBaseService {
} }
} }
public void listNamespaces(org.apache.thrift.async.AsyncMethodCallback<java.util.List<java.lang.String>> resultHandler) throws org.apache.thrift.TException {
checkReady();
listNamespaces_call method_call = new listNamespaces_call(resultHandler, this, ___protocolFactory, ___transport);
this.___currentMethod = method_call;
___manager.call(method_call);
}
public static class listNamespaces_call extends org.apache.thrift.async.TAsyncMethodCall<java.util.List<java.lang.String>> {
public listNamespaces_call(org.apache.thrift.async.AsyncMethodCallback<java.util.List<java.lang.String>> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
super(client, protocolFactory, transport, resultHandler, false);
}
public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("listNamespaces", org.apache.thrift.protocol.TMessageType.CALL, 0));
listNamespaces_args args = new listNamespaces_args();
args.write(prot);
prot.writeMessageEnd();
}
public java.util.List<java.lang.String> getResult() throws TIOError, org.apache.thrift.TException {
if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
throw new java.lang.IllegalStateException("Method call not finished!");
}
org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
return (new Client(prot)).recv_listNamespaces();
}
}
} }
public static class Processor<I extends Iface> extends org.apache.thrift.TBaseProcessor<I> implements org.apache.thrift.TProcessor { public static class Processor<I extends Iface> extends org.apache.thrift.TBaseProcessor<I> implements org.apache.thrift.TProcessor {
@ -3411,6 +3473,7 @@ public class THBaseService {
processMap.put("deleteNamespace", new deleteNamespace()); processMap.put("deleteNamespace", new deleteNamespace());
processMap.put("getNamespaceDescriptor", new getNamespaceDescriptor()); processMap.put("getNamespaceDescriptor", new getNamespaceDescriptor());
processMap.put("listNamespaceDescriptors", new listNamespaceDescriptors()); processMap.put("listNamespaceDescriptors", new listNamespaceDescriptors());
processMap.put("listNamespaces", new listNamespaces());
return processMap; return processMap;
} }
@ -4733,6 +4796,35 @@ public class THBaseService {
} }
} }
public static class listNamespaces<I extends Iface> extends org.apache.thrift.ProcessFunction<I, listNamespaces_args> {
public listNamespaces() {
super("listNamespaces");
}
public listNamespaces_args getEmptyArgsInstance() {
return new listNamespaces_args();
}
protected boolean isOneway() {
return false;
}
@Override
protected boolean rethrowUnhandledExceptions() {
return false;
}
public listNamespaces_result getResult(I iface, listNamespaces_args args) throws org.apache.thrift.TException {
listNamespaces_result result = new listNamespaces_result();
try {
result.success = iface.listNamespaces();
} catch (TIOError io) {
result.io = io;
}
return result;
}
}
} }
public static class AsyncProcessor<I extends AsyncIface> extends org.apache.thrift.TBaseAsyncProcessor<I> { public static class AsyncProcessor<I extends AsyncIface> extends org.apache.thrift.TBaseAsyncProcessor<I> {
@ -4791,6 +4883,7 @@ public class THBaseService {
processMap.put("deleteNamespace", new deleteNamespace()); processMap.put("deleteNamespace", new deleteNamespace());
processMap.put("getNamespaceDescriptor", new getNamespaceDescriptor()); processMap.put("getNamespaceDescriptor", new getNamespaceDescriptor());
processMap.put("listNamespaceDescriptors", new listNamespaceDescriptors()); processMap.put("listNamespaceDescriptors", new listNamespaceDescriptors());
processMap.put("listNamespaces", new listNamespaces());
return processMap; return processMap;
} }
@ -7720,6 +7813,71 @@ public class THBaseService {
} }
} }
public static class listNamespaces<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, listNamespaces_args, java.util.List<java.lang.String>> {
public listNamespaces() {
super("listNamespaces");
}
public listNamespaces_args getEmptyArgsInstance() {
return new listNamespaces_args();
}
public org.apache.thrift.async.AsyncMethodCallback<java.util.List<java.lang.String>> getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) {
final org.apache.thrift.AsyncProcessFunction fcall = this;
return new org.apache.thrift.async.AsyncMethodCallback<java.util.List<java.lang.String>>() {
public void onComplete(java.util.List<java.lang.String> o) {
listNamespaces_result result = new listNamespaces_result();
result.success = o;
try {
fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid);
} catch (org.apache.thrift.transport.TTransportException e) {
_LOGGER.error("TTransportException writing to internal frame buffer", e);
fb.close();
} catch (java.lang.Exception e) {
_LOGGER.error("Exception writing to internal frame buffer", e);
onError(e);
}
}
public void onError(java.lang.Exception e) {
byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;
org.apache.thrift.TSerializable msg;
listNamespaces_result result = new listNamespaces_result();
if (e instanceof TIOError) {
result.io = (TIOError) e;
result.setIoIsSet(true);
msg = result;
} else if (e instanceof org.apache.thrift.transport.TTransportException) {
_LOGGER.error("TTransportException inside handler", e);
fb.close();
return;
} else if (e instanceof org.apache.thrift.TApplicationException) {
_LOGGER.error("TApplicationException inside handler", e);
msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
msg = (org.apache.thrift.TApplicationException)e;
} else {
_LOGGER.error("Exception inside handler", e);
msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
}
try {
fcall.sendResponse(fb,msg,msgType,seqid);
} catch (java.lang.Exception ex) {
_LOGGER.error("Exception writing to internal frame buffer", ex);
fb.close();
}
}
};
}
protected boolean isOneway() {
return false;
}
public void start(I iface, listNamespaces_args args, org.apache.thrift.async.AsyncMethodCallback<java.util.List<java.lang.String>> resultHandler) throws org.apache.thrift.TException {
iface.listNamespaces(resultHandler);
}
}
} }
public static class exists_args implements org.apache.thrift.TBase<exists_args, exists_args._Fields>, java.io.Serializable, Cloneable, Comparable<exists_args> { public static class exists_args implements org.apache.thrift.TBase<exists_args, exists_args._Fields>, java.io.Serializable, Cloneable, Comparable<exists_args> {
@ -50391,4 +50549,782 @@ public class THBaseService {
} }
} }
public static class listNamespaces_args implements org.apache.thrift.TBase<listNamespaces_args, listNamespaces_args._Fields>, java.io.Serializable, Cloneable, Comparable<listNamespaces_args> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("listNamespaces_args");
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new listNamespaces_argsStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new listNamespaces_argsTupleSchemeFactory();
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
;
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
static {
for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) {
byName.put(field.getFieldName(), field);
}
}
/**
* Find the _Fields constant that matches fieldId, or null if its not found.
*/
@org.apache.thrift.annotation.Nullable
public static _Fields findByThriftId(int fieldId) {
switch(fieldId) {
default:
return null;
}
}
/**
* Find the _Fields constant that matches fieldId, throwing an exception
* if it is not found.
*/
public static _Fields findByThriftIdOrThrow(int fieldId) {
_Fields fields = findByThriftId(fieldId);
if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!");
return fields;
}
/**
* Find the _Fields constant that matches name, or null if its not found.
*/
@org.apache.thrift.annotation.Nullable
public static _Fields findByName(java.lang.String name) {
return byName.get(name);
}
private final short _thriftId;
private final java.lang.String _fieldName;
_Fields(short thriftId, java.lang.String fieldName) {
_thriftId = thriftId;
_fieldName = fieldName;
}
public short getThriftFieldId() {
return _thriftId;
}
public java.lang.String getFieldName() {
return _fieldName;
}
}
public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
static {
java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(listNamespaces_args.class, metaDataMap);
}
public listNamespaces_args() {
}
/**
* Performs a deep copy on <i>other</i>.
*/
public listNamespaces_args(listNamespaces_args other) {
}
public listNamespaces_args deepCopy() {
return new listNamespaces_args(this);
}
@Override
public void clear() {
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
}
throw new java.lang.IllegalStateException();
}
/** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
public boolean isSet(_Fields field) {
if (field == null) {
throw new java.lang.IllegalArgumentException();
}
switch (field) {
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof listNamespaces_args)
return this.equals((listNamespaces_args)that);
return false;
}
public boolean equals(listNamespaces_args that) {
if (that == null)
return false;
if (this == that)
return true;
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
return hashCode;
}
@Override
public int compareTo(listNamespaces_args other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
return 0;
}
@org.apache.thrift.annotation.Nullable
public _Fields fieldForId(int fieldId) {
return _Fields.findByThriftId(fieldId);
}
public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
scheme(iprot).read(iprot, this);
}
public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
scheme(oprot).write(oprot, this);
}
@Override
public java.lang.String toString() {
java.lang.StringBuilder sb = new java.lang.StringBuilder("listNamespaces_args(");
boolean first = true;
sb.append(")");
return sb.toString();
}
public void validate() throws org.apache.thrift.TException {
// check for required fields
// check for sub-struct validity
}
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
try {
write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
} catch (org.apache.thrift.TException te) {
throw new java.io.IOException(te);
}
}
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException {
try {
read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
} catch (org.apache.thrift.TException te) {
throw new java.io.IOException(te);
}
}
private static class listNamespaces_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public listNamespaces_argsStandardScheme getScheme() {
return new listNamespaces_argsStandardScheme();
}
}
private static class listNamespaces_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme<listNamespaces_args> {
public void read(org.apache.thrift.protocol.TProtocol iprot, listNamespaces_args struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TField schemeField;
iprot.readStructBegin();
while (true)
{
schemeField = iprot.readFieldBegin();
if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
break;
}
switch (schemeField.id) {
default:
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
iprot.readFieldEnd();
}
iprot.readStructEnd();
// check for required fields of primitive type, which can't be checked in the validate method
struct.validate();
}
public void write(org.apache.thrift.protocol.TProtocol oprot, listNamespaces_args struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class listNamespaces_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public listNamespaces_argsTupleScheme getScheme() {
return new listNamespaces_argsTupleScheme();
}
}
private static class listNamespaces_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme<listNamespaces_args> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, listNamespaces_args struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, listNamespaces_args struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
}
}
private static <S extends org.apache.thrift.scheme.IScheme> S scheme(org.apache.thrift.protocol.TProtocol proto) {
return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
}
}
public static class listNamespaces_result implements org.apache.thrift.TBase<listNamespaces_result, listNamespaces_result._Fields>, java.io.Serializable, Cloneable, Comparable<listNamespaces_result> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("listNamespaces_result");
private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.LIST, (short)0);
private static final org.apache.thrift.protocol.TField IO_FIELD_DESC = new org.apache.thrift.protocol.TField("io", org.apache.thrift.protocol.TType.STRUCT, (short)1);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new listNamespaces_resultStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new listNamespaces_resultTupleSchemeFactory();
public @org.apache.thrift.annotation.Nullable java.util.List<java.lang.String> success; // required
public @org.apache.thrift.annotation.Nullable TIOError io; // required
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
SUCCESS((short)0, "success"),
IO((short)1, "io");
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
static {
for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) {
byName.put(field.getFieldName(), field);
}
}
/**
* Find the _Fields constant that matches fieldId, or null if its not found.
*/
@org.apache.thrift.annotation.Nullable
public static _Fields findByThriftId(int fieldId) {
switch(fieldId) {
case 0: // SUCCESS
return SUCCESS;
case 1: // IO
return IO;
default:
return null;
}
}
/**
* Find the _Fields constant that matches fieldId, throwing an exception
* if it is not found.
*/
public static _Fields findByThriftIdOrThrow(int fieldId) {
_Fields fields = findByThriftId(fieldId);
if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!");
return fields;
}
/**
* Find the _Fields constant that matches name, or null if its not found.
*/
@org.apache.thrift.annotation.Nullable
public static _Fields findByName(java.lang.String name) {
return byName.get(name);
}
private final short _thriftId;
private final java.lang.String _fieldName;
_Fields(short thriftId, java.lang.String fieldName) {
_thriftId = thriftId;
_fieldName = fieldName;
}
public short getThriftFieldId() {
return _thriftId;
}
public java.lang.String getFieldName() {
return _fieldName;
}
}
// isset id assignments
public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
static {
java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))));
tmpMap.put(_Fields.IO, new org.apache.thrift.meta_data.FieldMetaData("io", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TIOError.class)));
metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(listNamespaces_result.class, metaDataMap);
}
public listNamespaces_result() {
}
public listNamespaces_result(
java.util.List<java.lang.String> success,
TIOError io)
{
this();
this.success = success;
this.io = io;
}
/**
* Performs a deep copy on <i>other</i>.
*/
public listNamespaces_result(listNamespaces_result other) {
if (other.isSetSuccess()) {
java.util.List<java.lang.String> __this__success = new java.util.ArrayList<java.lang.String>(other.success);
this.success = __this__success;
}
if (other.isSetIo()) {
this.io = new TIOError(other.io);
}
}
public listNamespaces_result deepCopy() {
return new listNamespaces_result(this);
}
@Override
public void clear() {
this.success = null;
this.io = null;
}
public int getSuccessSize() {
return (this.success == null) ? 0 : this.success.size();
}
@org.apache.thrift.annotation.Nullable
public java.util.Iterator<java.lang.String> getSuccessIterator() {
return (this.success == null) ? null : this.success.iterator();
}
public void addToSuccess(java.lang.String elem) {
if (this.success == null) {
this.success = new java.util.ArrayList<java.lang.String>();
}
this.success.add(elem);
}
@org.apache.thrift.annotation.Nullable
public java.util.List<java.lang.String> getSuccess() {
return this.success;
}
public listNamespaces_result setSuccess(@org.apache.thrift.annotation.Nullable java.util.List<java.lang.String> success) {
this.success = success;
return this;
}
public void unsetSuccess() {
this.success = null;
}
/** Returns true if field success is set (has been assigned a value) and false otherwise */
public boolean isSetSuccess() {
return this.success != null;
}
public void setSuccessIsSet(boolean value) {
if (!value) {
this.success = null;
}
}
@org.apache.thrift.annotation.Nullable
public TIOError getIo() {
return this.io;
}
public listNamespaces_result setIo(@org.apache.thrift.annotation.Nullable TIOError io) {
this.io = io;
return this;
}
public void unsetIo() {
this.io = null;
}
/** Returns true if field io is set (has been assigned a value) and false otherwise */
public boolean isSetIo() {
return this.io != null;
}
public void setIoIsSet(boolean value) {
if (!value) {
this.io = null;
}
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case SUCCESS:
if (value == null) {
unsetSuccess();
} else {
setSuccess((java.util.List<java.lang.String>)value);
}
break;
case IO:
if (value == null) {
unsetIo();
} else {
setIo((TIOError)value);
}
break;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
case SUCCESS:
return getSuccess();
case IO:
return getIo();
}
throw new java.lang.IllegalStateException();
}
/** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
public boolean isSet(_Fields field) {
if (field == null) {
throw new java.lang.IllegalArgumentException();
}
switch (field) {
case SUCCESS:
return isSetSuccess();
case IO:
return isSetIo();
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof listNamespaces_result)
return this.equals((listNamespaces_result)that);
return false;
}
public boolean equals(listNamespaces_result that) {
if (that == null)
return false;
if (this == that)
return true;
boolean this_present_success = true && this.isSetSuccess();
boolean that_present_success = true && that.isSetSuccess();
if (this_present_success || that_present_success) {
if (!(this_present_success && that_present_success))
return false;
if (!this.success.equals(that.success))
return false;
}
boolean this_present_io = true && this.isSetIo();
boolean that_present_io = true && that.isSetIo();
if (this_present_io || that_present_io) {
if (!(this_present_io && that_present_io))
return false;
if (!this.io.equals(that.io))
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287);
if (isSetSuccess())
hashCode = hashCode * 8191 + success.hashCode();
hashCode = hashCode * 8191 + ((isSetIo()) ? 131071 : 524287);
if (isSetIo())
hashCode = hashCode * 8191 + io.hashCode();
return hashCode;
}
@Override
public int compareTo(listNamespaces_result other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetSuccess()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetIo()).compareTo(other.isSetIo());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetIo()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.io, other.io);
if (lastComparison != 0) {
return lastComparison;
}
}
return 0;
}
@org.apache.thrift.annotation.Nullable
public _Fields fieldForId(int fieldId) {
return _Fields.findByThriftId(fieldId);
}
public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
scheme(iprot).read(iprot, this);
}
public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
scheme(oprot).write(oprot, this);
}
@Override
public java.lang.String toString() {
java.lang.StringBuilder sb = new java.lang.StringBuilder("listNamespaces_result(");
boolean first = true;
sb.append("success:");
if (this.success == null) {
sb.append("null");
} else {
sb.append(this.success);
}
first = false;
if (!first) sb.append(", ");
sb.append("io:");
if (this.io == null) {
sb.append("null");
} else {
sb.append(this.io);
}
first = false;
sb.append(")");
return sb.toString();
}
public void validate() throws org.apache.thrift.TException {
// check for required fields
// check for sub-struct validity
}
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
try {
write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
} catch (org.apache.thrift.TException te) {
throw new java.io.IOException(te);
}
}
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException {
try {
read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
} catch (org.apache.thrift.TException te) {
throw new java.io.IOException(te);
}
}
private static class listNamespaces_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public listNamespaces_resultStandardScheme getScheme() {
return new listNamespaces_resultStandardScheme();
}
}
private static class listNamespaces_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme<listNamespaces_result> {
public void read(org.apache.thrift.protocol.TProtocol iprot, listNamespaces_result struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TField schemeField;
iprot.readStructBegin();
while (true)
{
schemeField = iprot.readFieldBegin();
if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
break;
}
switch (schemeField.id) {
case 0: // SUCCESS
if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
{
org.apache.thrift.protocol.TList _list342 = iprot.readListBegin();
struct.success = new java.util.ArrayList<java.lang.String>(_list342.size);
@org.apache.thrift.annotation.Nullable java.lang.String _elem343;
for (int _i344 = 0; _i344 < _list342.size; ++_i344)
{
_elem343 = iprot.readString();
struct.success.add(_elem343);
}
iprot.readListEnd();
}
struct.setSuccessIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 1: // IO
if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
struct.io = new TIOError();
struct.io.read(iprot);
struct.setIoIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
default:
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
iprot.readFieldEnd();
}
iprot.readStructEnd();
// check for required fields of primitive type, which can't be checked in the validate method
struct.validate();
}
public void write(org.apache.thrift.protocol.TProtocol oprot, listNamespaces_result struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
if (struct.success != null) {
oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
{
oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, struct.success.size()));
for (java.lang.String _iter345 : struct.success)
{
oprot.writeString(_iter345);
}
oprot.writeListEnd();
}
oprot.writeFieldEnd();
}
if (struct.io != null) {
oprot.writeFieldBegin(IO_FIELD_DESC);
struct.io.write(oprot);
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class listNamespaces_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public listNamespaces_resultTupleScheme getScheme() {
return new listNamespaces_resultTupleScheme();
}
}
private static class listNamespaces_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme<listNamespaces_result> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, listNamespaces_result struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
java.util.BitSet optionals = new java.util.BitSet();
if (struct.isSetSuccess()) {
optionals.set(0);
}
if (struct.isSetIo()) {
optionals.set(1);
}
oprot.writeBitSet(optionals, 2);
if (struct.isSetSuccess()) {
{
oprot.writeI32(struct.success.size());
for (java.lang.String _iter346 : struct.success)
{
oprot.writeString(_iter346);
}
}
}
if (struct.isSetIo()) {
struct.io.write(oprot);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, listNamespaces_result struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
java.util.BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
{
org.apache.thrift.protocol.TList _list347 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, iprot.readI32());
struct.success = new java.util.ArrayList<java.lang.String>(_list347.size);
@org.apache.thrift.annotation.Nullable java.lang.String _elem348;
for (int _i349 = 0; _i349 < _list347.size; ++_i349)
{
_elem348 = iprot.readString();
struct.success.add(_elem348);
}
}
struct.setSuccessIsSet(true);
}
if (incoming.get(1)) {
struct.io = new TIOError();
struct.io.read(iprot);
struct.setIoIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> S scheme(org.apache.thrift.protocol.TProtocol proto) {
return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
}
}
} }

View File

@ -1032,4 +1032,10 @@ service THBaseService {
**/ **/
list<TNamespaceDescriptor> listNamespaceDescriptors( list<TNamespaceDescriptor> listNamespaceDescriptors(
) throws (1: TIOError io) ) throws (1: TIOError io)
/**
* @return all namespace names
**/
list<string> listNamespaces(
) throws (1: TIOError io)
} }