Search in sources :

Example 71 with DrainDispatcher

use of org.apache.hadoop.yarn.event.DrainDispatcher in project hadoop by apache.

the class TestLocalResourcesTrackerImpl method testHierarchicalLocalCacheDirectories.

@Test(timeout = 10000)
@SuppressWarnings("unchecked")
public void testHierarchicalLocalCacheDirectories() {
    String user = "testuser";
    DrainDispatcher dispatcher = null;
    try {
        Configuration conf = new Configuration();
        // setting per directory file limit to 1.
        conf.set(YarnConfiguration.NM_LOCAL_CACHE_MAX_FILES_PER_DIRECTORY, "37");
        dispatcher = createDispatcher(conf);
        EventHandler<LocalizerEvent> localizerEventHandler = mock(EventHandler.class);
        EventHandler<LocalizerEvent> containerEventHandler = mock(EventHandler.class);
        dispatcher.register(LocalizerEventType.class, localizerEventHandler);
        dispatcher.register(ContainerEventType.class, containerEventHandler);
        DeletionService mockDelService = mock(DeletionService.class);
        ConcurrentMap<LocalResourceRequest, LocalizedResource> localrsrc = new ConcurrentHashMap<LocalResourceRequest, LocalizedResource>();
        LocalResourcesTracker tracker = new LocalResourcesTrackerImpl(user, null, dispatcher, localrsrc, true, conf, new NMNullStateStoreService(), null);
        // This is a random path. NO File creation will take place at this place.
        Path localDir = new Path("/tmp");
        // Container 1 needs lr1 resource
        ContainerId cId1 = BuilderUtils.newContainerId(1, 1, 1, 1);
        LocalResourceRequest lr1 = createLocalResourceRequest(user, 1, 1, LocalResourceVisibility.PUBLIC);
        LocalizerContext lc1 = new LocalizerContext(user, cId1, null);
        // Container 1 requests lr1 to be localized
        ResourceEvent reqEvent1 = new ResourceRequestEvent(lr1, LocalResourceVisibility.PUBLIC, lc1);
        tracker.handle(reqEvent1);
        // Simulate the process of localization of lr1
        // NOTE: Localization path from tracker has resource ID at end
        Path hierarchicalPath1 = tracker.getPathForLocalization(lr1, localDir, null).getParent();
        // Simulate lr1 getting localized
        ResourceLocalizedEvent rle1 = new ResourceLocalizedEvent(lr1, new Path(hierarchicalPath1.toUri().toString() + Path.SEPARATOR + "file1"), 120);
        tracker.handle(rle1);
        // Localization successful.
        LocalResourceRequest lr2 = createLocalResourceRequest(user, 3, 3, LocalResourceVisibility.PUBLIC);
        // Container 1 requests lr2 to be localized.
        ResourceEvent reqEvent2 = new ResourceRequestEvent(lr2, LocalResourceVisibility.PUBLIC, lc1);
        tracker.handle(reqEvent2);
        Path hierarchicalPath2 = tracker.getPathForLocalization(lr2, localDir, null).getParent();
        // localization failed.
        ResourceFailedLocalizationEvent rfe2 = new ResourceFailedLocalizationEvent(lr2, new Exception("Test").toString());
        tracker.handle(rfe2);
        /*
       * The path returned for two localization should be different because we
       * are limiting one file per sub-directory.
       */
        Assert.assertNotSame(hierarchicalPath1, hierarchicalPath2);
        LocalResourceRequest lr3 = createLocalResourceRequest(user, 2, 2, LocalResourceVisibility.PUBLIC);
        ResourceEvent reqEvent3 = new ResourceRequestEvent(lr3, LocalResourceVisibility.PUBLIC, lc1);
        tracker.handle(reqEvent3);
        Path hierarchicalPath3 = tracker.getPathForLocalization(lr3, localDir, null).getParent();
        // localization successful
        ResourceLocalizedEvent rle3 = new ResourceLocalizedEvent(lr3, new Path(hierarchicalPath3.toUri().toString() + Path.SEPARATOR + "file3"), 120);
        tracker.handle(rle3);
        // Verifying that path created is inside the subdirectory
        Assert.assertEquals(hierarchicalPath3.toUri().toString(), hierarchicalPath1.toUri().toString() + Path.SEPARATOR + "0");
        // Container 1 releases resource lr1
        ResourceEvent relEvent1 = new ResourceReleaseEvent(lr1, cId1);
        tracker.handle(relEvent1);
        // Validate the file counts now
        int resources = 0;
        Iterator<LocalizedResource> iter = tracker.iterator();
        while (iter.hasNext()) {
            iter.next();
            resources++;
        }
        // There should be only two resources lr1 and lr3 now.
        Assert.assertEquals(2, resources);
        // Now simulate cache cleanup - removes unused resources.
        iter = tracker.iterator();
        while (iter.hasNext()) {
            LocalizedResource rsrc = iter.next();
            if (rsrc.getRefCount() == 0) {
                Assert.assertTrue(tracker.remove(rsrc, mockDelService));
                resources--;
            }
        }
        // lr1 is not used by anyone and will be removed, only lr3 will hang
        // around
        Assert.assertEquals(1, resources);
    } finally {
        if (dispatcher != null) {
            dispatcher.stop();
        }
    }
}
Also used : DrainDispatcher(org.apache.hadoop.yarn.event.DrainDispatcher) Path(org.apache.hadoop.fs.Path) ResourceFailedLocalizationEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceFailedLocalizationEvent) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ResourceLocalizedEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceLocalizedEvent) ContainerResourceLocalizedEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerResourceLocalizedEvent) DeletionService(org.apache.hadoop.yarn.server.nodemanager.DeletionService) ResourceReleaseEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceReleaseEvent) NMNullStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService) IOException(java.io.IOException) LocalizerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizerEvent) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) LocalizerResourceRequestEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizerResourceRequestEvent) ResourceRequestEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceRequestEvent) ResourceEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 72 with DrainDispatcher

use of org.apache.hadoop.yarn.event.DrainDispatcher in project hadoop by apache.

the class TestLocalResourcesTrackerImpl method testRecoveredResourceWithDirCacheMgr.

@Test
@SuppressWarnings("unchecked")
public void testRecoveredResourceWithDirCacheMgr() throws Exception {
    final String user = "someuser";
    final ApplicationId appId = ApplicationId.newInstance(1, 1);
    // This is a random path. NO File creation will take place at this place.
    final Path localDirRoot = new Path("/tmp/localdir");
    Configuration conf = new YarnConfiguration();
    DrainDispatcher dispatcher = null;
    dispatcher = createDispatcher(conf);
    EventHandler<LocalizerEvent> localizerEventHandler = mock(EventHandler.class);
    EventHandler<LocalizerEvent> containerEventHandler = mock(EventHandler.class);
    dispatcher.register(LocalizerEventType.class, localizerEventHandler);
    dispatcher.register(ContainerEventType.class, containerEventHandler);
    NMStateStoreService stateStore = mock(NMStateStoreService.class);
    try {
        LocalResourcesTrackerImpl tracker = new LocalResourcesTrackerImpl(user, appId, dispatcher, true, conf, stateStore);
        LocalResourceRequest lr1 = createLocalResourceRequest(user, 1, 1, LocalResourceVisibility.PUBLIC);
        Assert.assertNull(tracker.getLocalizedResource(lr1));
        final long localizedId1 = 52;
        Path hierarchicalPath1 = new Path(localDirRoot + "/4/2", Long.toString(localizedId1));
        Path localizedPath1 = new Path(hierarchicalPath1, "resource.jar");
        tracker.handle(new ResourceRecoveredEvent(lr1, localizedPath1, 120));
        dispatcher.await();
        Assert.assertNotNull(tracker.getLocalizedResource(lr1));
        LocalCacheDirectoryManager dirMgrRoot = tracker.getDirectoryManager(localDirRoot);
        Assert.assertEquals(0, dirMgrRoot.getDirectory("").getCount());
        Assert.assertEquals(1, dirMgrRoot.getDirectory("4/2").getCount());
        LocalResourceRequest lr2 = createLocalResourceRequest(user, 2, 2, LocalResourceVisibility.PUBLIC);
        Assert.assertNull(tracker.getLocalizedResource(lr2));
        final long localizedId2 = localizedId1 + 1;
        Path hierarchicalPath2 = new Path(localDirRoot + "/4/2", Long.toString(localizedId2));
        Path localizedPath2 = new Path(hierarchicalPath2, "resource.jar");
        tracker.handle(new ResourceRecoveredEvent(lr2, localizedPath2, 120));
        dispatcher.await();
        Assert.assertNotNull(tracker.getLocalizedResource(lr2));
        Assert.assertEquals(0, dirMgrRoot.getDirectory("").getCount());
        Assert.assertEquals(2, dirMgrRoot.getDirectory("4/2").getCount());
        LocalResourceRequest lr3 = createLocalResourceRequest(user, 3, 3, LocalResourceVisibility.PUBLIC);
        Assert.assertNull(tracker.getLocalizedResource(lr3));
        final long localizedId3 = 128;
        Path hierarchicalPath3 = new Path(localDirRoot + "/4/3", Long.toString(localizedId3));
        Path localizedPath3 = new Path(hierarchicalPath3, "resource.jar");
        tracker.handle(new ResourceRecoveredEvent(lr3, localizedPath3, 120));
        dispatcher.await();
        Assert.assertNotNull(tracker.getLocalizedResource(lr3));
        Assert.assertEquals(0, dirMgrRoot.getDirectory("").getCount());
        Assert.assertEquals(2, dirMgrRoot.getDirectory("4/2").getCount());
        Assert.assertEquals(1, dirMgrRoot.getDirectory("4/3").getCount());
        LocalResourceRequest lr4 = createLocalResourceRequest(user, 4, 4, LocalResourceVisibility.PUBLIC);
        Assert.assertNull(tracker.getLocalizedResource(lr4));
        final long localizedId4 = 256;
        Path hierarchicalPath4 = new Path(localDirRoot + "/4", Long.toString(localizedId4));
        Path localizedPath4 = new Path(hierarchicalPath4, "resource.jar");
        tracker.handle(new ResourceRecoveredEvent(lr4, localizedPath4, 120));
        dispatcher.await();
        Assert.assertNotNull(tracker.getLocalizedResource(lr4));
        Assert.assertEquals(0, dirMgrRoot.getDirectory("").getCount());
        Assert.assertEquals(1, dirMgrRoot.getDirectory("4").getCount());
        Assert.assertEquals(2, dirMgrRoot.getDirectory("4/2").getCount());
        Assert.assertEquals(1, dirMgrRoot.getDirectory("4/3").getCount());
    } finally {
        if (dispatcher != null) {
            dispatcher.stop();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) DrainDispatcher(org.apache.hadoop.yarn.event.DrainDispatcher) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ResourceRecoveredEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceRecoveredEvent) NMStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService) LocalizerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizerEvent) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 73 with DrainDispatcher

use of org.apache.hadoop.yarn.event.DrainDispatcher in project hadoop by apache.

the class TestLocalResourcesTrackerImpl method testReleaseWhileDownloading.

@Test
@SuppressWarnings("unchecked")
public void testReleaseWhileDownloading() throws Exception {
    String user = "testuser";
    DrainDispatcher dispatcher = null;
    try {
        Configuration conf = new Configuration();
        dispatcher = createDispatcher(conf);
        EventHandler<LocalizerEvent> localizerEventHandler = mock(EventHandler.class);
        EventHandler<LocalizerEvent> containerEventHandler = mock(EventHandler.class);
        dispatcher.register(LocalizerEventType.class, localizerEventHandler);
        dispatcher.register(ContainerEventType.class, containerEventHandler);
        ContainerId cId = BuilderUtils.newContainerId(1, 1, 1, 1);
        LocalizerContext lc = new LocalizerContext(user, cId, null);
        LocalResourceRequest req = createLocalResourceRequest(user, 1, 1, LocalResourceVisibility.PUBLIC);
        LocalizedResource lr = createLocalizedResource(req, dispatcher);
        ConcurrentMap<LocalResourceRequest, LocalizedResource> localrsrc = new ConcurrentHashMap<LocalResourceRequest, LocalizedResource>();
        localrsrc.put(req, lr);
        LocalResourcesTracker tracker = new LocalResourcesTrackerImpl(user, null, dispatcher, localrsrc, false, conf, new NMNullStateStoreService(), null);
        // request the resource
        ResourceEvent reqEvent = new ResourceRequestEvent(req, LocalResourceVisibility.PUBLIC, lc);
        tracker.handle(reqEvent);
        // release the resource
        ResourceEvent relEvent = new ResourceReleaseEvent(req, cId);
        tracker.handle(relEvent);
        // download completing after release
        ResourceLocalizedEvent rle = new ResourceLocalizedEvent(req, new Path("file:///tmp/r1"), 1);
        tracker.handle(rle);
        dispatcher.await();
    } finally {
        if (dispatcher != null) {
            dispatcher.stop();
        }
    }
}
Also used : DrainDispatcher(org.apache.hadoop.yarn.event.DrainDispatcher) Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ResourceLocalizedEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceLocalizedEvent) ContainerResourceLocalizedEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerResourceLocalizedEvent) ResourceReleaseEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceReleaseEvent) NMNullStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService) LocalizerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizerEvent) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) LocalizerResourceRequestEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizerResourceRequestEvent) ResourceRequestEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceRequestEvent) ResourceEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 74 with DrainDispatcher

use of org.apache.hadoop.yarn.event.DrainDispatcher in project hadoop by apache.

the class TestLocalResourcesTrackerImpl method testGetPathForLocalization.

@Test
@SuppressWarnings("unchecked")
public void testGetPathForLocalization() throws Exception {
    FileContext lfs = FileContext.getLocalFSFileContext();
    Path base_path = new Path("target", TestLocalResourcesTrackerImpl.class.getSimpleName());
    final String user = "someuser";
    final ApplicationId appId = ApplicationId.newInstance(1, 1);
    Configuration conf = new YarnConfiguration();
    DrainDispatcher dispatcher = null;
    dispatcher = createDispatcher(conf);
    EventHandler<LocalizerEvent> localizerEventHandler = mock(EventHandler.class);
    EventHandler<LocalizerEvent> containerEventHandler = mock(EventHandler.class);
    dispatcher.register(LocalizerEventType.class, localizerEventHandler);
    dispatcher.register(ContainerEventType.class, containerEventHandler);
    NMStateStoreService stateStore = mock(NMStateStoreService.class);
    DeletionService delService = mock(DeletionService.class);
    try {
        LocalResourceRequest req1 = createLocalResourceRequest(user, 1, 1, LocalResourceVisibility.PUBLIC);
        LocalizedResource lr1 = createLocalizedResource(req1, dispatcher);
        ConcurrentMap<LocalResourceRequest, LocalizedResource> localrsrc = new ConcurrentHashMap<LocalResourceRequest, LocalizedResource>();
        localrsrc.put(req1, lr1);
        LocalResourcesTrackerImpl tracker = new LocalResourcesTrackerImpl(user, appId, dispatcher, localrsrc, true, conf, stateStore, null);
        Path conflictPath = new Path(base_path, "10");
        Path qualifiedConflictPath = lfs.makeQualified(conflictPath);
        lfs.mkdir(qualifiedConflictPath, null, true);
        Path rPath = tracker.getPathForLocalization(req1, base_path, delService);
        Assert.assertFalse(lfs.util().exists(rPath));
        verify(delService, times(1)).delete(eq(user), eq(conflictPath));
    } finally {
        lfs.delete(base_path, true);
        if (dispatcher != null) {
            dispatcher.stop();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) DrainDispatcher(org.apache.hadoop.yarn.event.DrainDispatcher) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) DeletionService(org.apache.hadoop.yarn.server.nodemanager.DeletionService) NMStateStoreService(org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService) LocalizerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizerEvent) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FileContext(org.apache.hadoop.fs.FileContext) Test(org.junit.Test)

Example 75 with DrainDispatcher

use of org.apache.hadoop.yarn.event.DrainDispatcher in project hadoop by apache.

the class TestJobImpl method testFailAbortDoesntHang.

@Test(timeout = 10000)
public void testFailAbortDoesntHang() throws IOException {
    Configuration conf = new Configuration();
    conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
    conf.set(MRJobConfig.MR_AM_COMMITTER_CANCEL_TIMEOUT_MS, "1000");
    DrainDispatcher dispatcher = new DrainDispatcher();
    dispatcher.init(conf);
    dispatcher.start();
    OutputCommitter committer = Mockito.mock(OutputCommitter.class);
    CommitterEventHandler commitHandler = createCommitterEventHandler(dispatcher, committer);
    commitHandler.init(conf);
    commitHandler.start();
    //Job has only 1 mapper task. No reducers
    conf.setInt(MRJobConfig.NUM_REDUCES, 0);
    conf.setInt(MRJobConfig.MAP_MAX_ATTEMPTS, 1);
    JobImpl job = createRunningStubbedJob(conf, dispatcher, 1, null);
    //FAIL_ABORT state
    for (Task t : job.tasks.values()) {
        TaskImpl task = (TaskImpl) t;
        task.handle(new TaskEvent(task.getID(), TaskEventType.T_SCHEDULE));
        for (TaskAttempt ta : task.getAttempts().values()) {
            task.handle(new TaskTAttemptEvent(ta.getID(), TaskEventType.T_ATTEMPT_FAILED));
        }
    }
    dispatcher.await();
    //Verify abortJob is called once and the job failed
    Mockito.verify(committer, Mockito.timeout(2000).times(1)).abortJob((JobContext) Mockito.any(), (State) Mockito.any());
    assertJobState(job, JobStateInternal.FAILED);
    dispatcher.stop();
}
Also used : DrainDispatcher(org.apache.hadoop.yarn.event.DrainDispatcher) OutputCommitter(org.apache.hadoop.mapreduce.OutputCommitter) Task(org.apache.hadoop.mapreduce.v2.app.job.Task) Configuration(org.apache.hadoop.conf.Configuration) JobTaskEvent(org.apache.hadoop.mapreduce.v2.app.job.event.JobTaskEvent) TaskEvent(org.apache.hadoop.mapreduce.v2.app.job.event.TaskEvent) CommitterEventHandler(org.apache.hadoop.mapreduce.v2.app.commit.CommitterEventHandler) TaskTAttemptEvent(org.apache.hadoop.mapreduce.v2.app.job.event.TaskTAttemptEvent) TaskAttempt(org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt) Test(org.junit.Test)

Aggregations

DrainDispatcher (org.apache.hadoop.yarn.event.DrainDispatcher)84 Test (org.junit.Test)73 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)54 Configuration (org.apache.hadoop.conf.Configuration)50 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)41 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)35 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)32 Path (org.apache.hadoop.fs.Path)24 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)24 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)23 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)21 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)20 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 DeletionService (org.apache.hadoop.yarn.server.nodemanager.DeletionService)16 LocalizerEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizerEvent)15 HashMap (java.util.HashMap)14 LocalDirsHandlerService (org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)14 LocalResourceVisibility (org.apache.hadoop.yarn.api.records.LocalResourceVisibility)12 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)12