Exemple #1
0
        /// <summary>Create a new cache pool based on a CachePoolInfo object and the defaults.
        ///     </summary>
        /// <remarks>
        /// Create a new cache pool based on a CachePoolInfo object and the defaults.
        /// We will fill in information that was not supplied according to the
        /// defaults.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        internal static CachePool CreateFromInfoAndDefaults(CachePoolInfo info)
        {
            UserGroupInformation ugi = null;
            string ownerName         = info.GetOwnerName();

            if (ownerName == null)
            {
                ugi       = NameNode.GetRemoteUser();
                ownerName = ugi.GetShortUserName();
            }
            string groupName = info.GetGroupName();

            if (groupName == null)
            {
                if (ugi == null)
                {
                    ugi = NameNode.GetRemoteUser();
                }
                groupName = ugi.GetPrimaryGroupName();
            }
            FsPermission mode = (info.GetMode() == null) ? FsPermission.GetCachePoolDefault()
                                 : info.GetMode();
            long limit = info.GetLimit() == null ? CachePoolInfo.DefaultLimit : info.GetLimit
                             ();
            long maxRelativeExpiry = info.GetMaxRelativeExpiryMs() == null ? CachePoolInfo.DefaultMaxRelativeExpiry
                                 : info.GetMaxRelativeExpiryMs();

            return(new CachePool(info.GetPoolName(), ownerName, groupName, mode, limit, maxRelativeExpiry
                                 ));
        }
        /// <exception cref="Org.Xml.Sax.SAXException"/>
        public static void WriteCachePoolInfo(ContentHandler contentHandler, CachePoolInfo
                                              info)
        {
            XMLUtils.AddSaxString(contentHandler, "POOLNAME", info.GetPoolName());
            string       ownerName         = info.GetOwnerName();
            string       groupName         = info.GetGroupName();
            long         limit             = info.GetLimit();
            FsPermission mode              = info.GetMode();
            long         maxRelativeExpiry = info.GetMaxRelativeExpiryMs();

            if (ownerName != null)
            {
                XMLUtils.AddSaxString(contentHandler, "OWNERNAME", ownerName);
            }
            if (groupName != null)
            {
                XMLUtils.AddSaxString(contentHandler, "GROUPNAME", groupName);
            }
            if (mode != null)
            {
                FSEditLogOp.FsPermissionToXml(contentHandler, mode);
            }
            if (limit != null)
            {
                XMLUtils.AddSaxString(contentHandler, "LIMIT", System.Convert.ToString(limit));
            }
            if (maxRelativeExpiry != null)
            {
                XMLUtils.AddSaxString(contentHandler, "MAXRELATIVEEXPIRY", System.Convert.ToString
                                          (maxRelativeExpiry));
            }
        }
        /// <exception cref="System.IO.IOException"/>
        public static void WriteCachePoolInfo(DataOutputStream @out, CachePoolInfo info)
        {
            WriteString(info.GetPoolName(), @out);
            string       ownerName         = info.GetOwnerName();
            string       groupName         = info.GetGroupName();
            long         limit             = info.GetLimit();
            FsPermission mode              = info.GetMode();
            long         maxRelativeExpiry = info.GetMaxRelativeExpiryMs();
            bool         hasOwner;
            bool         hasGroup;
            bool         hasMode;
            bool         hasLimit;
            bool         hasMaxRelativeExpiry;

            hasOwner             = ownerName != null;
            hasGroup             = groupName != null;
            hasMode              = mode != null;
            hasLimit             = limit != null;
            hasMaxRelativeExpiry = maxRelativeExpiry != null;
            int flags = (hasOwner ? unchecked ((int)(0x1)) : 0) | (hasGroup ? unchecked ((int)(
                                                                                             0x2)) : 0) | (hasMode ? unchecked ((int)(0x4)) : 0) | (hasLimit ? unchecked ((int)
                                                                                                                                                                          (0x8)) : 0) | (hasMaxRelativeExpiry ? unchecked ((int)(0x10)) : 0);

            WriteInt(flags, @out);
            if (hasOwner)
            {
                WriteString(ownerName, @out);
            }
            if (hasGroup)
            {
                WriteString(groupName, @out);
            }
            if (hasMode)
            {
                mode.Write(@out);
            }
            if (hasLimit)
            {
                WriteLong(limit, @out);
            }
            if (hasMaxRelativeExpiry)
            {
                WriteLong(maxRelativeExpiry, @out);
            }
        }
Exemple #4
0
 /// <summary>Create a new cache pool based on a CachePoolInfo object.</summary>
 /// <remarks>
 /// Create a new cache pool based on a CachePoolInfo object.
 /// No fields in the CachePoolInfo can be blank.
 /// </remarks>
 internal static CachePool CreateFromInfo(CachePoolInfo info)
 {
     return(new CachePool(info.GetPoolName(), info.GetOwnerName(), info.GetGroupName()
                          , info.GetMode(), info.GetLimit(), info.GetMaxRelativeExpiryMs()));
 }
Exemple #5
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);
            }