public virtual void TestLogDirWithDriveLetter()
        {
            //To verify that logs paths which include drive letters (Windows)
            //do not lose their drive letter specification
            LocalDirsHandlerService localDirs = Org.Mockito.Mockito.Mock <LocalDirsHandlerService
                                                                          >();
            IList <string> logDirs = new AList <string>();

            logDirs.AddItem("F:/nmlogs");
            Org.Mockito.Mockito.When(localDirs.GetLogDirsForRead()).ThenReturn(logDirs);
            ApplicationIdPBImpl appId = Org.Mockito.Mockito.Mock <ApplicationIdPBImpl>();

            Org.Mockito.Mockito.When(appId.ToString()).ThenReturn("app_id_1");
            ApplicationAttemptIdPBImpl appAttemptId = Org.Mockito.Mockito.Mock <ApplicationAttemptIdPBImpl
                                                                                >();

            Org.Mockito.Mockito.When(appAttemptId.GetApplicationId()).ThenReturn(appId);
            ContainerId containerId = Org.Mockito.Mockito.Mock <ContainerIdPBImpl>();

            Org.Mockito.Mockito.When(containerId.GetApplicationAttemptId()).ThenReturn(appAttemptId
                                                                                       );
            IList <FilePath> logDirFiles = ContainerLogsUtils.GetContainerLogDirs(containerId,
                                                                                  localDirs);

            NUnit.Framework.Assert.IsTrue("logDir lost drive letter " + logDirFiles[0], logDirFiles
                                          [0].ToString().IndexOf("F:" + FilePath.separator + "nmlogs") > -1);
        }
Esempio n. 2
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        internal static IList <FilePath> GetContainerLogDirs(ContainerId containerId, LocalDirsHandlerService
                                                             dirsHandler)
        {
            IList <string>   logDirs          = dirsHandler.GetLogDirsForRead();
            IList <FilePath> containerLogDirs = new AList <FilePath>(logDirs.Count);

            foreach (string logDir in logDirs)
            {
                logDir = new FilePath(logDir).ToURI().GetPath();
                string appIdStr = ConverterUtils.ToString(containerId.GetApplicationAttemptId().GetApplicationId
                                                              ());
                FilePath appLogDir = new FilePath(logDir, appIdStr);
                containerLogDirs.AddItem(new FilePath(appLogDir, containerId.ToString()));
            }
            return(containerLogDirs);
        }
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        public virtual void TestContainerLogDirs()
        {
            FilePath absLogDir = new FilePath("target", typeof(TestNMWebServer).Name + "LogDir"
                                              ).GetAbsoluteFile();
            string        logdirwithFile = absLogDir.ToURI().ToString();
            Configuration conf           = new Configuration();

            conf.Set(YarnConfiguration.NmLogDirs, logdirwithFile);
            NodeHealthCheckerService healthChecker = new NodeHealthCheckerService();

            healthChecker.Init(conf);
            LocalDirsHandlerService dirsHandler = healthChecker.GetDiskHandler();

            NodeManager.NMContext nmContext = new NodeManager.NMContext(null, null, dirsHandler
                                                                        , new ApplicationACLsManager(conf), new NMNullStateStoreService());
            // Add an application and the corresponding containers
            RecordFactory recordFactory    = RecordFactoryProvider.GetRecordFactory(conf);
            string        user             = "******";
            long          clusterTimeStamp = 1234;
            ApplicationId appId            = BuilderUtils.NewApplicationId(recordFactory, clusterTimeStamp
                                                                           , 1);

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = Org.Mockito.Mockito.Mock <Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                                                >();
            Org.Mockito.Mockito.When(app.GetUser()).ThenReturn(user);
            Org.Mockito.Mockito.When(app.GetAppId()).ThenReturn(appId);
            ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(appId, 1
                                                                                     );
            ContainerId container1 = BuilderUtils.NewContainerId(recordFactory, appId, appAttemptId
                                                                 , 0);

            nmContext.GetApplications()[appId] = app;
            MockContainer container = new MockContainer(appAttemptId, new AsyncDispatcher(),
                                                        conf, user, appId, 1);

            container.SetState(ContainerState.Running);
            nmContext.GetContainers()[container1] = container;
            IList <FilePath> files = null;

            files = ContainerLogsUtils.GetContainerLogDirs(container1, user, nmContext);
            NUnit.Framework.Assert.IsTrue(!(files[0].ToString().Contains("file:")));
            // After container is completed, it is removed from nmContext
            Sharpen.Collections.Remove(nmContext.GetContainers(), container1);
            NUnit.Framework.Assert.IsNull(nmContext.GetContainers()[container1]);
            files = ContainerLogsUtils.GetContainerLogDirs(container1, user, nmContext);
            NUnit.Framework.Assert.IsTrue(!(files[0].ToString().Contains("file:")));
            // Create a new context to check if correct container log dirs are fetched
            // on full disk.
            LocalDirsHandlerService dirsHandlerForFullDisk = Org.Mockito.Mockito.Spy(dirsHandler
                                                                                     );

            // good log dirs are empty and nm log dir is in the full log dir list.
            Org.Mockito.Mockito.When(dirsHandlerForFullDisk.GetLogDirs()).ThenReturn(new AList
                                                                                     <string>());
            Org.Mockito.Mockito.When(dirsHandlerForFullDisk.GetLogDirsForRead()).ThenReturn(Arrays
                                                                                            .AsList(new string[] { absLogDir.GetAbsolutePath() }));
            nmContext = new NodeManager.NMContext(null, null, dirsHandlerForFullDisk, new ApplicationACLsManager
                                                      (conf), new NMNullStateStoreService());
            nmContext.GetApplications()[appId] = app;
            container.SetState(ContainerState.Running);
            nmContext.GetContainers()[container1] = container;
            IList <FilePath> dirs = ContainerLogsUtils.GetContainerLogDirs(container1, user, nmContext
                                                                           );
            FilePath containerLogDir = new FilePath(absLogDir, appId + "/" + container1);

            NUnit.Framework.Assert.IsTrue(dirs.Contains(containerLogDir));
        }