示例#1
0
 public override string ToString()
 {
     if (isRelative)
     {
         return(DFSUtil.DurationToString(ms));
     }
     return(DFSUtil.DateToIso8601String(Sharpen.Extensions.CreateDate(ms)));
 }
示例#2
0
        private void PrintBlockDeletionTime(Logger log)
        {
            log.Info(DFSConfigKeys.DfsNamenodeStartupDelayBlockDeletionSecKey + " is set to "
                     + DFSUtil.DurationToString(pendingPeriodInMs));
            SimpleDateFormat sdf      = new SimpleDateFormat("yyyy MMM dd HH:mm:ss");
            Calendar         calendar = new GregorianCalendar();

            calendar.Add(Calendar.Second, (int)(this.pendingPeriodInMs / 1000));
            log.Info("The block deletion will start around " + sdf.Format(calendar.GetTime())
                     );
        }
示例#3
0
 /// <exception cref="System.Exception"/>
 public virtual void TestDurationToString()
 {
     NUnit.Framework.Assert.AreEqual("000:00:00:00.000", DFSUtil.DurationToString(0));
     NUnit.Framework.Assert.AreEqual("001:01:01:01.000", DFSUtil.DurationToString(((24
                                                                                    * 60 * 60) + (60 * 60) + (60) + 1) * 1000));
     NUnit.Framework.Assert.AreEqual("000:23:59:59.999", DFSUtil.DurationToString(((23
                                                                                    * 60 * 60) + (59 * 60) + (59)) * 1000 + 999));
     NUnit.Framework.Assert.AreEqual("-001:01:01:01.000", DFSUtil.DurationToString(-((
                                                                                         24 * 60 * 60) + (60 * 60) + (60) + 1) * 1000));
     NUnit.Framework.Assert.AreEqual("-000:23:59:59.574", DFSUtil.DurationToString(-((
                                                                                         (23 * 60 * 60) + (59 * 60) + (59)) * 1000 + 574)));
 }
示例#4
0
            /// <exception cref="System.IO.IOException"/>
            public virtual int Run(Configuration conf, IList <string> args)
            {
                string name       = StringUtils.PopFirstNonOption(args);
                bool   printStats = StringUtils.PopOption("-stats", args);

                if (!args.IsEmpty())
                {
                    System.Console.Error.Write("Can't understand arguments: " + Joiner.On(" ").Join(args
                                                                                                    ) + "\n");
                    System.Console.Error.WriteLine("Usage is " + GetShortUsage());
                    return(1);
                }
                DistributedFileSystem dfs = AdminHelper.GetDFS(conf);

                TableListing.Builder builder = new TableListing.Builder().AddField("NAME", TableListing.Justification
                                                                                   .Left).AddField("OWNER", TableListing.Justification.Left).AddField("GROUP", TableListing.Justification
                                                                                                                                                      .Left).AddField("MODE", TableListing.Justification.Left).AddField("LIMIT", TableListing.Justification
                                                                                                                                                                                                                        .Right).AddField("MAXTTL", TableListing.Justification.Right);
                if (printStats)
                {
                    builder.AddField("BYTES_NEEDED", TableListing.Justification.Right).AddField("BYTES_CACHED"
                                                                                                , TableListing.Justification.Right).AddField("BYTES_OVERLIMIT", TableListing.Justification
                                                                                                                                             .Right).AddField("FILES_NEEDED", TableListing.Justification.Right).AddField("FILES_CACHED"
                                                                                                                                                                                                                         , TableListing.Justification.Right);
                }
                TableListing listing    = builder.Build();
                int          numResults = 0;

                try
                {
                    RemoteIterator <CachePoolEntry> iter = dfs.ListCachePools();
                    while (iter.HasNext())
                    {
                        CachePoolEntry entry = iter.Next();
                        CachePoolInfo  info  = entry.GetInfo();
                        List <string>  row   = new List <string>();
                        if (name == null || info.GetPoolName().Equals(name))
                        {
                            row.AddItem(info.GetPoolName());
                            row.AddItem(info.GetOwnerName());
                            row.AddItem(info.GetGroupName());
                            row.AddItem(info.GetMode() != null ? info.GetMode().ToString() : null);
                            long   limit = info.GetLimit();
                            string limitString;
                            if (limit != null && limit.Equals(CachePoolInfo.LimitUnlimited))
                            {
                                limitString = "unlimited";
                            }
                            else
                            {
                                limitString = string.Empty + limit;
                            }
                            row.AddItem(limitString);
                            long   maxTtl       = info.GetMaxRelativeExpiryMs();
                            string maxTtlString = null;
                            if (maxTtl != null)
                            {
                                if (maxTtl == CachePoolInfo.RelativeExpiryNever)
                                {
                                    maxTtlString = "never";
                                }
                                else
                                {
                                    maxTtlString = DFSUtil.DurationToString(maxTtl);
                                }
                            }
                            row.AddItem(maxTtlString);
                            if (printStats)
                            {
                                CachePoolStats stats = entry.GetStats();
                                row.AddItem(System.Convert.ToString(stats.GetBytesNeeded()));
                                row.AddItem(System.Convert.ToString(stats.GetBytesCached()));
                                row.AddItem(System.Convert.ToString(stats.GetBytesOverlimit()));
                                row.AddItem(System.Convert.ToString(stats.GetFilesNeeded()));
                                row.AddItem(System.Convert.ToString(stats.GetFilesCached()));
                            }
                            listing.AddRow(Sharpen.Collections.ToArray(row, new string[row.Count]));
                            ++numResults;
                            if (name != null)
                            {
                                break;
                            }
                        }
                    }
                }
                catch (IOException e)
                {
                    System.Console.Error.WriteLine(AdminHelper.PrettifyException(e));
                    return(2);
                }
                System.Console.Out.Write(string.Format("Found %d result%s.%n", numResults, (numResults
                                                                                            == 1 ? string.Empty : "s")));
                if (numResults > 0)
                {
                    System.Console.Out.Write(listing);
                }
                // If list pools succeed, we return 0 (success exit code)
                return(0);
            }