Search in sources :

Example 51 with MRApp

use of org.apache.hadoop.mapreduce.v2.app.MRApp in project hadoop by apache.

the class TestMRApp method testJobRebootOnLastRetryOnUnregistrationFailure.

@Test
public void testJobRebootOnLastRetryOnUnregistrationFailure() throws Exception {
    // make startCount as 2 since this is last retry which equals to
    // DEFAULT_MAX_AM_RETRY
    // The last param mocks the unregistration failure
    MRApp app = new MRApp(1, 0, false, this.getClass().getName(), true, 2, false);
    Configuration conf = new Configuration();
    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);
    //send an reboot event
    app.getContext().getEventHandler().handle(new JobEvent(job.getID(), JobEventType.JOB_AM_REBOOT));
    app.waitForInternalState((JobImpl) job, JobStateInternal.REBOOT);
    // return exteranl state as RUNNING if this is the last retry while
    // unregistration fails
    app.waitForState(job, JobState.RUNNING);
}
Also used : Task(org.apache.hadoop.mapreduce.v2.app.job.Task) Configuration(org.apache.hadoop.conf.Configuration) JobEvent(org.apache.hadoop.mapreduce.v2.app.job.event.JobEvent) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) Test(org.junit.Test)

Example 52 with MRApp

use of org.apache.hadoop.mapreduce.v2.app.MRApp in project hadoop by apache.

the class TestMRApp method testMapReduce.

@Test
public void testMapReduce() throws Exception {
    MRApp app = new MRApp(2, 2, true, this.getClass().getName(), true);
    Job job = app.submit(new Configuration());
    app.waitForState(job, JobState.SUCCEEDED);
    app.verifyCompleted();
    Assert.assertEquals(System.getProperty("user.name"), job.getUserName());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) Test(org.junit.Test)

Example 53 with MRApp

use of org.apache.hadoop.mapreduce.v2.app.MRApp in project hadoop by apache.

the class TestMRApp method testJobError.

@Test
public void testJobError() throws Exception {
    MRApp app = new MRApp(1, 0, false, this.getClass().getName(), true);
    Job job = app.submit(new Configuration());
    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);
    //send an invalid event on task at current state
    app.getContext().getEventHandler().handle(new TaskEvent(task.getID(), TaskEventType.T_SCHEDULE));
    //this must lead to job error
    app.waitForState(job, JobState.ERROR);
}
Also used : Task(org.apache.hadoop.mapreduce.v2.app.job.Task) Configuration(org.apache.hadoop.conf.Configuration) TaskEvent(org.apache.hadoop.mapreduce.v2.app.job.event.TaskEvent) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) Test(org.junit.Test)

Example 54 with MRApp

use of org.apache.hadoop.mapreduce.v2.app.MRApp in project hadoop by apache.

the class TestMRApp method testContainerPassThrough.

@Test
public void testContainerPassThrough() throws Exception {
    MRApp app = new MRApp(0, 1, true, this.getClass().getName(), true) {

        @Override
        protected ContainerLauncher createContainerLauncher(AppContext context) {
            return new MockContainerLauncher() {

                @Override
                public void handle(ContainerLauncherEvent event) {
                    if (event instanceof ContainerRemoteLaunchEvent) {
                        containerObtainedByContainerLauncher = ((ContainerRemoteLaunchEvent) event).getAllocatedContainer();
                    }
                    super.handle(event);
                }
            };
        }

        ;
    };
    Job job = app.submit(new Configuration());
    app.waitForState(job, JobState.SUCCEEDED);
    app.verifyCompleted();
    Collection<Task> tasks = job.getTasks().values();
    Collection<TaskAttempt> taskAttempts = tasks.iterator().next().getAttempts().values();
    TaskAttemptImpl taskAttempt = (TaskAttemptImpl) taskAttempts.iterator().next();
    // Container from RM should pass through to the launcher. Container object
    // should be the same.
    Assert.assertTrue(taskAttempt.container == containerObtainedByContainerLauncher);
}
Also used : Task(org.apache.hadoop.mapreduce.v2.app.job.Task) Configuration(org.apache.hadoop.conf.Configuration) ContainerLauncherEvent(org.apache.hadoop.mapreduce.v2.app.launcher.ContainerLauncherEvent) TaskAttemptImpl(org.apache.hadoop.mapreduce.v2.app.job.impl.TaskAttemptImpl) TaskAttempt(org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) ContainerRemoteLaunchEvent(org.apache.hadoop.mapreduce.v2.app.launcher.ContainerRemoteLaunchEvent) Test(org.junit.Test)

Example 55 with MRApp

use of org.apache.hadoop.mapreduce.v2.app.MRApp in project hadoop by apache.

the class TestJobEndNotifier method testNotificationOnLastRetryNormalShutdown.

@Test
public void testNotificationOnLastRetryNormalShutdown() throws Exception {
    HttpServer2 server = startHttpServer();
    // Act like it is the second attempt. Default max attempts is 2
    MRApp app = spy(new MRAppWithCustomContainerAllocator(2, 2, true, this.getClass().getName(), true, 2, true));
    doNothing().when(app).sysexit();
    JobConf conf = new JobConf();
    conf.set(JobContext.MR_JOB_END_NOTIFICATION_URL, JobEndServlet.baseUrl + "jobend?jobid=$jobId&status=$jobStatus");
    JobImpl job = (JobImpl) app.submit(conf);
    app.waitForInternalState(job, JobStateInternal.SUCCEEDED);
    // Unregistration succeeds: successfullyUnregistered is set
    app.shutDownJob();
    Assert.assertTrue(app.isLastAMRetry());
    Assert.assertEquals(1, JobEndServlet.calledTimes);
    Assert.assertEquals("jobid=" + job.getID() + "&status=SUCCEEDED", JobEndServlet.requestUri.getQuery());
    Assert.assertEquals(JobState.SUCCEEDED.toString(), JobEndServlet.foundJobState);
    server.stop();
}
Also used : JobImpl(org.apache.hadoop.mapreduce.v2.app.job.impl.JobImpl) HttpServer2(org.apache.hadoop.http.HttpServer2) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)61 Configuration (org.apache.hadoop.conf.Configuration)60 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)57 Task (org.apache.hadoop.mapreduce.v2.app.job.Task)44 TaskAttempt (org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt)37 TaskAttemptEvent (org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptEvent)26 MRApp (org.apache.hadoop.mapreduce.v2.app.MRApp)23 TaskId (org.apache.hadoop.mapreduce.v2.api.records.TaskId)15 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)14 TaskAttemptId (org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId)14 JobEvent (org.apache.hadoop.mapreduce.v2.app.job.event.JobEvent)8 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)8 IOException (java.io.IOException)6 HistoryFileInfo (org.apache.hadoop.mapreduce.v2.hs.HistoryFileManager.HistoryFileInfo)6 AppContext (org.apache.hadoop.mapreduce.v2.app.AppContext)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)4 FileContext (org.apache.hadoop.fs.FileContext)4 Path (org.apache.hadoop.fs.Path)4 TaskAttemptCompletionEvent (org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptCompletionEvent)4