diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java index 6a7b840692..ec3eb4f038 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java @@ -993,6 +993,7 @@ public boolean complete(String src, String clientName, public void reportBadBlocks(LocatedBlock[] blocks) throws IOException { checkNNStartup(); namesystem.reportBadBlocks(blocks); + namesystem.logAuditEvent(true, "reportBadBlocks", null); } @Override // ClientProtocol diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java index d34d6ca737..d746375014 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAuditLoggerWithCommands.java @@ -33,6 +33,7 @@ import org.apache.hadoop.hdfs.protocol.CachePoolEntry; import org.apache.hadoop.hdfs.protocol.CachePoolInfo; import org.apache.hadoop.hdfs.protocol.HdfsConstants; +import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.server.protocol.DatanodeStorageReport; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; import org.apache.hadoop.ipc.RPC; @@ -1218,6 +1219,25 @@ public void testDeleteRoot() throws Exception { verifyAuditLogs(aceDeletePattern); } + @Test + public void testReportBadBlocks() throws IOException { + String auditLogString = + ".*allowed=true.*cmd=reportBadBlocks.*"; + FSNamesystem fsNamesystem = spy(cluster.getNamesystem()); + when(fsNamesystem.isExternalInvocation()).thenReturn(true); + Server.Call call = spy(new Server.Call( + 1, 1, null, null, RPC.RpcKind.RPC_BUILTIN, new byte[] {1, 2, 3})); + when(call.getRemoteUser()).thenReturn( + UserGroupInformation.createRemoteUser(System.getProperty("user.name"))); + Server.getCurCall().set(call); + try { + cluster.getNameNodeRpc().reportBadBlocks(new LocatedBlock[]{}); + verifyAuditLogs(auditLogString); + } catch (Exception e) { + fail(" The operation threw an exception" + e); + } + } + private void verifyAuditRestoreFailedStorageACE( FSNamesystem fsNamesystem, String arg) throws IOException { String operationName = fsNamesystem.getFailedStorageCommand(arg);