Exemple #1
0
            /// <exception cref="System.IO.IOException"/>
            public virtual int Run(Configuration conf, IList <string> args)
            {
                if (!args.IsEmpty())
                {
                    System.Console.Error.WriteLine("Can't understand argument: " + args[0]);
                    return(1);
                }
                DistributedFileSystem dfs = AdminHelper.GetDFS(conf);

                try
                {
                    TableListing listing = new TableListing.Builder().AddField(string.Empty).AddField
                                               (string.Empty, true).WrapWidth(AdminHelper.MaxLineWidth).HideHeaders().Build();
                    RemoteIterator <EncryptionZone> it = dfs.ListEncryptionZones();
                    while (it.HasNext())
                    {
                        EncryptionZone ez = it.Next();
                        listing.AddRow(ez.GetPath(), ez.GetKeyName());
                    }
                    System.Console.Out.WriteLine(listing.ToString());
                }
                catch (IOException e)
                {
                    System.Console.Error.WriteLine(PrettifyException(e));
                    return(2);
                }
                return(0);
            }
Exemple #2
0
        /// <exception cref="System.IO.IOException"/>
        private int ListSpanReceivers(IList <string> args)
        {
            SpanReceiverInfo[] infos = remote.ListSpanReceivers();
            if (infos.Length == 0)
            {
                System.Console.Out.WriteLine("[no span receivers found]");
                return(0);
            }
            TableListing listing = new TableListing.Builder().AddField("ID").AddField("CLASS"
                                                                                      ).ShowHeaders().Build();

            foreach (SpanReceiverInfo info in infos)
            {
                listing.AddRow(string.Empty + info.GetId(), info.GetClassName());
            }
            System.Console.Out.WriteLine(listing.ToString());
            return(0);
        }
Exemple #3
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);
            }
Exemple #4
0
            /// <exception cref="System.IO.IOException"/>
            public virtual int Run(Configuration conf, IList <string> args)
            {
                CacheDirectiveInfo.Builder builder = new CacheDirectiveInfo.Builder();
                string pathFilter = StringUtils.PopOptionWithArgument("-path", args);

                if (pathFilter != null)
                {
                    builder.SetPath(new Path(pathFilter));
                }
                string poolFilter = StringUtils.PopOptionWithArgument("-pool", args);

                if (poolFilter != null)
                {
                    builder.SetPool(poolFilter);
                }
                bool   printStats = StringUtils.PopOption("-stats", args);
                string idFilter   = StringUtils.PopOptionWithArgument("-id", args);

                if (idFilter != null)
                {
                    builder.SetId(long.Parse(idFilter));
                }
                if (!args.IsEmpty())
                {
                    System.Console.Error.WriteLine("Can't understand argument: " + args[0]);
                    return(1);
                }
                TableListing.Builder tableBuilder = new TableListing.Builder().AddField("ID", TableListing.Justification
                                                                                        .Right).AddField("POOL", TableListing.Justification.Left).AddField("REPL", TableListing.Justification
                                                                                                                                                           .Right).AddField("EXPIRY", TableListing.Justification.Left).AddField("PATH", TableListing.Justification
                                                                                                                                                                                                                                .Left);
                if (printStats)
                {
                    tableBuilder.AddField("BYTES_NEEDED", TableListing.Justification.Right).AddField(
                        "BYTES_CACHED", TableListing.Justification.Right).AddField("FILES_NEEDED", TableListing.Justification
                                                                                   .Right).AddField("FILES_CACHED", TableListing.Justification.Right);
                }
                TableListing tableListing = tableBuilder.Build();

                try
                {
                    DistributedFileSystem dfs = AdminHelper.GetDFS(conf);
                    RemoteIterator <CacheDirectiveEntry> iter = dfs.ListCacheDirectives(builder.Build(
                                                                                            ));
                    int numEntries = 0;
                    while (iter.HasNext())
                    {
                        CacheDirectiveEntry entry     = iter.Next();
                        CacheDirectiveInfo  directive = entry.GetInfo();
                        CacheDirectiveStats stats     = entry.GetStats();
                        IList <string>      row       = new List <string>();
                        row.AddItem(string.Empty + directive.GetId());
                        row.AddItem(directive.GetPool());
                        row.AddItem(string.Empty + directive.GetReplication());
                        string expiry;
                        // This is effectively never, round for nice printing
                        if (directive.GetExpiration().GetMillis() > CacheDirectiveInfo.Expiration.MaxRelativeExpiryMs
                            / 2)
                        {
                            expiry = "never";
                        }
                        else
                        {
                            expiry = directive.GetExpiration().ToString();
                        }
                        row.AddItem(expiry);
                        row.AddItem(directive.GetPath().ToUri().GetPath());
                        if (printStats)
                        {
                            row.AddItem(string.Empty + stats.GetBytesNeeded());
                            row.AddItem(string.Empty + stats.GetBytesCached());
                            row.AddItem(string.Empty + stats.GetFilesNeeded());
                            row.AddItem(string.Empty + stats.GetFilesCached());
                        }
                        tableListing.AddRow(Sharpen.Collections.ToArray(row, new string[row.Count]));
                        numEntries++;
                    }
                    System.Console.Out.Write(string.Format("Found %d entr%s%n", numEntries, numEntries
                                                           == 1 ? "y" : "ies"));
                    if (numEntries > 0)
                    {
                        System.Console.Out.Write(tableListing);
                    }
                }
                catch (IOException e)
                {
                    System.Console.Error.WriteLine(AdminHelper.PrettifyException(e));
                    return(2);
                }
                return(0);
            }