|
@@ -19,50 +19,107 @@
|
|
|
package org.apache.hadoop.yarn.server.router.webapp;
|
|
|
|
|
|
import com.sun.jersey.api.client.Client;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.util.StringUtils;
|
|
|
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
|
|
|
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
|
|
|
+import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeInfo;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodesInfo;
|
|
|
import org.apache.hadoop.yarn.server.router.Router;
|
|
|
-import org.apache.hadoop.yarn.util.Times;
|
|
|
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;
|
|
|
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet.TABLE;
|
|
|
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet.TBODY;
|
|
|
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet.TR;
|
|
|
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
|
|
|
-import org.apache.hadoop.yarn.webapp.view.HtmlBlock;
|
|
|
|
|
|
import com.google.inject.Inject;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+import static org.apache.hadoop.yarn.webapp.YarnWebParams.NODE_SC;
|
|
|
+
|
|
|
/**
|
|
|
* Nodes block for the Router Web UI.
|
|
|
*/
|
|
|
-public class NodesBlock extends HtmlBlock {
|
|
|
-
|
|
|
- private static final long BYTES_IN_MB = 1024 * 1024;
|
|
|
+public class NodesBlock extends RouterBlock {
|
|
|
|
|
|
private final Router router;
|
|
|
|
|
|
@Inject
|
|
|
NodesBlock(Router router, ViewContext ctx) {
|
|
|
- super(ctx);
|
|
|
+ super(router, ctx);
|
|
|
this.router = router;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void render(Block html) {
|
|
|
- // Get the node info from the federation
|
|
|
+
|
|
|
+ boolean isEnabled = isYarnFederationEnabled();
|
|
|
+
|
|
|
+ // Get subClusterName
|
|
|
+ String subClusterName = $(NODE_SC);
|
|
|
+
|
|
|
+ // We will try to get the subClusterName.
|
|
|
+ // If the subClusterName is not empty,
|
|
|
+ // it means that we need to get the Node list of a subCluster.
|
|
|
+ NodesInfo nodesInfo = null;
|
|
|
+ if (subClusterName != null && !subClusterName.isEmpty()) {
|
|
|
+ initSubClusterMetricsOverviewTable(html, subClusterName);
|
|
|
+ nodesInfo = getSubClusterNodesInfo(subClusterName);
|
|
|
+ } else {
|
|
|
+ // Metrics Overview Table
|
|
|
+ html.__(MetricsOverviewTable.class);
|
|
|
+ nodesInfo = getYarnFederationNodesInfo(isEnabled);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Initialize NodeInfo List
|
|
|
+ initYarnFederationNodesOfCluster(nodesInfo, html);
|
|
|
+ }
|
|
|
+
|
|
|
+ private NodesInfo getYarnFederationNodesInfo(boolean isEnabled) {
|
|
|
+ if (isEnabled) {
|
|
|
+ String webAddress = WebAppUtils.getRouterWebAppURLWithScheme(this.router.getConfig());
|
|
|
+ return getSubClusterNodesInfoByWebAddress(webAddress);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private NodesInfo getSubClusterNodesInfo(String subCluster) {
|
|
|
+ try {
|
|
|
+ SubClusterId subClusterId = SubClusterId.newInstance(subCluster);
|
|
|
+ FederationStateStoreFacade facade = FederationStateStoreFacade.getInstance();
|
|
|
+ SubClusterInfo subClusterInfo = facade.getSubCluster(subClusterId);
|
|
|
+
|
|
|
+ if (subClusterInfo != null) {
|
|
|
+ // Prepare webAddress
|
|
|
+ String webAddress = subClusterInfo.getRMWebServiceAddress();
|
|
|
+ String herfWebAppAddress = "";
|
|
|
+ if (webAddress != null && !webAddress.isEmpty()) {
|
|
|
+ herfWebAppAddress =
|
|
|
+ WebAppUtils.getHttpSchemePrefix(this.router.getConfig()) + webAddress;
|
|
|
+ return getSubClusterNodesInfoByWebAddress(herfWebAppAddress);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.error("get NodesInfo From SubCluster = {} error.", subCluster, e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private NodesInfo getSubClusterNodesInfoByWebAddress(String webAddress) {
|
|
|
Configuration conf = this.router.getConfig();
|
|
|
Client client = RouterWebServiceUtil.createJerseyClient(conf);
|
|
|
- String webAppAddress = WebAppUtils.getRouterWebAppURLWithScheme(conf);
|
|
|
NodesInfo nodes = RouterWebServiceUtil
|
|
|
- .genericForward(webAppAddress, null, NodesInfo.class, HTTPMethods.GET,
|
|
|
- RMWSConsts.RM_WEB_SERVICE_PATH + RMWSConsts.NODES, null, null, conf,
|
|
|
- client);
|
|
|
-
|
|
|
- setTitle("Nodes");
|
|
|
+ .genericForward(webAddress, null, NodesInfo.class, HTTPMethods.GET,
|
|
|
+ RMWSConsts.RM_WEB_SERVICE_PATH + RMWSConsts.NODES, null, null, conf,
|
|
|
+ client);
|
|
|
+ return nodes;
|
|
|
+ }
|
|
|
|
|
|
+ private void initYarnFederationNodesOfCluster(NodesInfo nodesInfo, Block html) {
|
|
|
TBODY<TABLE<Hamlet>> tbody = html.table("#nodes").thead().tr()
|
|
|
.th(".nodelabels", "Node Labels")
|
|
|
.th(".rack", "Rack")
|
|
@@ -79,34 +136,42 @@ public class NodesBlock extends HtmlBlock {
|
|
|
.th(".nodeManagerVersion", "Version")
|
|
|
.__().__().tbody();
|
|
|
|
|
|
- // Add nodes to the web UI
|
|
|
- for (NodeInfo info : nodes.getNodes()) {
|
|
|
- int usedMemory = (int) info.getUsedMemory();
|
|
|
- int availableMemory = (int) info.getAvailableMemory();
|
|
|
- TR<TBODY<TABLE<Hamlet>>> row = tbody.tr();
|
|
|
- row.td().__(StringUtils.join(",", info.getNodeLabels())).__();
|
|
|
- row.td().__(info.getRack()).__();
|
|
|
- row.td().__(info.getState()).__();
|
|
|
- row.td().__(info.getNodeId()).__();
|
|
|
- boolean isInactive = false;
|
|
|
- if (isInactive) {
|
|
|
- row.td().__("N/A").__();
|
|
|
- } else {
|
|
|
- String httpAddress = info.getNodeHTTPAddress();
|
|
|
- row.td().a("//" + httpAddress, httpAddress).__();
|
|
|
+ if (nodesInfo != null && CollectionUtils.isNotEmpty(nodesInfo.getNodes())) {
|
|
|
+ for (NodeInfo info : nodesInfo.getNodes()) {
|
|
|
+ int usedMemory = (int) info.getUsedMemory();
|
|
|
+ int availableMemory = (int) info.getAvailableMemory();
|
|
|
+ TR<TBODY<TABLE<Hamlet>>> row = tbody.tr();
|
|
|
+ row.td().__(StringUtils.join(",", info.getNodeLabels())).__();
|
|
|
+ row.td().__(info.getRack()).__();
|
|
|
+ row.td().__(info.getState()).__();
|
|
|
+ row.td().__(info.getNodeId()).__();
|
|
|
+ boolean isInactive = false;
|
|
|
+ if (isInactive) {
|
|
|
+ row.td().__(UNAVAILABLE).__();
|
|
|
+ } else {
|
|
|
+ String httpAddress = info.getNodeHTTPAddress();
|
|
|
+ String herfWebAppAddress = "";
|
|
|
+ if (httpAddress != null && !httpAddress.isEmpty()) {
|
|
|
+ herfWebAppAddress =
|
|
|
+ WebAppUtils.getHttpSchemePrefix(this.router.getConfig()) + httpAddress;
|
|
|
+ }
|
|
|
+ row.td().a(herfWebAppAddress, httpAddress).__();
|
|
|
+ }
|
|
|
+
|
|
|
+ row.td().br().$title(String.valueOf(info.getLastHealthUpdate())).__()
|
|
|
+ .__(new Date(info.getLastHealthUpdate())).__()
|
|
|
+ .td(info.getHealthReport())
|
|
|
+ .td(String.valueOf(info.getNumContainers())).td().br()
|
|
|
+ .$title(String.valueOf(usedMemory)).__()
|
|
|
+ .__(StringUtils.byteDesc(usedMemory * BYTES_IN_MB)).__().td().br()
|
|
|
+ .$title(String.valueOf(availableMemory)).__()
|
|
|
+ .__(StringUtils.byteDesc(availableMemory * BYTES_IN_MB)).__()
|
|
|
+ .td(String.valueOf(info.getUsedVirtualCores()))
|
|
|
+ .td(String.valueOf(info.getAvailableVirtualCores()))
|
|
|
+ .td(info.getVersion()).__();
|
|
|
}
|
|
|
- row.td().br().$title(String.valueOf(info.getLastHealthUpdate())).__()
|
|
|
- .__(Times.format(info.getLastHealthUpdate())).__()
|
|
|
- .td(info.getHealthReport())
|
|
|
- .td(String.valueOf(info.getNumContainers())).td().br()
|
|
|
- .$title(String.valueOf(usedMemory)).__()
|
|
|
- .__(StringUtils.byteDesc(usedMemory * BYTES_IN_MB)).__().td().br()
|
|
|
- .$title(String.valueOf(availableMemory)).__()
|
|
|
- .__(StringUtils.byteDesc(availableMemory * BYTES_IN_MB)).__()
|
|
|
- .td(String.valueOf(info.getUsedVirtualCores()))
|
|
|
- .td(String.valueOf(info.getAvailableVirtualCores()))
|
|
|
- .td(info.getVersion()).__();
|
|
|
}
|
|
|
+
|
|
|
tbody.__().__();
|
|
|
}
|
|
|
}
|