/// <exception cref="System.IO.IOException"/> public static void WriteCacheDirectiveInfo(DataOutputStream @out, CacheDirectiveInfo directive) { WriteLong(directive.GetId(), @out); int flags = ((directive.GetPath() != null) ? unchecked ((int)(0x1)) : 0) | ((directive .GetReplication() != null) ? unchecked ((int)(0x2)) : 0) | ((directive.GetPool() != null) ? unchecked ((int)(0x4)) : 0) | ((directive.GetExpiration() != null) ? unchecked ( (int)(0x8)) : 0); @out.WriteInt(flags); if (directive.GetPath() != null) { WriteString(directive.GetPath().ToUri().GetPath(), @out); } if (directive.GetReplication() != null) { WriteShort(directive.GetReplication(), @out); } if (directive.GetPool() != null) { WriteString(directive.GetPool(), @out); } if (directive.GetExpiration() != null) { WriteLong(directive.GetExpiration().GetMillis(), @out); } }
/// <exception cref="Org.Xml.Sax.SAXException"/> public static void WriteCacheDirectiveInfo(ContentHandler contentHandler, CacheDirectiveInfo directive) { XMLUtils.AddSaxString(contentHandler, "ID", System.Convert.ToString(directive.GetId ())); if (directive.GetPath() != null) { XMLUtils.AddSaxString(contentHandler, "PATH", directive.GetPath().ToUri().GetPath ()); } if (directive.GetReplication() != null) { XMLUtils.AddSaxString(contentHandler, "REPLICATION", short.ToString(directive.GetReplication ())); } if (directive.GetPool() != null) { XMLUtils.AddSaxString(contentHandler, "POOL", directive.GetPool()); } if (directive.GetExpiration() != null) { XMLUtils.AddSaxString(contentHandler, "EXPIRATION", string.Empty + directive.GetExpiration ().GetMillis()); } }
/// <exception cref="System.IO.IOException"/> internal static CacheDirectiveInfo AddCacheDirective(FSNamesystem fsn, CacheManager cacheManager, CacheDirectiveInfo directive, EnumSet <CacheFlag> flags, bool logRetryCache ) { FSPermissionChecker pc = GetFsPermissionChecker(fsn); if (directive.GetId() != null) { throw new IOException("addDirective: you cannot specify an ID " + "for this operation." ); } CacheDirectiveInfo effectiveDirective = cacheManager.AddDirective(directive, pc, flags); fsn.GetEditLog().LogAddCacheDirectiveInfo(effectiveDirective, logRetryCache); return(effectiveDirective); }
/// <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); }