PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesFairScheduler.java

http://github.com/apache/hadoop-common
Java | 120 lines | 89 code | 14 blank | 17 comment | 0 complexity | 92c4dc0ac2b63602e24958cd1da94dd1 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.yarn.server.resourcemanager.webapp;
  19. import static org.junit.Assert.assertEquals;
  20. import javax.ws.rs.core.MediaType;
  21. import org.apache.hadoop.yarn.conf.YarnConfiguration;
  22. import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
  23. import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
  24. import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
  25. import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
  26. import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
  27. import org.apache.hadoop.yarn.server.resourcemanager.security.QueueACLsManager;
  28. import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
  29. import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
  30. import org.codehaus.jettison.json.JSONException;
  31. import org.codehaus.jettison.json.JSONObject;
  32. import org.junit.Test;
  33. import com.google.inject.Guice;
  34. import com.google.inject.Injector;
  35. import com.google.inject.servlet.GuiceServletContextListener;
  36. import com.google.inject.servlet.ServletModule;
  37. import com.sun.jersey.api.client.ClientResponse;
  38. import com.sun.jersey.api.client.WebResource;
  39. import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
  40. import com.sun.jersey.test.framework.JerseyTest;
  41. import com.sun.jersey.test.framework.WebAppDescriptor;
  42. public class TestRMWebServicesFairScheduler extends JerseyTest {
  43. private static MockRM rm;
  44. private YarnConfiguration conf;
  45. private Injector injector = Guice.createInjector(new ServletModule() {
  46. @Override
  47. protected void configureServlets() {
  48. bind(JAXBContextResolver.class);
  49. bind(RMWebServices.class);
  50. bind(GenericExceptionHandler.class);
  51. conf = new YarnConfiguration();
  52. conf.setClass(YarnConfiguration.RM_SCHEDULER, FairScheduler.class,
  53. ResourceScheduler.class);
  54. rm = new MockRM(conf);
  55. bind(ResourceManager.class).toInstance(rm);
  56. bind(RMContext.class).toInstance(rm.getRMContext());
  57. bind(ApplicationACLsManager.class).toInstance(
  58. rm.getApplicationACLsManager());
  59. bind(QueueACLsManager.class).toInstance(rm.getQueueACLsManager());
  60. serve("/*").with(GuiceContainer.class);
  61. }
  62. });
  63. public class GuiceServletConfig extends GuiceServletContextListener {
  64. @Override
  65. protected Injector getInjector() {
  66. return injector;
  67. }
  68. }
  69. public TestRMWebServicesFairScheduler() {
  70. super(new WebAppDescriptor.Builder(
  71. "org.apache.hadoop.yarn.server.resourcemanager.webapp")
  72. .contextListenerClass(GuiceServletConfig.class)
  73. .filterClass(com.google.inject.servlet.GuiceFilter.class)
  74. .contextPath("jersey-guice-filter").servletPath("/").build());
  75. }
  76. @Test
  77. public void testClusterScheduler() throws JSONException, Exception {
  78. WebResource r = resource();
  79. ClientResponse response = r.path("ws").path("v1").path("cluster")
  80. .path("scheduler").accept(MediaType.APPLICATION_JSON)
  81. .get(ClientResponse.class);
  82. assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  83. JSONObject json = response.getEntity(JSONObject.class);
  84. verifyClusterScheduler(json);
  85. }
  86. @Test
  87. public void testClusterSchedulerSlash() throws JSONException, Exception {
  88. WebResource r = resource();
  89. ClientResponse response = r.path("ws").path("v1").path("cluster")
  90. .path("scheduler/").accept(MediaType.APPLICATION_JSON)
  91. .get(ClientResponse.class);
  92. assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  93. JSONObject json = response.getEntity(JSONObject.class);
  94. verifyClusterScheduler(json);
  95. }
  96. private void verifyClusterScheduler(JSONObject json) throws JSONException,
  97. Exception {
  98. assertEquals("incorrect number of elements", 1, json.length());
  99. JSONObject info = json.getJSONObject("scheduler");
  100. assertEquals("incorrect number of elements", 1, info.length());
  101. info = info.getJSONObject("schedulerInfo");
  102. assertEquals("incorrect number of elements", 2, info.length());
  103. JSONObject rootQueue = info.getJSONObject("rootQueue");
  104. assertEquals("root", rootQueue.getString("queueName"));
  105. }
  106. }