/// <exception cref="Org.Apache.Hadoop.Hdfs.Util.XMLUtils.InvalidXmlException"/> public static CacheDirectiveInfo ReadCacheDirectiveInfo(XMLUtils.Stanza st) { CacheDirectiveInfo.Builder builder = new CacheDirectiveInfo.Builder(); builder.SetId(long.Parse(st.GetValue("ID"))); string path = st.GetValueOrNull("PATH"); if (path != null) { builder.SetPath(new Path(path)); } string replicationString = st.GetValueOrNull("REPLICATION"); if (replicationString != null) { builder.SetReplication(short.ParseShort(replicationString)); } string pool = st.GetValueOrNull("POOL"); if (pool != null) { builder.SetPool(pool); } string expiryTime = st.GetValueOrNull("EXPIRATION"); if (expiryTime != null) { builder.SetExpiration(CacheDirectiveInfo.Expiration.NewAbsolute(long.Parse(expiryTime ))); } return(builder.Build()); }
/// <exception cref="System.IO.IOException"/> public static CacheDirectiveInfo ReadCacheDirectiveInfo(DataInput @in) { CacheDirectiveInfo.Builder builder = new CacheDirectiveInfo.Builder(); builder.SetId(ReadLong(@in)); int flags = @in.ReadInt(); if ((flags & unchecked ((int)(0x1))) != 0) { builder.SetPath(new Path(ReadString(@in))); } if ((flags & unchecked ((int)(0x2))) != 0) { builder.SetReplication(ReadShort(@in)); } if ((flags & unchecked ((int)(0x4))) != 0) { builder.SetPool(ReadString(@in)); } if ((flags & unchecked ((int)(0x8))) != 0) { builder.SetExpiration(CacheDirectiveInfo.Expiration.NewAbsolute(ReadLong(@in))); } if ((flags & ~unchecked ((int)(0xF))) != 0) { throw new IOException("unknown flags set in " + "ModifyCacheDirectiveInfoOp: " + flags); } return(builder.Build()); }
/// <exception cref="System.IO.IOException"/> public virtual int Run(Configuration conf, IList <string> args) { CacheDirectiveInfo.Builder builder = new CacheDirectiveInfo.Builder(); bool modified = false; string idString = StringUtils.PopOptionWithArgument("-id", args); if (idString == null) { System.Console.Error.WriteLine("You must specify a directive ID with -id."); return(1); } builder.SetId(long.Parse(idString)); string path = StringUtils.PopOptionWithArgument("-path", args); if (path != null) { builder.SetPath(new Path(path)); modified = true; } bool force = StringUtils.PopOption("-force", args); string replicationString = StringUtils.PopOptionWithArgument("-replication", args ); if (replicationString != null) { builder.SetReplication(short.ParseShort(replicationString)); modified = true; } string poolName = StringUtils.PopOptionWithArgument("-pool", args); if (poolName != null) { builder.SetPool(poolName); modified = true; } string ttlString = StringUtils.PopOptionWithArgument("-ttl", args); try { CacheDirectiveInfo.Expiration ex = ParseExpirationString(ttlString); if (ex != null) { builder.SetExpiration(ex); modified = true; } } 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]); System.Console.Error.WriteLine("Usage is " + GetShortUsage()); return(1); } if (!modified) { System.Console.Error.WriteLine("No modifications were specified."); return(1); } DistributedFileSystem dfs = AdminHelper.GetDFS(conf); EnumSet <CacheFlag> flags = EnumSet.NoneOf <CacheFlag>(); if (force) { flags.AddItem(CacheFlag.Force); } try { dfs.ModifyCacheDirective(builder.Build(), flags); System.Console.Out.WriteLine("Modified cache directive " + idString); } 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); }