Exemple #1
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);
            }
Exemple #2
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);
            }