HBASE-20653 Add missing observer hooks for region server group to MasterObserver

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Nihal Jain 2018-05-30 23:37:48 +05:30 committed by tedyu
parent c19fbf2be0
commit 40a73a5ca7
5 changed files with 267 additions and 27 deletions

View File

@ -161,11 +161,17 @@ public class RSGroupAdminEndpoint implements MasterCoprocessor, MasterObserver {
LOG.info(master.getClientIdAuditPrefix() + " initiates rsgroup info retrieval, group="
+ groupName);
try {
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().preGetRSGroupInfo(groupName);
}
checkPermission("getRSGroupInfo");
RSGroupInfo rsGroupInfo = groupAdminServer.getRSGroupInfo(groupName);
if (rsGroupInfo != null) {
builder.setRSGroupInfo(RSGroupProtobufUtil.toProtoGroupInfo(rsGroupInfo));
}
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().postGetRSGroupInfo(groupName);
}
} catch (IOException e) {
CoprocessorRpcUtils.setControllerException(controller, e);
}
@ -180,11 +186,17 @@ public class RSGroupAdminEndpoint implements MasterCoprocessor, MasterObserver {
LOG.info(master.getClientIdAuditPrefix() + " initiates rsgroup info retrieval, table="
+ tableName);
try {
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().preGetRSGroupInfoOfTable(tableName);
}
checkPermission("getRSGroupInfoOfTable");
RSGroupInfo RSGroupInfo = groupAdminServer.getRSGroupInfoOfTable(tableName);
if (RSGroupInfo != null) {
builder.setRSGroupInfo(RSGroupProtobufUtil.toProtoGroupInfo(RSGroupInfo));
}
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().postGetRSGroupInfoOfTable(tableName);
}
} catch (IOException e) {
CoprocessorRpcUtils.setControllerException(controller, e);
}
@ -312,10 +324,16 @@ public class RSGroupAdminEndpoint implements MasterCoprocessor, MasterObserver {
ListRSGroupInfosResponse.Builder builder = ListRSGroupInfosResponse.newBuilder();
LOG.info(master.getClientIdAuditPrefix() + " list rsgroup");
try {
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().preListRSGroups();
}
checkPermission("listRSGroup");
for (RSGroupInfo RSGroupInfo : groupAdminServer.listRSGroups()) {
builder.addRSGroupInfo(RSGroupProtobufUtil.toProtoGroupInfo(RSGroupInfo));
}
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().postListRSGroups();
}
} catch (IOException e) {
CoprocessorRpcUtils.setControllerException(controller, e);
}
@ -331,11 +349,17 @@ public class RSGroupAdminEndpoint implements MasterCoprocessor, MasterObserver {
LOG.info(master.getClientIdAuditPrefix() + " initiates rsgroup info retrieval, server="
+ hp);
try {
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().preGetRSGroupInfoOfServer(hp);
}
checkPermission("getRSGroupInfoOfServer");
RSGroupInfo info = groupAdminServer.getRSGroupOfServer(hp);
if (info != null) {
builder.setRSGroupInfo(RSGroupProtobufUtil.toProtoGroupInfo(info));
}
if (master.getMasterCoprocessorHost() != null) {
master.getMasterCoprocessorHost().postGetRSGroupInfoOfServer(hp);
}
} catch (IOException e) {
CoprocessorRpcUtils.setControllerException(controller, e);
}

View File

@ -292,6 +292,14 @@ public class TestRSGroups extends TestRSGroupsBase {
boolean postRemoveServersCalled = false;
boolean preMoveServersAndTables = false;
boolean postMoveServersAndTables = false;
boolean preGetRSGroupInfoCalled = false;
boolean postGetRSGroupInfoCalled = false;
boolean preGetRSGroupInfoOfTableCalled = false;
boolean postGetRSGroupInfoOfTableCalled = false;
boolean preListRSGroupsCalled = false;
boolean postListRSGroupsCalled = false;
boolean preGetRSGroupInfoOfServerCalled = false;
boolean postGetRSGroupInfoOfServerCalled = false;
@Override
public Optional<MasterObserver> getMasterObserver() {
@ -370,7 +378,85 @@ public class TestRSGroups extends TestRSGroupsBase {
String groupName, boolean balancerRan) throws IOException {
postBalanceRSGroupCalled = true;
}
@Override
public void preGetRSGroupInfo(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final String groupName) throws IOException {
preGetRSGroupInfoCalled = true;
}
@Override
public void postGetRSGroupInfo(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final String groupName) throws IOException {
postGetRSGroupInfoCalled = true;
}
@Override
public void preGetRSGroupInfoOfTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final TableName tableName) throws IOException {
preGetRSGroupInfoOfTableCalled = true;
}
@Override
public void postGetRSGroupInfoOfTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final TableName tableName) throws IOException {
postGetRSGroupInfoOfTableCalled = true;
}
@Override
public void preListRSGroups(final ObserverContext<MasterCoprocessorEnvironment> ctx)
throws IOException {
preListRSGroupsCalled = true;
}
@Override
public void postListRSGroups(final ObserverContext<MasterCoprocessorEnvironment> ctx)
throws IOException {
postListRSGroupsCalled = true;
}
@Override
public void preGetRSGroupInfoOfServer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final Address server) throws IOException {
preGetRSGroupInfoOfServerCalled = true;
}
@Override
public void postGetRSGroupInfoOfServer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final Address server) throws IOException {
postGetRSGroupInfoOfServerCalled = true;
}
}
@Test
public void testGetRSGroupInfoCPHookCalled() throws Exception {
rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP);
assertTrue(observer.preGetRSGroupInfoCalled);
assertTrue(observer.postGetRSGroupInfoCalled);
}
@Test
public void testGetRSGroupInfoOfTableCPHookCalled() throws Exception {
rsGroupAdmin.getRSGroupInfoOfTable(TableName.META_TABLE_NAME);
assertTrue(observer.preGetRSGroupInfoOfTableCalled);
assertTrue(observer.postGetRSGroupInfoOfTableCalled);
}
@Test
public void testListRSGroupsCPHookCalled() throws Exception {
rsGroupAdmin.listRSGroups();
assertTrue(observer.preListRSGroupsCalled);
assertTrue(observer.postListRSGroupsCalled);
}
@Test
public void testGetRSGroupInfoOfServerCPHookCalled() throws Exception {
ServerName masterServerName = ((MiniHBaseCluster) cluster).getMaster().getServerName();
rsGroupAdmin.getRSGroupOfServer(masterServerName.getAddress());
assertTrue(observer.preGetRSGroupInfoOfServerCalled);
assertTrue(observer.postGetRSGroupInfoOfServerCalled);
}
@Test
public void testMoveServersAndTables() throws Exception {
super.testMoveServersAndTables();

View File

@ -223,9 +223,7 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
validateAdminPermissions(action);
}
@Test
@ -235,9 +233,7 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
validateAdminPermissions(action);
}
@Test
@ -247,9 +243,7 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
validateAdminPermissions(action);
}
@Test
@ -259,9 +253,7 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
validateAdminPermissions(action);
}
@Test
@ -271,9 +263,7 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
validateAdminPermissions(action);
}
@Test
@ -283,9 +273,7 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
validateAdminPermissions(action);
}
@Test
@ -295,9 +283,7 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
validateAdminPermissions(action);
}
@Test
@ -307,9 +293,7 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
validateAdminPermissions(action);
}
@Test
@ -319,9 +303,7 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
validateAdminPermissions(action);
}
@Test
@ -331,6 +313,20 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
return null;
};
validateAdminPermissions(action);
}
@Test
public void testRemoveServers() throws Exception {
AccessTestAction action = () -> {
rsGroupAdminEndpoint.checkPermission("removeServers");
return null;
};
validateAdminPermissions(action);
}
private void validateAdminPermissions(AccessTestAction action) throws Exception {
verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_GROUP_ADMIN);
verifyDenied(action, USER_CREATE, USER_OWNER, USER_RW, USER_RO,
USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);

View File

@ -1212,6 +1212,68 @@ public interface MasterObserver {
final ObserverContext<MasterCoprocessorEnvironment> ctx,
Set<Address> servers) throws IOException {}
/**
* Called before getting region server group info of the passed groupName.
* @param ctx the environment to interact with the framework and master
* @param groupName name of the group to get RSGroupInfo for
*/
default void preGetRSGroupInfo(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final String groupName) throws IOException {}
/**
* Called after getting region server group info of the passed groupName.
* @param ctx the environment to interact with the framework and master
* @param groupName name of the group to get RSGroupInfo for
*/
default void postGetRSGroupInfo(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final String groupName) throws IOException {}
/**
* Called before getting region server group info of the passed tableName.
* @param ctx the environment to interact with the framework and master
* @param tableName name of the table to get RSGroupInfo for
*/
default void preGetRSGroupInfoOfTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final TableName tableName) throws IOException {}
/**
* Called after getting region server group info of the passed tableName.
* @param ctx the environment to interact with the framework and master
* @param tableName name of the table to get RSGroupInfo for
*/
default void postGetRSGroupInfoOfTable(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final TableName tableName) throws IOException {}
/**
* Called before listing region server group information.
* @param ctx the environment to interact with the framework and master
*/
default void preListRSGroups(final ObserverContext<MasterCoprocessorEnvironment> ctx)
throws IOException {}
/**
* Called after listing region server group information.
* @param ctx the environment to interact with the framework and master
*/
default void postListRSGroups(final ObserverContext<MasterCoprocessorEnvironment> ctx)
throws IOException {}
/**
* Called before getting region server group info of the passed server.
* @param ctx the environment to interact with the framework and master
* @param server server to get RSGroupInfo for
*/
default void preGetRSGroupInfoOfServer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final Address server) throws IOException {}
/**
* Called after getting region server group info of the passed server.
* @param ctx the environment to interact with the framework and master
* @param server server to get RSGroupInfo for
*/
default void postGetRSGroupInfoOfServer(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final Address server) throws IOException {}
/**
* Called before add a replication peer
* @param ctx the environment to interact with the framework and master

View File

@ -1404,6 +1404,78 @@ public class MasterCoprocessorHost
});
}
public void preGetRSGroupInfo(final String groupName) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preGetRSGroupInfo(this, groupName);
}
});
}
public void postGetRSGroupInfo(final String groupName) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postGetRSGroupInfo(this, groupName);
}
});
}
public void preGetRSGroupInfoOfTable(final TableName tableName) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preGetRSGroupInfoOfTable(this, tableName);
}
});
}
public void postGetRSGroupInfoOfTable(final TableName tableName) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postGetRSGroupInfoOfTable(this, tableName);
}
});
}
public void preListRSGroups() throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preListRSGroups(this);
}
});
}
public void postListRSGroups() throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postListRSGroups(this);
}
});
}
public void preGetRSGroupInfoOfServer(final Address server) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.preGetRSGroupInfoOfServer(this, server);
}
});
}
public void postGetRSGroupInfoOfServer(final Address server) throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {
@Override
public void call(MasterObserver observer) throws IOException {
observer.postGetRSGroupInfoOfServer(this, server);
}
});
}
public void preAddReplicationPeer(final String peerId, final ReplicationPeerConfig peerConfig)
throws IOException {
execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() {