Search in sources :

Example 6 with LoggingFilter

use of com.sun.jersey.api.client.filter.LoggingFilter 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 7 with LoggingFilter

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

the class TestRMWebServicesAppsModification method testUpdateAppTimeout.

@Test(timeout = 90000)
public void testUpdateAppTimeout() throws Exception {
    client().addFilter(new LoggingFilter(System.out));
    rm.start();
    rm.registerNode("127.0.0.1:1234", 2048);
    String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
    MediaType[] contentTypes = { MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE };
    for (String mediaType : mediaTypes) {
        for (MediaType contentType : contentTypes) {
            // application submitted without timeout
            RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
            ClientResponse response = this.constructWebResource("apps", app.getApplicationId().toString(), "timeouts").accept(mediaType).get(ClientResponse.class);
            if (mediaType.contains(MediaType.APPLICATION_JSON)) {
                assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
                JSONObject js = response.getEntity(JSONObject.class).getJSONObject("timeouts");
                JSONArray entity = js.getJSONArray("timeout");
                verifyAppTimeoutJson(entity.getJSONObject(0), ApplicationTimeoutType.LIFETIME, "UNLIMITED", -1);
            }
            long timeOutFromNow = 60;
            String expireTime = Times.formatISO8601(System.currentTimeMillis() + timeOutFromNow * 1000);
            Object entity = getAppTimeoutInfoEntity(ApplicationTimeoutType.LIFETIME, contentType, expireTime);
            response = this.constructWebResource("apps", app.getApplicationId().toString(), "timeout").entity(entity, contentType).accept(mediaType).put(ClientResponse.class);
            if (!isAuthenticationEnabled()) {
                assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
                continue;
            }
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            if (mediaType.contains(MediaType.APPLICATION_JSON)) {
                verifyAppTimeoutJson(response, ApplicationTimeoutType.LIFETIME, expireTime, timeOutFromNow);
            } else {
                verifyAppTimeoutXML(response, ApplicationTimeoutType.LIFETIME, expireTime, timeOutFromNow);
            }
            // verify for negative cases
            entity = getAppTimeoutInfoEntity(null, contentType, null);
            response = this.constructWebResource("apps", app.getApplicationId().toString(), "timeout").entity(entity, contentType).accept(mediaType).put(ClientResponse.class);
            assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
            // invoke get
            response = this.constructWebResource("apps", app.getApplicationId().toString(), "timeouts", ApplicationTimeoutType.LIFETIME.toString()).accept(mediaType).get(ClientResponse.class);
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            if (mediaType.contains(MediaType.APPLICATION_JSON)) {
                verifyAppTimeoutJson(response, ApplicationTimeoutType.LIFETIME, expireTime, timeOutFromNow);
            }
        }
    }
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) JSONObject(org.codehaus.jettison.json.JSONObject) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) JSONArray(org.codehaus.jettison.json.JSONArray) MediaType(javax.ws.rs.core.MediaType) JSONObject(org.codehaus.jettison.json.JSONObject) Test(org.junit.Test)

Example 8 with LoggingFilter

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

the class TestRMWebServicesAppsModification method testGetNewApplication.

// Simple test - just post to /apps/new-application and validate the response
@Test
public void testGetNewApplication() throws Exception {
    client().addFilter(new LoggingFilter(System.out));
    rm.start();
    String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
    for (String acceptMedia : mediaTypes) {
        testGetNewApplication(acceptMedia);
    }
    rm.stop();
}
Also used : LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) Test(org.junit.Test)

Example 9 with LoggingFilter

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

the class TestRMWebServicesAppsModification method testUpdateAppPriority.

@Test(timeout = 90000)
public void testUpdateAppPriority() throws Exception {
    client().addFilter(new LoggingFilter(System.out));
    if (!(rm.getResourceScheduler() instanceof CapacityScheduler)) {
        // till the fair scheduler modifications for priority is completed
        return;
    }
    CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
    Configuration conf = new Configuration();
    conf.setInt(YarnConfiguration.MAX_CLUSTER_LEVEL_APPLICATION_PRIORITY, 10);
    cs.setClusterMaxPriority(conf);
    // default root queue allows anyone to have admin acl
    CapacitySchedulerConfiguration csconf = new CapacitySchedulerConfiguration();
    String[] queues = { "default", "test" };
    csconf.setQueues("root", queues);
    csconf.setCapacity("root.default", 50.0f);
    csconf.setCapacity("root.test", 50.0f);
    csconf.setAcl("root", QueueACL.ADMINISTER_QUEUE, "someuser");
    csconf.setAcl("root.default", QueueACL.ADMINISTER_QUEUE, "someuser");
    csconf.setAcl("root.test", QueueACL.ADMINISTER_QUEUE, "someuser");
    rm.getResourceScheduler().reinitialize(csconf, rm.getRMContext());
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
    MediaType[] contentTypes = { MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE };
    for (String mediaType : mediaTypes) {
        for (MediaType contentType : contentTypes) {
            RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
            amNodeManager.nodeHeartbeat(true);
            int modifiedPriority = 8;
            AppPriority priority = new AppPriority(modifiedPriority);
            Object entity;
            if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
                entity = appPriorityToJSON(priority);
            } else {
                entity = priority;
            }
            ClientResponse response = this.constructWebResource("apps", app.getApplicationId().toString(), "priority").entity(entity, contentType).accept(mediaType).put(ClientResponse.class);
            if (!isAuthenticationEnabled()) {
                assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
                continue;
            }
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            if (mediaType.contains(MediaType.APPLICATION_JSON)) {
                verifyAppPriorityJson(response, modifiedPriority);
            } else {
                verifyAppPriorityXML(response, modifiedPriority);
            }
            response = this.constructWebResource("apps", app.getApplicationId().toString(), "priority").accept(mediaType).get(ClientResponse.class);
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            if (mediaType.contains(MediaType.APPLICATION_JSON)) {
                verifyAppPriorityJson(response, modifiedPriority);
            } else {
                verifyAppPriorityXML(response, modifiedPriority);
            }
            // check unauthorized
            app = rm.submitApp(CONTAINER_MB, "", "someuser");
            amNodeManager.nodeHeartbeat(true);
            response = this.constructWebResource("apps", app.getApplicationId().toString(), "priority").entity(entity, contentType).accept(mediaType).put(ClientResponse.class);
            assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
        }
    }
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) AppPriority(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppPriority) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) FairSchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration) JSONConfiguration(com.sun.jersey.api.json.JSONConfiguration) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) MediaType(javax.ws.rs.core.MediaType) JSONObject(org.codehaus.jettison.json.JSONObject) CapacityScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Test(org.junit.Test)

Example 10 with LoggingFilter

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

the class TestRMWebServicesAppsModification method testAppMove.

@Test(timeout = 90000)
public void testAppMove() throws Exception {
    client().addFilter(new LoggingFilter(System.out));
    boolean isCapacityScheduler = rm.getResourceScheduler() instanceof CapacityScheduler;
    // default root queue allows anyone to have admin acl
    CapacitySchedulerConfiguration csconf = new CapacitySchedulerConfiguration();
    String[] queues = { "default", "test" };
    csconf.setQueues("root", queues);
    csconf.setCapacity("root.default", 50.0f);
    csconf.setCapacity("root.test", 50.0f);
    csconf.setAcl("root", QueueACL.ADMINISTER_QUEUE, "someuser");
    csconf.setAcl("root.default", QueueACL.ADMINISTER_QUEUE, "someuser");
    csconf.setAcl("root.test", QueueACL.ADMINISTER_QUEUE, "someuser");
    rm.getResourceScheduler().reinitialize(csconf, rm.getRMContext());
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
    MediaType[] contentTypes = { MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE };
    for (String mediaType : mediaTypes) {
        for (MediaType contentType : contentTypes) {
            RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
            amNodeManager.nodeHeartbeat(true);
            AppQueue targetQueue = new AppQueue("test");
            Object entity;
            if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
                entity = appQueueToJSON(targetQueue);
            } else {
                entity = targetQueue;
            }
            ClientResponse response = this.constructWebResource("apps", app.getApplicationId().toString(), "queue").entity(entity, contentType).accept(mediaType).put(ClientResponse.class);
            if (!isAuthenticationEnabled()) {
                assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
                continue;
            }
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            String expectedQueue = "test";
            if (!isCapacityScheduler) {
                expectedQueue = "root.test";
            }
            if (mediaType.contains(MediaType.APPLICATION_JSON)) {
                verifyAppQueueJson(response, expectedQueue);
            } else {
                verifyAppQueueXML(response, expectedQueue);
            }
            Assert.assertEquals(expectedQueue, app.getQueue());
            // check unauthorized
            app = rm.submitApp(CONTAINER_MB, "", "someuser");
            amNodeManager.nodeHeartbeat(true);
            response = this.constructWebResource("apps", app.getApplicationId().toString(), "queue").entity(entity, contentType).accept(mediaType).put(ClientResponse.class);
            assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo());
            if (isCapacityScheduler) {
                Assert.assertEquals("default", app.getQueue());
            } else {
                Assert.assertEquals("root.someuser", app.getQueue());
            }
        }
    }
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) AppQueue(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppQueue) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) MediaType(javax.ws.rs.core.MediaType) JSONObject(org.codehaus.jettison.json.JSONObject) CapacityScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Test(org.junit.Test)

Aggregations

LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)12 ClientResponse (com.sun.jersey.api.client.ClientResponse)10 Test (org.junit.Test)9 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)5 WebResource (com.sun.jersey.api.client.WebResource)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 MediaType (javax.ws.rs.core.MediaType)3 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)3 CapacityScheduler (org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler)3 CapacitySchedulerConfiguration (org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ServletException (javax.servlet.ServletException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)2 DelegationToken (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.DelegationToken)2 JSONArray (org.codehaus.jettison.json.JSONArray)2 JSONException (org.codehaus.jettison.json.JSONException)2 SAXException (org.xml.sax.SAXException)2 WebServiceClient (code.satyagraha.gfm.support.api.WebServiceClient)1