Search in sources :

Example 86 with MockNM

use of org.apache.hadoop.yarn.server.resourcemanager.MockNM in project hadoop by apache.

the class TestRMWebServicesAppsModification method testSingleAppState.

@Test
public void testSingleAppState() throws Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
    for (String mediaType : mediaTypes) {
        RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
        amNodeManager.nodeHeartbeat(true);
        ClientResponse response = this.constructWebResource("apps", app.getApplicationId().toString(), "state").accept(mediaType).get(ClientResponse.class);
        assertResponseStatusCode(Status.OK, response.getStatusInfo());
        if (mediaType.contains(MediaType.APPLICATION_JSON)) {
            verifyAppStateJson(response, RMAppState.ACCEPTED);
        } else if (mediaType.contains(MediaType.APPLICATION_XML)) {
            verifyAppStateXML(response, RMAppState.ACCEPTED);
        }
    }
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) Test(org.junit.Test)

Example 87 with MockNM

use of org.apache.hadoop.yarn.server.resourcemanager.MockNM in project hadoop by apache.

the class TestRMWebServicesAppsModification method testSingleAppKill.

@Test(timeout = 120000)
public void testSingleAppKill() throws Exception {
    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 };
    String diagnostic = "message1";
    for (String mediaType : mediaTypes) {
        for (MediaType contentType : contentTypes) {
            RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
            amNodeManager.nodeHeartbeat(true);
            AppState targetState = new AppState(YarnApplicationState.KILLED.toString());
            targetState.setDiagnostics(diagnostic);
            Object entity;
            if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
                entity = appStateToJSON(targetState);
            } else {
                entity = targetState;
            }
            ClientResponse response = this.constructWebResource("apps", app.getApplicationId().toString(), "state").entity(entity, contentType).accept(mediaType).put(ClientResponse.class);
            if (!isAuthenticationEnabled()) {
                assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
                continue;
            }
            assertResponseStatusCode(Status.ACCEPTED, response.getStatusInfo());
            if (mediaType.contains(MediaType.APPLICATION_JSON)) {
                verifyAppStateJson(response, RMAppState.FINAL_SAVING, RMAppState.KILLED, RMAppState.KILLING, RMAppState.ACCEPTED);
            } else {
                verifyAppStateXML(response, RMAppState.FINAL_SAVING, RMAppState.KILLED, RMAppState.KILLING, RMAppState.ACCEPTED);
            }
            String locationHeaderValue = response.getHeaders().getFirst(HttpHeaders.LOCATION);
            Client c = Client.create();
            WebResource tmp = c.resource(locationHeaderValue);
            if (isAuthenticationEnabled()) {
                tmp = tmp.queryParam("user.name", webserviceUserName);
            }
            response = tmp.get(ClientResponse.class);
            assertResponseStatusCode(Status.OK, response.getStatusInfo());
            assertTrue(locationHeaderValue.endsWith("/ws/v1/cluster/apps/" + app.getApplicationId().toString() + "/state"));
            while (true) {
                Thread.sleep(100);
                response = this.constructWebResource("apps", app.getApplicationId().toString(), "state").accept(mediaType).entity(entity, contentType).put(ClientResponse.class);
                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);
                    } else {
                        verifyAppStateXML(response, RMAppState.KILLED);
                    }
                    assertTrue("Diagnostic message is incorrect", app.getDiagnostics().toString().contains(diagnostic));
                    break;
                }
            }
        }
    }
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) MediaType(javax.ws.rs.core.MediaType) WebResource(com.sun.jersey.api.client.WebResource) JSONObject(org.codehaus.jettison.json.JSONObject) RMAppState(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState) AppState(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState) Client(com.sun.jersey.api.client.Client) Test(org.junit.Test)

Example 88 with MockNM

use of org.apache.hadoop.yarn.server.resourcemanager.MockNM in project hadoop by apache.

the class TestRMWebServicesAppsModification method testSingleAppKillUnauthorized.

@Test(timeout = 60000)
public void testSingleAppKillUnauthorized() throws Exception {
    boolean isCapacityScheduler = rm.getResourceScheduler() instanceof CapacityScheduler;
    boolean isFairScheduler = rm.getResourceScheduler() instanceof FairScheduler;
    assumeTrue("This test is only supported on Capacity and Fair Scheduler", isCapacityScheduler || isFairScheduler);
    // FairScheduler use ALLOCATION_FILE to configure ACL
    if (isCapacityScheduler) {
        // default root queue allows anyone to have admin acl
        CapacitySchedulerConfiguration csconf = new CapacitySchedulerConfiguration();
        csconf.setAcl("root", QueueACL.ADMINISTER_QUEUE, "someuser");
        csconf.setAcl("root.default", 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 };
    for (String mediaType : mediaTypes) {
        RMApp app = rm.submitApp(CONTAINER_MB, "test", "someuser");
        amNodeManager.nodeHeartbeat(true);
        ClientResponse response = this.constructWebResource("apps", app.getApplicationId().toString(), "state").accept(mediaType).get(ClientResponse.class);
        AppState info = response.getEntity(AppState.class);
        info.setState(YarnApplicationState.KILLED.toString());
        response = this.constructWebResource("apps", app.getApplicationId().toString(), "state").accept(mediaType).entity(info, MediaType.APPLICATION_XML).put(ClientResponse.class);
        validateResponseStatus(response, Status.FORBIDDEN);
    }
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) FairScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) RMAppState(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState) AppState(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState) 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 89 with MockNM

use of org.apache.hadoop.yarn.server.resourcemanager.MockNM in project hadoop by apache.

the class TestRMWebServicesApps method testAppAttemptsSlash.

@Test
public void testAppAttemptsSlash() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    RMApp app1 = rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    testAppAttemptsHelper(app1.getApplicationId().toString() + "/", app1, MediaType.APPLICATION_JSON);
    rm.stop();
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) Test(org.junit.Test)

Example 90 with MockNM

use of org.apache.hadoop.yarn.server.resourcemanager.MockNM in project hadoop by apache.

the class TestRMWebServicesApps method testSingleAppsSlash.

@Test
public void testSingleAppsSlash() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    RMApp app1 = rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    testSingleAppsHelper(app1.getApplicationId().toString() + "/", app1, MediaType.APPLICATION_JSON);
    rm.stop();
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) Test(org.junit.Test)

Aggregations

MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)224 Test (org.junit.Test)218 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)196 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)128 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)127 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)79 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)69 FiCaSchedulerApp (org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp)48 ClientResponse (com.sun.jersey.api.client.ClientResponse)47 Configuration (org.apache.hadoop.conf.Configuration)47 WebResource (com.sun.jersey.api.client.WebResource)39 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)38 RMNode (org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode)37 JSONObject (org.codehaus.jettison.json.JSONObject)37 NodeUpdateSchedulerEvent (org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeUpdateSchedulerEvent)36 DrainDispatcher (org.apache.hadoop.yarn.event.DrainDispatcher)33 Container (org.apache.hadoop.yarn.api.records.Container)29 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)28 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)23 RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)22