HDFS-13271. WebHDFS: Add constructor in SnapshottableDirectoryStatus with HdfsFileStatus as argument. Contributed by Lokesh Jain

This commit is contained in:
Chris Douglas 2018-03-13 09:43:22 -07:00
parent 0355ec20eb
commit b2b9ce5859
3 changed files with 10 additions and 35 deletions

View File

@ -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<Flags> convert(Set<AttrFlags> attr) {
if (attr.isEmpty()) {
return EnumSet.noneOf(Flags.class);
}
EnumSet<Flags> 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
}
/**

View File

@ -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
*/

View File

@ -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<FileStatus.AttrFlags> 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;
}