diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/TestFederationSubCluster.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/TestFederationSubCluster.java index f9cd707821814..145bd31de9a45 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/TestFederationSubCluster.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/TestFederationSubCluster.java @@ -39,6 +39,8 @@ import org.apache.hadoop.yarn.server.federation.store.records.GetSubClustersInfoResponse; 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.dao.NodeInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodesInfo; import org.apache.hadoop.yarn.server.router.webapp.JavaProcess; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,9 +51,12 @@ import java.util.LinkedList; import java.util.List; import java.util.concurrent.TimeoutException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static javax.servlet.http.HttpServletResponse.SC_OK; import static javax.ws.rs.core.MediaType.APPLICATION_XML; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.NODES; import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.RM_WEB_SERVICE_PATH; import static org.apache.hadoop.yarn.server.router.webapp.TestRouterWebServicesREST.waitWebAppRunning; import static org.junit.Assert.assertEquals; @@ -207,4 +212,26 @@ public static T performGetCalls(final String routerAddress, final String pat return response.getEntity(returnType); }); } + + public static String getNodeId(String rmAddress) { + Client clientToRM = Client.create(); + clientToRM.setConnectTimeout(3000); + clientToRM.setReadTimeout(3000); + WebResource toRM = clientToRM.resource(rmAddress).path(RM_WEB_SERVICE_PATH + NODES); + ClientResponse response = + toRM.accept(APPLICATION_XML).get(ClientResponse.class); + NodesInfo ci = response.getEntity(NodesInfo.class); + List nodes = ci.getNodes(); + if (nodes.isEmpty()) { + return null; + } + return nodes.get(0).getNodeId(); + } + + public static String format(String format, Object... args) { + Pattern p = Pattern.compile("\\{.*?}"); + Matcher m = p.matcher(format); + String newFormat = m.replaceAll("%s"); + return String.format(newFormat, args); + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/capacity/TestYarnFederationWithCapacityScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/capacity/TestYarnFederationWithCapacityScheduler.java index 481d1f2a2eb2c..6ec7b8ffcc3b9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/capacity/TestYarnFederationWithCapacityScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/capacity/TestYarnFederationWithCapacityScheduler.java @@ -20,7 +20,13 @@ 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.*; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterUserInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterMetricsInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.CapacitySchedulerInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodesInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeInfo; 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; @@ -28,15 +34,23 @@ 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.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeoutException; -import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.*; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.RM_WEB_SERVICE_PATH; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.INFO; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.CLUSTER_USER_INFO; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.METRICS; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.SCHEDULER; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.NODES; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.STATES; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.NODES_NODEID; +import static org.apache.hadoop.yarn.server.router.subcluster.TestFederationSubCluster.format; +import static org.apache.hadoop.yarn.server.router.subcluster.TestFederationSubCluster.getNodeId; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -46,8 +60,8 @@ public class TestYarnFederationWithCapacityScheduler { private static TestFederationSubCluster testFederationSubCluster; private static Set subClusters; private static final String ROUTER_WEB_ADDRESS = "http://localhost:18089"; - private static final Logger LOG = - LoggerFactory.getLogger(TestYarnFederationWithCapacityScheduler.class); + private static final String SC1_RM_WEB_ADDRESS = "http://localhost:18088"; + private static final String SC2_RM_WEB_ADDRESS = "http://localhost:28088"; @BeforeClass public static void setUp() @@ -147,4 +161,58 @@ public void testSchedulerInfo() throws Exception { assertEquals(3, schedulerInfo.getQueues().getQueueInfoList().size()); } } + + @Test + public void testNodesEmpty() throws Exception { + // We are in 2 sub-clusters, each with 3 nodes, so our Router should correspond to 6 nodes. + GenericTestUtils.waitFor(() -> { + try { + NodesInfo nodesInfo = + TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, RM_WEB_SERVICE_PATH + NODES, + NodesInfo.class, null, null); + assertNotNull(nodesInfo); + ArrayList nodes = nodesInfo.getNodes(); + assertNotNull(nodes); + return (6 == nodes.size()); + } catch (Exception e) { + return false; + } + }, 5000, 50 * 5000); + } + + @Test + public void testNodesLost() throws Exception { + GenericTestUtils.waitFor(() -> { + try { + NodesInfo nodesInfo = + TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, RM_WEB_SERVICE_PATH + NODES, + NodesInfo.class, STATES, "LOST"); + assertNotNull(nodesInfo); + ArrayList nodes = nodesInfo.getNodes(); + assertNotNull(nodes); + return (0 == nodes.size()); + } catch (Exception e) { + return false; + } + }, 5000, 50 * 5000); + } + + @Test + public void testNode() throws Exception { + String rm1NodeId = getNodeId(SC1_RM_WEB_ADDRESS); + NodeInfo nodeInfo = + TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, + RM_WEB_SERVICE_PATH + format(NODES_NODEID, rm1NodeId), + NodeInfo.class, null, null); + assertNotNull(nodeInfo); + assertEquals(rm1NodeId, nodeInfo.getNodeId()); + + String rm2NodeId = getNodeId(SC2_RM_WEB_ADDRESS); + NodeInfo nodeInfo2 = + TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, + RM_WEB_SERVICE_PATH + format(NODES_NODEID, rm2NodeId), + NodeInfo.class, null, null); + assertNotNull(nodeInfo2); + assertEquals(rm2NodeId, nodeInfo2.getNodeId()); + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/fair/TestYarnFederationWithFairScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/fair/TestYarnFederationWithFairScheduler.java index 07ff1ea7be6a7..3f107b2363f16 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/fair/TestYarnFederationWithFairScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/subcluster/fair/TestYarnFederationWithFairScheduler.java @@ -20,7 +20,14 @@ 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.*; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterUserInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterMetricsInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.FairSchedulerInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.FairSchedulerQueueInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodesInfo; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeInfo; 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; @@ -30,11 +37,21 @@ import org.junit.Test; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeoutException; -import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.*; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.RM_WEB_SERVICE_PATH; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.INFO; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.CLUSTER_USER_INFO; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.METRICS; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.SCHEDULER; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.NODES; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.STATES; +import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts.NODES_NODEID; +import static org.apache.hadoop.yarn.server.router.subcluster.TestFederationSubCluster.format; +import static org.apache.hadoop.yarn.server.router.subcluster.TestFederationSubCluster.getNodeId; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -43,6 +60,8 @@ public class TestYarnFederationWithFairScheduler { private static TestFederationSubCluster testFederationSubCluster; private static Set subClusters; private static final String ROUTER_WEB_ADDRESS = "http://localhost:28089"; + private static final String SC1_RM_WEB_ADDRESS = "http://localhost:38088"; + private static final String SC2_RM_WEB_ADDRESS = "http://localhost:48088"; @BeforeClass public static void setUp() @@ -142,4 +161,58 @@ public void testSchedulerInfo() throws Exception { assertEquals("fair", rootQueueInfo.getSchedulingPolicy()); } } + + @Test + public void testNodesEmpty() throws Exception { + // We are in 2 sub-clusters, each with 3 nodes, so our Router should correspond to 6 nodes. + GenericTestUtils.waitFor(() -> { + try { + NodesInfo nodesInfo = + TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, RM_WEB_SERVICE_PATH + NODES, + NodesInfo.class, null, null); + assertNotNull(nodesInfo); + ArrayList nodes = nodesInfo.getNodes(); + assertNotNull(nodes); + return (6 == nodes.size()); + } catch (Exception e) { + return false; + } + }, 5000, 50 * 5000); + } + + @Test + public void testNodesLost() throws Exception { + GenericTestUtils.waitFor(() -> { + try { + NodesInfo nodesInfo = + TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, RM_WEB_SERVICE_PATH + NODES, + NodesInfo.class, STATES, "LOST"); + assertNotNull(nodesInfo); + ArrayList nodes = nodesInfo.getNodes(); + assertNotNull(nodes); + return (0 == nodes.size()); + } catch (Exception e) { + return false; + } + }, 5000, 50 * 5000); + } + + @Test + public void testNode() throws Exception { + String rm1NodeId = getNodeId(SC1_RM_WEB_ADDRESS); + NodeInfo nodeInfo = + TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, + RM_WEB_SERVICE_PATH + format(NODES_NODEID, rm1NodeId), + NodeInfo.class, null, null); + assertNotNull(nodeInfo); + assertEquals(rm1NodeId, nodeInfo.getNodeId()); + + String rm2NodeId = getNodeId(SC2_RM_WEB_ADDRESS); + NodeInfo nodeInfo2 = + TestFederationSubCluster.performGetCalls(ROUTER_WEB_ADDRESS, + RM_WEB_SERVICE_PATH + format(NODES_NODEID, rm2NodeId), + NodeInfo.class, null, null); + assertNotNull(nodeInfo2); + assertEquals(rm2NodeId, nodeInfo2.getNodeId()); + } }