Exemple #1
0
        public virtual void TestLogsViewSingle()
        {
            Log.Info("HsLogsPage with params for single log and data limits");
            MockAppContext ctx = new MockAppContext(0, 1, 1, 1);
            IDictionary <string, string> @params = new Dictionary <string, string>();
            Configuration conf = new YarnConfiguration();

            conf.SetBoolean(YarnConfiguration.LogAggregationEnabled, true);
            @params["start"] = "-2048";
            @params["end"]   = "-1024";
            @params[YarnWebParams.ContainerLogType] = "syslog";
            @params[YarnWebParams.ContainerId]      = MRApp.NewContainerId(1, 1, 333, 1).ToString(
                );
            @params[YarnWebParams.NmNodename] = NodeId.NewInstance(MockJobs.NmHost, MockJobs.
                                                                   NmPort).ToString();
            @params[YarnWebParams.EntityString] = "container_10_0001_01_000001";
            @params[YarnWebParams.AppOwner]     = "owner";
            Injector injector = WebAppTests.TestPage <AppContext>(typeof(AggregatedLogsPage),
                                                                  ctx, @params, new _AbstractModule_201(conf));
            PrintWriter spyPw = WebAppTests.GetPrintWriter(injector);

            Org.Mockito.Mockito.Verify(spyPw).Write("Logs not available for container_10_0001_01_000001."
                                                    + " Aggregation may not be complete, " + "Check back later or try the nodemanager at "
                                                    + MockJobs.NmHost + ":" + MockJobs.NmPort);
        }
Exemple #2
0
        public virtual void TestLogsView1()
        {
            Log.Info("HsLogsPage");
            Injector injector = WebAppTests.TestPage <AppContext>(typeof(AggregatedLogsPage),
                                                                  new MockAppContext(0, 1, 1, 1));
            PrintWriter spyPw = WebAppTests.GetPrintWriter(injector);

            Org.Mockito.Mockito.Verify(spyPw).Write("Cannot get container logs without a ContainerId"
                                                    );
            Org.Mockito.Mockito.Verify(spyPw).Write("Cannot get container logs without a NodeId"
                                                    );
            Org.Mockito.Mockito.Verify(spyPw).Write("Cannot get container logs without an app owner"
                                                    );
        }
Exemple #3
0
        public virtual void TestLogsView2()
        {
            Log.Info("HsLogsPage with data");
            MockAppContext ctx = new MockAppContext(0, 1, 1, 1);
            IDictionary <string, string> @params = new Dictionary <string, string>();

            @params[YarnWebParams.ContainerId] = MRApp.NewContainerId(1, 1, 333, 1).ToString(
                );
            @params[YarnWebParams.NmNodename] = NodeId.NewInstance(MockJobs.NmHost, MockJobs.
                                                                   NmPort).ToString();
            @params[YarnWebParams.EntityString] = "container_10_0001_01_000001";
            @params[YarnWebParams.AppOwner]     = "owner";
            Injector injector = WebAppTests.TestPage <AppContext>(typeof(AggregatedLogsPage),
                                                                  ctx, @params);
            PrintWriter spyPw = WebAppTests.GetPrintWriter(injector);

            Org.Mockito.Mockito.Verify(spyPw).Write("Aggregation is not enabled. Try the nodemanager at "
                                                    + MockJobs.NmHost + ":" + MockJobs.NmPort);
        }
Exemple #4
0
        public virtual void TestLogsViewBadStartEnd()
        {
            Log.Info("HsLogsPage with bad start/end params");
            MockAppContext ctx = new MockAppContext(0, 1, 1, 1);
            IDictionary <string, string> @params = new Dictionary <string, string>();

            @params["start"] = "foo";
            @params["end"]   = "bar";
            @params[YarnWebParams.ContainerId] = MRApp.NewContainerId(1, 1, 333, 1).ToString(
                );
            @params[YarnWebParams.NmNodename] = NodeId.NewInstance(MockJobs.NmHost, MockJobs.
                                                                   NmPort).ToString();
            @params[YarnWebParams.EntityString] = "container_10_0001_01_000001";
            @params[YarnWebParams.AppOwner]     = "owner";
            Injector injector = WebAppTests.TestPage <AppContext>(typeof(AggregatedLogsPage),
                                                                  ctx, @params);
            PrintWriter spyPw = WebAppTests.GetPrintWriter(injector);

            Org.Mockito.Mockito.Verify(spyPw).Write("Invalid log start value: foo");
            Org.Mockito.Mockito.Verify(spyPw).Write("Invalid log end value: bar");
        }
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestContainerLogPageAccess()
        {
            // SecureIOUtils require Native IO to be enabled. This test will run
            // only if it is enabled.
            Assume.AssumeTrue(NativeIO.IsAvailable());
            string   user         = "******" + Runtime.CurrentTimeMillis();
            FilePath absLogDir    = null;
            FilePath appDir       = null;
            FilePath containerDir = null;
            FilePath syslog       = null;

            try
            {
                // target log directory
                absLogDir = new FilePath("target", typeof(TestContainerLogsPage).Name + "LogDir")
                            .GetAbsoluteFile();
                absLogDir.Mkdir();
                Configuration conf = new Configuration();
                conf.Set(YarnConfiguration.NmLogDirs, absLogDir.ToURI().ToString());
                conf.Set(CommonConfigurationKeysPublic.HadoopSecurityAuthentication, "kerberos");
                UserGroupInformation.SetConfiguration(conf);
                NodeHealthCheckerService healthChecker = new NodeHealthCheckerService();
                healthChecker.Init(conf);
                LocalDirsHandlerService dirsHandler = healthChecker.GetDiskHandler();
                // Add an application and the corresponding containers
                RecordFactory recordFactory    = RecordFactoryProvider.GetRecordFactory(conf);
                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.GetAppId()).ThenReturn(appId);
                // Making sure that application returns a random user. This is required
                // for SecureIOUtils' file owner check.
                Org.Mockito.Mockito.When(app.GetUser()).ThenReturn(user);
                ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(appId, 1
                                                                                         );
                ContainerId container1 = BuilderUtils.NewContainerId(recordFactory, appId, appAttemptId
                                                                     , 0);
                // Testing secure read access for log files
                // Creating application and container directory and syslog file.
                appDir = new FilePath(absLogDir, appId.ToString());
                appDir.Mkdir();
                containerDir = new FilePath(appDir, container1.ToString());
                containerDir.Mkdir();
                syslog = new FilePath(containerDir, "syslog");
                syslog.CreateNewFile();
                BufferedOutputStream @out = new BufferedOutputStream(new FileOutputStream(syslog)
                                                                     );
                @out.Write(Sharpen.Runtime.GetBytesForString("Log file Content"));
                @out.Close();
                Context context = Org.Mockito.Mockito.Mock <Context>();
                ConcurrentMap <ApplicationId, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                               > appMap = new ConcurrentHashMap <ApplicationId, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                                                                 >();
                appMap[appId] = app;
                Org.Mockito.Mockito.When(context.GetApplications()).ThenReturn(appMap);
                ConcurrentHashMap <ContainerId, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container
                                   > containers = new ConcurrentHashMap <ContainerId, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container
                                                                         >();
                Org.Mockito.Mockito.When(context.GetContainers()).ThenReturn(containers);
                Org.Mockito.Mockito.When(context.GetLocalDirsHandler()).ThenReturn(dirsHandler);
                MockContainer container = new MockContainer(appAttemptId, new AsyncDispatcher(),
                                                            conf, user, appId, 1);
                container.SetState(ContainerState.Running);
                context.GetContainers()[container1] = container;
                ContainerLogsPage.ContainersLogsBlock cLogsBlock = new ContainerLogsPage.ContainersLogsBlock
                                                                       (context);
                IDictionary <string, string> @params = new Dictionary <string, string>();
                @params[YarnWebParams.ContainerId]      = container1.ToString();
                @params[YarnWebParams.ContainerLogType] = "syslog";
                Injector injector = WebAppTests.TestPage <ContainerLogsPage.ContainersLogsBlock>(typeof(
                                                                                                     ContainerLogsPage), cLogsBlock, @params, (Module[])null);
                PrintWriter spyPw = WebAppTests.GetPrintWriter(injector);
                Org.Mockito.Mockito.Verify(spyPw).Write("Exception reading log file. Application submitted by '"
                                                        + user + "' doesn't own requested log file : syslog");
            }
            finally
            {
                if (syslog != null)
                {
                    syslog.Delete();
                }
                if (containerDir != null)
                {
                    containerDir.Delete();
                }
                if (appDir != null)
                {
                    appDir.Delete();
                }
                if (absLogDir != null)
                {
                    absLogDir.Delete();
                }
            }
        }