From de22fabed2682cace6c64ef566677437070e4950 Mon Sep 17 00:00:00 2001 From: tedyu Date: Sun, 13 Aug 2017 21:21:43 -0700 Subject: [PATCH] HBASE-18566 [RSGROUP]Log the client IP/port of the rsgroup admin (Guangxu Cheng) --- .../hbase/rsgroup/RSGroupAdminEndpoint.java | 15 +++++++++++++++ .../org/apache/hadoop/hbase/master/HMaster.java | 2 +- .../hadoop/hbase/master/MasterServices.java | 2 ++ .../hbase/master/MockNoopMasterServices.java | 5 +++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminEndpoint.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminEndpoint.java index 228454ec8e3..d186334fd33 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminEndpoint.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminEndpoint.java @@ -121,6 +121,8 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService GetRSGroupInfoRequest request, RpcCallback done) { GetRSGroupInfoResponse.Builder builder = GetRSGroupInfoResponse.newBuilder(); String groupName = request.getRSGroupName(); + LOG.info(master.getClientIdAuditPrefix() + " initiates rsgroup info retrieval, group=" + + groupName); try { RSGroupInfo rsGroupInfo = groupAdminServer.getRSGroupInfo(groupName); if (rsGroupInfo != null) { @@ -138,6 +140,8 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService GetRSGroupInfoOfTableResponse.Builder builder = GetRSGroupInfoOfTableResponse.newBuilder(); try { TableName tableName = ProtobufUtil.toTableName(request.getTableName()); + LOG.info(master.getClientIdAuditPrefix() + " initiates rsgroup info retrieval, table=" + + tableName); RSGroupInfo RSGroupInfo = groupAdminServer.getRSGroupInfoOfTable(tableName); if (RSGroupInfo != null) { builder.setRSGroupInfo(RSGroupProtobufUtil.toProtoGroupInfo(RSGroupInfo)); @@ -157,6 +161,8 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService for (HBaseProtos.ServerName el : request.getServersList()) { hostPorts.add(Address.fromParts(el.getHostName(), el.getPort())); } + LOG.info(master.getClientIdAuditPrefix() + " move servers " + hostPorts +" to rsgroup " + + request.getTargetGroup()); groupAdminServer.moveServers(hostPorts, request.getTargetGroup()); } catch (IOException e) { CoprocessorRpcUtils.setControllerException(controller, e); @@ -173,6 +179,8 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService for (TableProtos.TableName tableName : request.getTableNameList()) { tables.add(ProtobufUtil.toTableName(tableName)); } + LOG.info(master.getClientIdAuditPrefix() + " move tables " + tables +" to rsgroup " + + request.getTargetGroup()); groupAdminServer.moveTables(tables, request.getTargetGroup()); } catch (IOException e) { CoprocessorRpcUtils.setControllerException(controller, e); @@ -184,6 +192,7 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService public void addRSGroup(RpcController controller, AddRSGroupRequest request, RpcCallback done) { AddRSGroupResponse.Builder builder = AddRSGroupResponse.newBuilder(); + LOG.info(master.getClientIdAuditPrefix() + " add rsgroup " + request.getRSGroupName()); try { groupAdminServer.addRSGroup(request.getRSGroupName()); } catch (IOException e) { @@ -197,6 +206,7 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService RemoveRSGroupRequest request, RpcCallback done) { RemoveRSGroupResponse.Builder builder = RemoveRSGroupResponse.newBuilder(); + LOG.info(master.getClientIdAuditPrefix() + " remove rsgroup " + request.getRSGroupName()); try { groupAdminServer.removeRSGroup(request.getRSGroupName()); } catch (IOException e) { @@ -209,6 +219,7 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService public void balanceRSGroup(RpcController controller, BalanceRSGroupRequest request, RpcCallback done) { BalanceRSGroupResponse.Builder builder = BalanceRSGroupResponse.newBuilder(); + LOG.info(master.getClientIdAuditPrefix() + " balance rsgroup, group=" + request.getRSGroupName()); try { builder.setBalanceRan(groupAdminServer.balanceRSGroup(request.getRSGroupName())); } catch (IOException e) { @@ -222,6 +233,7 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService public void listRSGroupInfos(RpcController controller, ListRSGroupInfosRequest request, RpcCallback done) { ListRSGroupInfosResponse.Builder builder = ListRSGroupInfosResponse.newBuilder(); + LOG.info(master.getClientIdAuditPrefix() + " list rsgroup"); try { for (RSGroupInfo RSGroupInfo : groupAdminServer.listRSGroups()) { builder.addRSGroupInfo(RSGroupProtobufUtil.toProtoGroupInfo(RSGroupInfo)); @@ -239,6 +251,7 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService try { Address hp = Address.fromParts(request.getServer().getHostName(), request.getServer().getPort()); + LOG.info(master.getClientIdAuditPrefix() + " initiates rsgroup info retrieval, server=" + hp); RSGroupInfo RSGroupInfo = groupAdminServer.getRSGroupOfServer(hp); if (RSGroupInfo != null) { builder.setRSGroupInfo(RSGroupProtobufUtil.toProtoGroupInfo(RSGroupInfo)); @@ -262,6 +275,8 @@ public class RSGroupAdminEndpoint implements MasterObserver, CoprocessorService for (TableProtos.TableName tableName : request.getTableNameList()) { tables.add(ProtobufUtil.toTableName(tableName)); } + LOG.info(master.getClientIdAuditPrefix() + " move servers " + hostPorts + + " and tables " + tables + " to rsgroup" + request.getTargetGroup()); groupAdminServer.moveServersAndTables(hostPorts, tables, request.getTargetGroup()); } catch (IOException e) { CoprocessorRpcUtils.setControllerException(controller, e); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index faf0893d775..ce83838097c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -1517,7 +1517,7 @@ public class HMaster extends HRegionServer implements MasterServices { /** * @return Client info for use as prefix on an audit log string; who did an action */ - String getClientIdAuditPrefix() { + public String getClientIdAuditPrefix() { return "Client=" + RpcServer.getRequestUserName() + "/" + RpcServer.getRemoteAddress(); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java index f7f5d069c1d..6e97bf47564 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java @@ -508,4 +508,6 @@ public interface MasterServices extends Server { * method to make sure meta is initialized. */ boolean recoverMeta() throws IOException; + + String getClientIdAuditPrefix(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockNoopMasterServices.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockNoopMasterServices.java index aac0e212fe1..27c9a5fec70 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockNoopMasterServices.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MockNoopMasterServices.java @@ -459,6 +459,11 @@ public class MockNoopMasterServices implements MasterServices, Server { return false; } + @Override + public String getClientIdAuditPrefix() { + return null; + } + @Override public ProcedureEvent getInitializedEvent() { // TODO Auto-generated method stub