/// <exception cref="System.IO.IOException"/> public virtual int Run(Configuration conf, IList <string> args) { string path = StringUtils.PopOptionWithArgument("-path", args); if (path == null) { System.Console.Error.WriteLine("You must specify a path with -path."); return(1); } if (!args.IsEmpty()) { System.Console.Error.WriteLine("Can't understand argument: " + args[0]); System.Console.Error.WriteLine("Usage is " + GetShortUsage()); return(1); } int exitCode = 0; try { DistributedFileSystem dfs = AdminHelper.GetDFS(conf); RemoteIterator <CacheDirectiveEntry> iter = dfs.ListCacheDirectives(new CacheDirectiveInfo.Builder ().SetPath(new Path(path)).Build()); while (iter.HasNext()) { CacheDirectiveEntry entry = iter.Next(); try { dfs.RemoveCacheDirective(entry.GetInfo().GetId()); System.Console.Out.WriteLine("Removed cache directive " + entry.GetInfo().GetId() ); } catch (IOException e) { System.Console.Error.WriteLine(AdminHelper.PrettifyException(e)); exitCode = 2; } } } catch (IOException e) { System.Console.Error.WriteLine(AdminHelper.PrettifyException(e)); exitCode = 2; } if (exitCode == 0) { System.Console.Out.WriteLine("Removed every cache directive with path " + path); } return(exitCode); }
/// <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); }