/// <exception cref="System.Exception"/> public virtual int Run(string[] argv) { string description = "hdfs lsSnapshottableDir: \n" + "\tGet the list of snapshottable directories that are owned by the current user.\n" + "\tReturn all the snapshottable directories if the current user is a super user.\n"; if (argv.Length != 0) { System.Console.Error.WriteLine("Usage: \n" + description); return(1); } FileSystem fs = FileSystem.Get(GetConf()); if (!(fs is DistributedFileSystem)) { System.Console.Error.WriteLine("LsSnapshottableDir can only be used in DistributedFileSystem" ); return(1); } DistributedFileSystem dfs = (DistributedFileSystem)fs; try { SnapshottableDirectoryStatus[] stats = dfs.GetSnapshottableDirListing(); SnapshottableDirectoryStatus.Print(stats, System.Console.Out); } catch (IOException e) { string[] content = e.GetLocalizedMessage().Split("\n"); System.Console.Error.WriteLine("lsSnapshottableDir: " + content[0]); return(1); } return(0); }
/// <summary>List all the snapshottable directories that are owned by the current user. /// </summary> /// <param name="userName">Current user name.</param> /// <returns> /// Snapshottable directories that are owned by the current user, /// represented as an array of /// <see cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshottableDirectoryStatus"/> /// . If /// <paramref name="userName"/> /// is null, return all the snapshottable dirs. /// </returns> public virtual SnapshottableDirectoryStatus[] GetSnapshottableDirListing(string userName ) { if (snapshottables.IsEmpty()) { return(null); } IList <SnapshottableDirectoryStatus> statusList = new AList <SnapshottableDirectoryStatus >(); foreach (INodeDirectory dir in snapshottables.Values) { if (userName == null || userName.Equals(dir.GetUserName())) { SnapshottableDirectoryStatus status = new SnapshottableDirectoryStatus(dir.GetModificationTime (), dir.GetAccessTime(), dir.GetFsPermission(), dir.GetUserName(), dir.GetGroupName (), dir.GetLocalNameBytes(), dir.GetId(), dir.GetChildrenNum(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .CurrentStateId), dir.GetDirectorySnapshottableFeature().GetNumSnapshots(), dir. GetDirectorySnapshottableFeature().GetSnapshotQuota(), dir.GetParent() == null ? DFSUtil.EmptyBytes : DFSUtil.String2Bytes(dir.GetParent().GetFullPathName())); statusList.AddItem(status); } } statusList.Sort(SnapshottableDirectoryStatus.Comparator); return(Sharpen.Collections.ToArray(statusList, new SnapshottableDirectoryStatus[statusList .Count])); }