Search in sources :

Example 6 with ApplicationSubmissionContextInfo

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo in project hadoop by apache.

the class TestRMWebappAuthentication method testAnonymousSimpleUser.

private void testAnonymousSimpleUser() throws Exception {
    ApplicationSubmissionContextInfo app = new ApplicationSubmissionContextInfo();
    String appid = "application_123_0";
    app.setApplicationId(appid);
    String requestBody = TestRMWebServicesDelegationTokenAuthentication.getMarshalledAppInfo(app);
    URL url = new URL("http://localhost:8088/ws/v1/cluster/apps");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    TestRMWebServicesDelegationTokenAuthentication.setupConn(conn, "POST", "application/xml", requestBody);
    conn.getInputStream();
    assertEquals(Status.ACCEPTED.getStatusCode(), conn.getResponseCode());
    boolean appExists = rm.getRMContext().getRMApps().containsKey(ApplicationId.fromString(appid));
    assertTrue(appExists);
    RMApp actualApp = rm.getRMContext().getRMApps().get(ApplicationId.fromString(appid));
    String owner = actualApp.getUser();
    assertEquals(rm.getConfig().get(CommonConfigurationKeys.HADOOP_HTTP_STATIC_USER, CommonConfigurationKeys.DEFAULT_HADOOP_HTTP_STATIC_USER), owner);
    appid = "application_123_1";
    app.setApplicationId(appid);
    requestBody = TestRMWebServicesDelegationTokenAuthentication.getMarshalledAppInfo(app);
    url = new URL("http://localhost:8088/ws/v1/cluster/apps?user.name=client");
    conn = (HttpURLConnection) url.openConnection();
    TestRMWebServicesDelegationTokenAuthentication.setupConn(conn, "POST", MediaType.APPLICATION_XML, requestBody);
    conn.getInputStream();
    appExists = rm.getRMContext().getRMApps().containsKey(ApplicationId.fromString(appid));
    assertTrue(appExists);
    actualApp = rm.getRMContext().getRMApps().get(ApplicationId.fromString(appid));
    owner = actualApp.getUser();
    assertEquals("client", owner);
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) HttpURLConnection(java.net.HttpURLConnection) ApplicationSubmissionContextInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo) URL(java.net.URL)

Example 7 with ApplicationSubmissionContextInfo

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo in project hadoop by apache.

the class TestRMWebServicesDelegationTokenAuthentication method testDelegationTokenAuth.

// Test that you can authenticate with only delegation tokens
// 1. Get a delegation token using Kerberos auth(this ends up
// testing the fallback authenticator)
// 2. Submit an app without kerberos or delegation-token
// - we should get an UNAUTHORIZED response
// 3. Submit same app with delegation-token
// - we should get OK response
// - confirm owner of the app is the user whose
// delegation-token we used
@Test
public void testDelegationTokenAuth() throws Exception {
    final String token = getDelegationToken("test");
    ApplicationSubmissionContextInfo app = new ApplicationSubmissionContextInfo();
    String appid = "application_123_0";
    app.setApplicationId(appid);
    String requestBody = getMarshalledAppInfo(app);
    URL url = new URL("http://localhost:8088/ws/v1/cluster/apps");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    setupConn(conn, "POST", "application/xml", requestBody);
    // auth is kerberos or delegation token
    try {
        conn.getInputStream();
        fail("we should not be here");
    } catch (IOException e) {
        assertEquals(Status.UNAUTHORIZED.getStatusCode(), conn.getResponseCode());
    }
    conn = (HttpURLConnection) url.openConnection();
    conn.setRequestProperty(delegationTokenHeader, token);
    setupConn(conn, "POST", MediaType.APPLICATION_XML, requestBody);
    // this should not fail
    try {
        conn.getInputStream();
    } catch (IOException ie) {
        InputStream errorStream = conn.getErrorStream();
        String error = "";
        BufferedReader reader = null;
        reader = new BufferedReader(new InputStreamReader(errorStream, "UTF8"));
        for (String line; (line = reader.readLine()) != null; ) {
            error += line;
        }
        reader.close();
        errorStream.close();
        fail("Response " + conn.getResponseCode() + "; " + error);
    }
    boolean appExists = rm.getRMContext().getRMApps().containsKey(ApplicationId.fromString(appid));
    assertTrue(appExists);
    RMApp actualApp = rm.getRMContext().getRMApps().get(ApplicationId.fromString(appid));
    String owner = actualApp.getUser();
    assertEquals("client", owner);
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ApplicationSubmissionContextInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo) URL(java.net.URL) Test(org.junit.Test)

Example 8 with ApplicationSubmissionContextInfo

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo in project hadoop by apache.

the class TestRMWebServicesAppsModification method testAppSubmitBadJsonAndXML.

@Test
public void testAppSubmitBadJsonAndXML() throws Exception {
    // submit a bunch of bad XML and JSON via the
    // REST API and make sure we get error response codes
    String urlPath = "apps";
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    amNodeManager.nodeHeartbeat(true);
    ApplicationSubmissionContextInfo appInfo = new ApplicationSubmissionContextInfo();
    appInfo.setApplicationName("test");
    appInfo.setPriority(3);
    appInfo.setMaxAppAttempts(2);
    appInfo.setQueue("testqueue");
    appInfo.setApplicationType("test-type");
    HashMap<String, LocalResourceInfo> lr = new HashMap<>();
    LocalResourceInfo y = new LocalResourceInfo();
    y.setUrl(new URI("http://www.test.com/file.txt"));
    y.setSize(100);
    y.setTimestamp(System.currentTimeMillis());
    y.setType(LocalResourceType.FILE);
    y.setVisibility(LocalResourceVisibility.APPLICATION);
    lr.put("example", y);
    appInfo.getContainerLaunchContextInfo().setResources(lr);
    appInfo.getResource().setMemory(1024);
    appInfo.getResource().setvCores(1);
    String body = "<?xml version=\"1.0\" encoding=\"UTF-8\" " + "standalone=\"yes\"?><blah/>";
    ClientResponse response = this.constructWebResource(urlPath).accept(MediaType.APPLICATION_XML).entity(body, MediaType.APPLICATION_XML).post(ClientResponse.class);
    assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
    body = "{\"a\" : \"b\"}";
    response = this.constructWebResource(urlPath).accept(MediaType.APPLICATION_XML).entity(body, MediaType.APPLICATION_JSON).post(ClientResponse.class);
    validateResponseStatus(response, Status.BAD_REQUEST);
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) LocalResourceInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LocalResourceInfo) HashMap(java.util.HashMap) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) ApplicationSubmissionContextInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo) URI(java.net.URI) Test(org.junit.Test)

Aggregations

ApplicationSubmissionContextInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo)8 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 IOException (java.io.IOException)4 Test (org.junit.Test)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 HashMap (java.util.HashMap)3 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)3 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URI (java.net.URI)2 LocalResourceInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LocalResourceInfo)2 WebResource (com.sun.jersey.api.client.WebResource)1 LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1