From d746e2cdd80335c86526b293f284187ce07758c4 Mon Sep 17 00:00:00 2001 From: litao Date: Tue, 23 Nov 2021 10:18:30 +0800 Subject: [PATCH] HDFS-16337. Show start time of Datanode on Web (#3682) Reviewed-by: Inigo Goiri (cherry picked from commit 0ed817babbcaa0560c11e2065cff3fff0bf328c5) --- .../org/apache/hadoop/hdfs/server/datanode/DataNode.java | 8 ++++++++ .../hadoop/hdfs/server/datanode/DataNodeMXBean.java | 7 +++++++ .../hadoop-hdfs/src/main/webapps/datanode/datanode.html | 1 + .../hadoop/hdfs/server/datanode/TestDataNodeMXBean.java | 3 +++ 4 files changed, 19 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java index 256ae4e29b..bd57f40296 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java @@ -50,6 +50,7 @@ import static org.apache.hadoop.hdfs.protocol.datatransfer.BlockConstructionStage.PIPELINE_SETUP_CREATE; import static org.apache.hadoop.hdfs.protocol.datatransfer.BlockConstructionStage.PIPELINE_SETUP_STREAMING_RECOVERY; import static org.apache.hadoop.util.ExitUtil.terminate; +import static org.apache.hadoop.util.Time.now; import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.hdfs.protocol.proto.ReconfigurationProtocolProtos.ReconfigurationProtocolService; @@ -415,6 +416,8 @@ private static Tracer createTracer(Configuration conf) { private ScheduledThreadPoolExecutor metricsLoggerTimer; + private final long startTime = now(); + /** * Creates a dummy DataNode for testing purpose. */ @@ -3109,6 +3112,11 @@ public String getHttpPort(){ return this.getConf().get("dfs.datanode.info.port"); } + @Override // DataNodeMXBean + public long getDNStartedTimeInMillis() { + return this.startTime; + } + public String getRevision() { return VersionInfo.getRevision(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeMXBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeMXBean.java index 7a8f59bb66..6553775474 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeMXBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeMXBean.java @@ -157,4 +157,11 @@ public interface DataNodeMXBean { * @return true, if security is enabled. */ boolean isSecurityEnabled(); + + /** + * Get the start time of the DataNode. + * + * @return Start time of the DataNode. + */ + long getDNStartedTimeInMillis(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/datanode.html b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/datanode.html index 7301064651..b680f0a37e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/datanode.html +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/datanode/datanode.html @@ -71,6 +71,7 @@ +
Cluster ID:{ClusterId}
Started:{DNStartedTimeInMillis|date_tostring}
Version:{Version}
{/dn} diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java index 73f664b980..f72f1bce13 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java @@ -75,6 +75,9 @@ public void testDataNodeMXBean() throws Exception { // get attribute "Version" String version = (String)mbs.getAttribute(mxbeanName, "Version"); Assert.assertEquals(datanode.getVersion(),version); + // get attribute "DNStartedTimeInMillis" + long startTime = (long) mbs.getAttribute(mxbeanName, "DNStartedTimeInMillis"); + Assert.assertEquals(datanode.getDNStartedTimeInMillis(), startTime); // get attribute "SotfwareVersion" String softwareVersion = (String)mbs.getAttribute(mxbeanName, "SoftwareVersion");