From b2b9ce585984a1791a8af3e2287c75c75b95586f Mon Sep 17 00:00:00 2001 From: Chris Douglas Date: Tue, 13 Mar 2018 09:43:22 -0700 Subject: [PATCH] HDFS-13271. WebHDFS: Add constructor in SnapshottableDirectoryStatus with HdfsFileStatus as argument. Contributed by Lokesh Jain --- .../hadoop/hdfs/protocol/HdfsFileStatus.java | 27 +------------------ .../SnapshottableDirectoryStatus.java | 8 ++++++ .../hadoop/hdfs/web/JsonUtilClient.java | 10 +------ 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsFileStatus.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsFileStatus.java index cb05c7553e..264e3f4050 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsFileStatus.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/HdfsFileStatus.java @@ -50,32 +50,7 @@ enum Flags { HAS_ACL, HAS_CRYPT, HAS_EC, - SNAPSHOT_ENABLED; - - /** - * Generates an enum set of Flags from a set of attr flags. - * @param attr Set of attr flags - * @return EnumSet of Flags - */ - public static EnumSet convert(Set attr) { - if (attr.isEmpty()) { - return EnumSet.noneOf(Flags.class); - } - EnumSet flags = EnumSet.noneOf(Flags.class); - if (attr.contains(AttrFlags.HAS_ACL)) { - flags.add(Flags.HAS_ACL); - } - if (attr.contains(AttrFlags.HAS_EC)) { - flags.add(Flags.HAS_EC); - } - if (attr.contains(AttrFlags.HAS_CRYPT)) { - flags.add(Flags.HAS_CRYPT); - } - if (attr.contains(AttrFlags.SNAPSHOT_ENABLED)) { - flags.add(Flags.SNAPSHOT_ENABLED); - } - return flags; - } + SNAPSHOT_ENABLED } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java index 6cdb2eed87..0d352385c5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java @@ -79,6 +79,14 @@ public SnapshottableDirectoryStatus(long modification_time, long access_time, this.parentFullPath = parentFullPath; } + public SnapshottableDirectoryStatus(HdfsFileStatus dirStatus, + int snapshotNumber, int snapshotQuota, byte[] parentFullPath) { + this.dirStatus = dirStatus; + this.snapshotNumber = snapshotNumber; + this.snapshotQuota = snapshotQuota; + this.parentFullPath = parentFullPath; + } + /** * @return Number of snapshots that have been taken for the directory */ diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java index aa79dc46be..13c5226cfe 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java @@ -65,7 +65,6 @@ import java.util.EnumSet; import java.util.List; import java.util.Map; -import java.util.Set; class JsonUtilClient { static final DatanodeInfo[] EMPTY_DATANODE_INFO_ARRAY = {}; @@ -772,15 +771,8 @@ private static SnapshottableDirectoryStatus toSnapshottableDirectoryStatus( byte[] parentFullPath = toByteArray((String) json.get("parentFullPath")); HdfsFileStatus dirStatus = toFileStatus((Map) json.get("dirStatus"), false); - Set attrFlags = FileStatus - .attributes(dirStatus.hasAcl(), dirStatus.isEncrypted(), - dirStatus.isErasureCoded(), dirStatus.isSnapshotEnabled()); SnapshottableDirectoryStatus snapshottableDirectoryStatus = - new SnapshottableDirectoryStatus(dirStatus.getModificationTime(), - dirStatus.getAccessTime(), dirStatus.getPermission(), - HdfsFileStatus.Flags.convert(attrFlags), dirStatus.getOwner(), - dirStatus.getGroup(), dirStatus.getLocalNameInBytes(), - dirStatus.getFileId(), dirStatus.getChildrenNum(), snapshotNumber, + new SnapshottableDirectoryStatus(dirStatus, snapshotNumber, snapshotQuota, parentFullPath); return snapshottableDirectoryStatus; }