HADOOP-9613. [JDK8] Update jersey version to latest 1.x release.
This commit is contained in:
parent
8c1f81d4bf
commit
5d58858bb6
|
@ -115,6 +115,11 @@
|
|||
<artifactId>jersey-core</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-servlet</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- Used, even though 'mvn dependency:analyze' doesn't find it -->
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.mapreduce.v2.app.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -33,6 +34,7 @@ import org.apache.hadoop.conf.Configuration;
|
|||
import org.apache.hadoop.mapreduce.v2.app.AppContext;
|
||||
import org.apache.hadoop.mapreduce.v2.app.MockAppContext;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -46,8 +48,6 @@ import org.xml.sax.InputSource;
|
|||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -69,7 +69,7 @@ public class TestAMWebServices extends JerseyTest {
|
|||
private static Configuration conf = new Configuration();
|
||||
private static MockAppContext appContext;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
|
@ -84,20 +84,19 @@ public class TestAMWebServices extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestAMWebServices() {
|
||||
|
@ -207,7 +206,7 @@ public class TestAMWebServices extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -223,7 +222,7 @@ public class TestAMWebServices extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -239,8 +238,8 @@ public class TestAMWebServices extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
|||
import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
|
||||
import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -55,9 +55,7 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
|
@ -77,7 +75,8 @@ public class TestAMWebServicesAttempt extends JerseyTest {
|
|||
private static AppContext appContext;
|
||||
private String webserviceUserName = "testuser";
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
appContext = new MockAppContext(0, 1, 2, 1);
|
||||
|
@ -90,7 +89,7 @@ public class TestAMWebServicesAttempt extends JerseyTest {
|
|||
serve("/*").with(GuiceContainer.class);
|
||||
filter("/*").through(TestRMCustomAuthFilter.class);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@Singleton
|
||||
public static class TestRMCustomAuthFilter extends AuthenticationFilter {
|
||||
|
@ -112,18 +111,17 @@ public class TestAMWebServicesAttempt extends JerseyTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestAMWebServicesAttempt() {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.apache.hadoop.mapreduce.v2.app.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -44,6 +45,7 @@ import org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt;
|
|||
import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
||||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -56,8 +58,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.UniformInterfaceException;
|
||||
|
@ -80,10 +80,10 @@ public class TestAMWebServicesAttempts extends JerseyTest {
|
|||
private static Configuration conf = new Configuration();
|
||||
private static AppContext appContext;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
appContext = new MockAppContext(0, 1, 2, 1);
|
||||
bind(JAXBContextResolver.class);
|
||||
bind(AMWebServices.class);
|
||||
|
@ -93,21 +93,19 @@ public class TestAMWebServicesAttempts extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestAMWebServicesAttempts() {
|
||||
|
@ -379,7 +377,7 @@ public class TestAMWebServicesAttempts extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
|
|
@ -40,16 +40,11 @@ import org.apache.hadoop.fs.Path;
|
|||
import org.apache.hadoop.mapreduce.MRJobConfig;
|
||||
import org.apache.hadoop.mapreduce.v2.api.records.JobId;
|
||||
import org.apache.hadoop.mapreduce.v2.app.AppContext;
|
||||
import org.apache.hadoop.mapreduce.v2.app.ClusterInfo;
|
||||
import org.apache.hadoop.mapreduce.v2.app.MockAppContext;
|
||||
import org.apache.hadoop.mapreduce.v2.app.MockJobs;
|
||||
import org.apache.hadoop.mapreduce.v2.app.job.Job;
|
||||
import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||
import org.apache.hadoop.yarn.event.EventHandler;
|
||||
import org.apache.hadoop.yarn.util.Clock;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -62,10 +57,7 @@ import org.w3c.dom.Element;
|
|||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
|
@ -87,7 +79,8 @@ public class TestAMWebServicesJobConf extends JerseyTest {
|
|||
private static File testConfDir = new File("target",
|
||||
TestAMWebServicesJobConf.class.getSimpleName() + "confDir");
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
|
@ -124,14 +117,11 @@ public class TestAMWebServicesJobConf extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -139,7 +129,8 @@ public class TestAMWebServicesJobConf extends JerseyTest {
|
|||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
testConfDir.mkdir();
|
||||
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.hadoop.mapreduce.v2.app.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.util.StringHelper.ujoin;
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -45,6 +46,7 @@ import org.apache.hadoop.security.authorize.AccessControlList;
|
|||
import org.apache.hadoop.yarn.api.records.NodeId;
|
||||
import org.apache.hadoop.yarn.util.Times;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -57,8 +59,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -82,10 +82,9 @@ public class TestAMWebServicesJobs extends JerseyTest {
|
|||
private static Configuration conf = new Configuration();
|
||||
private static AppContext appContext;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
appContext = new MockAppContext(0, 1, 2, 1);
|
||||
bind(JAXBContextResolver.class);
|
||||
bind(AMWebServices.class);
|
||||
|
@ -95,21 +94,19 @@ public class TestAMWebServicesJobs extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestAMWebServicesJobs() {
|
||||
|
@ -256,7 +253,7 @@ public class TestAMWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -283,7 +280,7 @@ public class TestAMWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -306,7 +303,7 @@ public class TestAMWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -329,7 +326,7 @@ public class TestAMWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
|
||||
String msg = response.getEntity(String.class);
|
||||
System.out.println(msg);
|
||||
|
@ -368,7 +365,7 @@ public class TestAMWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.mapreduce.v2.app.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -41,6 +42,7 @@ import org.apache.hadoop.mapreduce.v2.app.job.Job;
|
|||
import org.apache.hadoop.mapreduce.v2.app.job.Task;
|
||||
import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -53,8 +55,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -77,7 +77,7 @@ public class TestAMWebServicesTasks extends JerseyTest {
|
|||
private static Configuration conf = new Configuration();
|
||||
private static AppContext appContext;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
|
@ -90,21 +90,19 @@ public class TestAMWebServicesTasks extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestAMWebServicesTasks() {
|
||||
|
@ -254,7 +252,7 @@ public class TestAMWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -348,7 +346,7 @@ public class TestAMWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -382,7 +380,7 @@ public class TestAMWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -414,7 +412,7 @@ public class TestAMWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -448,7 +446,7 @@ public class TestAMWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -482,7 +480,7 @@ public class TestAMWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.mapreduce.v2.hs.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
@ -35,6 +36,7 @@ import org.apache.hadoop.mapreduce.v2.hs.JobHistoryServer;
|
|||
import org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext;
|
||||
import org.apache.hadoop.util.VersionInfo;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -47,8 +49,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -70,10 +70,9 @@ public class TestHsWebServices extends JerseyTest {
|
|||
private static HistoryContext appContext;
|
||||
private static HsWebApp webApp;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
appContext = new MockHistoryContext(0, 1, 1, 1);
|
||||
JobHistory jobHistoryService = new JobHistory();
|
||||
HistoryContext historyContext = (HistoryContext) jobHistoryService;
|
||||
|
@ -89,20 +88,19 @@ public class TestHsWebServices extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestHsWebServices() {
|
||||
|
@ -212,7 +210,7 @@ public class TestHsWebServices extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -228,7 +226,7 @@ public class TestHsWebServices extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -244,8 +242,8 @@ public class TestHsWebServices extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.mapreduce.v2.hs.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -46,6 +47,7 @@ import org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext;
|
|||
import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
||||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
|
@ -59,8 +61,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -85,10 +85,9 @@ public class TestHsWebServicesAttempts extends JerseyTest {
|
|||
private static HistoryContext appContext;
|
||||
private static HsWebApp webApp;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
appContext = new MockHistoryContext(0, 1, 2, 1);
|
||||
webApp = mock(HsWebApp.class);
|
||||
when(webApp.name()).thenReturn("hsmockwebapp");
|
||||
|
@ -103,26 +102,24 @@ public class TestHsWebServicesAttempts extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestHsWebServicesAttempts() {
|
||||
super(new WebAppDescriptor.Builder(
|
||||
"org.apache.hadoop.mapreduce.v2.hs.webapp")
|
||||
super(
|
||||
new WebAppDescriptor.Builder("org.apache.hadoop.mapreduce.v2.hs.webapp")
|
||||
.contextListenerClass(GuiceServletConfig.class)
|
||||
.filterClass(com.google.inject.servlet.GuiceFilter.class)
|
||||
.contextPath("jersey-guice-filter").servletPath("/").build());
|
||||
|
@ -397,7 +394,7 @@ public class TestHsWebServicesAttempts extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.apache.hadoop.mapreduce.v2.hs.HistoryContext;
|
|||
import org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext;
|
||||
import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
|
@ -61,8 +62,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
|
@ -85,7 +84,8 @@ public class TestHsWebServicesJobConf extends JerseyTest {
|
|||
private static File testConfDir = new File("target",
|
||||
TestHsWebServicesJobConf.class.getSimpleName() + "confDir");
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
|
@ -127,14 +127,11 @@ public class TestHsWebServicesJobConf extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -142,7 +139,8 @@ public class TestHsWebServicesJobConf extends JerseyTest {
|
|||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
testConfDir.mkdir();
|
||||
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.hadoop.mapreduce.v2.hs.webapp;
|
|||
|
||||
import static org.apache.hadoop.yarn.util.StringHelper.join;
|
||||
import static org.apache.hadoop.yarn.util.StringHelper.ujoin;
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -44,6 +45,7 @@ import org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext;
|
|||
import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
||||
import org.apache.hadoop.yarn.api.records.NodeId;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
|
@ -57,8 +59,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -82,10 +82,9 @@ public class TestHsWebServicesJobs extends JerseyTest {
|
|||
private static MockHistoryContext appContext;
|
||||
private static HsWebApp webApp;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
appContext = new MockHistoryContext(0, 1, 2, 1, false);
|
||||
webApp = mock(HsWebApp.class);
|
||||
when(webApp.name()).thenReturn("hsmockwebapp");
|
||||
|
@ -100,21 +99,19 @@ public class TestHsWebServicesJobs extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestHsWebServicesJobs() {
|
||||
|
@ -331,7 +328,7 @@ public class TestHsWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -359,7 +356,7 @@ public class TestHsWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -383,7 +380,7 @@ public class TestHsWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -407,7 +404,7 @@ public class TestHsWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
|
||||
String msg = response.getEntity(String.class);
|
||||
System.out.println(msg);
|
||||
|
@ -446,7 +443,7 @@ public class TestHsWebServicesJobs extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -527,7 +524,7 @@ public class TestHsWebServicesJobs extends JerseyTest {
|
|||
public void testJobCountersForKilledJob() throws Exception {
|
||||
WebResource r = resource();
|
||||
appContext = new MockHistoryContext(0, 1, 1, 1, true);
|
||||
injector = Guice.createInjector(new ServletModule() {
|
||||
GuiceServletConfig.setInjector(Guice.createInjector(new ServletModule() {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
|
@ -544,7 +541,7 @@ public class TestHsWebServicesJobs extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
Map<JobId, Job> jobsMap = appContext.getAllJobs();
|
||||
for (JobId id : jobsMap.keySet()) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.mapreduce.v2.hs.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -39,6 +40,7 @@ import org.apache.hadoop.mapreduce.v2.hs.HistoryContext;
|
|||
import org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext;
|
||||
import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
|
@ -48,8 +50,6 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -70,10 +70,9 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
private static MockHistoryContext appContext;
|
||||
private static HsWebApp webApp;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
appContext = new MockHistoryContext(3, 2, 1);
|
||||
webApp = mock(HsWebApp.class);
|
||||
when(webApp.name()).thenReturn("hsmockwebapp");
|
||||
|
@ -88,21 +87,19 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestHsWebServicesJobsQuery() {
|
||||
|
@ -136,7 +133,8 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("jobs is not null", JSONObject.NULL, json.get("jobs"));
|
||||
assertEquals("jobs is not empty",
|
||||
new JSONObject().toString(), json.get("jobs").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -173,7 +171,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
.path("mapreduce").path("jobs").queryParam("state", "InvalidState")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -202,7 +200,8 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("jobs is not null", JSONObject.NULL, json.get("jobs"));
|
||||
assertEquals("jobs is not empty",
|
||||
new JSONObject().toString(), json.get("jobs").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -248,7 +247,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
.path("mapreduce").path("jobs").queryParam("limit", "-1")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -287,7 +286,8 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("jobs is not null", JSONObject.NULL, json.get("jobs"));
|
||||
assertEquals("jobs is not empty",
|
||||
new JSONObject().toString(), json.get("jobs").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -319,7 +319,8 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("jobs is not null", JSONObject.NULL, json.get("jobs"));
|
||||
assertEquals("jobs is not empty",
|
||||
new JSONObject().toString(), json.get("jobs").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -360,7 +361,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
.queryParam("startedTimeBegin", String.valueOf(now))
|
||||
.queryParam("startedTimeEnd", String.valueOf(40000))
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -386,7 +387,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
ClientResponse response = r.path("ws").path("v1").path("history")
|
||||
.path("mapreduce").path("jobs").queryParam("startedTimeBegin", "efsd")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -412,7 +413,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
ClientResponse response = r.path("ws").path("v1").path("history")
|
||||
.path("mapreduce").path("jobs").queryParam("startedTimeEnd", "efsd")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -438,7 +439,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
.path("mapreduce").path("jobs")
|
||||
.queryParam("startedTimeBegin", String.valueOf(-1000))
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -464,7 +465,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
.path("mapreduce").path("jobs")
|
||||
.queryParam("startedTimeEnd", String.valueOf(-1000))
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -488,7 +489,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
.path("mapreduce").path("jobs")
|
||||
.queryParam("finishedTimeEnd", String.valueOf(-1000))
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -512,7 +513,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
.path("mapreduce").path("jobs")
|
||||
.queryParam("finishedTimeBegin", String.valueOf(-1000))
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -539,7 +540,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
.queryParam("finishedTimeBegin", String.valueOf(now))
|
||||
.queryParam("finishedTimeEnd", String.valueOf(40000))
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -565,7 +566,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
ClientResponse response = r.path("ws").path("v1").path("history")
|
||||
.path("mapreduce").path("jobs").queryParam("finishedTimeBegin", "efsd")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -591,7 +592,7 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
ClientResponse response = r.path("ws").path("v1").path("history")
|
||||
.path("mapreduce").path("jobs").queryParam("finishedTimeEnd", "efsd")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -639,7 +640,8 @@ public class TestHsWebServicesJobsQuery extends JerseyTest {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("jobs is not null", JSONObject.NULL, json.get("jobs"));
|
||||
assertEquals("jobs is not empty",
|
||||
new JSONObject().toString(), json.get("jobs").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.mapreduce.v2.hs.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -44,6 +45,7 @@ import org.apache.hadoop.mapreduce.v2.hs.HistoryContext;
|
|||
import org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext;
|
||||
import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
|
@ -57,8 +59,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -82,10 +82,9 @@ public class TestHsWebServicesTasks extends JerseyTest {
|
|||
private static MockHistoryContext appContext;
|
||||
private static HsWebApp webApp;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
||||
appContext = new MockHistoryContext(0, 1, 2, 1);
|
||||
webApp = mock(HsWebApp.class);
|
||||
when(webApp.name()).thenReturn("hsmockwebapp");
|
||||
|
@ -100,20 +99,19 @@ public class TestHsWebServicesTasks extends JerseyTest {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestHsWebServicesTasks() {
|
||||
|
@ -266,7 +264,7 @@ public class TestHsWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -361,7 +359,7 @@ public class TestHsWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -395,7 +393,7 @@ public class TestHsWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -427,7 +425,7 @@ public class TestHsWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -461,7 +459,7 @@ public class TestHsWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -495,7 +493,7 @@ public class TestHsWebServicesTasks extends JerseyTest {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
<avro.version>1.7.4</avro.version>
|
||||
|
||||
<!-- jersey version -->
|
||||
<jersey.version>1.9</jersey.version>
|
||||
<jersey.version>1.19</jersey.version>
|
||||
|
||||
<!-- jackson versions -->
|
||||
<jackson.version>1.9.13</jackson.version>
|
||||
|
@ -546,6 +546,11 @@
|
|||
<artifactId>jersey-core</artifactId>
|
||||
<version>${jersey.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-servlet</artifactId>
|
||||
<version>${jersey.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-json</artifactId>
|
||||
|
@ -946,7 +951,17 @@
|
|||
<dependency>
|
||||
<groupId>org.glassfish.grizzly</groupId>
|
||||
<artifactId>grizzly-http-servlet</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<version>2.2.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.grizzly</groupId>
|
||||
<artifactId>grizzly-http</artifactId>
|
||||
<version>2.2.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.grizzly</groupId>
|
||||
<artifactId>grizzly-http-server</artifactId>
|
||||
<version>2.2.21</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -342,7 +342,8 @@ public class LogsCLI extends Configured implements Tool {
|
|||
webResource.path("ws").path("v1").path("node").path("containers")
|
||||
.path(containerIdStr).accept(MediaType.APPLICATION_XML)
|
||||
.get(ClientResponse.class);
|
||||
if (response.getClientResponseStatus().equals(ClientResponse.Status.OK)) {
|
||||
if (response.getStatusInfo().getStatusCode() ==
|
||||
ClientResponse.Status.OK.getStatusCode()) {
|
||||
try {
|
||||
String xml = response.getEntity(String.class);
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
|
|
|
@ -42,12 +42,18 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- 'mvn dependency:analyze' fails to detect use of this dependency -->
|
||||
<dependency>
|
||||
<groupId>org.apache.hadoop</groupId>
|
||||
<artifactId>hadoop-yarn-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.hadoop</groupId>
|
||||
<artifactId>hadoop-auth</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
|
|
|
@ -126,7 +126,8 @@ public abstract class TimelineWriter implements Flushable {
|
|||
throw (IOException)new InterruptedIOException().initCause(ie);
|
||||
}
|
||||
if (resp == null ||
|
||||
resp.getClientResponseStatus() != ClientResponse.Status.OK) {
|
||||
resp.getStatusInfo().getStatusCode()
|
||||
!= ClientResponse.Status.OK.getStatusCode()) {
|
||||
String msg =
|
||||
"Failed to get the response from the timeline server.";
|
||||
LOG.error(msg);
|
||||
|
|
|
@ -330,7 +330,7 @@ public class TestTimelineClient {
|
|||
}
|
||||
doReturn(response).when(spyTimelineWriter)
|
||||
.doPostingObject(any(TimelineEntities.class), any(String.class));
|
||||
when(response.getClientResponseStatus()).thenReturn(status);
|
||||
when(response.getStatusInfo()).thenReturn(status);
|
||||
TimelinePutResponse.TimelinePutError error =
|
||||
new TimelinePutResponse.TimelinePutError();
|
||||
error.setEntityId("test entity id");
|
||||
|
@ -356,7 +356,7 @@ public class TestTimelineClient {
|
|||
}
|
||||
doReturn(response).when(spyTimelineWriter)
|
||||
.doPostingObject(any(TimelineDomain.class), any(String.class));
|
||||
when(response.getClientResponseStatus()).thenReturn(status);
|
||||
when(response.getStatusInfo()).thenReturn(status);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ public class TestTimelineClientForATS1_5 {
|
|||
new FileSystemTimelineWriter(conf, authUgi, client, resURI) {
|
||||
public ClientResponse doPostingObject(Object object, String path) {
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
when(response.getClientResponseStatus()).thenReturn(
|
||||
when(response.getStatusInfo()).thenReturn(
|
||||
ClientResponse.Status.OK);
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.yarn.webapp;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
|
||||
/**
|
||||
* GuiceServletConfig is a wrapper class to have a static Injector instance
|
||||
* instead of having the instance inside test classes. This allow us to use
|
||||
* Jersey test framework after 1.13.
|
||||
* Please check test cases to know how to use this class:
|
||||
* e.g. TestRMWithCSRFFilter.java
|
||||
*/
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
private static Injector internalInjector = null;
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return internalInjector;
|
||||
}
|
||||
|
||||
public static Injector setInjector(Injector in) {
|
||||
internalInjector = in;
|
||||
return internalInjector;
|
||||
}
|
||||
}
|
|
@ -18,10 +18,12 @@
|
|||
|
||||
package org.apache.hadoop.yarn.webapp;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ws.rs.core.Response.StatusType;
|
||||
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Element;
|
||||
|
@ -119,4 +121,13 @@ public class WebServicesTestUtils {
|
|||
got.equals(expected));
|
||||
}
|
||||
|
||||
public static void assertResponseStatusCode(StatusType expected,
|
||||
StatusType actual) {
|
||||
assertResponseStatusCode(null, expected, actual);
|
||||
}
|
||||
|
||||
public static void assertResponseStatusCode(String errmsg,
|
||||
StatusType expected, StatusType actual) {
|
||||
assertEquals(errmsg, expected.getStatusCode(), actual.getStatusCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.applicationhistoryservice.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -67,6 +68,7 @@ import org.apache.hadoop.yarn.server.timeline.security.TimelineACLsManager;
|
|||
import org.apache.hadoop.yarn.api.records.timeline.TimelineAbout;
|
||||
import org.apache.hadoop.yarn.util.timeline.TimelineUtils;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
|
||||
|
@ -75,15 +77,14 @@ import org.codehaus.jettison.json.JSONException;
|
|||
import org.codehaus.jettison.json.JSONObject;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -132,6 +133,8 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
historyClientService.start();
|
||||
ahsWebservice = new AHSWebServices(historyClientService, conf);
|
||||
fs = FileSystem.get(conf);
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -148,8 +151,7 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
return Arrays.asList(new Object[][] { { 0 }, { 1 } });
|
||||
}
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
|
@ -159,7 +161,14 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
serve("/*").with(GuiceContainer.class);
|
||||
filter("/*").through(TestSimpleAuthFilter.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class TestSimpleAuthFilter extends AuthenticationFilter {
|
||||
|
@ -174,14 +183,6 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
|
||||
private int round;
|
||||
|
||||
public TestAHSWebServices(int round) {
|
||||
|
@ -203,8 +204,8 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
.queryParam("user.name", USERS[round])
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.get(ClientResponse.class);
|
||||
assertEquals("404 not found expected", Status.NOT_FOUND,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode("404 not found expected",
|
||||
Status.NOT_FOUND, response.getStatusInfo());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -221,11 +222,11 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.get(ClientResponse.class);
|
||||
if (round == 1) {
|
||||
assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
return;
|
||||
}
|
||||
assertEquals("404 not found expected", Status.NOT_FOUND,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode("404 not found expected",
|
||||
Status.NOT_FOUND, response.getStatusInfo());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -245,12 +246,11 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.get(ClientResponse.class);
|
||||
if (round == 1) {
|
||||
assertEquals(
|
||||
Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
return;
|
||||
}
|
||||
assertEquals("404 not found expected", Status.NOT_FOUND,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode("404 not found expected",
|
||||
Status.NOT_FOUND, response.getStatusInfo());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -265,7 +265,7 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
|
@ -282,7 +282,7 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -300,8 +300,8 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -388,8 +388,7 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
.queryParam("user.name", USERS[round])
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
if (round == 1) {
|
||||
assertEquals(
|
||||
Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
return;
|
||||
}
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
|
@ -415,8 +414,7 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.get(ClientResponse.class);
|
||||
if (round == 1) {
|
||||
assertEquals(
|
||||
Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
return;
|
||||
}
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
|
@ -445,8 +443,7 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
.queryParam("user.name", USERS[round])
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
if (round == 1) {
|
||||
assertEquals(
|
||||
Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
return;
|
||||
}
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
|
@ -474,8 +471,7 @@ public class TestAHSWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.get(ClientResponse.class);
|
||||
if (round == 1) {
|
||||
assertEquals(
|
||||
Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
return;
|
||||
}
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.timeline.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
|
@ -61,14 +62,14 @@ import org.apache.hadoop.yarn.server.timeline.security.TimelineAuthenticationFil
|
|||
import org.apache.hadoop.yarn.api.records.timeline.TimelineAbout;
|
||||
import org.apache.hadoop.yarn.util.timeline.TimelineUtils;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.YarnJacksonJaxbJsonProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
|
@ -81,10 +82,9 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
private static TimelineStore store;
|
||||
private static TimelineACLsManager timelineACLsManager;
|
||||
private static AdminACLsManager adminACLsManager;
|
||||
private long beforeTime;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static long beforeTime;
|
||||
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
@ -146,18 +146,21 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
}
|
||||
filter("/*").through(taFilter);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
|
||||
private TimelineStore mockTimelineStore()
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
private static TimelineStore mockTimelineStore()
|
||||
throws Exception {
|
||||
beforeTime = System.currentTimeMillis() - 1;
|
||||
TestMemoryTimelineStore store =
|
||||
|
@ -477,8 +480,7 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
.type(MediaType.APPLICATION_JSON)
|
||||
.post(ClientResponse.class, entities);
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
assertEquals(ClientResponse.Status.FORBIDDEN,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
|
||||
response = r.path("ws").path("v1").path("timeline")
|
||||
.queryParam("user.name", "tester")
|
||||
|
@ -519,8 +521,7 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
.queryParam("user.name", "tester").accept(MediaType.APPLICATION_JSON)
|
||||
.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, entities);
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
assertEquals(ClientResponse.Status.BAD_REQUEST,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -703,8 +704,7 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.get(ClientResponse.class);
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
assertEquals(ClientResponse.Status.NOT_FOUND,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
} finally {
|
||||
timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
|
||||
}
|
||||
|
@ -869,8 +869,7 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.get(ClientResponse.class);
|
||||
Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
Assert.assertEquals(ClientResponse.Status.NOT_FOUND,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
} finally {
|
||||
timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
|
||||
}
|
||||
|
@ -938,8 +937,7 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
.type(MediaType.APPLICATION_JSON)
|
||||
.put(ClientResponse.class, domain);
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
assertEquals(ClientResponse.Status.FORBIDDEN,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
|
||||
response = r.path("ws").path("v1")
|
||||
.path("timeline").path("domain")
|
||||
|
@ -947,7 +945,7 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.put(ClientResponse.class, domain);
|
||||
assertEquals(Status.OK.getStatusCode(), response.getStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
|
||||
// Verify the domain exists
|
||||
response = r.path("ws").path("v1").path("timeline")
|
||||
|
@ -969,7 +967,7 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.put(ClientResponse.class, domain);
|
||||
assertEquals(Status.OK.getStatusCode(), response.getStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
|
||||
// Verify the domain is updated
|
||||
response = r.path("ws").path("v1").path("timeline")
|
||||
|
@ -997,7 +995,7 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.put(ClientResponse.class, domain);
|
||||
assertEquals(Status.OK.getStatusCode(), response.getStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
|
||||
// Update the domain by another user
|
||||
response = r.path("ws").path("v1")
|
||||
|
@ -1006,7 +1004,7 @@ public class TestTimelineWebServices extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON)
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.put(ClientResponse.class, domain);
|
||||
assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
} finally {
|
||||
timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.nodemanager.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -30,6 +31,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.junit.Assert;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileUtil;
|
||||
|
@ -69,8 +71,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -95,7 +95,7 @@ public class TestNMWebServices extends JerseyTestBase {
|
|||
private static File testLogDir = new File("target",
|
||||
TestNMWebServices.class.getSimpleName() + "LogDir");
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
@ -148,14 +148,11 @@ public class TestNMWebServices extends JerseyTestBase {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -164,6 +161,8 @@ public class TestNMWebServices extends JerseyTestBase {
|
|||
super.setUp();
|
||||
testRootDir.mkdirs();
|
||||
testLogDir.mkdir();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -190,7 +189,7 @@ public class TestNMWebServices extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -206,8 +205,8 @@ public class TestNMWebServices extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -222,7 +221,7 @@ public class TestNMWebServices extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -418,7 +417,7 @@ public class TestNMWebServices extends JerseyTestBase {
|
|||
response = r.path("ws").path("v1").path("node")
|
||||
.path("containerlogs").path(containerIdStr).path("uhhh")
|
||||
.accept(MediaType.TEXT_PLAIN).get(ClientResponse.class);
|
||||
Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
responseText = response.getEntity(String.class);
|
||||
assertTrue(responseText.contains("Cannot find this log on the local disk."));
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.nodemanager.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -33,7 +34,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileUtil;
|
||||
import org.apache.hadoop.util.NodeHealthScriptRunner;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
||||
import org.apache.hadoop.yarn.api.records.NodeId;
|
||||
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||
|
@ -51,6 +51,7 @@ import org.apache.hadoop.yarn.server.nodemanager.webapp.WebServer.NMWebApp;
|
|||
import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
|
||||
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
|
@ -67,8 +68,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -91,8 +90,7 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
private static File testLogDir = new File("target",
|
||||
TestNMWebServicesApps.class.getSimpleName() + "LogDir");
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
conf.set(YarnConfiguration.NM_LOCAL_DIRS, testRootDir.getAbsolutePath());
|
||||
|
@ -148,20 +146,19 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
testRootDir.mkdirs();
|
||||
testLogDir.mkdir();
|
||||
}
|
||||
|
@ -187,7 +184,8 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("apps isn't NULL", JSONObject.NULL, json.get("apps"));
|
||||
assertEquals("apps isn't empty",
|
||||
new JSONObject().toString(), json.get("apps").toString());
|
||||
}
|
||||
|
||||
private HashMap<String, String> addAppContainers(Application app)
|
||||
|
@ -297,7 +295,8 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
.get(ClientResponse.class);
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
|
||||
assertEquals("apps is not empty",
|
||||
new JSONObject().toString(), json.get("apps").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -317,7 +316,7 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -379,7 +378,8 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
|
||||
assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
|
||||
assertEquals("apps is not empty",
|
||||
new JSONObject().toString(), json.get("apps").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -400,7 +400,7 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -430,7 +430,7 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -461,7 +461,7 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
|
||||
String msg = response.getEntity(String.class);
|
||||
|
||||
|
@ -556,7 +556,7 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid user query");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -593,7 +593,7 @@ public class TestNMWebServicesApps extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid user query");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.nodemanager.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.apache.hadoop.yarn.util.StringHelper.ujoin;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -38,7 +39,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
import com.sun.jersey.api.client.filter.LoggingFilter;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileUtil;
|
||||
import org.apache.hadoop.util.NodeHealthScriptRunner;
|
||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
||||
import org.apache.hadoop.yarn.api.records.ContainerId;
|
||||
import org.apache.hadoop.yarn.api.records.NodeId;
|
||||
|
@ -58,6 +58,7 @@ import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
|
|||
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
|
||||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
|
@ -73,8 +74,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -97,7 +96,7 @@ public class TestNMWebServicesContainers extends JerseyTestBase {
|
|||
private static File testLogDir = new File("target",
|
||||
TestNMWebServicesContainers.class.getSimpleName() + "LogDir");
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
resourceView = new ResourceView() {
|
||||
|
@ -158,20 +157,19 @@ public class TestNMWebServicesContainers extends JerseyTestBase {
|
|||
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
testRootDir.mkdirs();
|
||||
testLogDir.mkdir();
|
||||
}
|
||||
|
@ -198,7 +196,8 @@ public class TestNMWebServicesContainers extends JerseyTestBase {
|
|||
.get(ClientResponse.class);
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("apps isn't NULL", JSONObject.NULL, json.get("containers"));
|
||||
assertEquals("apps isn't empty",
|
||||
new JSONObject().toString(), json.get("containers").toString());
|
||||
}
|
||||
|
||||
private HashMap<String, String> addAppContainers(Application app)
|
||||
|
@ -337,7 +336,7 @@ public class TestNMWebServicesContainers extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid user query");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -371,7 +370,7 @@ public class TestNMWebServicesContainers extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid user query");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -405,7 +404,7 @@ public class TestNMWebServicesContainers extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid user query");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -41,9 +42,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.io.TwoDArrayWritable;
|
||||
import org.apache.hadoop.service.Service.STATE;
|
||||
import org.apache.hadoop.test.GenericTestUtils.SleepAnswer;
|
||||
import org.apache.hadoop.util.VersionInfo;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest;
|
||||
import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse;
|
||||
|
@ -68,6 +67,7 @@ import org.apache.hadoop.yarn.util.AdHocLogDumper;
|
|||
import org.apache.hadoop.yarn.util.YarnVersionInfo;
|
||||
import org.apache.hadoop.yarn.webapp.ForbiddenException;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -81,8 +81,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -95,7 +93,7 @@ public class TestRMWebServices extends JerseyTestBase {
|
|||
|
||||
private static MockRM rm;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
|
@ -108,20 +106,19 @@ public class TestRMWebServices extends JerseyTestBase {
|
|||
bind(ResourceManager.class).toInstance(rm);
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestRMWebServices() {
|
||||
|
@ -162,7 +159,7 @@ public class TestRMWebServices extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
|
@ -178,7 +175,7 @@ public class TestRMWebServices extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
@ -194,8 +191,8 @@ public class TestRMWebServices extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid uri");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.INTERNAL_SERVER_ERROR,
|
||||
response.getStatusInfo());
|
||||
WebServicesTestUtils.checkStringMatch(
|
||||
"error string exists and shouldn't", "", responseStr);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -46,6 +47,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptS
|
|||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
|
@ -59,8 +61,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -76,7 +76,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
|
||||
private static final int CONTAINER_MB = 1024;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
|
@ -91,20 +91,19 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
bind(ResourceManager.class).toInstance(rm);
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestRMWebServicesApps() {
|
||||
|
@ -350,7 +349,8 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
|
||||
assertEquals("apps is not empty",
|
||||
new JSONObject().toString(), json.get("apps").toString());
|
||||
rm.stop();
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,8 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
|
||||
assertEquals("apps is not empty",
|
||||
new JSONObject().toString(), json.get("apps").toString());
|
||||
rm.stop();
|
||||
}
|
||||
|
||||
|
@ -388,7 +389,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid state query");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -425,7 +426,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid state query");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -484,7 +485,8 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
|
||||
assertEquals("apps is not null",
|
||||
new JSONObject().toString(), json.get("apps").toString());
|
||||
rm.stop();
|
||||
}
|
||||
|
||||
|
@ -503,7 +505,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
fail("should have thrown exception on invalid state query");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -660,7 +662,8 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
|
||||
assertEquals("apps is not empty",
|
||||
new JSONObject().toString(), json.get("apps").toString());
|
||||
rm.stop();
|
||||
}
|
||||
|
||||
|
@ -1070,7 +1073,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
.path("appstatistics")
|
||||
.queryParam("applicationTypes", "MAPREDUCE,OTHER")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
|
@ -1117,7 +1120,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
response = r.path("ws").path("v1").path("cluster")
|
||||
.path("appstatistics").queryParam("states", "wrong_state")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
|
@ -1185,7 +1188,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -1223,7 +1226,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
|
@ -1515,7 +1518,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -1554,7 +1557,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -1592,7 +1595,7 @@ public class TestRMWebServicesApps extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
@ -87,6 +88,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LocalResourceInf
|
|||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LogAggregationContextInfo;
|
||||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -107,7 +109,6 @@ import org.xml.sax.SAXException;
|
|||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.Client;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
|
@ -126,7 +127,6 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
|
||||
private static final int CONTAINER_MB = 1024;
|
||||
|
||||
private static Injector injector;
|
||||
private String webserviceUserName = "testuser";
|
||||
|
||||
private boolean setAuthFilter = false;
|
||||
|
@ -136,14 +136,6 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
private static final String FS_ALLOC_FILE = new File(TEST_DIR,
|
||||
"test-fs-queues.xml").getAbsolutePath();
|
||||
|
||||
public static class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper class to allow testing of RM web services which require
|
||||
* authorization Add this class as a filter in the Guice injector for the
|
||||
|
@ -298,19 +290,19 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
case 0:
|
||||
default:
|
||||
// No Auth Capacity Scheduler
|
||||
injector = getNoAuthInjectorCap();
|
||||
GuiceServletConfig.setInjector(getNoAuthInjectorCap());
|
||||
break;
|
||||
case 1:
|
||||
// Simple Auth Capacity Scheduler
|
||||
injector = getSimpleAuthInjectorCap();
|
||||
GuiceServletConfig.setInjector(getSimpleAuthInjectorCap());
|
||||
break;
|
||||
case 2:
|
||||
// No Auth Fair Scheduler
|
||||
injector = getNoAuthInjectorFair();
|
||||
GuiceServletConfig.setInjector(getNoAuthInjectorFair());
|
||||
break;
|
||||
case 3:
|
||||
// Simple Auth Fair Scheduler
|
||||
injector = getSimpleAuthInjectorFair();
|
||||
GuiceServletConfig.setInjector(getSimpleAuthInjectorFair());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +341,7 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
this
|
||||
.constructWebResource("apps", app.getApplicationId().toString(),
|
||||
"state").accept(mediaType).get(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
if (mediaType.equals(MediaType.APPLICATION_JSON)) {
|
||||
verifyAppStateJson(response, RMAppState.ACCEPTED);
|
||||
} else if (mediaType.equals(MediaType.APPLICATION_XML)) {
|
||||
|
@ -388,10 +380,11 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
.put(ClientResponse.class);
|
||||
|
||||
if (!isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED,
|
||||
response.getStatusInfo());
|
||||
continue;
|
||||
}
|
||||
assertEquals(Status.ACCEPTED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.ACCEPTED, response.getStatusInfo());
|
||||
if (mediaType.equals(MediaType.APPLICATION_JSON)) {
|
||||
verifyAppStateJson(response, RMAppState.FINAL_SAVING,
|
||||
RMAppState.KILLED, RMAppState.KILLING, RMAppState.ACCEPTED);
|
||||
|
@ -408,7 +401,7 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
tmp = tmp.queryParam("user.name", webserviceUserName);
|
||||
}
|
||||
response = tmp.get(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
assertTrue(locationHeaderValue.endsWith("/ws/v1/cluster/apps/"
|
||||
+ app.getApplicationId().toString() + "/state"));
|
||||
|
||||
|
@ -419,9 +412,13 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
.constructWebResource("apps",
|
||||
app.getApplicationId().toString(), "state").accept(mediaType)
|
||||
.entity(entity, contentType).put(ClientResponse.class);
|
||||
assertTrue((response.getClientResponseStatus() == Status.ACCEPTED)
|
||||
|| (response.getClientResponseStatus() == Status.OK));
|
||||
if (response.getClientResponseStatus() == Status.OK) {
|
||||
assertTrue(
|
||||
(response.getStatusInfo().getStatusCode()
|
||||
== Status.ACCEPTED.getStatusCode())
|
||||
|| (response.getStatusInfo().getStatusCode()
|
||||
== Status.OK.getStatusCode()));
|
||||
if (response.getStatusInfo().getStatusCode()
|
||||
== Status.OK.getStatusCode()) {
|
||||
assertEquals(RMAppState.KILLED, app.getState());
|
||||
if (mediaType.equals(MediaType.APPLICATION_JSON)) {
|
||||
verifyAppStateJson(response, RMAppState.KILLED);
|
||||
|
@ -470,11 +467,12 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
.put(ClientResponse.class);
|
||||
|
||||
if (!isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED,
|
||||
response.getStatusInfo());
|
||||
continue;
|
||||
}
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST,
|
||||
response.getStatusInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -588,13 +586,16 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
.accept(MediaType.APPLICATION_XML)
|
||||
.entity(info, MediaType.APPLICATION_XML).put(ClientResponse.class);
|
||||
if (!isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED,
|
||||
response.getStatusInfo());
|
||||
continue;
|
||||
}
|
||||
if (i == 0) {
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND,
|
||||
response.getStatusInfo());
|
||||
} else {
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST,
|
||||
response.getStatusInfo());
|
||||
}
|
||||
}
|
||||
rm.stop();
|
||||
|
@ -641,9 +642,11 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
public void validateResponseStatus(ClientResponse response,
|
||||
Status expectedUnauthorizedMode, Status expectedAuthorizedMode) {
|
||||
if (!isAuthenticationEnabled()) {
|
||||
assertEquals(expectedUnauthorizedMode, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(expectedUnauthorizedMode,
|
||||
response.getStatusInfo());
|
||||
} else {
|
||||
assertEquals(expectedAuthorizedMode, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(expectedAuthorizedMode,
|
||||
response.getStatusInfo());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -845,10 +848,10 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
.entity(appInfo, contentMedia).post(ClientResponse.class);
|
||||
|
||||
if (!this.isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
|
||||
return;
|
||||
}
|
||||
assertEquals(Status.ACCEPTED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.ACCEPTED, response.getStatusInfo());
|
||||
assertTrue(!response.getHeaders().getFirst(HttpHeaders.LOCATION).isEmpty());
|
||||
String locURL = response.getHeaders().getFirst(HttpHeaders.LOCATION);
|
||||
assertTrue(locURL.contains("/apps/application"));
|
||||
|
@ -857,7 +860,7 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
WebResource res = resource().uri(new URI(locURL));
|
||||
res = res.queryParam("user.name", webserviceUserName);
|
||||
response = res.get(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
|
||||
RMApp app =
|
||||
rm.getRMContext().getRMApps()
|
||||
|
@ -916,7 +919,7 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
response =
|
||||
this.constructWebResource("apps", appId).accept(acceptMedia)
|
||||
.get(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
}
|
||||
|
||||
public void testAppSubmitErrors(String acceptMedia, String contentMedia)
|
||||
|
@ -1004,7 +1007,7 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
ClientResponse response =
|
||||
this.constructWebResource(urlPath).accept(MediaType.APPLICATION_XML)
|
||||
.entity(body, MediaType.APPLICATION_XML).post(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
body = "{\"a\" : \"b\"}";
|
||||
response =
|
||||
this.constructWebResource(urlPath).accept(MediaType.APPLICATION_XML)
|
||||
|
@ -1029,7 +1032,7 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
this
|
||||
.constructWebResource("apps", app.getApplicationId().toString(),
|
||||
"queue").accept(contentType).get(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
String expectedQueue = "default";
|
||||
if(!isCapacityScheduler) {
|
||||
expectedQueue = "root." + webserviceUserName;
|
||||
|
@ -1094,10 +1097,11 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
.put(ClientResponse.class);
|
||||
|
||||
if (!isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED,
|
||||
response.getStatusInfo());
|
||||
continue;
|
||||
}
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
if (mediaType.equals(MediaType.APPLICATION_JSON)) {
|
||||
verifyAppPriorityJson(response, modifiedPriority);
|
||||
} else {
|
||||
|
@ -1108,7 +1112,7 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
.constructWebResource("apps", app.getApplicationId().toString(),
|
||||
"priority")
|
||||
.accept(mediaType).get(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
if (mediaType.equals(MediaType.APPLICATION_JSON)) {
|
||||
verifyAppPriorityJson(response, modifiedPriority);
|
||||
} else {
|
||||
|
@ -1123,7 +1127,7 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
"priority")
|
||||
.entity(entity, contentType).accept(mediaType)
|
||||
.put(ClientResponse.class);
|
||||
assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
}
|
||||
}
|
||||
rm.stop();
|
||||
|
@ -1173,10 +1177,11 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
.put(ClientResponse.class);
|
||||
|
||||
if (!isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED,
|
||||
response.getStatusInfo());
|
||||
continue;
|
||||
}
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
String expectedQueue = "test";
|
||||
if(!isCapacityScheduler) {
|
||||
expectedQueue = "root.test";
|
||||
|
@ -1196,7 +1201,7 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
|||
.constructWebResource("apps", app.getApplicationId().toString(),
|
||||
"queue").entity(entity, contentType).accept(mediaType)
|
||||
.put(ClientResponse.class);
|
||||
assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
if(isCapacityScheduler) {
|
||||
Assert.assertEquals("default", app.getQueue());
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.Capacity
|
|||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
|
||||
import org.apache.hadoop.yarn.util.resource.Resources;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
|
@ -53,8 +54,6 @@ import org.w3c.dom.NodeList;
|
|||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
|
@ -64,8 +63,8 @@ import com.sun.jersey.test.framework.WebAppDescriptor;
|
|||
public class TestRMWebServicesCapacitySched extends JerseyTestBase {
|
||||
|
||||
private static MockRM rm;
|
||||
private CapacitySchedulerConfiguration csConf;
|
||||
private YarnConfiguration conf;
|
||||
private static CapacitySchedulerConfiguration csConf;
|
||||
private static YarnConfiguration conf;
|
||||
|
||||
private class QueueInfo {
|
||||
float capacity;
|
||||
|
@ -89,7 +88,7 @@ public class TestRMWebServicesCapacitySched extends JerseyTestBase {
|
|||
float userLimitFactor;
|
||||
}
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
|
@ -104,62 +103,62 @@ public class TestRMWebServicesCapacitySched extends JerseyTestBase {
|
|||
bind(ResourceManager.class).toInstance(rm);
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
private static void setupQueueConfiguration(
|
||||
CapacitySchedulerConfiguration conf) {
|
||||
CapacitySchedulerConfiguration config) {
|
||||
|
||||
// Define top-level queues
|
||||
conf.setQueues(CapacitySchedulerConfiguration.ROOT, new String[] { "a", "b" });
|
||||
config.setQueues(CapacitySchedulerConfiguration.ROOT,
|
||||
new String[] {"a", "b"});
|
||||
|
||||
final String A = CapacitySchedulerConfiguration.ROOT + ".a";
|
||||
conf.setCapacity(A, 10.5f);
|
||||
conf.setMaximumCapacity(A, 50);
|
||||
config.setCapacity(A, 10.5f);
|
||||
config.setMaximumCapacity(A, 50);
|
||||
|
||||
final String B = CapacitySchedulerConfiguration.ROOT + ".b";
|
||||
conf.setCapacity(B, 89.5f);
|
||||
config.setCapacity(B, 89.5f);
|
||||
|
||||
// Define 2nd-level queues
|
||||
final String A1 = A + ".a1";
|
||||
final String A2 = A + ".a2";
|
||||
conf.setQueues(A, new String[] { "a1", "a2" });
|
||||
conf.setCapacity(A1, 30);
|
||||
conf.setMaximumCapacity(A1, 50);
|
||||
config.setQueues(A, new String[] {"a1", "a2"});
|
||||
config.setCapacity(A1, 30);
|
||||
config.setMaximumCapacity(A1, 50);
|
||||
|
||||
conf.setUserLimitFactor(A1, 100.0f);
|
||||
conf.setCapacity(A2, 70);
|
||||
conf.setUserLimitFactor(A2, 100.0f);
|
||||
config.setUserLimitFactor(A1, 100.0f);
|
||||
config.setCapacity(A2, 70);
|
||||
config.setUserLimitFactor(A2, 100.0f);
|
||||
|
||||
final String B1 = B + ".b1";
|
||||
final String B2 = B + ".b2";
|
||||
final String B3 = B + ".b3";
|
||||
conf.setQueues(B, new String[] { "b1", "b2", "b3" });
|
||||
conf.setCapacity(B1, 60);
|
||||
conf.setUserLimitFactor(B1, 100.0f);
|
||||
conf.setCapacity(B2, 39.5f);
|
||||
conf.setUserLimitFactor(B2, 100.0f);
|
||||
conf.setCapacity(B3, 0.5f);
|
||||
conf.setUserLimitFactor(B3, 100.0f);
|
||||
config.setQueues(B, new String[] {"b1", "b2", "b3"});
|
||||
config.setCapacity(B1, 60);
|
||||
config.setUserLimitFactor(B1, 100.0f);
|
||||
config.setCapacity(B2, 39.5f);
|
||||
config.setUserLimitFactor(B2, 100.0f);
|
||||
config.setCapacity(B3, 0.5f);
|
||||
config.setUserLimitFactor(B3, 100.0f);
|
||||
|
||||
conf.setQueues(A1, new String[] {"a1a", "a1b"});
|
||||
config.setQueues(A1, new String[] {"a1a", "a1b"});
|
||||
final String A1A = A1 + ".a1a";
|
||||
conf.setCapacity(A1A, 85);
|
||||
config.setCapacity(A1A, 85);
|
||||
final String A1B = A1 + ".a1b";
|
||||
conf.setCapacity(A1B, 15);
|
||||
config.setCapacity(A1B, 15);
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestRMWebServicesCapacitySched() {
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
@ -54,6 +56,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler
|
|||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.DelegationToken;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -79,7 +82,6 @@ import static org.junit.Assert.assertFalse;
|
|||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -97,7 +99,6 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.getServerPrincipal();
|
||||
private static MiniKdc testMiniKDC;
|
||||
private static MockRM rm;
|
||||
private Injector injector;
|
||||
private boolean isKerberosAuth = false;
|
||||
|
||||
// Make sure the test uses the published header string
|
||||
|
@ -200,14 +201,6 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
});
|
||||
}
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> guiceConfigs() {
|
||||
return Arrays.asList(new Object[][] { { 0 }, { 1 } });
|
||||
|
@ -222,10 +215,10 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
switch (run) {
|
||||
case 0:
|
||||
default:
|
||||
injector = getKerberosAuthInjector();
|
||||
GuiceServletConfig.setInjector(getKerberosAuthInjector());
|
||||
break;
|
||||
case 1:
|
||||
injector = getSimpleAuthInjector();
|
||||
GuiceServletConfig.setInjector(getSimpleAuthInjector());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +298,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.path("delegation-token").queryParam("user.name", "testuser")
|
||||
.accept(contentType).entity(body, mediaType)
|
||||
.post(ClientResponse.class);
|
||||
assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
}
|
||||
|
||||
private void verifyKerberosAuthCreate(String mType, String cType,
|
||||
|
@ -321,7 +314,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token").accept(contentType)
|
||||
.entity(body, mediaType).post(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
DelegationToken tok = getDelegationTokenFromResponse(response);
|
||||
assertFalse(tok.getToken().isEmpty());
|
||||
Token<RMDelegationTokenIdentifier> token =
|
||||
|
@ -334,7 +327,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token").accept(contentType)
|
||||
.entity(dtoken, mediaType).post(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
tok = getDelegationTokenFromResponse(response);
|
||||
assertFalse(tok.getToken().isEmpty());
|
||||
token = new Token<RMDelegationTokenIdentifier>();
|
||||
|
@ -375,7 +368,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token").accept(contentType)
|
||||
.entity(dummyToken, mediaType).post(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
DelegationToken tok = getDelegationTokenFromResponse(response);
|
||||
assertFalse(tok.getToken().isEmpty());
|
||||
String body = generateRenewTokenBody(mediaType, tok.getToken());
|
||||
|
@ -385,8 +378,8 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.header(yarnTokenHeader, tok.getToken())
|
||||
.accept(contentType).entity(body, mediaType)
|
||||
.post(ClientResponse.class);
|
||||
assertEquals(Status.FORBIDDEN,
|
||||
response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN,
|
||||
response.getStatusInfo());
|
||||
return tok;
|
||||
}
|
||||
});
|
||||
|
@ -406,7 +399,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.header(yarnTokenHeader, responseToken.getToken())
|
||||
.accept(contentType).entity(body, mediaType)
|
||||
.post(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
DelegationToken tok = getDelegationTokenFromResponse(response);
|
||||
String message =
|
||||
"Expiration time not as expected: old = " + oldExpirationTime
|
||||
|
@ -421,7 +414,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.header(yarnTokenHeader, responseToken.getToken())
|
||||
.accept(contentType).entity(body, mediaType)
|
||||
.post(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
tok = getDelegationTokenFromResponse(response);
|
||||
message =
|
||||
"Expiration time not as expected: old = " + oldExpirationTime
|
||||
|
@ -443,7 +436,8 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.header(yarnTokenHeader, responseToken.getToken())
|
||||
.accept(contentType).entity(body, mediaType)
|
||||
.post(ClientResponse.class);
|
||||
assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN,
|
||||
response.getStatusInfo());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -469,7 +463,8 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.path("delegation-token").path("expiration")
|
||||
.accept(contentType).entity(body, mediaType)
|
||||
.post(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST,
|
||||
response.getStatusInfo());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -498,7 +493,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.path("delegation-token").queryParam("user.name", "testuser")
|
||||
.accept(contentType).entity(body, mediaType)
|
||||
.post(ClientResponse.class);
|
||||
assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
}
|
||||
|
||||
// Test to verify cancel functionality - create a token and then try to cancel
|
||||
|
@ -528,14 +523,14 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token").accept(contentType)
|
||||
.entity(dtoken, mediaType).post(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
DelegationToken tok = getDelegationTokenFromResponse(response);
|
||||
response =
|
||||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token")
|
||||
.header(yarnTokenHeader, tok.getToken()).accept(contentType)
|
||||
.delete(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
assertTokenCancelled(tok.getToken());
|
||||
return null;
|
||||
}
|
||||
|
@ -550,7 +545,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token").accept(contentType)
|
||||
.entity(dtoken, mediaType).post(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
DelegationToken tok = getDelegationTokenFromResponse(response);
|
||||
return tok;
|
||||
}
|
||||
|
@ -564,7 +559,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.path("delegation-token")
|
||||
.header(yarnTokenHeader, tmpToken.getToken())
|
||||
.accept(contentType).delete(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
assertTokenCancelled(tmpToken.getToken());
|
||||
return null;
|
||||
}
|
||||
|
@ -579,7 +574,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token").accept(contentType)
|
||||
.entity(dtoken, mediaType).post(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
DelegationToken tok = getDelegationTokenFromResponse(response);
|
||||
return tok;
|
||||
}
|
||||
|
@ -593,7 +588,8 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.path("delegation-token")
|
||||
.header(yarnTokenHeader, tmpToken2.getToken())
|
||||
.accept(contentType).delete(ClientResponse.class);
|
||||
assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN,
|
||||
response.getStatusInfo());
|
||||
assertValidRMToken(tmpToken2.getToken());
|
||||
return null;
|
||||
}
|
||||
|
@ -625,7 +621,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.path("delegation-token")
|
||||
.header(yarnTokenHeader, "random-string").accept(contentType)
|
||||
.delete(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -638,7 +634,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token").accept(contentType)
|
||||
.delete(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -653,7 +649,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token").accept(contentType)
|
||||
.entity(dtoken, mediaType).post(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
DelegationToken tok = getDelegationTokenFromResponse(response);
|
||||
return tok;
|
||||
}
|
||||
|
@ -667,13 +663,13 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.path("delegation-token")
|
||||
.header(yarnTokenHeader, tmpToken.getToken()).accept(contentType)
|
||||
.delete(ClientResponse.class);
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
response =
|
||||
resource().path("ws").path("v1").path("cluster")
|
||||
.path("delegation-token")
|
||||
.header(yarnTokenHeader, tmpToken.getToken()).accept(contentType)
|
||||
.delete(ClientResponse.class);
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -686,7 +682,7 @@ public class TestRMWebServicesDelegationTokens extends JerseyTestBase {
|
|||
.path("delegation-token").queryParam("user.name", "testuser")
|
||||
.header(RMWebServices.DELEGATION_TOKEN_HEADER, "random")
|
||||
.delete(ClientResponse.class);
|
||||
assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
|
||||
}
|
||||
|
||||
private DelegationToken
|
||||
|
|
|
@ -30,15 +30,15 @@ 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.QueueManager;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
|
@ -47,9 +47,9 @@ import com.sun.jersey.test.framework.WebAppDescriptor;
|
|||
|
||||
public class TestRMWebServicesFairScheduler extends JerseyTestBase {
|
||||
private static MockRM rm;
|
||||
private YarnConfiguration conf;
|
||||
private static YarnConfiguration conf;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
|
@ -62,14 +62,19 @@ public class TestRMWebServicesFairScheduler extends JerseyTestBase {
|
|||
bind(ResourceManager.class).toInstance(rm);
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestRMWebServicesFairScheduler() {
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler
|
|||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
|
@ -53,8 +54,6 @@ import org.xml.sax.InputSource;
|
|||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
|
@ -78,10 +77,10 @@ public class TestRMWebServicesForCSWithPartitions extends JerseyTestBase {
|
|||
private static final ImmutableSet<String> CLUSTER_LABELS =
|
||||
ImmutableSet.of(LABEL_LX, LABEL_LY, DEFAULT_PARTITION);
|
||||
private static MockRM rm;
|
||||
private CapacitySchedulerConfiguration csConf;
|
||||
private YarnConfiguration conf;
|
||||
static private CapacitySchedulerConfiguration csConf;
|
||||
static private YarnConfiguration conf;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
|
@ -106,76 +105,79 @@ public class TestRMWebServicesForCSWithPartitions extends JerseyTestBase {
|
|||
bind(ResourceManager.class).toInstance(rm);
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
private static void setupQueueConfiguration(
|
||||
CapacitySchedulerConfiguration conf, ResourceManager rm) {
|
||||
CapacitySchedulerConfiguration config, ResourceManager resourceManager) {
|
||||
|
||||
// Define top-level queues
|
||||
conf.setQueues(CapacitySchedulerConfiguration.ROOT,
|
||||
config.setQueues(CapacitySchedulerConfiguration.ROOT,
|
||||
new String[] { QUEUE_A, QUEUE_B, QUEUE_C });
|
||||
String interMediateQueueC =
|
||||
CapacitySchedulerConfiguration.ROOT + "." + QUEUE_C;
|
||||
conf.setQueues(interMediateQueueC,
|
||||
config.setQueues(interMediateQueueC,
|
||||
new String[] { LEAF_QUEUE_C1, LEAF_QUEUE_C2 });
|
||||
conf.setCapacityByLabel(CapacitySchedulerConfiguration.ROOT, LABEL_LX, 100);
|
||||
conf.setCapacityByLabel(CapacitySchedulerConfiguration.ROOT, LABEL_LY, 100);
|
||||
config.setCapacityByLabel(
|
||||
CapacitySchedulerConfiguration.ROOT, LABEL_LX, 100);
|
||||
config.setCapacityByLabel(
|
||||
CapacitySchedulerConfiguration.ROOT, LABEL_LY, 100);
|
||||
|
||||
String leafQueueA = CapacitySchedulerConfiguration.ROOT + "." + QUEUE_A;
|
||||
conf.setCapacity(leafQueueA, 30);
|
||||
conf.setMaximumCapacity(leafQueueA, 50);
|
||||
config.setCapacity(leafQueueA, 30);
|
||||
config.setMaximumCapacity(leafQueueA, 50);
|
||||
|
||||
String leafQueueB = CapacitySchedulerConfiguration.ROOT + "." + QUEUE_B;
|
||||
conf.setCapacity(leafQueueB, 30);
|
||||
conf.setMaximumCapacity(leafQueueB, 50);
|
||||
config.setCapacity(leafQueueB, 30);
|
||||
config.setMaximumCapacity(leafQueueB, 50);
|
||||
|
||||
conf.setCapacity(interMediateQueueC, 40);
|
||||
conf.setMaximumCapacity(interMediateQueueC, 50);
|
||||
config.setCapacity(interMediateQueueC, 40);
|
||||
config.setMaximumCapacity(interMediateQueueC, 50);
|
||||
|
||||
String leafQueueC1 = interMediateQueueC + "." + LEAF_QUEUE_C1;
|
||||
conf.setCapacity(leafQueueC1, 50);
|
||||
conf.setMaximumCapacity(leafQueueC1, 60);
|
||||
config.setCapacity(leafQueueC1, 50);
|
||||
config.setMaximumCapacity(leafQueueC1, 60);
|
||||
|
||||
String leafQueueC2 = interMediateQueueC + "." + LEAF_QUEUE_C2;
|
||||
conf.setCapacity(leafQueueC2, 50);
|
||||
conf.setMaximumCapacity(leafQueueC2, 70);
|
||||
config.setCapacity(leafQueueC2, 50);
|
||||
config.setMaximumCapacity(leafQueueC2, 70);
|
||||
|
||||
// Define label specific configuration
|
||||
conf.setAccessibleNodeLabels(leafQueueA, ImmutableSet.of(DEFAULT_PARTITION));
|
||||
conf.setAccessibleNodeLabels(leafQueueB, ImmutableSet.of(LABEL_LX));
|
||||
conf.setAccessibleNodeLabels(interMediateQueueC,
|
||||
config.setAccessibleNodeLabels(
|
||||
leafQueueA, ImmutableSet.of(DEFAULT_PARTITION));
|
||||
config.setAccessibleNodeLabels(leafQueueB, ImmutableSet.of(LABEL_LX));
|
||||
config.setAccessibleNodeLabels(interMediateQueueC,
|
||||
ImmutableSet.of(LABEL_LX, LABEL_LY));
|
||||
conf.setAccessibleNodeLabels(leafQueueC1,
|
||||
config.setAccessibleNodeLabels(leafQueueC1,
|
||||
ImmutableSet.of(LABEL_LX, LABEL_LY));
|
||||
conf.setAccessibleNodeLabels(leafQueueC2,
|
||||
config.setAccessibleNodeLabels(leafQueueC2,
|
||||
ImmutableSet.of(LABEL_LX, LABEL_LY));
|
||||
conf.setDefaultNodeLabelExpression(leafQueueB, LABEL_LX);
|
||||
conf.setDefaultNodeLabelExpression(leafQueueC1, LABEL_LX);
|
||||
conf.setDefaultNodeLabelExpression(leafQueueC2, LABEL_LY);
|
||||
config.setDefaultNodeLabelExpression(leafQueueB, LABEL_LX);
|
||||
config.setDefaultNodeLabelExpression(leafQueueC1, LABEL_LX);
|
||||
config.setDefaultNodeLabelExpression(leafQueueC2, LABEL_LY);
|
||||
|
||||
conf.setCapacityByLabel(leafQueueB, LABEL_LX, 30);
|
||||
conf.setCapacityByLabel(interMediateQueueC, LABEL_LX, 70);
|
||||
conf.setCapacityByLabel(leafQueueC1, LABEL_LX, 40);
|
||||
conf.setCapacityByLabel(leafQueueC2, LABEL_LX, 60);
|
||||
config.setCapacityByLabel(leafQueueB, LABEL_LX, 30);
|
||||
config.setCapacityByLabel(interMediateQueueC, LABEL_LX, 70);
|
||||
config.setCapacityByLabel(leafQueueC1, LABEL_LX, 40);
|
||||
config.setCapacityByLabel(leafQueueC2, LABEL_LX, 60);
|
||||
|
||||
conf.setCapacityByLabel(interMediateQueueC, LABEL_LY, 100);
|
||||
conf.setCapacityByLabel(leafQueueC1, LABEL_LY, 50);
|
||||
conf.setCapacityByLabel(leafQueueC2, LABEL_LY, 50);
|
||||
conf.setMaximumCapacityByLabel(leafQueueC1, LABEL_LY, 75);
|
||||
conf.setMaximumCapacityByLabel(leafQueueC2, LABEL_LY, 75);
|
||||
config.setCapacityByLabel(interMediateQueueC, LABEL_LY, 100);
|
||||
config.setCapacityByLabel(leafQueueC1, LABEL_LY, 50);
|
||||
config.setCapacityByLabel(leafQueueC2, LABEL_LY, 50);
|
||||
config.setMaximumCapacityByLabel(leafQueueC1, LABEL_LY, 75);
|
||||
config.setMaximumCapacityByLabel(leafQueueC2, LABEL_LY, 75);
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestRMWebServicesForCSWithPartitions() {
|
||||
|
|
|
@ -41,16 +41,16 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsEntr
|
|||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsInfo;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsEntryList;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.UniformInterfaceException;
|
||||
|
@ -69,13 +69,13 @@ public class TestRMWebServicesNodeLabels extends JerseyTestBase {
|
|||
.getLog(TestRMWebServicesNodeLabels.class);
|
||||
|
||||
private static MockRM rm;
|
||||
private YarnConfiguration conf;
|
||||
private static YarnConfiguration conf;
|
||||
|
||||
private String userName;
|
||||
private String notUserName;
|
||||
private RMWebServices rmWebService;
|
||||
private static String userName;
|
||||
private static String notUserName;
|
||||
private static RMWebServices rmWebService;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
|
@ -98,14 +98,14 @@ public class TestRMWebServicesNodeLabels extends JerseyTestBase {
|
|||
TestRMWebServicesAppsModification.TestRMCustomAuthFilter.class);
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
};
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestRMWebServicesNodeLabels() {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -51,6 +52,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerNodeRepo
|
|||
import org.apache.hadoop.yarn.util.RackResolver;
|
||||
import org.apache.hadoop.yarn.util.YarnVersionInfo;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
|
@ -65,8 +67,6 @@ import org.xml.sax.InputSource;
|
|||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -79,7 +79,7 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
|
||||
private static MockRM rm;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
|
@ -91,20 +91,19 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
bind(ResourceManager.class).toInstance(rm);
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestRMWebServicesNodes() {
|
||||
|
@ -227,7 +226,8 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("nodes is not null", JSONObject.NULL, json.get("nodes"));
|
||||
assertEquals("nodes is not empty",
|
||||
new JSONObject().toString(), json.get("nodes").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -245,7 +245,7 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
|
@ -357,7 +357,8 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject json = response.getEntity(JSONObject.class);
|
||||
assertEquals("incorrect number of elements", 1, json.length());
|
||||
assertEquals("nodes is not null", JSONObject.NULL, json.get("nodes"));
|
||||
assertEquals("nodes is not empty",
|
||||
new JSONObject().toString(), json.get("nodes").toString());
|
||||
}
|
||||
|
||||
public void testNodesHelper(String path, String media) throws JSONException,
|
||||
|
@ -436,7 +437,7 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
fail("should have thrown exception on non-existent nodeid");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -462,7 +463,7 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
fail("should have thrown exception on non-existent nodeid");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
@ -488,7 +489,7 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
fail("should have thrown exception on non-existent nodeid");
|
||||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
|
||||
String msg = response.getEntity(String.class);
|
||||
System.out.println(msg);
|
||||
|
@ -531,7 +532,7 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
} catch (UniformInterfaceException ue) {
|
||||
ClientResponse response = ue.getResponse();
|
||||
|
||||
assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
JSONObject msg = response.getEntity(JSONObject.class);
|
||||
JSONObject exception = msg.getJSONObject("RemoteException");
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.hadoop.yarn.server.resourcemanager.webapp;
|
||||
|
||||
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -56,6 +57,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationUpdat
|
|||
import org.apache.hadoop.yarn.util.Clock;
|
||||
import org.apache.hadoop.yarn.util.UTCClock;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.codehaus.jettison.json.JSONArray;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
|
@ -70,7 +72,6 @@ import org.junit.runners.Parameterized.Parameters;
|
|||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
|
@ -86,10 +87,9 @@ import com.sun.jersey.test.framework.WebAppDescriptor;
|
|||
public class TestRMWebServicesReservation extends JerseyTestBase {
|
||||
|
||||
private String webserviceUserName = "testuser";
|
||||
private boolean setAuthFilter = false;
|
||||
private static boolean setAuthFilter = false;
|
||||
|
||||
private static MockRM rm;
|
||||
private static Injector injector;
|
||||
|
||||
private static final int MINIMUM_RESOURCE_DURATION = 1000000;
|
||||
private static final Clock clock = new UTCClock();
|
||||
|
@ -103,14 +103,6 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
private static final String GET_NEW_RESERVATION_PATH =
|
||||
"reservation/new-reservation";
|
||||
|
||||
public static class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper class to allow testing of RM web services which require
|
||||
* authorization Add this class as a filter in the Guice injector for the
|
||||
|
@ -139,7 +131,7 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
|
||||
}
|
||||
|
||||
private abstract class TestServletModule extends ServletModule {
|
||||
private static abstract class TestServletModule extends ServletModule {
|
||||
public Configuration conf = new Configuration();
|
||||
|
||||
public abstract void configureScheduler();
|
||||
|
@ -175,7 +167,7 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
private class CapTestServletModule extends TestServletModule {
|
||||
private static class CapTestServletModule extends TestServletModule {
|
||||
@Override
|
||||
public void configureScheduler() {
|
||||
conf.set("yarn.resourcemanager.scheduler.class",
|
||||
|
@ -183,7 +175,7 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
private class FairTestServletModule extends TestServletModule {
|
||||
private static class FairTestServletModule extends TestServletModule {
|
||||
@Override
|
||||
public void configureScheduler() {
|
||||
try {
|
||||
|
@ -209,18 +201,15 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
private Injector getNoAuthInjectorCap() {
|
||||
return Guice.createInjector(new CapTestServletModule() {
|
||||
private static class NoAuthServletModule extends CapTestServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
setAuthFilter = false;
|
||||
super.configureServlets();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Injector getSimpleAuthInjectorCap() {
|
||||
return Guice.createInjector(new CapTestServletModule() {
|
||||
private static class SimpleAuthServletModule extends CapTestServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
setAuthFilter = true;
|
||||
|
@ -230,21 +219,18 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
conf.setStrings(YarnConfiguration.YARN_ADMIN_ACL, "testuser1");
|
||||
super.configureServlets();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Injector getNoAuthInjectorFair() {
|
||||
return Guice.createInjector(new FairTestServletModule() {
|
||||
private static class FairNoAuthServletModule extends FairTestServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
setAuthFilter = false;
|
||||
super.configureServlets();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Injector getSimpleAuthInjectorFair() {
|
||||
return Guice.createInjector(new FairTestServletModule() {
|
||||
private static class FairSimpleAuthServletModule extends
|
||||
FairTestServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
setAuthFilter = true;
|
||||
|
@ -254,7 +240,26 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
conf.setStrings(YarnConfiguration.YARN_ADMIN_ACL, "testuser1");
|
||||
super.configureServlets();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Injector initNoAuthInjectorCap() {
|
||||
return GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new NoAuthServletModule()));
|
||||
}
|
||||
|
||||
private Injector initSimpleAuthInjectorCap() {
|
||||
return GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new SimpleAuthServletModule()));
|
||||
}
|
||||
|
||||
private Injector initNoAuthInjectorFair() {
|
||||
return GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new FairNoAuthServletModule()));
|
||||
}
|
||||
|
||||
private Injector initSimpleAuthInjectorFair() {
|
||||
return GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new FairSimpleAuthServletModule()));
|
||||
}
|
||||
|
||||
@Parameters
|
||||
|
@ -279,19 +284,19 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
case 0:
|
||||
default:
|
||||
// No Auth Capacity Scheduler
|
||||
injector = getNoAuthInjectorCap();
|
||||
initNoAuthInjectorCap();
|
||||
break;
|
||||
case 1:
|
||||
// Simple Auth Capacity Scheduler
|
||||
injector = getSimpleAuthInjectorCap();
|
||||
initSimpleAuthInjectorCap();
|
||||
break;
|
||||
case 2:
|
||||
// No Auth Fair Scheduler
|
||||
injector = getNoAuthInjectorFair();
|
||||
initNoAuthInjectorFair();
|
||||
break;
|
||||
case 3:
|
||||
// Simple Auth Fair Scheduler
|
||||
injector = getSimpleAuthInjectorFair();
|
||||
initSimpleAuthInjectorFair();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -959,7 +964,7 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
.post(ClientResponse.class);
|
||||
|
||||
if (!this.isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
|
||||
return ReservationId.newInstance(clock.getTime(), fallbackReservationId);
|
||||
}
|
||||
|
||||
|
@ -1013,7 +1018,7 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
.accept(media).post(ClientResponse.class);
|
||||
|
||||
if (!this.isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
|
||||
}
|
||||
|
||||
return response;
|
||||
|
@ -1046,13 +1051,13 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
.accept(media).post(ClientResponse.class);
|
||||
|
||||
if (!this.isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("RESPONSE:" + response);
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
|
||||
}
|
||||
|
||||
|
@ -1095,13 +1100,13 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
.accept(media).post(ClientResponse.class);
|
||||
|
||||
if (!this.isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("RESPONSE:" + response);
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.OK, response.getStatusInfo());
|
||||
}
|
||||
|
||||
private void testRDLHelper(JSONObject json) throws JSONException {
|
||||
|
@ -1126,12 +1131,12 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
ClientResponse response = resource.get(ClientResponse.class);
|
||||
|
||||
if (!this.isAuthenticationEnabled()) {
|
||||
assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
|
||||
return null;
|
||||
}
|
||||
|
||||
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
||||
assertEquals(status, response.getClientResponseStatus());
|
||||
assertResponseStatusCode(status, response.getStatusInfo());
|
||||
|
||||
return response.getEntity(JSONObject.class);
|
||||
}
|
||||
|
@ -1152,7 +1157,7 @@ public class TestRMWebServicesReservation extends JerseyTestBase {
|
|||
}
|
||||
|
||||
private boolean isHttpSuccessResponse(ClientResponse response) {
|
||||
return (response.getStatus() / 100) == 2;
|
||||
return (response.getStatusInfo().getStatusCode() / 100) == 2;
|
||||
}
|
||||
|
||||
private void setupCluster(int nodes) throws Exception {
|
||||
|
|
|
@ -19,12 +19,9 @@
|
|||
package org.apache.hadoop.yarn.webapp;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.ClientResponse.Status;
|
||||
import com.sun.jersey.api.client.UniformInterfaceException;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
||||
import com.sun.jersey.test.framework.WebAppDescriptor;
|
||||
|
@ -33,7 +30,6 @@ import org.apache.hadoop.security.http.RestCsrfPreventionFilter;
|
|||
import org.apache.hadoop.service.Service.STATE;
|
||||
import org.apache.hadoop.util.VersionInfo;
|
||||
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.ClusterMetrics;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
||||
|
@ -41,10 +37,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoSchedule
|
|||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.JAXBContextResolver;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices;
|
||||
import org.apache.hadoop.yarn.util.YarnVersionInfo;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
@ -60,7 +53,6 @@ import java.util.Map;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Used TestRMWebServices as an example of web invocations of RM and added
|
||||
|
@ -70,7 +62,7 @@ public class TestRMWithCSRFFilter extends JerseyTestBase {
|
|||
|
||||
private static MockRM rm;
|
||||
|
||||
private Injector injector = Guice.createInjector(new ServletModule() {
|
||||
private static class WebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
|
@ -89,20 +81,14 @@ public class TestRMWithCSRFFilter extends JerseyTestBase {
|
|||
"OPTIONS,HEAD,TRACE");
|
||||
filter("/*").through(csrfFilter, initParams);
|
||||
}
|
||||
});
|
||||
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new WebServletModule()));
|
||||
}
|
||||
|
||||
public TestRMWithCSRFFilter() {
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
package org.apache.hadoop.yarn.webapp;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
|
@ -52,19 +50,6 @@ public class TestRMWithXFSFilter extends JerseyTestBase {
|
|||
|
||||
private static MockRM rm;
|
||||
|
||||
private Injector injector;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
@Override
|
||||
protected Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
|
@ -103,7 +88,7 @@ public class TestRMWithXFSFilter extends JerseyTestBase {
|
|||
|
||||
protected void createInjector(final String headerValue,
|
||||
final boolean explicitlyDisabled) {
|
||||
injector = Guice.createInjector(new ServletModule() {
|
||||
GuiceServletConfig.setInjector(Guice.createInjector(new ServletModule() {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
|
@ -127,7 +112,7 @@ public class TestRMWithXFSFilter extends JerseyTestBase {
|
|||
|
||||
filter("/*").through(xfsFilter, initParams);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue