From 50f85aa155a82623650819b2f24fcc62c3ffc6fe Mon Sep 17 00:00:00 2001
From: maobaolong <307499405@qq.com>
Date: Sun, 28 Jun 2020 10:07:43 +0800
Subject: [PATCH 1/3] HDDS-3885. Create Datanode home page
---
hadoop-hdds/container-service/pom.xml | 31 ++++++++
.../org/apache/hadoop/ozone/DNMXBean.java} | 14 +++-
.../org/apache/hadoop/ozone/DNMXBeanImpl.java | 32 ++++++++
.../hadoop/ozone/HddsDatanodeService.java | 34 +++++++--
.../webapps/hddsDatanode/dn-overview.html | 21 +++++
.../main/resources/webapps/hddsDatanode/dn.js | 35 +++++++++
.../resources/webapps/hddsDatanode/index.html | 76 +++++++++++++++++++
.../resources/webapps/hddsDatanode/main.html | 20 +++++
8 files changed, 257 insertions(+), 6 deletions(-)
rename hadoop-hdds/container-service/src/main/{resources/webapps/hddsDatanode/.gitkeep => java/org/apache/hadoop/ozone/DNMXBean.java} (72%)
create mode 100644 hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/DNMXBeanImpl.java
create mode 100644 hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/dn-overview.html
create mode 100644 hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/dn.js
create mode 100644 hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/index.html
create mode 100644 hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/main.html
diff --git a/hadoop-hdds/container-service/pom.xml b/hadoop-hdds/container-service/pom.xml
index d10d2a358ce1..392cc44c72a1 100644
--- a/hadoop-hdds/container-service/pom.xml
+++ b/hadoop-hdds/container-service/pom.xml
@@ -107,6 +107,37 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
${basedir}/dev-support/findbugsExcludeFile.xml
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-common-html
+ prepare-package
+
+ unpack
+
+
+
+
+ org.apache.hadoop
+ hadoop-hdds-server-framework
+ ${project.build.outputDirectory}
+
+ webapps/static/**/*.*
+
+
+ org.apache.hadoop
+ hadoop-hdds-docs
+ ${project.build.outputDirectory}/webapps/hddsDatanode
+ docs/**/*.*
+
+
+ true
+
+
+
+
diff --git a/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/.gitkeep b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/DNMXBean.java
similarity index 72%
rename from hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/.gitkeep
rename to hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/DNMXBean.java
index ff1232e5fcaa..d36fcdb6fc70 100644
--- a/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/.gitkeep
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/DNMXBean.java
@@ -14,4 +14,16 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
\ No newline at end of file
+ */
+
+package org.apache.hadoop.ozone;
+
+import org.apache.hadoop.hdds.annotation.InterfaceAudience;
+import org.apache.hadoop.hdds.server.ServiceRuntimeInfo;
+
+/**
+ * This is the JMX management interface for DN information.
+ */
+@InterfaceAudience.Private
+public interface DNMXBean extends ServiceRuntimeInfo {
+}
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/DNMXBeanImpl.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/DNMXBeanImpl.java
new file mode 100644
index 000000000000..18ad66ce5a69
--- /dev/null
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/DNMXBeanImpl.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone;
+
+import org.apache.hadoop.hdds.server.ServiceRuntimeInfoImpl;
+import org.apache.hadoop.hdds.utils.VersionInfo;
+
+/**
+ * This is the JMX management class for DN information.
+ */
+public class DNMXBeanImpl extends ServiceRuntimeInfoImpl implements DNMXBean {
+ public DNMXBeanImpl(
+ VersionInfo versionInfo) {
+ super(versionInfo);
+ }
+}
\ No newline at end of file
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java
index 615588a16aba..3f5ceeed3333 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java
@@ -22,13 +22,11 @@
import java.net.InetAddress;
import java.security.KeyPair;
import java.security.cert.CertificateException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.ConcurrentHashMap;
+import com.sun.jmx.mbeanserver.Introspector;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.hdds.DFSConfigKeysLegacy;
import org.apache.hadoop.hdds.HddsUtils;
@@ -49,6 +47,7 @@
import org.apache.hadoop.hdds.server.http.RatisDropwizardExports;
import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.hdds.utils.HddsVersionInfo;
+import org.apache.hadoop.metrics2.util.MBeans;
import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils;
import org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine;
import org.apache.hadoop.ozone.container.common.utils.HddsVolumeUtil;
@@ -70,6 +69,8 @@
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
+import javax.management.ObjectName;
+
/**
* Datanode service plugin to start the HDDS container services.
*/
@@ -95,6 +96,10 @@ public class HddsDatanodeService extends GenericCli implements ServicePlugin {
private volatile AtomicBoolean isStopped = new AtomicBoolean(false);
private final Map ratisMetricsMap =
new ConcurrentHashMap<>();
+ private DNMXBeanImpl serviceRuntimeInfo =
+ new DNMXBeanImpl(HddsVersionInfo.HDDS_VERSION_INFO) {};
+ private ObjectName dnInfoBeanName;
+
//Constructor for DataNode PluginService
public HddsDatanodeService(){}
@@ -132,6 +137,7 @@ private static HddsDatanodeService createHddsDatanodeService(
public static void main(String[] args) {
try {
+ Introspector.checkCompliance(DNMXBeanImpl.class);
HddsDatanodeService hddsDatanodeService =
createHddsDatanodeService(args, true);
hddsDatanodeService.run(args);
@@ -180,6 +186,8 @@ public void start(OzoneConfiguration configuration) {
}
public void start() {
+ serviceRuntimeInfo.setStartTime();
+
RatisDropwizardExports.
registerRatisMetricReporters(ratisMetricsMap);
@@ -245,7 +253,7 @@ public void start() {
.equalsIgnoreCase(System.getenv("OZONE_DATANODE_STANDALONE_TEST"))) {
startRatisForTest();
}
-
+ registerMXBean();
} catch (IOException e) {
throw new RuntimeException("Can't start the HDDS datanode plugin", e);
} catch (AuthenticationException ex) {
@@ -345,6 +353,21 @@ private void getSCMSignedCert(OzoneConfiguration config) {
}
}
+ private void registerMXBean() {
+ Map jmxProperties = new HashMap<>();
+ jmxProperties.put("component", "ServerRuntime");
+ this.dnInfoBeanName = HddsUtils.registerWithJmxProperties(
+ "HddsDatanodeService",
+ "HddsDatanodeServiceInfo", jmxProperties, this.serviceRuntimeInfo);
+ }
+
+ private void unregisterMXBean() {
+ if (this.dnInfoBeanName != null) {
+ MBeans.unregister(this.dnInfoBeanName);
+ this.dnInfoBeanName = null;
+ }
+ }
+
/**
* Creates CSR for DN.
* @param config
@@ -513,6 +536,7 @@ public void stop() {
LOG.error("Stopping HttpServer is failed.", e);
}
}
+ unregisterMXBean();
}
}
diff --git a/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/dn-overview.html b/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/dn-overview.html
new file mode 100644
index 000000000000..d4f7a17c0b76
--- /dev/null
+++ b/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/dn-overview.html
@@ -0,0 +1,21 @@
+
+
+
+
+
+
diff --git a/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/dn.js b/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/dn.js
new file mode 100644
index 000000000000..c43eb42bdc25
--- /dev/null
+++ b/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/dn.js
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+(function () {
+ "use strict";
+ angular.module('dn', ['ozone', 'nvd3']);
+
+ angular.module('dn').component('dnOverview', {
+ templateUrl: 'dn-overview.html',
+ require: {
+ overview: "^overview"
+ },
+ controller: function ($http) {
+ var ctrl = this;
+ $http.get("jmx?qry=Hadoop:service=HddsDatanode,name=StorageContainerMetrics")
+ .then(function (result) {
+ ctrl.dnmetrics = result.data.beans[0];
+ });
+ }
+ });
+})();
diff --git a/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/index.html b/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/index.html
new file mode 100644
index 000000000000..921e481bd361
--- /dev/null
+++ b/hadoop-hdds/container-service/src/main/resources/webapps/hddsDatanode/index.html
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
+
+ HDDS Datanode Service
+
+
+
+
+
+
+
+
+
+
+
+
+