Esempio n. 1
0
 /// <summary>List all cache pools.</summary>
 /// <returns>
 /// A remote iterator from which you can get CachePoolEntry objects.
 /// Requests will be made as needed.
 /// </returns>
 /// <exception cref="System.IO.IOException">If there was an error listing cache pools.
 ///     </exception>
 public virtual RemoteIterator <CachePoolEntry> ListCachePools()
 {
     return(dfs.ListCachePools());
 }
Esempio n. 2
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);
            }