From c7fcec24b845fc7c74cc50f16931305bb526dba6 Mon Sep 17 00:00:00 2001 From: Lei Xu Date: Thu, 11 Feb 2016 20:33:51 -0800 Subject: [PATCH] HDFS-9795. OIV Delimited should show which files are ACL-enabled (lei) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 2 ++ .../PBImageDelimitedTextWriter.java | 6 +++- .../TestOfflineImageViewerForAcl.java | 36 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 612451c0f54..e2463f10bc8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -223,6 +223,8 @@ Trunk (Unreleased) HDFS-9260. Improve the performance and GC friendliness of NameNode startup and full block reports (Staffan Friberg via cmccabe) + HDFS-9795. OIV Delimited should show which files are ACL-enabled (lei) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageDelimitedTextWriter.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageDelimitedTextWriter.java index 3ddc1355070..8fab34c06f8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageDelimitedTextWriter.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageDelimitedTextWriter.java @@ -85,11 +85,13 @@ public class PBImageDelimitedTextWriter extends PBImageTextWriter { buffer.append(path.toString()); PermissionStatus p = null; boolean isDir = false; + boolean hasAcl = false; switch (inode.getType()) { case FILE: INodeFile file = inode.getFile(); p = getPermission(file.getPermission()); + hasAcl = file.hasAcl() && file.getAcl().getEntriesCount() > 0; append(buffer, file.getReplication()); append(buffer, formatDate(file.getModificationTime())); append(buffer, formatDate(file.getAccessTime())); @@ -102,6 +104,7 @@ public class PBImageDelimitedTextWriter extends PBImageTextWriter { case DIRECTORY: INodeDirectory dir = inode.getDirectory(); p = getPermission(dir.getPermission()); + hasAcl = dir.hasAcl() && dir.getAcl().getEntriesCount() > 0; append(buffer, 0); // Replication append(buffer, formatDate(dir.getModificationTime())); append(buffer, formatDate(0)); // Access time. @@ -129,7 +132,8 @@ public class PBImageDelimitedTextWriter extends PBImageTextWriter { } assert p != null; String dirString = isDir ? "d" : "-"; - append(buffer, dirString + p.getPermission().toString()); + String aclString = hasAcl ? "+" : ""; + append(buffer, dirString + p.getPermission().toString() + aclString); append(buffer, p.getUserName()); append(buffer, p.getGroupName()); return buffer.toString(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForAcl.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForAcl.java index 7104ba104e4..c66c2deb575 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForAcl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForAcl.java @@ -17,10 +17,13 @@ */ package org.apache.hadoop.hdfs.tools.offlineImageViewer; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStreamReader; import java.io.PrintStream; import java.io.RandomAccessFile; import java.io.StringReader; @@ -226,4 +229,37 @@ public class TestOfflineImageViewerForAcl { final String xml = output.toString(); parser.parse(new InputSource(new StringReader(xml)), new DefaultHandler()); } + + @Test + public void testPBDelimitedWriterForAcl() throws Exception { + final String DELIMITER = "\t"; + ByteArrayOutputStream output = new ByteArrayOutputStream(); + + try (PrintStream o = new PrintStream(output)) { + PBImageDelimitedTextWriter v = + new PBImageDelimitedTextWriter(o, DELIMITER, ""); // run in memory. + v.visit(new RandomAccessFile(originalFsimage, "r")); + } + + try ( + ByteArrayInputStream input = + new ByteArrayInputStream(output.toByteArray()); + BufferedReader reader = + new BufferedReader(new InputStreamReader(input))) { + String line; + boolean header = true; + while ((line = reader.readLine()) != null) { + String[] fields = line.split(DELIMITER); + if (!header) { + String filePath = fields[0]; + String permission = fields[9]; + if (!filePath.equals("/")) { + boolean hasAcl = !filePath.toLowerCase().contains("noacl"); + assertEquals(hasAcl, permission.endsWith("+")); + } + } + header = false; + } + } + } }