/// <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"/> 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="System.IO.IOException"/> internal static BatchedRemoteIterator.BatchedListEntries <CacheDirectiveEntry> ListCacheDirectives (FSNamesystem fsn, CacheManager cacheManager, long startId, CacheDirectiveInfo filter ) { FSPermissionChecker pc = GetFsPermissionChecker(fsn); return(cacheManager.ListCacheDirectives(startId, filter, pc)); }
/// <exception cref="System.IO.IOException"/> internal static void ModifyCacheDirective(FSNamesystem fsn, CacheManager cacheManager , CacheDirectiveInfo directive, EnumSet <CacheFlag> flags, bool logRetryCache) { FSPermissionChecker pc = GetFsPermissionChecker(fsn); cacheManager.ModifyDirective(directive, pc, flags); fsn.GetEditLog().LogModifyCacheDirectiveInfo(directive, logRetryCache); }
/// <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); }
/// <summary>List cache directives.</summary> /// <remarks>List cache directives. Incrementally fetches results from the server.</remarks> /// <param name="filter"> /// Filter parameters to use when listing the directives, null to /// list all directives visible to us. /// </param> /// <returns>A RemoteIterator which returns CacheDirectiveInfo objects.</returns> /// <exception cref="System.IO.IOException"/> public virtual RemoteIterator <CacheDirectiveEntry> ListCacheDirectives(CacheDirectiveInfo filter) { return(dfs.ListCacheDirectives(filter)); }
/// <summary>Modify a CacheDirective.</summary> /// <param name="info"> /// Information about the directive to modify. You must set the ID /// to indicate which CacheDirective you want to modify. /// </param> /// <param name="flags"> /// /// <see cref="Org.Apache.Hadoop.FS.CacheFlag"/> /// s to use for this operation. /// </param> /// <exception cref="System.IO.IOException">if the directive could not be modified</exception> public virtual void ModifyCacheDirective(CacheDirectiveInfo info, EnumSet <CacheFlag > flags) { dfs.ModifyCacheDirective(info, flags); }
/// <summary>Add a new CacheDirectiveInfo.</summary> /// <param name="info">Information about a directive to add.</param> /// <param name="flags"> /// /// <see cref="Org.Apache.Hadoop.FS.CacheFlag"/> /// s to use for this operation. /// </param> /// <returns>the ID of the directive that was created.</returns> /// <exception cref="System.IO.IOException">if the directive could not be added</exception> public virtual long AddCacheDirective(CacheDirectiveInfo info, EnumSet <CacheFlag> flags) { return(dfs.AddCacheDirective(info, flags)); }
/// <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); }
/// <exception cref="System.IO.IOException"/> public virtual int Run(Configuration conf, IList <string> args) { CacheDirectiveInfo.Builder builder = new CacheDirectiveInfo.Builder(); string path = StringUtils.PopOptionWithArgument("-path", args); if (path == null) { System.Console.Error.WriteLine("You must specify a path with -path."); return(1); } builder.SetPath(new Path(path)); string poolName = StringUtils.PopOptionWithArgument("-pool", args); if (poolName == null) { System.Console.Error.WriteLine("You must specify a pool name with -pool."); return(1); } builder.SetPool(poolName); bool force = StringUtils.PopOption("-force", args); string replicationString = StringUtils.PopOptionWithArgument("-replication", args ); if (replicationString != null) { short replication = short.ParseShort(replicationString); builder.SetReplication(replication); } string ttlString = StringUtils.PopOptionWithArgument("-ttl", args); try { CacheDirectiveInfo.Expiration ex = ParseExpirationString(ttlString); if (ex != null) { builder.SetExpiration(ex); } } catch (IOException e) { System.Console.Error.WriteLine("Error while parsing ttl value: " + e.Message); return(1); } if (!args.IsEmpty()) { System.Console.Error.WriteLine("Can't understand argument: " + args[0]); return(1); } DistributedFileSystem dfs = AdminHelper.GetDFS(conf); CacheDirectiveInfo directive = builder.Build(); EnumSet <CacheFlag> flags = EnumSet.NoneOf <CacheFlag>(); if (force) { flags.AddItem(CacheFlag.Force); } try { long id = dfs.AddCacheDirective(directive, flags); System.Console.Out.WriteLine("Added cache directive " + id); } catch (IOException e) { System.Console.Error.WriteLine(AdminHelper.PrettifyException(e)); return(2); } return(0); }