diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 1c4f6c869e8..70723be8687 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -41,6 +41,9 @@ Release 2.5.0 - UNRELEASED HDFS-6162. Format strings should use platform independent line separator. (suresh) + HDFS-6156. Simplify the JMX API that provides snapshot information. + (wheat9) + Release 2.4.0 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshotInfo.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshotInfo.java index d50c856074e..3ddfc85638a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshotInfo.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshotInfo.java @@ -86,10 +86,11 @@ public class SnapshotInfo { private final String snapshotDirectory; private final long modificationTime; - public Bean(Snapshot s) { - this.snapshotID = s.getRoot().getLocalName(); - this.snapshotDirectory = s.getRoot().getFullPathName(); - this.modificationTime = s.getRoot().getModificationTime(); + public Bean(String snapshotID, String snapshotDirectory, + long modificationTime) { + this.snapshotID = snapshotID; + this.snapshotDirectory = snapshotDirectory; + this.modificationTime = modificationTime; } public String getSnapshotID() { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java index 43bdedfe1ce..959439b6342 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java @@ -176,16 +176,15 @@ public class SnapshottableDirectoryStatus { private final String owner; private final String group; - public Bean(SnapshottableDirectoryStatus s) { - this.path = s.getFullPath().toString(); - this.snapshotNumber = s.getSnapshotNumber(); - this.snapshotQuota = s.getSnapshotQuota(); - this.modificationTime = s.getDirStatus().getModificationTime(); - this.permission = - Short.valueOf(Integer.toOctalString( - s.getDirStatus().getPermission().toShort())); - this.owner = s.getDirStatus().getOwner(); - this.group = s.getDirStatus().getGroup(); + public Bean(String path, int snapshotNumber, int snapshotQuota, + long modificationTime, short permission, String owner, String group) { + this.path = path; + this.snapshotNumber = snapshotNumber; + this.snapshotQuota = snapshotQuota; + this.modificationTime = modificationTime; + this.permission = permission; + this.owner = owner; + this.group = group; } public String getPath() { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java index 48d57bd485d..51479473011 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java @@ -387,44 +387,43 @@ public class SnapshotManager implements SnapshotStatsMXBean { } @Override // SnapshotStatsMXBean - public SnapshotDirectoryMXBean getSnapshotStats() { - SnapshottableDirectoryStatus[] stats = getSnapshottableDirListing(null); - if (stats == null) { - return null; + public SnapshottableDirectoryStatus.Bean[] + getSnapshottableDirectories() { + List beans = + new ArrayList(); + for (INodeDirectorySnapshottable d : getSnapshottableDirs()) { + beans.add(toBean(d)); } - return new SnapshotDirectoryMXBean(stats); + return beans.toArray(new SnapshottableDirectoryStatus.Bean[beans.size()]); } - public class SnapshotDirectoryMXBean { - private List directory = - new ArrayList(); - private List snapshots = - new ArrayList(); - - public SnapshotDirectoryMXBean(SnapshottableDirectoryStatus[] stats) { - set(stats); - } - - public void set(SnapshottableDirectoryStatus[] stats) { - for (SnapshottableDirectoryStatus s : stats) { - directory.add(new SnapshottableDirectoryStatus.Bean(s)); - try { - for (Snapshot shot : getSnapshottableRoot( - s.getFullPath().toString()).getSnapshotList()) { - snapshots.add(new SnapshotInfo.Bean(shot)); - } - } catch (IOException e) { - continue; - } + @Override // SnapshotStatsMXBean + public SnapshotInfo.Bean[] getSnapshots() { + List beans = new ArrayList(); + for (INodeDirectorySnapshottable d : getSnapshottableDirs()) { + for (Snapshot s : d.getSnapshotList()) { + beans.add(toBean(s)); } } + return beans.toArray(new SnapshotInfo.Bean[beans.size()]); + } - public List getDirectory() { - return directory; - } + public static SnapshottableDirectoryStatus.Bean toBean( + INodeDirectorySnapshottable d) { + return new SnapshottableDirectoryStatus.Bean( + d.getFullPathName(), + d.getNumSnapshots(), + d.getSnapshotQuota(), + d.getModificationTime(), + Short.valueOf(Integer.toOctalString( + d.getFsPermissionShort())), + d.getUserName(), + d.getGroupName()); + } - public List getSnapshots() { - return snapshots; - } + public static SnapshotInfo.Bean toBean(Snapshot s) { + return new SnapshotInfo.Bean( + s.getRoot().getLocalName(), s.getRoot().getFullPathName(), + s.getRoot().getModificationTime()); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotStatsMXBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotStatsMXBean.java index fafa2f578a6..6a9b28d540f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotStatsMXBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotStatsMXBean.java @@ -17,7 +17,8 @@ */ package org.apache.hadoop.hdfs.server.namenode.snapshot; -import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotManager.SnapshotDirectoryMXBean; +import org.apache.hadoop.hdfs.protocol.SnapshotInfo; +import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus; /** * This is an interface used to retrieve statistic information related to @@ -30,5 +31,13 @@ public interface SnapshotStatsMXBean { * * @return the list of snapshottable directories */ - public SnapshotDirectoryMXBean getSnapshotStats(); + public SnapshottableDirectoryStatus.Bean[] getSnapshottableDirectories(); + + /** + * Return the list of snapshots + * + * @return the list of snapshots + */ + public SnapshotInfo.Bean[] getSnapshots(); + } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.html b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.html index bce156ee82c..e0d509354f9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.html +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.html @@ -189,7 +189,7 @@ diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotStatsMXBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotStatsMXBean.java index dc96c0bb692..e65084f3da6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotStatsMXBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotStatsMXBean.java @@ -59,17 +59,20 @@ public class TestSnapshotStatsMXBean { ObjectName mxbeanName = new ObjectName( "Hadoop:service=NameNode,name=SnapshotInfo"); - CompositeData statsbean = - (CompositeData) mbs.getAttribute(mxbeanName, "SnapshotStats"); - int numDirectories = Array.getLength(statsbean.get("directory")); + CompositeData[] directories = + (CompositeData[]) mbs.getAttribute( + mxbeanName, "SnapshottableDirectories"); + int numDirectories = Array.getLength(directories); assertEquals(sm.getNumSnapshottableDirs(), numDirectories); - int numSnapshots = Array.getLength(statsbean.get("snapshots")); + CompositeData[] snapshots = + (CompositeData[]) mbs.getAttribute(mxbeanName, "Snapshots"); + int numSnapshots = Array.getLength(snapshots); assertEquals(sm.getNumSnapshots(), numSnapshots); - CompositeData directory = (CompositeData) Array.get(statsbean.get("directory"), 0); - CompositeData snapshots = (CompositeData) Array.get(statsbean.get("snapshots"), 0); - assertTrue(((String) directory.get("path")).contains(pathName)); - assertTrue(((String) snapshots.get("snapshotDirectory")).contains(pathName)); + CompositeData d = (CompositeData) Array.get(directories, 0); + CompositeData s = (CompositeData) Array.get(snapshots, 0); + assertTrue(((String) d.get("path")).contains(pathName)); + assertTrue(((String) s.get("snapshotDirectory")).contains(pathName)); } finally { if (cluster != null) { cluster.shutdown();