Skip to content

Commit

Permalink
YARN-9013. Fix CheckStyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 committed Oct 15, 2023
1 parent 07d0c8e commit 856caa9
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ public AppState getAppState(HttpServletRequest hsr, String appId)
} catch (YarnException | IllegalArgumentException e) {
LOG.error("getHomeSubClusterInfoByAppId error, applicationId = {}.", appId, e);
}
return null;
return new AppState();
}

@Override
Expand Down Expand Up @@ -1279,7 +1279,7 @@ public ActivitiesInfo getActivities(HttpServletRequest hsr, String nodeId,
try {
// Check the parameters to ensure that the parameters are not empty
Validate.checkNotNullAndNotEmpty(nodeId, "nodeId");
Validate.checkNotNullAndNotEmpty(groupBy, "groupBy");
// Validate.checkNotNullAndNotEmpty(groupBy, "groupBy");

// Query SubClusterInfo according to id,
// if the nodeId cannot get SubClusterInfo, an exception will be thrown directly.
Expand Down Expand Up @@ -1317,7 +1317,7 @@ public BulkActivitiesInfo getBulkActivities(HttpServletRequest hsr,
String groupBy, int activitiesCount) throws InterruptedException {
try {
// Step1. Check the parameters to ensure that the parameters are not empty
Validate.checkNotNullAndNotEmpty(groupBy, "groupBy");
// Validate.checkNotNullAndNotEmpty(groupBy, "groupBy");
Validate.checkNotNegative(activitiesCount, "activitiesCount");

// Step2. Call the interface of subCluster concurrently and get the returned result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public BulkActivitiesInfo getBulkActivities(
MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
@Override
public AppActivitiesInfo getAppActivities(@Context HttpServletRequest hsr,
@QueryParam(RMWSConsts.APP_ID) String appId,
@PathParam(RMWSConsts.APPID) String appId,
@QueryParam(RMWSConsts.MAX_TIME) String time,
@QueryParam(RMWSConsts.REQUEST_PRIORITIES) Set<String> requestPriorities,
@QueryParam(RMWSConsts.ALLOCATION_REQUEST_IDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
*/
package org.apache.hadoop.yarn.server.router.subcluster.capacity;

import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Sets;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterInfo;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.*;
import org.apache.hadoop.yarn.server.router.subcluster.TestFederationSubCluster;
import org.apache.hadoop.yarn.server.router.webapp.dao.FederationClusterInfo;
import org.apache.hadoop.yarn.server.router.webapp.dao.FederationClusterUserInfo;
import org.apache.hadoop.yarn.server.router.webapp.dao.FederationSchedulerTypeInfo;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;
Expand All @@ -42,6 +46,8 @@ public class TestYarnFederationWithCapacityScheduler {
private static TestFederationSubCluster testFederationSubCluster;
private static Set<String> subClusters;
private static final String ROUTER_WEB_ADDRESS = "http://localhost:18089";
private static final Logger LOG =
LoggerFactory.getLogger(TestYarnFederationWithCapacityScheduler.class);

@BeforeClass
public static void setUp()
Expand Down Expand Up @@ -90,9 +96,55 @@ public void testInfo() throws InterruptedException, IOException {
}

@Test
public void testClusterInfoXML() throws Exception {
public void testClusterUserInfo() throws Exception {
FederationClusterUserInfo federationClusterUserInfo =
TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, RM_WEB_SERVICE_PATH + CLUSTER_USER_INFO,
TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS,
RM_WEB_SERVICE_PATH + CLUSTER_USER_INFO,
FederationClusterUserInfo.class, null, null);
List<ClusterUserInfo> clusterUserInfos = federationClusterUserInfo.getList();
assertNotNull(clusterUserInfos);
assertEquals(2, clusterUserInfos.size());
for (ClusterUserInfo clusterUserInfo : clusterUserInfos) {
assertNotNull(clusterUserInfo);
assertTrue(subClusters.contains(clusterUserInfo.getSubClusterId()));
}
}

@Test
public void testMetricsInfo() throws Exception {
// It takes time to start the sub-cluster. We need to wait for the sub-cluster to be completely started,
// so we need to set the waiting time.
// The resources of the two sub-clusters we registered are 24C and 12G,
// so the resources that the Router should collect are 48C and 24G.
GenericTestUtils.waitFor(() -> {
try {
ClusterMetricsInfo clusterMetricsInfo =
TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, RM_WEB_SERVICE_PATH + METRICS,
ClusterMetricsInfo.class, null, null);
assertNotNull(clusterMetricsInfo);
return (48 == clusterMetricsInfo.getTotalVirtualCores() && 24576 == clusterMetricsInfo.getTotalMB());
} catch (Exception e) {
return false;
}
}, 5000, 50 * 5000);
}

@Test
public void testSchedulerInfo() throws Exception {
FederationSchedulerTypeInfo schedulerTypeInfo =
TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, RM_WEB_SERVICE_PATH + SCHEDULER,
FederationSchedulerTypeInfo.class, null, null);
assertNotNull(schedulerTypeInfo);
List<SchedulerTypeInfo> schedulerTypeInfos = schedulerTypeInfo.getList();
assertNotNull(schedulerTypeInfos);
assertEquals(2, schedulerTypeInfos.size());
for (SchedulerTypeInfo schedulerTypeInfoItem : schedulerTypeInfos) {
assertNotNull(schedulerTypeInfoItem);
assertTrue(subClusters.contains(schedulerTypeInfoItem.getSubClusterId()));
CapacitySchedulerInfo schedulerInfo =
(CapacitySchedulerInfo) schedulerTypeInfoItem.getSchedulerInfo();
assertNotNull(schedulerInfo);
assertEquals(3, schedulerInfo.getQueues().getQueueInfoList().size());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
*/
package org.apache.hadoop.yarn.server.router.subcluster.fair;

import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Sets;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterInfo;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.*;
import org.apache.hadoop.yarn.server.router.subcluster.TestFederationSubCluster;
import org.apache.hadoop.yarn.server.router.webapp.dao.FederationClusterInfo;
import org.apache.hadoop.yarn.server.router.webapp.dao.FederationClusterUserInfo;
import org.apache.hadoop.yarn.server.router.webapp.dao.FederationSchedulerTypeInfo;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -31,8 +34,7 @@
import java.util.Set;
import java.util.concurrent.TimeoutException;

import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.INFO;
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.RM_WEB_SERVICE_PATH;
import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -87,4 +89,57 @@ public void testInfo() throws InterruptedException, IOException {
assertTrue(subClusters.contains(clusterInfo.getSubClusterId()));
}
}

@Test
public void testClusterUserInfo() throws Exception {
FederationClusterUserInfo federationClusterUserInfo =
TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS,
RM_WEB_SERVICE_PATH + CLUSTER_USER_INFO,
FederationClusterUserInfo.class, null, null);
List<ClusterUserInfo> clusterUserInfos = federationClusterUserInfo.getList();
assertNotNull(clusterUserInfos);
assertEquals(2, clusterUserInfos.size());
for (ClusterUserInfo clusterUserInfo : clusterUserInfos) {
assertNotNull(clusterUserInfo);
assertTrue(subClusters.contains(clusterUserInfo.getSubClusterId()));
}
}

@Test
public void testMetricsInfo() throws Exception {
// It takes time to start the sub-cluster. We need to wait for the sub-cluster to be completely started,
// so we need to set the waiting time.
// The resources of the two sub-clusters we registered are 24C and 12G,
// so the resources that the Router should collect are 48C and 24G.
GenericTestUtils.waitFor(() -> {
try {
ClusterMetricsInfo clusterMetricsInfo =
TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, RM_WEB_SERVICE_PATH + METRICS,
ClusterMetricsInfo.class, null, null);
assertNotNull(clusterMetricsInfo);
return (48 == clusterMetricsInfo.getTotalVirtualCores() && 24576 == clusterMetricsInfo.getTotalMB());
} catch (Exception e) {
return false;
}
}, 5000, 50 * 5000);
}

@Test
public void testSchedulerInfo() throws Exception {
FederationSchedulerTypeInfo schedulerTypeInfo =
TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, RM_WEB_SERVICE_PATH + SCHEDULER,
FederationSchedulerTypeInfo.class, null, null);
assertNotNull(schedulerTypeInfo);
List<SchedulerTypeInfo> schedulerTypeInfos = schedulerTypeInfo.getList();
assertNotNull(schedulerTypeInfos);
assertEquals(2, schedulerTypeInfos.size());
for (SchedulerTypeInfo schedulerTypeInfoItem : schedulerTypeInfos) {
assertNotNull(schedulerTypeInfoItem);
assertTrue(subClusters.contains(schedulerTypeInfoItem.getSubClusterId()));
FairSchedulerQueueInfo rootQueueInfo =
((FairSchedulerInfo) schedulerTypeInfoItem.getSchedulerInfo()).getRootQueueInfo();
assertNotNull(rootQueueInfo);
assertEquals("fair", rootQueueInfo.getSchedulingPolicy());
}
}
}

0 comments on commit 856caa9

Please sign in to comment.