Search in sources :

Example 6 with AppState

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

the class TestRMWebServicesAppsModification method testSingleAppKillInvalidState.

@Test
public void testSingleAppKillInvalidState() 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[] targetStates = { YarnApplicationState.FINISHED.toString(), "blah" };
    for (String mediaType : mediaTypes) {
        for (MediaType contentType : contentTypes) {
            for (String targetStateString : targetStates) {
                RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
                amNodeManager.nodeHeartbeat(true);
                ClientResponse response;
                AppState targetState = new AppState(targetStateString);
                Object entity;
                if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
                    entity = appStateToJSON(targetState);
                } else {
                    entity = targetState;
                }
                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.BAD_REQUEST, response.getStatusInfo());
            }
        }
    }
    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) 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) Test(org.junit.Test)

Example 7 with AppState

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

the class RMWebServices method killApp.

protected Response killApp(RMApp app, UserGroupInformation callerUGI, HttpServletRequest hsr, String diagnostic) throws IOException, InterruptedException {
    if (app == null) {
        throw new IllegalArgumentException("app cannot be null");
    }
    String userName = callerUGI.getUserName();
    final ApplicationId appid = app.getApplicationId();
    KillApplicationResponse resp = null;
    try {
        resp = callerUGI.doAs(new PrivilegedExceptionAction<KillApplicationResponse>() {

            @Override
            public KillApplicationResponse run() throws IOException, YarnException {
                KillApplicationRequest req = KillApplicationRequest.newInstance(appid);
                if (diagnostic != null) {
                    req.setDiagnostics(diagnostic);
                }
                return rm.getClientRMService().forceKillApplication(req);
            }
        });
    } catch (UndeclaredThrowableException ue) {
        // bubble that up to the user
        if (ue.getCause() instanceof YarnException) {
            YarnException ye = (YarnException) ue.getCause();
            if (ye.getCause() instanceof AccessControlException) {
                String appId = app.getApplicationId().toString();
                String msg = "Unauthorized attempt to kill appid " + appId + " by remote user " + userName;
                return Response.status(Status.FORBIDDEN).entity(msg).build();
            } else {
                throw ue;
            }
        } else {
            throw ue;
        }
    }
    AppState ret = new AppState();
    ret.setState(app.getState().toString());
    if (resp.getIsKillCompleted()) {
        RMAuditLogger.logSuccess(userName, AuditConstants.KILL_APP_REQUEST, "RMWebService", app.getApplicationId());
    } else {
        return Response.status(Status.ACCEPTED).entity(ret).header(HttpHeaders.LOCATION, hsr.getRequestURL()).build();
    }
    return Response.status(Status.OK).entity(ret).build();
}
Also used : KillApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationResponse) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) AccessControlException(java.security.AccessControlException) KillApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.KillApplicationRequest) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) AppState(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

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