Search in sources :

Example 1 with AppState

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState 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 2 with AppState

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState 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 3 with AppState

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

the class TestRMWebServicesAppsModification method testSingleAppKillInvalidId.

@Test
public void testSingleAppKillInvalidId() throws Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    amNodeManager.nodeHeartbeat(true);
    String[] testAppIds = { "application_1391705042196_0001", "random_string" };
    for (int i = 0; i < testAppIds.length; i++) {
        AppState info = new AppState("KILLED");
        ClientResponse response = this.constructWebResource("apps", testAppIds[i], "state").accept(MediaType.APPLICATION_XML).entity(info, MediaType.APPLICATION_XML).put(ClientResponse.class);
        if (!isAuthenticationEnabled()) {
            assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
            continue;
        }
        if (i == 0) {
            assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
        } else {
            assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
        }
    }
    rm.stop();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) 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) Test(org.junit.Test)

Example 4 with AppState

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

the class RMWebServices method updateAppState.

// can't return POJO because we can't control the status code
// it's always set to 200 when we need to allow it to be set
// to 202
@PUT
@Path("/apps/{appid}/state")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateAppState(AppState targetState, @Context HttpServletRequest hsr, @PathParam("appid") String appId) throws AuthorizationException, YarnException, InterruptedException, IOException {
    init();
    UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true);
    if (callerUGI == null) {
        String msg = "Unable to obtain user name, user not authenticated";
        throw new AuthorizationException(msg);
    }
    if (UserGroupInformation.isSecurityEnabled() && isStaticUser(callerUGI)) {
        String msg = "The default static user cannot carry out this operation.";
        return Response.status(Status.FORBIDDEN).entity(msg).build();
    }
    String userName = callerUGI.getUserName();
    RMApp app = null;
    try {
        app = getRMAppForAppId(appId);
    } catch (NotFoundException e) {
        RMAuditLogger.logFailure(userName, AuditConstants.KILL_APP_REQUEST, "UNKNOWN", "RMWebService", "Trying to kill an absent application " + appId);
        throw e;
    }
    if (!app.getState().toString().equals(targetState.getState())) {
        if (targetState.getState().equals(YarnApplicationState.KILLED.toString())) {
            return killApp(app, callerUGI, hsr, targetState.getDiagnostics());
        }
        throw new BadRequestException("Only '" + YarnApplicationState.KILLED.toString() + "' is allowed as a target state.");
    }
    AppState ret = new AppState();
    ret.setState(app.getState().toString());
    return Response.status(Status.OK).entity(ret).build();
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) AppState(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 5 with AppState

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

the class RMWebServices method getAppState.

@GET
@Path("/apps/{appid}/state")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public AppState getAppState(@Context HttpServletRequest hsr, @PathParam("appid") String appId) throws AuthorizationException {
    init();
    UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true);
    String userName = "";
    if (callerUGI != null) {
        userName = callerUGI.getUserName();
    }
    RMApp app = null;
    try {
        app = getRMAppForAppId(appId);
    } catch (NotFoundException e) {
        RMAuditLogger.logFailure(userName, AuditConstants.GET_APP_STATE, "UNKNOWN", "RMWebService", "Trying to get state of an absent application " + appId);
        throw e;
    }
    AppState ret = new AppState();
    ret.setState(app.getState().toString());
    return ret;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) AppState(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

AppState (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState)7 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)4 RMAppState (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState)4 Test (org.junit.Test)4 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 MediaType (javax.ws.rs.core.MediaType)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Client (com.sun.jersey.api.client.Client)1 WebResource (com.sun.jersey.api.client.WebResource)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 AccessControlException (java.security.AccessControlException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1