/// <exception cref="Org.Apache.Hadoop.Hdfs.Util.XMLUtils.InvalidXmlException"/>
        public static CachePoolInfo ReadCachePoolInfo(XMLUtils.Stanza st)
        {
            string        poolName = st.GetValue("POOLNAME");
            CachePoolInfo info     = new CachePoolInfo(poolName);

            if (st.HasChildren("OWNERNAME"))
            {
                info.SetOwnerName(st.GetValue("OWNERNAME"));
            }
            if (st.HasChildren("GROUPNAME"))
            {
                info.SetGroupName(st.GetValue("GROUPNAME"));
            }
            if (st.HasChildren("MODE"))
            {
                info.SetMode(FSEditLogOp.FsPermissionFromXml(st));
            }
            if (st.HasChildren("LIMIT"))
            {
                info.SetLimit(long.Parse(st.GetValue("LIMIT")));
            }
            if (st.HasChildren("MAXRELATIVEEXPIRY"))
            {
                info.SetMaxRelativeExpiryMs(long.Parse(st.GetValue("MAXRELATIVEEXPIRY")));
            }
            return(info);
        }
        /// <exception cref="System.IO.IOException"/>
        public static CachePoolInfo ReadCachePoolInfo(DataInput @in)
        {
            string        poolName = ReadString(@in);
            CachePoolInfo info     = new CachePoolInfo(poolName);
            int           flags    = ReadInt(@in);

            if ((flags & unchecked ((int)(0x1))) != 0)
            {
                info.SetOwnerName(ReadString(@in));
            }
            if ((flags & unchecked ((int)(0x2))) != 0)
            {
                info.SetGroupName(ReadString(@in));
            }
            if ((flags & unchecked ((int)(0x4))) != 0)
            {
                info.SetMode(FsPermission.Read(@in));
            }
            if ((flags & unchecked ((int)(0x8))) != 0)
            {
                info.SetLimit(ReadLong(@in));
            }
            if ((flags & unchecked ((int)(0x10))) != 0)
            {
                info.SetMaxRelativeExpiryMs(ReadLong(@in));
            }
            if ((flags & ~unchecked ((int)(0x1F))) != 0)
            {
                throw new IOException("Unknown flag in CachePoolInfo: " + flags);
            }
            return(info);
        }
Beispiel #3
0
            /// <exception cref="System.IO.IOException"/>
            public virtual int Run(Configuration conf, IList <string> args)
            {
                string owner        = StringUtils.PopOptionWithArgument("-owner", args);
                string group        = StringUtils.PopOptionWithArgument("-group", args);
                string modeString   = StringUtils.PopOptionWithArgument("-mode", args);
                int    mode         = (modeString == null) ? null : System.Convert.ToInt32(modeString, 8);
                string limitString  = StringUtils.PopOptionWithArgument("-limit", args);
                long   limit        = AdminHelper.ParseLimitString(limitString);
                string maxTtlString = StringUtils.PopOptionWithArgument("-maxTtl", args);
                long   maxTtl;

                try
                {
                    maxTtl = AdminHelper.ParseTtlString(maxTtlString);
                }
                catch (IOException e)
                {
                    System.Console.Error.WriteLine("Error while parsing maxTtl value: " + e.Message);
                    return(1);
                }
                string name = StringUtils.PopFirstNonOption(args);

                if (name == null)
                {
                    System.Console.Error.WriteLine("You must specify a name when creating a " + "cache pool."
                                                   );
                    return(1);
                }
                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);
                }
                bool          changed = false;
                CachePoolInfo info    = new CachePoolInfo(name);

                if (owner != null)
                {
                    info.SetOwnerName(owner);
                    changed = true;
                }
                if (group != null)
                {
                    info.SetGroupName(group);
                    changed = true;
                }
                if (mode != null)
                {
                    info.SetMode(new FsPermission(mode));
                    changed = true;
                }
                if (limit != null)
                {
                    info.SetLimit(limit);
                    changed = true;
                }
                if (maxTtl != null)
                {
                    info.SetMaxRelativeExpiryMs(maxTtl);
                    changed = true;
                }
                if (!changed)
                {
                    System.Console.Error.WriteLine("You must specify at least one attribute to " + "change in the cache pool."
                                                   );
                    return(1);
                }
                DistributedFileSystem dfs = AdminHelper.GetDFS(conf);

                try
                {
                    dfs.ModifyCachePool(info);
                }
                catch (IOException e)
                {
                    System.Console.Error.WriteLine(AdminHelper.PrettifyException(e));
                    return(2);
                }
                System.Console.Out.Write("Successfully modified cache pool " + name);
                string prefix = " to have ";

                if (owner != null)
                {
                    System.Console.Out.Write(prefix + "owner name " + owner);
                    prefix = " and ";
                }
                if (group != null)
                {
                    System.Console.Out.Write(prefix + "group name " + group);
                    prefix = " and ";
                }
                if (mode != null)
                {
                    System.Console.Out.Write(prefix + "mode " + new FsPermission(mode));
                    prefix = " and ";
                }
                if (limit != null)
                {
                    System.Console.Out.Write(prefix + "limit " + limit);
                    prefix = " and ";
                }
                if (maxTtl != null)
                {
                    System.Console.Out.Write(prefix + "max time-to-live " + maxTtlString);
                }
                System.Console.Out.Write("\n");
                return(0);
            }
Beispiel #4
0
            /// <exception cref="System.IO.IOException"/>
            public virtual int Run(Configuration conf, IList <string> args)
            {
                string name = StringUtils.PopFirstNonOption(args);

                if (name == null)
                {
                    System.Console.Error.WriteLine("You must specify a name when creating a " + "cache pool."
                                                   );
                    return(1);
                }
                CachePoolInfo info  = new CachePoolInfo(name);
                string        owner = StringUtils.PopOptionWithArgument("-owner", args);

                if (owner != null)
                {
                    info.SetOwnerName(owner);
                }
                string group = StringUtils.PopOptionWithArgument("-group", args);

                if (group != null)
                {
                    info.SetGroupName(group);
                }
                string modeString = StringUtils.PopOptionWithArgument("-mode", args);

                if (modeString != null)
                {
                    short mode = short.ParseShort(modeString, 8);
                    info.SetMode(new FsPermission(mode));
                }
                string limitString = StringUtils.PopOptionWithArgument("-limit", args);
                long   limit       = AdminHelper.ParseLimitString(limitString);

                if (limit != null)
                {
                    info.SetLimit(limit);
                }
                string maxTtlString = StringUtils.PopOptionWithArgument("-maxTtl", args);

                try
                {
                    long maxTtl = AdminHelper.ParseTtlString(maxTtlString);
                    if (maxTtl != null)
                    {
                        info.SetMaxRelativeExpiryMs(maxTtl);
                    }
                }
                catch (IOException e)
                {
                    System.Console.Error.WriteLine("Error while parsing maxTtl value: " + e.Message);
                    return(1);
                }
                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);

                try
                {
                    dfs.AddCachePool(info);
                }
                catch (IOException e)
                {
                    System.Console.Error.WriteLine(AdminHelper.PrettifyException(e));
                    return(2);
                }
                System.Console.Out.WriteLine("Successfully added cache pool " + name + ".");
                return(0);
            }