Skip to content

Commit

Permalink
YARN-11583. Improve Node Link for YARN Federation Web Page. (#6145) C…
Browse files Browse the repository at this point in the history
…ontributed by Shilun Fan.

Reviewed-by: Inigo Goiri <[email protected]>
Signed-off-by: Shilun Fan <[email protected]>
  • Loading branch information
slfan1989 authored Oct 8, 2023
1 parent ee1ebbe commit 42b32fb
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,19 @@ private void initFederationClusterNodesMetrics(Hamlet.DIV<Hamlet> div,
// Initialize table data information
tbody().$class("ui-widget-content").
tr().
td(String.valueOf(metrics.getActiveNodes())).
td(String.valueOf(metrics.getDecommissioningNodes())).
td(String.valueOf(metrics.getDecommissionedNodes())).
td(String.valueOf(metrics.getLostNodes())).
td(String.valueOf(metrics.getUnhealthyNodes())).
td(String.valueOf(metrics.getRebootedNodes())).
td(String.valueOf(metrics.getShutdownNodes())).
td().a(url("nodes"), String.valueOf(metrics.getActiveNodes())).__().
td().a(url("nodes/router/?node.state=decommissioning"),
String.valueOf(metrics.getDecommissioningNodes())).__().
td().a(url("nodes/router/?node.state=decommissioned"),
String.valueOf(metrics.getDecommissionedNodes())).__().
td().a(url("nodes/router/?node.state=lost"),
String.valueOf(metrics.getLostNodes())).__().
td().a(url("nodes/router/?node.state=unhealthy"),
String.valueOf(metrics.getUnhealthyNodes())).__().
td().a(url("nodes/router/?node.state=rebooted"),
String.valueOf(metrics.getRebootedNodes())).__().
td().a(url("nodes/router/?node.state=shutdown"),
String.valueOf(metrics.getShutdownNodes())).__().
__().
__().__();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.PartitionInfo;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo;
import org.apache.hadoop.yarn.server.router.Router;
import org.apache.hadoop.yarn.webapp.YarnWebParams;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;

Expand Down Expand Up @@ -158,6 +159,14 @@ private void initYarnFederationNodeLabelsOfCluster(NodeLabelsInfo nodeLabelsInfo
String type = (info.getExclusivity()) ? "Exclusive Partition" : "Non Exclusive Partition";
row = row.td(type);
int nActiveNMs = info.getActiveNMs();
if (nActiveNMs > 0) {
row = row.td().a(url("nodes",
"?" + YarnWebParams.NODE_LABEL + "=" + info.getName()), String.valueOf(nActiveNMs))
.__();
} else {
row = row.td(String.valueOf(nActiveNMs));
}

row = row.td(String.valueOf(nActiveNMs));
PartitionInfo partitionInfo = info.getPartitionInfo();
ResourceInfo available = partitionInfo.getResourceAvailable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import org.apache.hadoop.yarn.webapp.SubView;
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;

import static org.apache.hadoop.yarn.server.router.webapp.RouterWebServiceUtil.generateWebTitle;
import static org.apache.hadoop.yarn.webapp.YarnWebParams.NODE_SC;
import static org.apache.hadoop.yarn.webapp.YarnWebParams.NODE_LABEL;
import static org.apache.hadoop.yarn.webapp.view.JQueryUI.DATATABLES_ID;

/**
Expand All @@ -33,10 +35,15 @@ public class NodeLabelsPage extends RouterView {
protected void preHead(Hamlet.HTML<__> html) {
commonPreHead(html);
String type = $(NODE_SC);
String nodeLabel = $(NODE_LABEL);
String title = "Node labels of the cluster";
if (type != null && !type.isEmpty()) {
title = title + " (" + type + ")";

if (nodeLabel != null && !nodeLabel.isEmpty()) {
title = generateWebTitle(title, nodeLabel);
} else if (type != null && !type.isEmpty()) {
title = generateWebTitle(title, type);
}

setTitle(title);
set(DATATABLES_ID, "nodelabels");
setTableStyles(html, "nodelabels", ".healthStatus {width:10em}", ".healthReport {width:10em}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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.nodelabels.RMNodeLabelsManager;
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;
Expand All @@ -40,6 +41,8 @@
import java.util.Date;

import static org.apache.hadoop.yarn.webapp.YarnWebParams.NODE_SC;
import static org.apache.hadoop.yarn.webapp.YarnWebParams.NODE_LABEL;
import static org.apache.hadoop.yarn.webapp.YarnWebParams.NODE_STATE;

/**
* Nodes block for the Router Web UI.
Expand All @@ -61,12 +64,15 @@ protected void render(Block html) {

// Get subClusterName
String subClusterName = $(NODE_SC);
String state = $(NODE_STATE);
String nodeLabel = $(NODE_LABEL);

// 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;
if (subClusterName != null && !subClusterName.isEmpty()) {
if (subClusterName != null && !subClusterName.isEmpty() &&
!ROUTER.equalsIgnoreCase(subClusterName)) {
initSubClusterMetricsOverviewTable(html, subClusterName);
nodesInfo = getSubClusterNodesInfo(subClusterName);
} else {
Expand All @@ -76,7 +82,7 @@ protected void render(Block html) {
}

// Initialize NodeInfo List
initYarnFederationNodesOfCluster(nodesInfo, html);
initYarnFederationNodesOfCluster(nodesInfo, html, state, nodeLabel);
}

private NodesInfo getYarnFederationNodesInfo(boolean isEnabled) {
Expand All @@ -100,7 +106,7 @@ private NodesInfo getSubClusterNodesInfo(String subCluster) {
if (subClusterInfo != null) {
// Prepare webAddress
String webAddress = subClusterInfo.getRMWebServiceAddress();
String herfWebAppAddress = "";
String herfWebAppAddress;
if (webAddress != null && !webAddress.isEmpty()) {
herfWebAppAddress =
WebAppUtils.getHttpSchemePrefix(this.router.getConfig()) + webAddress;
Expand All @@ -124,7 +130,8 @@ private NodesInfo getSubClusterNodesInfoByWebAddress(String webAddress) {
return nodes;
}

private void initYarnFederationNodesOfCluster(NodesInfo nodesInfo, Block html) {
private void initYarnFederationNodesOfCluster(NodesInfo nodesInfo, Block html,
String filterState, String filterLabel) {
TBODY<TABLE<Hamlet>> tbody = html.table("#nodes").thead().tr()
.th(".nodelabels", "Node Labels")
.th(".rack", "Rack")
Expand All @@ -143,6 +150,23 @@ private void initYarnFederationNodesOfCluster(NodesInfo nodesInfo, Block html) {

if (nodesInfo != null && CollectionUtils.isNotEmpty(nodesInfo.getNodes())) {
for (NodeInfo info : nodesInfo.getNodes()) {
if (filterState != null && !filterState.isEmpty() && !filterState.equals(info.getState())) {
continue;
}

// Besides state, we need to filter label as well.
if (!filterLabel.equals(RMNodeLabelsManager.ANY)) {
if (filterLabel.isEmpty()) {
// Empty label filter means only shows nodes without label
if (!info.getNodeLabels().isEmpty()) {
continue;
}
} else if (!info.getNodeLabels().contains(filterLabel)) {
// Only nodes have given label can show on web page.
continue;
}
}

int usedMemory = (int) info.getUsedMemory();
int availableMemory = (int) info.getAvailableMemory();
TR<TBODY<TABLE<Hamlet>>> row = tbody.tr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package org.apache.hadoop.yarn.server.router.webapp;

import static org.apache.hadoop.yarn.server.router.webapp.RouterWebServiceUtil.generateWebTitle;
import static org.apache.hadoop.yarn.webapp.YarnWebParams.NODE_SC;
import static org.apache.hadoop.yarn.webapp.YarnWebParams.NODE_STATE;
import static org.apache.hadoop.yarn.webapp.view.JQueryUI.DATATABLES;
import static org.apache.hadoop.yarn.webapp.view.JQueryUI.DATATABLES_ID;
import static org.apache.hadoop.yarn.webapp.view.JQueryUI.initID;
Expand All @@ -32,9 +34,12 @@ class NodesPage extends RouterView {
protected void preHead(Page.HTML<__> html) {
commonPreHead(html);
String type = $(NODE_SC);
String state = $(NODE_STATE);
String title = "Nodes of the cluster";
if (type != null && !type.isEmpty()) {
title = title + " (" + type + ")";
if (state != null && !state.isEmpty()) {
title = generateWebTitle(title, state);
} else if (type != null && !type.isEmpty()) {
title = generateWebTitle(title, type);
}
setTitle(title);
set(DATATABLES_ID, "nodes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public abstract class RouterBlock extends HtmlBlock {
private final FederationStateStoreFacade facade;
private final Configuration conf;

public static final String ROUTER = "router";

public RouterBlock(Router router, ViewContext ctx) {
super(ctx);
this.ctx = ctx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,4 +764,13 @@ public static UserGroupInformation getKerberosUserGroupInformation(Configuration
// return caller UGI
return callerUGI;
}

public static String generateWebTitle(String title, String msg) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(title);
stringBuilder.append(" (");
stringBuilder.append(msg);
stringBuilder.append(")");
return stringBuilder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public RESTRequestInterceptor run() throws Exception {

Assert.assertNotNull(client1.interceptor);
Assert.assertNotNull(client2.interceptor);
Assert.assertTrue(client1.interceptor == client2.interceptor);
Assert.assertSame(client1.interceptor, client2.interceptor);
}

}

0 comments on commit 42b32fb

Please sign in to comment.