HDFS-6156. Simplify the JMX API that provides snapshot information. Contributed by Shinichi Yamashita.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1582847 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Haohui Mai 2014-03-28 18:10:21 +00:00
parent 92b9c6ff60
commit 2e799e5984
7 changed files with 76 additions and 62 deletions

View File

@ -286,6 +286,9 @@ Release 2.5.0 - UNRELEASED
HDFS-6162. Format strings should use platform independent line separator. HDFS-6162. Format strings should use platform independent line separator.
(suresh) (suresh)
HDFS-6156. Simplify the JMX API that provides snapshot information.
(wheat9)
Release 2.4.0 - UNRELEASED Release 2.4.0 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -86,10 +86,11 @@ public class SnapshotInfo {
private final String snapshotDirectory; private final String snapshotDirectory;
private final long modificationTime; private final long modificationTime;
public Bean(Snapshot s) { public Bean(String snapshotID, String snapshotDirectory,
this.snapshotID = s.getRoot().getLocalName(); long modificationTime) {
this.snapshotDirectory = s.getRoot().getFullPathName(); this.snapshotID = snapshotID;
this.modificationTime = s.getRoot().getModificationTime(); this.snapshotDirectory = snapshotDirectory;
this.modificationTime = modificationTime;
} }
public String getSnapshotID() { public String getSnapshotID() {

View File

@ -176,16 +176,15 @@ public class SnapshottableDirectoryStatus {
private final String owner; private final String owner;
private final String group; private final String group;
public Bean(SnapshottableDirectoryStatus s) { public Bean(String path, int snapshotNumber, int snapshotQuota,
this.path = s.getFullPath().toString(); long modificationTime, short permission, String owner, String group) {
this.snapshotNumber = s.getSnapshotNumber(); this.path = path;
this.snapshotQuota = s.getSnapshotQuota(); this.snapshotNumber = snapshotNumber;
this.modificationTime = s.getDirStatus().getModificationTime(); this.snapshotQuota = snapshotQuota;
this.permission = this.modificationTime = modificationTime;
Short.valueOf(Integer.toOctalString( this.permission = permission;
s.getDirStatus().getPermission().toShort())); this.owner = owner;
this.owner = s.getDirStatus().getOwner(); this.group = group;
this.group = s.getDirStatus().getGroup();
} }
public String getPath() { public String getPath() {

View File

@ -387,44 +387,43 @@ public class SnapshotManager implements SnapshotStatsMXBean {
} }
@Override // SnapshotStatsMXBean @Override // SnapshotStatsMXBean
public SnapshotDirectoryMXBean getSnapshotStats() { public SnapshottableDirectoryStatus.Bean[]
SnapshottableDirectoryStatus[] stats = getSnapshottableDirListing(null); getSnapshottableDirectories() {
if (stats == null) { List<SnapshottableDirectoryStatus.Bean> beans =
return null; new ArrayList<SnapshottableDirectoryStatus.Bean>();
for (INodeDirectorySnapshottable d : getSnapshottableDirs()) {
beans.add(toBean(d));
} }
return new SnapshotDirectoryMXBean(stats); return beans.toArray(new SnapshottableDirectoryStatus.Bean[beans.size()]);
} }
public class SnapshotDirectoryMXBean { @Override // SnapshotStatsMXBean
private List<SnapshottableDirectoryStatus.Bean> directory = public SnapshotInfo.Bean[] getSnapshots() {
new ArrayList<SnapshottableDirectoryStatus.Bean>(); List<SnapshotInfo.Bean> beans = new ArrayList<SnapshotInfo.Bean>();
private List<SnapshotInfo.Bean> snapshots = for (INodeDirectorySnapshottable d : getSnapshottableDirs()) {
new ArrayList<SnapshotInfo.Bean>(); for (Snapshot s : d.getSnapshotList()) {
beans.add(toBean(s));
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;
}
} }
} }
return beans.toArray(new SnapshotInfo.Bean[beans.size()]);
}
public List<SnapshottableDirectoryStatus.Bean> getDirectory() { public static SnapshottableDirectoryStatus.Bean toBean(
return directory; 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<SnapshotInfo.Bean> getSnapshots() { public static SnapshotInfo.Bean toBean(Snapshot s) {
return snapshots; return new SnapshotInfo.Bean(
} s.getRoot().getLocalName(), s.getRoot().getFullPathName(),
s.getRoot().getModificationTime());
} }
} }

View File

@ -17,7 +17,8 @@
*/ */
package org.apache.hadoop.hdfs.server.namenode.snapshot; 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 * This is an interface used to retrieve statistic information related to
@ -30,5 +31,13 @@ public interface SnapshotStatsMXBean {
* *
* @return the list of snapshottable directories * @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();
} }

View File

@ -189,7 +189,7 @@
<script type="text/x-dust-template" id="tmpl-snapshot"> <script type="text/x-dust-template" id="tmpl-snapshot">
<div class="page-header"><h1>Snapshot Summary</h1></div> <div class="page-header"><h1>Snapshot Summary</h1></div>
<div class="page-header"><h1><small>Snapshottable directories: {@size key=SnapshotStats.directory}{/size}</small></div> <div class="page-header"><h1><small>Snapshottable directories: {@size key=SnapshottableDirectories}{/size}</small></div>
<small> <small>
<table class="table"> <table class="table">
<thead> <thead>
@ -203,7 +203,7 @@
<th>Group</th> <th>Group</th>
</tr> </tr>
</thead> </thead>
{#SnapshotStats.directory} {#SnapshottableDirectories}
<tr> <tr>
<td>{path}</td> <td>{path}</td>
<td>{snapshotNumber}</td> <td>{snapshotNumber}</td>
@ -213,11 +213,11 @@
<td>{owner}</td> <td>{owner}</td>
<td>{group}</td> <td>{group}</td>
</tr> </tr>
{/SnapshotStats.directory} {/SnapshottableDirectories}
</table> </table>
</small> </small>
<div class="page-header"><h1><small>Snapshotted directories: {@size key=SnapshotStats.snapshots}{/size}</small></div> <div class="page-header"><h1><small>Snapshotted directories: {@size key=Snapshots}{/size}</small></div>
<small> <small>
<table class="table"> <table class="table">
@ -228,13 +228,13 @@
<th>Modification Time</th> <th>Modification Time</th>
</tr> </tr>
</thead> </thead>
{#SnapshotStats.snapshots} {#Snapshots}
<tr> <tr>
<td>{snapshotID}</td> <td>{snapshotID}</td>
<td>{snapshotDirectory}</td> <td>{snapshotDirectory}</td>
<td>{modificationTime|date_tostring}</td> <td>{modificationTime|date_tostring}</td>
</tr> </tr>
{/SnapshotStats.snapshots} {/Snapshots}
</table> </table>
</small> </small>
</script> </script>

View File

@ -59,17 +59,20 @@ public class TestSnapshotStatsMXBean {
ObjectName mxbeanName = new ObjectName( ObjectName mxbeanName = new ObjectName(
"Hadoop:service=NameNode,name=SnapshotInfo"); "Hadoop:service=NameNode,name=SnapshotInfo");
CompositeData statsbean = CompositeData[] directories =
(CompositeData) mbs.getAttribute(mxbeanName, "SnapshotStats"); (CompositeData[]) mbs.getAttribute(
int numDirectories = Array.getLength(statsbean.get("directory")); mxbeanName, "SnapshottableDirectories");
int numDirectories = Array.getLength(directories);
assertEquals(sm.getNumSnapshottableDirs(), numDirectories); 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); assertEquals(sm.getNumSnapshots(), numSnapshots);
CompositeData directory = (CompositeData) Array.get(statsbean.get("directory"), 0); CompositeData d = (CompositeData) Array.get(directories, 0);
CompositeData snapshots = (CompositeData) Array.get(statsbean.get("snapshots"), 0); CompositeData s = (CompositeData) Array.get(snapshots, 0);
assertTrue(((String) directory.get("path")).contains(pathName)); assertTrue(((String) d.get("path")).contains(pathName));
assertTrue(((String) snapshots.get("snapshotDirectory")).contains(pathName)); assertTrue(((String) s.get("snapshotDirectory")).contains(pathName));
} finally { } finally {
if (cluster != null) { if (cluster != null) {
cluster.shutdown(); cluster.shutdown();