Search in sources :

Example 1 with KillTaskAttemptRequest

use of org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptRequest in project hadoop by apache.

the class ClientServiceDelegate method killTask.

public boolean killTask(TaskAttemptID taskAttemptID, boolean fail) throws IOException {
    org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId attemptID = TypeConverter.toYarn(taskAttemptID);
    if (fail) {
        FailTaskAttemptRequest failRequest = recordFactory.newRecordInstance(FailTaskAttemptRequest.class);
        failRequest.setTaskAttemptId(attemptID);
        invoke("failTaskAttempt", FailTaskAttemptRequest.class, failRequest);
    } else {
        KillTaskAttemptRequest killRequest = recordFactory.newRecordInstance(KillTaskAttemptRequest.class);
        killRequest.setTaskAttemptId(attemptID);
        invoke("killTaskAttempt", KillTaskAttemptRequest.class, killRequest);
    }
    return true;
}
Also used : KillTaskAttemptRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptRequest) FailTaskAttemptRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.FailTaskAttemptRequest)

Example 2 with KillTaskAttemptRequest

use of org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptRequest 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)

Example 3 with KillTaskAttemptRequest

use of org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptRequest in project hadoop by apache.

the class TestMRClientService method testViewAclOnlyCannotModify.

@Test
public void testViewAclOnlyCannotModify() throws Exception {
    final MRAppWithClientService app = new MRAppWithClientService(1, 0, false);
    final Configuration conf = new Configuration();
    conf.setBoolean(MRConfig.MR_ACLS_ENABLED, true);
    conf.set(MRJobConfig.JOB_ACL_VIEW_JOB, "viewonlyuser");
    Job job = app.submit(conf);
    app.waitForState(job, JobState.RUNNING);
    Assert.assertEquals("Num tasks not correct", 1, job.getTasks().size());
    Iterator<Task> it = job.getTasks().values().iterator();
    Task task = it.next();
    app.waitForState(task, TaskState.RUNNING);
    TaskAttempt attempt = task.getAttempts().values().iterator().next();
    app.waitForState(attempt, TaskAttemptState.RUNNING);
    UserGroupInformation viewOnlyUser = UserGroupInformation.createUserForTesting("viewonlyuser", new String[] {});
    Assert.assertTrue("viewonlyuser cannot view job", job.checkAccess(viewOnlyUser, JobACL.VIEW_JOB));
    Assert.assertFalse("viewonlyuser can modify job", job.checkAccess(viewOnlyUser, JobACL.MODIFY_JOB));
    MRClientProtocol client = viewOnlyUser.doAs(new PrivilegedExceptionAction<MRClientProtocol>() {

        @Override
        public MRClientProtocol run() throws Exception {
            YarnRPC rpc = YarnRPC.create(conf);
            return (MRClientProtocol) rpc.getProxy(MRClientProtocol.class, app.clientService.getBindAddress(), conf);
        }
    });
    KillJobRequest killJobRequest = recordFactory.newRecordInstance(KillJobRequest.class);
    killJobRequest.setJobId(app.getJobId());
    try {
        client.killJob(killJobRequest);
        fail("viewonlyuser killed job");
    } catch (AccessControlException e) {
    // pass
    }
    KillTaskRequest killTaskRequest = recordFactory.newRecordInstance(KillTaskRequest.class);
    killTaskRequest.setTaskId(task.getID());
    try {
        client.killTask(killTaskRequest);
        fail("viewonlyuser killed task");
    } catch (AccessControlException e) {
    // pass
    }
    KillTaskAttemptRequest killTaskAttemptRequest = recordFactory.newRecordInstance(KillTaskAttemptRequest.class);
    killTaskAttemptRequest.setTaskAttemptId(attempt.getID());
    try {
        client.killTaskAttempt(killTaskAttemptRequest);
        fail("viewonlyuser killed task attempt");
    } catch (AccessControlException e) {
    // pass
    }
    FailTaskAttemptRequest failTaskAttemptRequest = recordFactory.newRecordInstance(FailTaskAttemptRequest.class);
    failTaskAttemptRequest.setTaskAttemptId(attempt.getID());
    try {
        client.failTaskAttempt(failTaskAttemptRequest);
        fail("viewonlyuser killed task attempt");
    } catch (AccessControlException e) {
    // pass
    }
}
Also used : Task(org.apache.hadoop.mapreduce.v2.app.job.Task) Configuration(org.apache.hadoop.conf.Configuration) FailTaskAttemptRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.FailTaskAttemptRequest) AccessControlException(org.apache.hadoop.security.AccessControlException) YarnRPC(org.apache.hadoop.yarn.ipc.YarnRPC) IOException(java.io.IOException) AccessControlException(org.apache.hadoop.security.AccessControlException) MRClientProtocol(org.apache.hadoop.mapreduce.v2.api.MRClientProtocol) KillTaskAttemptRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptRequest) KillJobRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillJobRequest) KillTaskRequest(org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskRequest) TaskAttempt(org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Aggregations

KillTaskAttemptRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptRequest)3 IOException (java.io.IOException)2 FailTaskAttemptRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.FailTaskAttemptRequest)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 AccessControlException (java.security.AccessControlException)1 Configuration (org.apache.hadoop.conf.Configuration)1 MRClientProtocol (org.apache.hadoop.mapreduce.v2.api.MRClientProtocol)1 KillJobRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillJobRequest)1 KillTaskAttemptResponse (org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptResponse)1 KillTaskRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskRequest)1 KillTaskAttemptRequestPBImpl (org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillTaskAttemptRequestPBImpl)1 TaskAttemptId (org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId)1 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)1 Task (org.apache.hadoop.mapreduce.v2.app.job.Task)1 TaskAttempt (org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt)1 JobTaskAttemptState (org.apache.hadoop.mapreduce.v2.app.webapp.dao.JobTaskAttemptState)1 AccessControlException (org.apache.hadoop.security.AccessControlException)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 YarnRPC (org.apache.hadoop.yarn.ipc.YarnRPC)1