Search in sources :

Example 91 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project hadoop by apache.

the class TestRMWebServicesApps method testInvalidApp.

@Test
public void testInvalidApp() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    WebResource r = resource();
    try {
        r.path("ws").path("v1").path("cluster").path("apps").path("application_invalid_12").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
        fail("should have thrown exception on invalid appid");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject msg = response.getEntity(JSONObject.class);
        JSONObject exception = msg.getJSONObject("RemoteException");
        assertEquals("incorrect number of elements", 3, exception.length());
        String message = exception.getString("message");
        String type = exception.getString("exception");
        String classname = exception.getString("javaClassName");
        WebServicesTestUtils.checkStringMatch("exception message", "java.lang.IllegalArgumentException: Invalid ApplicationId:" + " application_invalid_12", message);
        WebServicesTestUtils.checkStringMatch("exception type", "BadRequestException", type);
        WebServicesTestUtils.checkStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
    } finally {
        rm.stop();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.codehaus.jettison.json.JSONObject) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 92 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project hadoop by apache.

the class TestRMWebServicesDelegationTokens method verifyKerberosAuthCreate.

private void verifyKerberosAuthCreate(String mType, String cType, String reqBody, String renUser) throws Exception {
    final String mediaType = mType;
    final String contentType = cType;
    final String body = reqBody;
    final String renewer = renUser;
    KerberosTestUtils.doAsClient(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            ClientResponse response = resource().path("ws").path("v1").path("cluster").path("delegation-token").accept(contentType).entity(body, mediaType).post(ClientResponse.class);
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            DelegationToken tok = getDelegationTokenFromResponse(response);
            assertFalse(tok.getToken().isEmpty());
            Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>();
            token.decodeFromUrlString(tok.getToken());
            assertEquals(renewer, token.decodeIdentifier().getRenewer().toString());
            assertValidRMToken(tok.getToken());
            DelegationToken dtoken = new DelegationToken();
            response = resource().path("ws").path("v1").path("cluster").path("delegation-token").accept(contentType).entity(dtoken, mediaType).post(ClientResponse.class);
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            tok = getDelegationTokenFromResponse(response);
            assertFalse(tok.getToken().isEmpty());
            token = new Token<RMDelegationTokenIdentifier>();
            token.decodeFromUrlString(tok.getToken());
            assertEquals("", token.decodeIdentifier().getRenewer().toString());
            assertValidRMToken(tok.getToken());
            return null;
        }
    });
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) DelegationToken(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.DelegationToken) InvalidToken(org.apache.hadoop.security.token.SecretManager.InvalidToken) Token(org.apache.hadoop.security.token.Token) DelegationToken(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.DelegationToken) RMDelegationTokenIdentifier(org.apache.hadoop.yarn.security.client.RMDelegationTokenIdentifier) ServletException(javax.servlet.ServletException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) JSONException(org.codehaus.jettison.json.JSONException)

Example 93 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project hadoop by apache.

the class TestRMWebServicesDelegationTokens method testCancelDelegationToken.

// Test to verify cancel functionality - create a token and then try to cancel
// it. The owner and renewer should succeed; third user should fail
@Test
public void testCancelDelegationToken() throws Exception {
    rm.start();
    this.client().addFilter(new LoggingFilter(System.out));
    if (isKerberosAuth == false) {
        verifySimpleAuthCancel();
        return;
    }
    final DelegationToken dtoken = new DelegationToken();
    String renewer = "client2";
    dtoken.setRenewer(renewer);
    String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
    for (final String mediaType : mediaTypes) {
        for (final String contentType : mediaTypes) {
            // owner should be able to cancel delegation token
            KerberosTestUtils.doAsClient(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    ClientResponse response = resource().path("ws").path("v1").path("cluster").path("delegation-token").accept(contentType).entity(dtoken, mediaType).post(ClientResponse.class);
                    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);
                    assertResponseStatusCode(Status.OK, response.getStatusInfo());
                    assertTokenCancelled(tok.getToken());
                    return null;
                }
            });
            // renewer should be able to cancel token
            final DelegationToken tmpToken = KerberosTestUtils.doAsClient(new Callable<DelegationToken>() {

                @Override
                public DelegationToken call() throws Exception {
                    ClientResponse response = resource().path("ws").path("v1").path("cluster").path("delegation-token").accept(contentType).entity(dtoken, mediaType).post(ClientResponse.class);
                    assertResponseStatusCode(Status.OK, response.getStatusInfo());
                    DelegationToken tok = getDelegationTokenFromResponse(response);
                    return tok;
                }
            });
            KerberosTestUtils.doAs(renewer, new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    ClientResponse response = resource().path("ws").path("v1").path("cluster").path("delegation-token").header(yarnTokenHeader, tmpToken.getToken()).accept(contentType).delete(ClientResponse.class);
                    assertResponseStatusCode(Status.OK, response.getStatusInfo());
                    assertTokenCancelled(tmpToken.getToken());
                    return null;
                }
            });
            // third user should not be able to cancel token
            final DelegationToken tmpToken2 = KerberosTestUtils.doAsClient(new Callable<DelegationToken>() {

                @Override
                public DelegationToken call() throws Exception {
                    ClientResponse response = resource().path("ws").path("v1").path("cluster").path("delegation-token").accept(contentType).entity(dtoken, mediaType).post(ClientResponse.class);
                    assertResponseStatusCode(Status.OK, response.getStatusInfo());
                    DelegationToken tok = getDelegationTokenFromResponse(response);
                    return tok;
                }
            });
            KerberosTestUtils.doAs("client3", new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    ClientResponse response = resource().path("ws").path("v1").path("cluster").path("delegation-token").header(yarnTokenHeader, tmpToken2.getToken()).accept(contentType).delete(ClientResponse.class);
                    assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
                    assertValidRMToken(tmpToken2.getToken());
                    return null;
                }
            });
            testCancelTokenBadRequests(mediaType, contentType);
        }
    }
    rm.stop();
    return;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) DelegationToken(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.DelegationToken) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) ServletException(javax.servlet.ServletException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) JSONException(org.codehaus.jettison.json.JSONException) Test(org.junit.Test)

Example 94 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project hadoop by apache.

the class TestRMWebServicesFairScheduler method testClusterSchedulerSlash.

@Test
public void testClusterSchedulerSlash() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler/").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    verifyClusterScheduler(json);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 95 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project hadoop by apache.

the class TestRMWebServicesForCSWithPartitions method testSchedulerPartitions.

@Test
public void testSchedulerPartitions() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    verifySchedulerInfoJson(json);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Aggregations

ClientResponse (com.sun.jersey.api.client.ClientResponse)1970 Test (org.junit.Test)1136 WebResource (com.sun.jersey.api.client.WebResource)674 JSONObject (org.codehaus.jettison.json.JSONObject)412 URI (java.net.URI)292 Client (com.sun.jersey.api.client.Client)117 HashMap (java.util.HashMap)112 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)110 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)103 ArrayList (java.util.ArrayList)97 JSONArray (org.codehaus.jettison.json.JSONArray)81 IOException (java.io.IOException)78 InputStream (java.io.InputStream)77 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)76 JSONException (org.codehaus.jettison.json.JSONException)58 List (java.util.List)56 Gson (com.google.gson.Gson)52 JavaResult (org.milyn.payload.JavaResult)52 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)49 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)47