diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 51f5da1efd6..469272a0b2b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -306,6 +306,9 @@ Release 2.8.0 - UNRELEASED HDFS-8589. Fix unused imports in BPServiceActor and BlockReportLeaseManager (cmccabe) + HDFS-6249. Output AclEntry in PBImageXmlWriter. + (surendra singh lilhore via aajisaka) + OPTIMIZATIONS HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java index f3fe8860897..4415c5d267b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java @@ -29,6 +29,7 @@ import java.util.Comparator; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CacheDirectiveInfoExpirationProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CacheDirectiveInfoProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CachePoolInfoProto; @@ -41,6 +42,7 @@ import org.apache.hadoop.hdfs.server.namenode.FsImageProto.FileSummary; import org.apache.hadoop.hdfs.server.namenode.FsImageProto.FilesUnderConstructionSection.FileUnderConstructionEntry; import org.apache.hadoop.hdfs.server.namenode.FsImageProto.INodeDirectorySection; import org.apache.hadoop.hdfs.server.namenode.FsImageProto.INodeSection; +import org.apache.hadoop.hdfs.server.namenode.FsImageProto.INodeSection.AclFeatureProto; import org.apache.hadoop.hdfs.server.namenode.FsImageProto.INodeSection.INodeDirectory; import org.apache.hadoop.hdfs.server.namenode.FsImageProto.INodeSection.INodeSymlink; import org.apache.hadoop.hdfs.server.namenode.FsImageProto.INodeReferenceSection; @@ -51,7 +53,7 @@ import org.apache.hadoop.hdfs.server.namenode.FsImageProto.SnapshotSection; import org.apache.hadoop.hdfs.server.namenode.FsImageProto.StringTableSection; import org.apache.hadoop.hdfs.util.XMLUtils; import org.apache.hadoop.util.LimitInputStream; - +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; /** @@ -188,7 +190,7 @@ public final class PBImageXmlWriter { private void dumpINodeDirectory(INodeDirectory d) { o("mtime", d.getModificationTime()).o("permission", dumpPermission(d.getPermission())); - + dumpAcls(d.getAcl()); if (d.hasDsQuota() && d.hasNsQuota()) { o("nsquota", d.getNsQuota()).o("dsquota", d.getDsQuota()); } @@ -242,7 +244,7 @@ public final class PBImageXmlWriter { .o("atime", f.getAccessTime()) .o("perferredBlockSize", f.getPreferredBlockSize()) .o("permission", dumpPermission(f.getPermission())); - + dumpAcls(f.getAcl()); if (f.getBlocksCount() > 0) { out.print(""); for (BlockProto b : f.getBlocksList()) { @@ -263,6 +265,18 @@ public final class PBImageXmlWriter { } } + private void dumpAcls(AclFeatureProto aclFeatureProto) { + ImmutableList aclEntryList = FSImageFormatPBINode.Loader + .loadAclEntries(aclFeatureProto, stringTable); + if (aclEntryList.size() > 0) { + out.print(""); + for (AclEntry aclEntry : aclEntryList) { + o("acl", aclEntry.toString()); + } + out.print(""); + } + } + private void dumpINodeSection(InputStream in) throws IOException { INodeSection s = INodeSection.parseDelimitedFrom(in); out.print(""); 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 56963a675d6..7104ba104e4 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,14 +17,23 @@ */ package org.apache.hadoop.hdfs.tools.offlineImageViewer; +import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.PrintStream; +import java.io.RandomAccessFile; +import java.io.StringReader; import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.HashMap; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -42,6 +51,9 @@ import org.apache.hadoop.net.NetUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; import static org.apache.hadoop.fs.permission.AclEntryScope.ACCESS; import static org.apache.hadoop.fs.permission.AclEntryScope.DEFAULT; @@ -202,4 +214,16 @@ public class TestOfflineImageViewerForAcl { viewer.close(); } } + + @Test + public void testPBImageXmlWriterForAcl() throws Exception{ + ByteArrayOutputStream output = new ByteArrayOutputStream(); + PrintStream o = new PrintStream(output); + PBImageXmlWriter v = new PBImageXmlWriter(new Configuration(), o); + v.visit(new RandomAccessFile(originalFsimage, "r")); + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser parser = spf.newSAXParser(); + final String xml = output.toString(); + parser.parse(new InputSource(new StringReader(xml)), new DefaultHandler()); + } }