Skip to content

Commit

Permalink
HDFS-16444. Show start time of JournalNode on Web (#3943)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomscut authored Jan 30, 2022
1 parent 39cad5f commit bd50b91
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_JOURNALNODE_HTTP_BIND_HOST_KEY;
import static org.apache.hadoop.util.ExitUtil.terminate;
import static org.apache.hadoop.util.Time.now;
import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
Expand Down Expand Up @@ -83,6 +84,7 @@ public class JournalNode implements Tool, Configurable, JournalNodeMXBean {
private String httpServerURI;
private final ArrayList<File> localDir = Lists.newArrayList();
Tracer tracer;
private long startTime = 0;

static {
HdfsConfiguration.init();
Expand Down Expand Up @@ -241,6 +243,7 @@ public void start() throws IOException {

rpcServer = new JournalNodeRpcServer(conf, this);
rpcServer.start();
startTime = now();
} catch (IOException ioe) {
//Shutdown JournalNode of JournalNodeRpcServer fails to start
LOG.error("Failed to start JournalNode.", ioe);
Expand Down Expand Up @@ -415,6 +418,11 @@ public String getVersion() {
return VersionInfo.getVersion() + ", r" + VersionInfo.getRevision();
}

@Override // JournalNodeMXBean
public long getJNStartedTimeInMillis() {
return this.startTime;
}

/**
* Register JournalNodeMXBean
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ public interface JournalNodeMXBean {
* @return the version of Hadoop.
*/
String getVersion();

/**
* Get the start time of the JournalNode.
*
* @return the start time of the JournalNode.
*/
long getJNStartedTimeInMillis();
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<div class="page-header"><h1>JournalNode on <small>{HostAndPort}</small></h1></div>
<table class="table table-bordered table-striped">
<tr><th>Cluster ID:</th><td>{ClusterIds}</td></tr>
<tr><th>Started:</th><td>{JNStartedTimeInMillis|date_tostring}</td></tr>
<tr><th>Version:</th><td>{Version}</td></tr>
</table>
{/jn}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public void testJournalNodeMXBean() throws Exception {
String[] clusterId = (String[]) mbs.getAttribute(mxbeanName, "ClusterIds");
assertEquals(jn.getClusterIds().size(), clusterId.length);
assertEquals("mycluster", clusterId[0]);
long startTime = (long) mbs.getAttribute(mxbeanName, "JNStartedTimeInMillis");
assertTrue("JournalNode start time should not be 0", startTime > 0);
assertEquals(jn.getJNStartedTimeInMillis(), startTime);
String version = (String) mbs.getAttribute(mxbeanName, "Version");
assertEquals(jn.getVersion(), version);

Expand Down

0 comments on commit bd50b91

Please sign in to comment.