|
@@ -6,9 +6,9 @@
|
|
* to you under the Apache License, Version 2.0 (the
|
|
* to you under the Apache License, Version 2.0 (the
|
|
* "License"); you may not use this file except in compliance
|
|
* "License"); you may not use this file except in compliance
|
|
* with the License. You may obtain a copy of the License at
|
|
* with the License. You may obtain a copy of the License at
|
|
- *
|
|
|
|
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
- *
|
|
|
|
|
|
+ * <p>
|
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
+ * <p>
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
@@ -16,13 +16,14 @@
|
|
* limitations under the License.
|
|
* limitations under the License.
|
|
*/
|
|
*/
|
|
|
|
|
|
-package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
|
|
|
-
|
|
|
|
-import static org.junit.Assert.assertEquals;
|
|
|
|
-import static org.junit.Assert.fail;
|
|
|
|
-
|
|
|
|
-import javax.ws.rs.core.MediaType;
|
|
|
|
|
|
+package org.apache.hadoop.yarn.server.resourcemanager.webapp.fairscheduler;
|
|
|
|
|
|
|
|
+import com.google.inject.Guice;
|
|
|
|
+import com.google.inject.servlet.ServletModule;
|
|
|
|
+import com.sun.jersey.api.client.ClientResponse;
|
|
|
|
+import com.sun.jersey.api.client.WebResource;
|
|
|
|
+import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
|
|
|
+import com.sun.jersey.test.framework.WebAppDescriptor;
|
|
import org.apache.hadoop.http.JettyUtils;
|
|
import org.apache.hadoop.http.JettyUtils;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
|
|
@@ -30,6 +31,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.QueueManager;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.QueueManager;
|
|
|
|
+
|
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.webapp.JAXBContextResolver;
|
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices;
|
|
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
|
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
|
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
|
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
|
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
|
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
|
@@ -38,18 +42,18 @@ import org.codehaus.jettison.json.JSONException;
|
|
import org.codehaus.jettison.json.JSONObject;
|
|
import org.codehaus.jettison.json.JSONObject;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
+import javax.ws.rs.core.MediaType;
|
|
|
|
|
|
-import com.google.inject.Guice;
|
|
|
|
-import com.google.inject.servlet.ServletModule;
|
|
|
|
-import com.sun.jersey.api.client.ClientResponse;
|
|
|
|
-import com.sun.jersey.api.client.WebResource;
|
|
|
|
-import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
|
|
|
-import com.sun.jersey.test.framework.WebAppDescriptor;
|
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
|
+import static org.junit.Assert.fail;
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Tests RM Webservices fair scheduler resources.
|
|
|
|
+ */
|
|
public class TestRMWebServicesFairScheduler extends JerseyTestBase {
|
|
public class TestRMWebServicesFairScheduler extends JerseyTestBase {
|
|
private static MockRM rm;
|
|
private static MockRM rm;
|
|
private static YarnConfiguration conf;
|
|
private static YarnConfiguration conf;
|
|
-
|
|
|
|
|
|
+
|
|
private static class WebServletModule extends ServletModule {
|
|
private static class WebServletModule extends ServletModule {
|
|
@Override
|
|
@Override
|
|
protected void configureServlets() {
|
|
protected void configureServlets() {
|
|
@@ -58,7 +62,7 @@ public class TestRMWebServicesFairScheduler extends JerseyTestBase {
|
|
bind(GenericExceptionHandler.class);
|
|
bind(GenericExceptionHandler.class);
|
|
conf = new YarnConfiguration();
|
|
conf = new YarnConfiguration();
|
|
conf.setClass(YarnConfiguration.RM_SCHEDULER, FairScheduler.class,
|
|
conf.setClass(YarnConfiguration.RM_SCHEDULER, FairScheduler.class,
|
|
- ResourceScheduler.class);
|
|
|
|
|
|
+ ResourceScheduler.class);
|
|
rm = new MockRM(conf);
|
|
rm = new MockRM(conf);
|
|
bind(ResourceManager.class).toInstance(rm);
|
|
bind(ResourceManager.class).toInstance(rm);
|
|
serve("/*").with(GuiceContainer.class);
|
|
serve("/*").with(GuiceContainer.class);
|
|
@@ -66,32 +70,32 @@ public class TestRMWebServicesFairScheduler extends JerseyTestBase {
|
|
}
|
|
}
|
|
|
|
|
|
static {
|
|
static {
|
|
- GuiceServletConfig.setInjector(
|
|
|
|
- Guice.createInjector(new WebServletModule()));
|
|
|
|
|
|
+ GuiceServletConfig
|
|
|
|
+ .setInjector(Guice.createInjector(new WebServletModule()));
|
|
}
|
|
}
|
|
|
|
|
|
@Before
|
|
@Before
|
|
@Override
|
|
@Override
|
|
public void setUp() throws Exception {
|
|
public void setUp() throws Exception {
|
|
super.setUp();
|
|
super.setUp();
|
|
- GuiceServletConfig.setInjector(
|
|
|
|
- Guice.createInjector(new WebServletModule()));
|
|
|
|
|
|
+ GuiceServletConfig
|
|
|
|
+ .setInjector(Guice.createInjector(new WebServletModule()));
|
|
}
|
|
}
|
|
|
|
|
|
public TestRMWebServicesFairScheduler() {
|
|
public TestRMWebServicesFairScheduler() {
|
|
super(new WebAppDescriptor.Builder(
|
|
super(new WebAppDescriptor.Builder(
|
|
"org.apache.hadoop.yarn.server.resourcemanager.webapp")
|
|
"org.apache.hadoop.yarn.server.resourcemanager.webapp")
|
|
- .contextListenerClass(GuiceServletConfig.class)
|
|
|
|
- .filterClass(com.google.inject.servlet.GuiceFilter.class)
|
|
|
|
- .contextPath("jersey-guice-filter").servletPath("/").build());
|
|
|
|
|
|
+ .contextListenerClass(GuiceServletConfig.class)
|
|
|
|
+ .filterClass(com.google.inject.servlet.GuiceFilter.class)
|
|
|
|
+ .contextPath("jersey-guice-filter").servletPath("/").build());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
- public void testClusterScheduler() throws JSONException, Exception {
|
|
|
|
|
|
+ public void testClusterScheduler() throws JSONException {
|
|
WebResource r = resource();
|
|
WebResource r = resource();
|
|
- ClientResponse response = r.path("ws").path("v1").path("cluster")
|
|
|
|
- .path("scheduler").accept(MediaType.APPLICATION_JSON)
|
|
|
|
- .get(ClientResponse.class);
|
|
|
|
|
|
+ ClientResponse response =
|
|
|
|
+ r.path("ws").path("v1").path("cluster").path("scheduler")
|
|
|
|
+ .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
|
|
response.getType().toString());
|
|
response.getType().toString());
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
@@ -99,52 +103,51 @@ public class TestRMWebServicesFairScheduler extends JerseyTestBase {
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testClusterSchedulerSlash() throws JSONException, Exception {
|
|
|
|
|
|
+ public void testClusterSchedulerSlash() throws JSONException {
|
|
WebResource r = resource();
|
|
WebResource r = resource();
|
|
- ClientResponse response = r.path("ws").path("v1").path("cluster")
|
|
|
|
- .path("scheduler/").accept(MediaType.APPLICATION_JSON)
|
|
|
|
- .get(ClientResponse.class);
|
|
|
|
|
|
+ ClientResponse response =
|
|
|
|
+ r.path("ws").path("v1").path("cluster").path("scheduler/")
|
|
|
|
+ .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
|
|
response.getType().toString());
|
|
response.getType().toString());
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
verifyClusterScheduler(json);
|
|
verifyClusterScheduler(json);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
- public void testClusterSchedulerWithSubQueues() throws JSONException,
|
|
|
|
- Exception {
|
|
|
|
- FairScheduler scheduler = (FairScheduler)rm.getResourceScheduler();
|
|
|
|
|
|
+ public void testClusterSchedulerWithSubQueues()
|
|
|
|
+ throws JSONException {
|
|
|
|
+ FairScheduler scheduler = (FairScheduler) rm.getResourceScheduler();
|
|
QueueManager queueManager = scheduler.getQueueManager();
|
|
QueueManager queueManager = scheduler.getQueueManager();
|
|
// create LeafQueue
|
|
// create LeafQueue
|
|
queueManager.getLeafQueue("root.q.subqueue1", true);
|
|
queueManager.getLeafQueue("root.q.subqueue1", true);
|
|
queueManager.getLeafQueue("root.q.subqueue2", true);
|
|
queueManager.getLeafQueue("root.q.subqueue2", true);
|
|
|
|
|
|
WebResource r = resource();
|
|
WebResource r = resource();
|
|
- ClientResponse response = r.path("ws").path("v1").path("cluster")
|
|
|
|
- .path("scheduler").accept(MediaType.APPLICATION_JSON)
|
|
|
|
- .get(ClientResponse.class);
|
|
|
|
|
|
+ ClientResponse response =
|
|
|
|
+ r.path("ws").path("v1").path("cluster").path("scheduler")
|
|
|
|
+ .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
|
|
response.getType().toString());
|
|
response.getType().toString());
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
JSONArray subQueueInfo = json.getJSONObject("scheduler")
|
|
JSONArray subQueueInfo = json.getJSONObject("scheduler")
|
|
.getJSONObject("schedulerInfo").getJSONObject("rootQueue")
|
|
.getJSONObject("schedulerInfo").getJSONObject("rootQueue")
|
|
- .getJSONObject("childQueues").getJSONArray("queue")
|
|
|
|
- .getJSONObject(1).getJSONObject("childQueues").getJSONArray("queue");
|
|
|
|
|
|
+ .getJSONObject("childQueues").getJSONArray("queue").getJSONObject(1)
|
|
|
|
+ .getJSONObject("childQueues").getJSONArray("queue");
|
|
// subQueueInfo is consist of subqueue1 and subqueue2 info
|
|
// subQueueInfo is consist of subqueue1 and subqueue2 info
|
|
assertEquals(2, subQueueInfo.length());
|
|
assertEquals(2, subQueueInfo.length());
|
|
|
|
|
|
// Verify 'childQueues' field is omitted from FairSchedulerLeafQueueInfo.
|
|
// Verify 'childQueues' field is omitted from FairSchedulerLeafQueueInfo.
|
|
try {
|
|
try {
|
|
subQueueInfo.getJSONObject(1).getJSONObject("childQueues");
|
|
subQueueInfo.getJSONObject(1).getJSONObject("childQueues");
|
|
- fail("FairSchedulerQueueInfo should omit field 'childQueues'" +
|
|
|
|
- "if child queue is empty.");
|
|
|
|
|
|
+ fail("FairSchedulerQueueInfo should omit field 'childQueues'"
|
|
|
|
+ + "if child queue is empty.");
|
|
} catch (JSONException je) {
|
|
} catch (JSONException je) {
|
|
assertEquals("JSONObject[\"childQueues\"] not found.", je.getMessage());
|
|
assertEquals("JSONObject[\"childQueues\"] not found.", je.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void verifyClusterScheduler(JSONObject json) throws JSONException,
|
|
|
|
- Exception {
|
|
|
|
|
|
+ private void verifyClusterScheduler(JSONObject json) throws JSONException {
|
|
assertEquals("incorrect number of elements", 1, json.length());
|
|
assertEquals("incorrect number of elements", 1, json.length());
|
|
JSONObject info = json.getJSONObject("scheduler");
|
|
JSONObject info = json.getJSONObject("scheduler");
|
|
assertEquals("incorrect number of elements", 1, info.length());
|
|
assertEquals("incorrect number of elements", 1, info.length());
|