Search in sources :

Example 1 with KillTaskAttemptRequestPBImpl

use of org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillTaskAttemptRequestPBImpl in project hadoop by apache.

the class AMWebServices method killJobTaskAttempt.

protected Response killJobTaskAttempt(TaskAttempt ta, UserGroupInformation callerUGI, HttpServletRequest hsr) throws IOException, InterruptedException {
    Preconditions.checkNotNull(ta, "ta cannot be null");
    String userName = callerUGI.getUserName();
    final TaskAttemptId attemptId = ta.getID();
    try {
        callerUGI.doAs(new PrivilegedExceptionAction<KillTaskAttemptResponse>() {

            @Override
            public KillTaskAttemptResponse run() throws IOException, YarnException {
                KillTaskAttemptRequest req = new KillTaskAttemptRequestPBImpl();
                req.setTaskAttemptId(attemptId);
                return service.forceKillTaskAttempt(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 taId = attemptId.toString();
                String msg = "Unauthorized attempt to kill task attempt " + taId + " by remote user " + userName;
                return Response.status(Status.FORBIDDEN).entity(msg).build();
            } else {
                throw ue;
            }
        } else {
            throw ue;
        }
    }
    JobTaskAttemptState ret = new JobTaskAttemptState();
    ret.setState(TaskAttemptState.KILLED.toString());
    return Response.status(Status.OK).entity(ret).build();
}
Also used : KillTaskAttemptRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptRequest) JobTaskAttemptState(org.apache.hadoop.mapreduce.v2.app.webapp.dao.JobTaskAttemptState) KillTaskAttemptRequestPBImpl(org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillTaskAttemptRequestPBImpl) TaskAttemptId(org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) KillTaskAttemptResponse(org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptResponse)

Aggregations

IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 AccessControlException (java.security.AccessControlException)1 KillTaskAttemptRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptRequest)1 KillTaskAttemptResponse (org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptResponse)1 KillTaskAttemptRequestPBImpl (org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillTaskAttemptRequestPBImpl)1 TaskAttemptId (org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId)1 JobTaskAttemptState (org.apache.hadoop.mapreduce.v2.app.webapp.dao.JobTaskAttemptState)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1