public virtual void TestForCorruptedAggregatedLogs()
        {
            Configuration conf             = new Configuration();
            FilePath      workDir          = new FilePath(testWorkDir, "testReadAcontainerLogs1");
            Path          remoteAppLogFile = new Path(workDir.GetAbsolutePath(), "aggregatedLogFile");
            Path          srcFileRoot      = new Path(workDir.GetAbsolutePath(), "srcFiles");
            ContainerId   testContainerId  = TestContainerId.NewContainerId(1, 1, 1, 1);
            Path          t = new Path(srcFileRoot, testContainerId.GetApplicationAttemptId().GetApplicationId
                                           ().ToString());
            Path srcFilePath = new Path(t, testContainerId.ToString());
            long numChars    = 950000;

            WriteSrcFileAndALog(srcFilePath, "stdout", numChars, remoteAppLogFile, srcFileRoot
                                , testContainerId);
            AggregatedLogFormat.LogReader logReader = new AggregatedLogFormat.LogReader(conf,
                                                                                        remoteAppLogFile);
            AggregatedLogFormat.LogKey rLogKey = new AggregatedLogFormat.LogKey();
            DataInputStream            dis     = logReader.Next(rLogKey);
            TextWriter writer = new StringWriter();

            try
            {
                AggregatedLogFormat.LogReader.ReadAcontainerLogs(dis, writer);
            }
            catch (Exception e)
            {
                if (e.ToString().Contains("NumberFormatException"))
                {
                    NUnit.Framework.Assert.Fail("Aggregated logs are corrupted.");
                }
            }
        }
Exemple #2
0
        public virtual int DumpAContainersLogs(string appId, string containerId, string nodeId
                                               , string jobOwner)
        {
            Path remoteRootLogDir = new Path(GetConf().Get(YarnConfiguration.NmRemoteAppLogDir
                                                           , YarnConfiguration.DefaultNmRemoteAppLogDir));
            string suffix          = LogAggregationUtils.GetRemoteNodeLogDirSuffix(GetConf());
            Path   remoteAppLogDir = LogAggregationUtils.GetRemoteAppLogDir(remoteRootLogDir, ConverterUtils
                                                                            .ToApplicationId(appId), jobOwner, suffix);
            RemoteIterator <FileStatus> nodeFiles;

            try
            {
                Path qualifiedLogDir = FileContext.GetFileContext(GetConf()).MakeQualified(remoteAppLogDir
                                                                                           );
                nodeFiles = FileContext.GetFileContext(qualifiedLogDir.ToUri(), GetConf()).ListStatus
                                (remoteAppLogDir);
            }
            catch (FileNotFoundException)
            {
                LogDirNotExist(remoteAppLogDir.ToString());
                return(-1);
            }
            bool foundContainerLogs = false;

            while (nodeFiles.HasNext())
            {
                FileStatus thisNodeFile = nodeFiles.Next();
                string     fileName     = thisNodeFile.GetPath().GetName();
                if (fileName.Contains(LogAggregationUtils.GetNodeString(nodeId)) && !fileName.EndsWith
                        (LogAggregationUtils.TmpFileSuffix))
                {
                    AggregatedLogFormat.LogReader reader = null;
                    try
                    {
                        reader = new AggregatedLogFormat.LogReader(GetConf(), thisNodeFile.GetPath());
                        if (DumpAContainerLogs(containerId, reader, System.Console.Out, thisNodeFile.GetModificationTime
                                                   ()) > -1)
                        {
                            foundContainerLogs = true;
                        }
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                }
            }
            if (!foundContainerLogs)
            {
                ContainerLogNotFound(containerId);
                return(-1);
            }
            return(0);
        }
Exemple #3
0
        public virtual int DumpAContainerLogs(string containerIdStr, AggregatedLogFormat.LogReader
                                              reader, TextWriter @out, long logUploadedTime)
        {
            DataInputStream valueStream;

            AggregatedLogFormat.LogKey key = new AggregatedLogFormat.LogKey();
            valueStream = reader.Next(key);
            while (valueStream != null && !key.ToString().Equals(containerIdStr))
            {
                // Next container
                key         = new AggregatedLogFormat.LogKey();
                valueStream = reader.Next(key);
            }
            if (valueStream == null)
            {
                return(-1);
            }
            bool foundContainerLogs = false;

            while (true)
            {
                try
                {
                    AggregatedLogFormat.LogReader.ReadAContainerLogsForALogType(valueStream, @out, logUploadedTime
                                                                                );
                    foundContainerLogs = true;
                }
                catch (EOFException)
                {
                    break;
                }
            }
            if (foundContainerLogs)
            {
                return(0);
            }
            return(-1);
        }
Exemple #4
0
        public virtual int DumpAllContainersLogs(ApplicationId appId, string appOwner, TextWriter
                                                 @out)
        {
            Path remoteRootLogDir = new Path(GetConf().Get(YarnConfiguration.NmRemoteAppLogDir
                                                           , YarnConfiguration.DefaultNmRemoteAppLogDir));
            string user         = appOwner;
            string logDirSuffix = LogAggregationUtils.GetRemoteNodeLogDirSuffix(GetConf());
            // TODO Change this to get a list of files from the LAS.
            Path remoteAppLogDir = LogAggregationUtils.GetRemoteAppLogDir(remoteRootLogDir, appId
                                                                          , user, logDirSuffix);
            RemoteIterator <FileStatus> nodeFiles;

            try
            {
                Path qualifiedLogDir = FileContext.GetFileContext(GetConf()).MakeQualified(remoteAppLogDir
                                                                                           );
                nodeFiles = FileContext.GetFileContext(qualifiedLogDir.ToUri(), GetConf()).ListStatus
                                (remoteAppLogDir);
            }
            catch (FileNotFoundException)
            {
                LogDirNotExist(remoteAppLogDir.ToString());
                return(-1);
            }
            bool foundAnyLogs = false;

            while (nodeFiles.HasNext())
            {
                FileStatus thisNodeFile = nodeFiles.Next();
                if (!thisNodeFile.GetPath().GetName().EndsWith(LogAggregationUtils.TmpFileSuffix))
                {
                    AggregatedLogFormat.LogReader reader = new AggregatedLogFormat.LogReader(GetConf(
                                                                                                 ), thisNodeFile.GetPath());
                    try
                    {
                        DataInputStream            valueStream;
                        AggregatedLogFormat.LogKey key = new AggregatedLogFormat.LogKey();
                        valueStream = reader.Next(key);
                        while (valueStream != null)
                        {
                            string containerString = "\n\nContainer: " + key + " on " + thisNodeFile.GetPath(
                                ).GetName();
                            @out.WriteLine(containerString);
                            @out.WriteLine(StringUtils.Repeat("=", containerString.Length));
                            while (true)
                            {
                                try
                                {
                                    AggregatedLogFormat.LogReader.ReadAContainerLogsForALogType(valueStream, @out, thisNodeFile
                                                                                                .GetModificationTime());
                                    foundAnyLogs = true;
                                }
                                catch (EOFException)
                                {
                                    break;
                                }
                            }
                            // Next container
                            key         = new AggregatedLogFormat.LogKey();
                            valueStream = reader.Next(key);
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
            }
            if (!foundAnyLogs)
            {
                EmptyLogDir(remoteAppLogDir.ToString());
                return(-1);
            }
            return(0);
        }
        /// <exception cref="System.Exception"/>
        private void TestReadAcontainerLog(bool logUploadedTime)
        {
            Configuration conf             = new Configuration();
            FilePath      workDir          = new FilePath(testWorkDir, "testReadAcontainerLogs1");
            Path          remoteAppLogFile = new Path(workDir.GetAbsolutePath(), "aggregatedLogFile");
            Path          srcFileRoot      = new Path(workDir.GetAbsolutePath(), "srcFiles");
            ContainerId   testContainerId  = TestContainerId.NewContainerId(1, 1, 1, 1);
            Path          t = new Path(srcFileRoot, testContainerId.GetApplicationAttemptId().GetApplicationId
                                           ().ToString());
            Path srcFilePath = new Path(t, testContainerId.ToString());
            int  numChars    = 80000;
            // create a sub-folder under srcFilePath
            // and create file logs in this sub-folder.
            // We only aggregate top level files.
            // So, this log file should be ignored.
            Path subDir = new Path(srcFilePath, "subDir");

            fs.Mkdirs(subDir);
            WriteSrcFile(subDir, "logs", numChars);
            // create file stderr and stdout in containerLogDir
            WriteSrcFile(srcFilePath, "stderr", numChars);
            WriteSrcFile(srcFilePath, "stdout", numChars);
            UserGroupInformation ugi = UserGroupInformation.GetCurrentUser();

            AggregatedLogFormat.LogWriter logWriter = new AggregatedLogFormat.LogWriter(conf,
                                                                                        remoteAppLogFile, ugi);
            AggregatedLogFormat.LogKey logKey = new AggregatedLogFormat.LogKey(testContainerId
                                                                               );
            AggregatedLogFormat.LogValue logValue = new AggregatedLogFormat.LogValue(Collections
                                                                                     .SingletonList(srcFileRoot.ToString()), testContainerId, ugi.GetShortUserName());
            // When we try to open FileInputStream for stderr, it will throw out an IOException.
            // Skip the log aggregation for stderr.
            AggregatedLogFormat.LogValue spyLogValue = Org.Mockito.Mockito.Spy(logValue);
            FilePath errorFile = new FilePath((new Path(srcFilePath, "stderr")).ToString());

            Org.Mockito.Mockito.DoThrow(new IOException("Mock can not open FileInputStream"))
            .When(spyLogValue).SecureOpenFile(errorFile);
            logWriter.Append(logKey, spyLogValue);
            logWriter.Close();
            // make sure permission are correct on the file
            FileStatus fsStatus = fs.GetFileStatus(remoteAppLogFile);

            NUnit.Framework.Assert.AreEqual("permissions on log aggregation file are wrong",
                                            FsPermission.CreateImmutable((short)0x1a0), fsStatus.GetPermission());
            AggregatedLogFormat.LogReader logReader = new AggregatedLogFormat.LogReader(conf,
                                                                                        remoteAppLogFile);
            AggregatedLogFormat.LogKey rLogKey = new AggregatedLogFormat.LogKey();
            DataInputStream            dis     = logReader.Next(rLogKey);
            TextWriter writer = new StringWriter();

            if (logUploadedTime)
            {
                AggregatedLogFormat.LogReader.ReadAcontainerLogs(dis, writer, Runtime.CurrentTimeMillis
                                                                     ());
            }
            else
            {
                AggregatedLogFormat.LogReader.ReadAcontainerLogs(dis, writer);
            }
            // We should only do the log aggregation for stdout.
            // Since we could not open the fileInputStream for stderr, this file is not
            // aggregated.
            string s = writer.ToString();
            int    expectedLength = "LogType:stdout".Length + (logUploadedTime ? ("\nLog Upload Time:"
                                                                                  + Times.Format(Runtime.CurrentTimeMillis())).Length : 0) + ("\nLogLength:" + numChars
                                                                                                                                              ).Length + "\nLog Contents:\n".Length + numChars + "\n".Length + "End of LogType:stdout\n"
                                    .Length;

            NUnit.Framework.Assert.IsTrue("LogType not matched", s.Contains("LogType:stdout")
                                          );
            NUnit.Framework.Assert.IsTrue("log file:stderr should not be aggregated.", !s.Contains
                                              ("LogType:stderr"));
            NUnit.Framework.Assert.IsTrue("log file:logs should not be aggregated.", !s.Contains
                                              ("LogType:logs"));
            NUnit.Framework.Assert.IsTrue("LogLength not matched", s.Contains("LogLength:" +
                                                                              numChars));
            NUnit.Framework.Assert.IsTrue("Log Contents not matched", s.Contains("Log Contents"
                                                                                 ));
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < numChars; i++)
            {
                sb.Append(filler);
            }
            string expectedContent = sb.ToString();

            NUnit.Framework.Assert.IsTrue("Log content incorrect", s.Contains(expectedContent
                                                                              ));
            NUnit.Framework.Assert.AreEqual(expectedLength, s.Length);
        }