Skip to content

Commit 845cf8b

Browse files
authored
YARN-11368. [Federation] Improve Yarn Router's Federation Page style. (#5105)
1 parent 44b8bb7 commit 845cf8b

File tree

3 files changed

+50
-16
lines changed
  • hadoop-yarn-project/hadoop-yarn

3 files changed

+50
-16
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/webapps/static/federation/federation.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $(document).ready(function() {
2828
var capabilityArr = scTableData.filter(item => (item.subcluster === row.id()));
2929
var capabilityObj = JSON.parse(capabilityArr[0].capability).clusterMetrics;
3030
row.child(
31-
'<table>' +
31+
'<table style="line-height:25px;" >' +
3232
' <tr>' +
3333
' <td>' +
3434
' <h3>Application Metrics</h3>' +
@@ -42,11 +42,12 @@ $(document).ready(function() {
4242
' <td>' +
4343
' <h3>Resource Metrics</h3>' +
4444
' <h4>Memory</h4>' +
45-
' TotalMB : ' + capabilityObj.totalMB + ' </p>' +
46-
' ReservedMB : ' + capabilityObj.reservedMB + ' </p>' +
47-
' AvailableMB : ' + capabilityObj.availableMB + ' </p>' +
48-
' AllocatedMB : ' + capabilityObj.allocatedMB + ' </p>' +
49-
' PendingMB : ' + capabilityObj.pendingMB + ' </p>' +
45+
' Total Memory : ' + capabilityArr[0].totalmemory + ' </p>' +
46+
' Reserved Memory : ' + capabilityArr[0].reservedmemory + ' </p>' +
47+
' Available Memory : ' + capabilityArr[0].availablememory + ' </p>' +
48+
' Allocated Memory : ' + capabilityArr[0].allocatedmemory + ' </p>' +
49+
' Pending Memory : ' + capabilityArr[0].pendingmemory + ' </p>' +
50+
' <hr />' +
5051
' <h4>VirtualCores</h4>' +
5152
' TotalVirtualCores : ' + capabilityObj.totalVirtualCores + ' </p>' +
5253
' ReservedVirtualCores : ' + capabilityObj.reservedVirtualCores + ' </p>' +

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationBlock.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
import java.util.List;
2424
import java.util.Map;
2525
import java.util.HashMap;
26+
import java.util.Date;
2627

2728
import com.google.gson.Gson;
2829
import org.apache.hadoop.util.StringUtils;
29-
import org.apache.commons.lang3.time.DateFormatUtils;
3030
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
3131
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
32+
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterState;
3233
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterMetricsInfo;
3334
import org.apache.hadoop.yarn.server.router.Router;
3435
import org.apache.hadoop.yarn.webapp.hamlet2.Hamlet;
@@ -149,32 +150,51 @@ private void initHtmlPageFederation(Block html, boolean isEnabled) {
149150
ClusterMetricsInfo subClusterInfo = getClusterMetricsInfo(capability);
150151

151152
// Prepare LastStartTime & LastHeartBeat
152-
String lastStartTime =
153-
DateFormatUtils.format(subcluster.getLastStartTime(), DATE_PATTERN);
154-
String lastHeartBeat =
155-
DateFormatUtils.format(subcluster.getLastHeartBeat(), DATE_PATTERN);
153+
Date lastStartTime = new Date(subcluster.getLastStartTime());
154+
Date lastHeartBeat = new Date(subcluster.getLastHeartBeat());
156155

157156
// Prepare Resource
158157
long totalMB = subClusterInfo.getTotalMB();
159158
String totalMBDesc = StringUtils.byteDesc(totalMB * BYTES_IN_MB);
160159
long totalVirtualCores = subClusterInfo.getTotalVirtualCores();
161-
String resources = String.format("<Memory:%s, VCore:%s>", totalMBDesc, totalVirtualCores);
160+
String resources = String.format("<memory:%s, vCores:%s>", totalMBDesc, totalVirtualCores);
162161

163162
// Prepare Node
164163
long totalNodes = subClusterInfo.getTotalNodes();
165164
long activeNodes = subClusterInfo.getActiveNodes();
166-
String nodes = String.format("<Total Nodes:%s, Active Nodes:%s>", totalNodes, activeNodes);
165+
String nodes = String.format("<totalNodes:%s, activeNodes:%s>", totalNodes, activeNodes);
167166

168167
// Prepare HTML Table
168+
String stateStyle = "color:#dc3545;font-weight:bolder";
169+
SubClusterState state = subcluster.getState();
170+
if (SubClusterState.SC_RUNNING == state) {
171+
stateStyle = "color:#28a745;font-weight:bolder";
172+
}
173+
169174
tbody.tr().$id(subClusterIdText)
170175
.td().$class("details-control").a(herfWebAppAddress, subClusterIdText).__()
171-
.td(subcluster.getState().name())
172-
.td(lastStartTime)
173-
.td(lastHeartBeat)
176+
.td().$style(stateStyle).__(state.name()).__()
177+
.td().__(lastStartTime).__()
178+
.td().__(lastHeartBeat).__()
174179
.td(resources)
175180
.td(nodes)
176181
.__();
177182

183+
// Formatted memory information
184+
long allocatedMB = subClusterInfo.getAllocatedMB();
185+
String allocatedMBDesc = StringUtils.byteDesc(allocatedMB * BYTES_IN_MB);
186+
long availableMB = subClusterInfo.getAvailableMB();
187+
String availableMBDesc = StringUtils.byteDesc(availableMB * BYTES_IN_MB);
188+
long pendingMB = subClusterInfo.getPendingMB();
189+
String pendingMBDesc = StringUtils.byteDesc(pendingMB * BYTES_IN_MB);
190+
long reservedMB = subClusterInfo.getReservedMB();
191+
String reservedMBDesc = StringUtils.byteDesc(reservedMB * BYTES_IN_MB);
192+
193+
subclusterMap.put("totalmemory", totalMBDesc);
194+
subclusterMap.put("allocatedmemory", allocatedMBDesc);
195+
subclusterMap.put("availablememory", availableMBDesc);
196+
subclusterMap.put("pendingmemory", pendingMBDesc);
197+
subclusterMap.put("reservedmemory", reservedMBDesc);
178198
subclusterMap.put("subcluster", subClusterId.getId());
179199
subclusterMap.put("capability", capability);
180200
lists.add(subclusterMap);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestFederationWebApp.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@
2323
import org.apache.hadoop.yarn.server.router.Router;
2424
import org.apache.hadoop.yarn.webapp.test.WebAppTests;
2525
import org.junit.Test;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
2628

2729
import java.io.IOException;
2830

2931
public class TestFederationWebApp extends TestRouterWebServicesREST {
3032

33+
private static final Logger LOG =
34+
LoggerFactory.getLogger(TestFederationWebApp.class);
35+
3136
@Test
3237
public void testFederationWebViewNotEnable()
3338
throws InterruptedException, YarnException, IOException {
39+
LOG.info("testFederationWebView - NotEnable Federation.");
3440
// Test Federation is not Enabled
3541
Configuration config = new YarnConfiguration();
3642
config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, false);
@@ -40,6 +46,7 @@ public void testFederationWebViewNotEnable()
4046
@Test
4147
public void testFederationWebViewEnable()
4248
throws InterruptedException, YarnException, IOException {
49+
LOG.info("testFederationWebView - Enable Federation.");
4350
// Test Federation Enabled
4451
Configuration config = new YarnConfiguration();
4552
config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, true);
@@ -49,6 +56,7 @@ public void testFederationWebViewEnable()
4956
@Test
5057
public void testFederationAboutViewEnable()
5158
throws InterruptedException, YarnException, IOException {
59+
LOG.info("testFederationAboutViewEnable - Enable Federation.");
5260
// Test Federation Enabled
5361
Configuration config = new YarnConfiguration();
5462
config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, true);
@@ -58,6 +66,7 @@ public void testFederationAboutViewEnable()
5866
@Test
5967
public void testFederationAboutViewNotEnable()
6068
throws InterruptedException, YarnException, IOException {
69+
LOG.info("testFederationAboutViewNotEnable - NotEnable Federation.");
6170
// Test Federation Not Enabled
6271
Configuration config = new YarnConfiguration();
6372
config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, false);
@@ -67,6 +76,7 @@ public void testFederationAboutViewNotEnable()
6776
@Test
6877
public void testFederationNodeViewEnable()
6978
throws InterruptedException, YarnException, IOException {
79+
LOG.info("testFederationNodeViewEnable - Enable Federation.");
7080
// Test Federation Enabled
7181
Configuration config = new YarnConfiguration();
7282
config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, true);
@@ -76,6 +86,7 @@ public void testFederationNodeViewEnable()
7686
@Test
7787
public void testFederationNodeViewNotEnable()
7888
throws InterruptedException, YarnException, IOException {
89+
LOG.info("testFederationNodeViewNotEnable - NotEnable Federation.");
7990
// Test Federation Not Enabled
8091
Configuration config = new YarnConfiguration();
8192
config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, false);
@@ -85,6 +96,7 @@ public void testFederationNodeViewNotEnable()
8596
@Test
8697
public void testFederationAppViewEnable()
8798
throws InterruptedException, YarnException, IOException {
99+
LOG.info("testFederationAppViewEnable - Enable Federation.");
88100
// Test Federation Enabled
89101
Configuration config = new YarnConfiguration();
90102
config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, true);
@@ -94,6 +106,7 @@ public void testFederationAppViewEnable()
94106
@Test
95107
public void testFederationAppViewNotEnable()
96108
throws InterruptedException, YarnException, IOException {
109+
LOG.info("testFederationAppViewNotEnable - NotEnable Federation.");
97110
// Test Federation Not Enabled
98111
Configuration config = new YarnConfiguration();
99112
config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, false);

0 commit comments

Comments
 (0)