|
@@ -21,36 +21,51 @@ package org.apache.hadoop.yarn.server.applicationhistoryservice.webapp;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
|
-import javax.ws.rs.core.MediaType;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Properties;
|
|
|
|
|
|
-import org.junit.Assert;
|
|
|
+import javax.servlet.FilterConfig;
|
|
|
+import javax.servlet.ServletException;
|
|
|
+import javax.ws.rs.core.MediaType;
|
|
|
+import javax.ws.rs.core.Response;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.http.lib.StaticUserWebFilter.StaticUserFilter;
|
|
|
+import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
|
|
|
+import org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler;
|
|
|
+import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerState;
|
|
|
import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
|
|
|
import org.apache.hadoop.yarn.api.records.NodeId;
|
|
|
-import org.apache.hadoop.yarn.api.records.Priority;
|
|
|
import org.apache.hadoop.yarn.api.records.YarnApplicationAttemptState;
|
|
|
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.server.api.ApplicationContext;
|
|
|
-import org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryManager;
|
|
|
-import org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryStore;
|
|
|
-import org.apache.hadoop.yarn.server.applicationhistoryservice.MemoryApplicationHistoryStore;
|
|
|
+import org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryManagerOnTimelineStore;
|
|
|
+import org.apache.hadoop.yarn.server.applicationhistoryservice.TestApplicationHistoryManagerOnTimelineStore;
|
|
|
+import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
|
|
|
+import org.apache.hadoop.yarn.server.timeline.TimelineDataManager;
|
|
|
+import org.apache.hadoop.yarn.server.timeline.TimelineStore;
|
|
|
+import org.apache.hadoop.yarn.server.timeline.security.TimelineACLsManager;
|
|
|
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
|
|
import org.apache.hadoop.yarn.webapp.WebServicesTestUtils;
|
|
|
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
|
|
|
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.AfterClass;
|
|
|
+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;
|
|
@@ -61,9 +76,40 @@ import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
|
|
import com.sun.jersey.test.framework.JerseyTest;
|
|
|
import com.sun.jersey.test.framework.WebAppDescriptor;
|
|
|
|
|
|
+@RunWith(Parameterized.class)
|
|
|
public class TestAHSWebServices extends JerseyTest {
|
|
|
|
|
|
- private static ApplicationHistoryManager ahManager;
|
|
|
+ private static ApplicationHistoryManagerOnTimelineStore historyManager;
|
|
|
+ private static final String[] USERS = new String[] { "foo" , "bar" };
|
|
|
+
|
|
|
+ @BeforeClass
|
|
|
+ public static void setupClass() throws Exception {
|
|
|
+ Configuration conf = new YarnConfiguration();
|
|
|
+ TimelineStore store =
|
|
|
+ TestApplicationHistoryManagerOnTimelineStore.createStore(5);
|
|
|
+ TimelineACLsManager aclsManager = new TimelineACLsManager(conf);
|
|
|
+ TimelineDataManager dataManager =
|
|
|
+ new TimelineDataManager(store, aclsManager);
|
|
|
+ conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
|
|
|
+ conf.set(YarnConfiguration.YARN_ADMIN_ACL, "foo");
|
|
|
+ ApplicationACLsManager appAclsManager = new ApplicationACLsManager(conf);
|
|
|
+ historyManager =
|
|
|
+ new ApplicationHistoryManagerOnTimelineStore(dataManager, appAclsManager);
|
|
|
+ historyManager.init(conf);
|
|
|
+ historyManager.start();
|
|
|
+ }
|
|
|
+
|
|
|
+ @AfterClass
|
|
|
+ public static void tearDownClass() throws Exception {
|
|
|
+ if (historyManager != null) {
|
|
|
+ historyManager.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Parameterized.Parameters
|
|
|
+ public static Collection<Object[]> rounds() {
|
|
|
+ return Arrays.asList(new Object[][] { { 0 }, { 1 } });
|
|
|
+ }
|
|
|
|
|
|
private Injector injector = Guice.createInjector(new ServletModule() {
|
|
|
|
|
@@ -72,16 +118,25 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
bind(JAXBContextResolver.class);
|
|
|
bind(AHSWebServices.class);
|
|
|
bind(GenericExceptionHandler.class);
|
|
|
- try {
|
|
|
- ahManager = mockApplicationHistoryManager();
|
|
|
- } catch (Exception e) {
|
|
|
- Assert.fail();
|
|
|
- }
|
|
|
- bind(ApplicationContext.class).toInstance(ahManager);
|
|
|
+ bind(ApplicationContext.class).toInstance(historyManager);
|
|
|
serve("/*").with(GuiceContainer.class);
|
|
|
+ filter("/*").through(TestSimpleAuthFilter.class);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ @Singleton
|
|
|
+ public static class TestSimpleAuthFilter extends AuthenticationFilter {
|
|
|
+ @Override
|
|
|
+ protected Properties getConfiguration(String configPrefix,
|
|
|
+ FilterConfig filterConfig) throws ServletException {
|
|
|
+ Properties properties =
|
|
|
+ super.getConfiguration(configPrefix, filterConfig);
|
|
|
+ properties.put(AuthenticationFilter.AUTH_TYPE, "simple");
|
|
|
+ properties.put(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, "false");
|
|
|
+ return properties;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public class GuiceServletConfig extends GuiceServletContextListener {
|
|
|
|
|
|
@Override
|
|
@@ -90,28 +145,15 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private ApplicationHistoryManager mockApplicationHistoryManager()
|
|
|
- throws Exception {
|
|
|
- ApplicationHistoryStore store = new MemoryApplicationHistoryStore();
|
|
|
- TestAHSWebApp testAHSWebApp = new TestAHSWebApp();
|
|
|
- testAHSWebApp.setApplicationHistoryStore(store);
|
|
|
- ApplicationHistoryManager ahManager =
|
|
|
- testAHSWebApp.mockApplicationHistoryManager(5, 5, 5);
|
|
|
- return ahManager;
|
|
|
- }
|
|
|
+ private int round;
|
|
|
|
|
|
- public TestAHSWebServices() {
|
|
|
+ public TestAHSWebServices(int round) {
|
|
|
super(new WebAppDescriptor.Builder(
|
|
|
"org.apache.hadoop.yarn.server.applicationhistoryservice.webapp")
|
|
|
.contextListenerClass(GuiceServletConfig.class)
|
|
|
.filterClass(com.google.inject.servlet.GuiceFilter.class)
|
|
|
.contextPath("jersey-guice-filter").servletPath("/").build());
|
|
|
- }
|
|
|
-
|
|
|
- @Before
|
|
|
- @Override
|
|
|
- public void setUp() throws Exception {
|
|
|
- super.setUp();
|
|
|
+ this.round = round;
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -121,6 +163,7 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
try {
|
|
|
responseStr =
|
|
|
r.path("ws").path("v1").path("applicationhistory").path("bogus")
|
|
|
+ .queryParam("user.name", USERS[round])
|
|
|
.accept(MediaType.APPLICATION_JSON).get(String.class);
|
|
|
fail("should have thrown exception on invalid uri");
|
|
|
} catch (UniformInterfaceException ue) {
|
|
@@ -137,7 +180,8 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
WebResource r = resource();
|
|
|
String responseStr = "";
|
|
|
try {
|
|
|
- responseStr = r.accept(MediaType.APPLICATION_JSON).get(String.class);
|
|
|
+ responseStr = r.queryParam("user.name", USERS[round])
|
|
|
+ .accept(MediaType.APPLICATION_JSON).get(String.class);
|
|
|
fail("should have thrown exception on invalid uri");
|
|
|
} catch (UniformInterfaceException ue) {
|
|
|
ClientResponse response = ue.getResponse();
|
|
@@ -154,6 +198,7 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
try {
|
|
|
responseStr =
|
|
|
r.path("ws").path("v1").path("applicationhistory")
|
|
|
+ .queryParam("user.name", USERS[round])
|
|
|
.accept(MediaType.TEXT_PLAIN).get(String.class);
|
|
|
fail("should have thrown exception on invalid uri");
|
|
|
} catch (UniformInterfaceException ue) {
|
|
@@ -171,6 +216,7 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
ClientResponse response =
|
|
|
r.path("ws").path("v1").path("applicationhistory").path("apps")
|
|
|
.queryParam("state", YarnApplicationState.FINISHED.toString())
|
|
|
+ .queryParam("user.name", USERS[round])
|
|
|
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
@@ -187,18 +233,21 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
WebResource r = resource();
|
|
|
ClientResponse response =
|
|
|
r.path("ws").path("v1").path("applicationhistory").path("apps")
|
|
|
- .path(appId.toString()).accept(MediaType.APPLICATION_JSON)
|
|
|
+ .path(appId.toString())
|
|
|
+ .queryParam("user.name", USERS[round])
|
|
|
+ .accept(MediaType.APPLICATION_JSON)
|
|
|
.get(ClientResponse.class);
|
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
|
assertEquals("incorrect number of elements", 1, json.length());
|
|
|
JSONObject app = json.getJSONObject("app");
|
|
|
assertEquals(appId.toString(), app.getString("appId"));
|
|
|
- assertEquals(appId.toString(), app.get("name"));
|
|
|
- assertEquals(appId.toString(), app.get("diagnosticsInfo"));
|
|
|
+ assertEquals("test app", app.get("name"));
|
|
|
+ assertEquals(round == 0 ? "test diagnostics info" : "",
|
|
|
+ app.get("diagnosticsInfo"));
|
|
|
assertEquals("test queue", app.get("queue"));
|
|
|
- assertEquals("test user", app.get("user"));
|
|
|
- assertEquals("test type", app.get("type"));
|
|
|
+ assertEquals("user1", app.get("user"));
|
|
|
+ assertEquals("test app type", app.get("type"));
|
|
|
assertEquals(FinalApplicationStatus.UNDEFINED.toString(),
|
|
|
app.get("finalAppStatus"));
|
|
|
assertEquals(YarnApplicationState.FINISHED.toString(), app.get("appState"));
|
|
@@ -211,7 +260,13 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
ClientResponse response =
|
|
|
r.path("ws").path("v1").path("applicationhistory").path("apps")
|
|
|
.path(appId.toString()).path("appattempts")
|
|
|
+ .queryParam("user.name", USERS[round])
|
|
|
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
|
|
+ if (round == 1) {
|
|
|
+ assertEquals(
|
|
|
+ Status.FORBIDDEN, response.getClientResponseStatus());
|
|
|
+ return;
|
|
|
+ }
|
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
|
assertEquals("incorrect number of elements", 1, json.length());
|
|
@@ -230,15 +285,22 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
ClientResponse response =
|
|
|
r.path("ws").path("v1").path("applicationhistory").path("apps")
|
|
|
.path(appId.toString()).path("appattempts")
|
|
|
- .path(appAttemptId.toString()).accept(MediaType.APPLICATION_JSON)
|
|
|
+ .path(appAttemptId.toString())
|
|
|
+ .queryParam("user.name", USERS[round])
|
|
|
+ .accept(MediaType.APPLICATION_JSON)
|
|
|
.get(ClientResponse.class);
|
|
|
+ if (round == 1) {
|
|
|
+ assertEquals(
|
|
|
+ Status.FORBIDDEN, response.getClientResponseStatus());
|
|
|
+ return;
|
|
|
+ }
|
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
|
assertEquals("incorrect number of elements", 1, json.length());
|
|
|
JSONObject appAttempt = json.getJSONObject("appAttempt");
|
|
|
assertEquals(appAttemptId.toString(), appAttempt.getString("appAttemptId"));
|
|
|
- assertEquals(appAttemptId.toString(), appAttempt.getString("host"));
|
|
|
- assertEquals(appAttemptId.toString(),
|
|
|
+ assertEquals("test host", appAttempt.getString("host"));
|
|
|
+ assertEquals("test diagnostics info",
|
|
|
appAttempt.getString("diagnosticsInfo"));
|
|
|
assertEquals("test tracking url", appAttempt.getString("trackingUrl"));
|
|
|
assertEquals(YarnApplicationAttemptState.FINISHED.toString(),
|
|
@@ -255,7 +317,13 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
r.path("ws").path("v1").path("applicationhistory").path("apps")
|
|
|
.path(appId.toString()).path("appattempts")
|
|
|
.path(appAttemptId.toString()).path("containers")
|
|
|
+ .queryParam("user.name", USERS[round])
|
|
|
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
|
|
+ if (round == 1) {
|
|
|
+ assertEquals(
|
|
|
+ Status.FORBIDDEN, response.getClientResponseStatus());
|
|
|
+ return;
|
|
|
+ }
|
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
|
assertEquals("incorrect number of elements", 1, json.length());
|
|
@@ -265,7 +333,6 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
assertEquals("incorrect number of elements", 5, array.length());
|
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("deprecation")
|
|
|
@Test
|
|
|
public void testSingleContainer() throws Exception {
|
|
|
ApplicationId appId = ApplicationId.newInstance(0, 1);
|
|
@@ -277,26 +344,31 @@ public class TestAHSWebServices extends JerseyTest {
|
|
|
r.path("ws").path("v1").path("applicationhistory").path("apps")
|
|
|
.path(appId.toString()).path("appattempts")
|
|
|
.path(appAttemptId.toString()).path("containers")
|
|
|
- .path(containerId.toString()).accept(MediaType.APPLICATION_JSON)
|
|
|
+ .path(containerId.toString())
|
|
|
+ .queryParam("user.name", USERS[round])
|
|
|
+ .accept(MediaType.APPLICATION_JSON)
|
|
|
.get(ClientResponse.class);
|
|
|
+ if (round == 1) {
|
|
|
+ assertEquals(
|
|
|
+ Status.FORBIDDEN, response.getClientResponseStatus());
|
|
|
+ return;
|
|
|
+ }
|
|
|
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
|
|
|
JSONObject json = response.getEntity(JSONObject.class);
|
|
|
assertEquals("incorrect number of elements", 1, json.length());
|
|
|
JSONObject container = json.getJSONObject("container");
|
|
|
assertEquals(containerId.toString(), container.getString("containerId"));
|
|
|
- assertEquals(containerId.toString(), container.getString("diagnosticsInfo"));
|
|
|
- assertEquals("0", container.getString("allocatedMB"));
|
|
|
- assertEquals("0", container.getString("allocatedVCores"));
|
|
|
- assertEquals(NodeId.newInstance("localhost", 0).toString(),
|
|
|
+ assertEquals("test diagnostics info", container.getString("diagnosticsInfo"));
|
|
|
+ assertEquals("-1", container.getString("allocatedMB"));
|
|
|
+ assertEquals("-1", container.getString("allocatedVCores"));
|
|
|
+ assertEquals(NodeId.newInstance("test host", 100).toString(),
|
|
|
container.getString("assignedNodeId"));
|
|
|
- assertEquals(Priority.newInstance(containerId.getId()).toString(),
|
|
|
- container.getString("priority"));
|
|
|
+ assertEquals("-1", container.getString("priority"));
|
|
|
Configuration conf = new YarnConfiguration();
|
|
|
assertEquals(WebAppUtils.getHttpSchemePrefix(conf) +
|
|
|
WebAppUtils.getAHSWebAppURLWithoutScheme(conf) +
|
|
|
- "/applicationhistory/logs/localhost:0/container_0_0001_01_000001/" +
|
|
|
- "container_0_0001_01_000001/test user",
|
|
|
- container.getString("logUrl"));
|
|
|
+ "/applicationhistory/logs/test host:100/container_0_0001_01_000001/" +
|
|
|
+ "container_0_0001_01_000001/user1", container.getString("logUrl"));
|
|
|
assertEquals(ContainerState.COMPLETE.toString(),
|
|
|
container.getString("containerState"));
|
|
|
}
|