/// <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.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="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 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); }
/// <summary>Get either full or partial information about this CachePool.</summary> /// <param name="fullInfo"> /// If true, only the name will be returned (i.e., what you /// would get if you didn't have read permission for this pool.) /// </param> /// <returns>Cache pool information.</returns> internal CachePoolInfo GetInfo(bool fullInfo) { CachePoolInfo info = new CachePoolInfo(poolName); if (!fullInfo) { return(info); } return(info.SetOwnerName(ownerName).SetGroupName(groupName).SetMode(new FsPermission (mode)).SetLimit(limit).SetMaxRelativeExpiryMs(maxRelativeExpiryMs)); }
/// <exception cref="System.IO.IOException"/> internal static void ModifyCachePool(FSNamesystem fsn, CacheManager cacheManager, CachePoolInfo req, bool logRetryCache) { FSPermissionChecker pc = GetFsPermissionChecker(fsn); if (pc != null) { pc.CheckSuperuserPrivilege(); } cacheManager.ModifyCachePool(req); fsn.GetEditLog().LogModifyCachePool(req, logRetryCache); }
/// <exception cref="System.IO.IOException"/> internal static CachePoolInfo AddCachePool(FSNamesystem fsn, CacheManager cacheManager , CachePoolInfo req, bool logRetryCache) { FSPermissionChecker pc = GetFsPermissionChecker(fsn); if (pc != null) { pc.CheckSuperuserPrivilege(); } CachePoolInfo info = cacheManager.AddCachePool(req); fsn.GetEditLog().LogAddCachePool(info, logRetryCache); return(info); }
/// <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); } }
/// <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())); }
/// <summary>Modify an existing cache pool.</summary> /// <param name="info">The request to modify a cache pool.</param> /// <exception cref="System.IO.IOException"> /// /// If the request could not be completed. /// </exception> public virtual void ModifyCachePool(CachePoolInfo info) { dfs.ModifyCachePool(info); }
/// <summary>Add a cache pool.</summary> /// <param name="info">The request to add a cache pool.</param> /// <exception cref="System.IO.IOException"> /// /// If the request could not be completed. /// </exception> public virtual void AddCachePool(CachePoolInfo info) { dfs.AddCachePool(info); }
/// <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); }
/// <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); }
/// <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); }