|
@@ -31,6 +31,11 @@ import org.apache.hadoop.fs.ContentSummary;
|
|
|
import org.apache.hadoop.fs.CreateFlag;
|
|
|
import org.apache.hadoop.fs.FsServerDefaults;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
+import org.apache.hadoop.fs.permission.AclEntry;
|
|
|
+import org.apache.hadoop.fs.permission.AclEntryScope;
|
|
|
+import org.apache.hadoop.fs.permission.AclEntryType;
|
|
|
+import org.apache.hadoop.fs.permission.AclStatus;
|
|
|
+import org.apache.hadoop.fs.permission.FsAction;
|
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
|
|
|
import org.apache.hadoop.ha.proto.HAServiceProtocolProtos;
|
|
@@ -59,6 +64,12 @@ import org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus;
|
|
|
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
|
|
|
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
|
|
|
import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus;
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEntryProto;
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclStatusProto;
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEntryProto.AclEntryScopeProto;
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEntryProto.AclEntryTypeProto;
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEntryProto.FsActionProto;
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.AclProtos.GetAclStatusResponseProto;
|
|
|
import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos;
|
|
|
import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CacheDirectiveEntryProto;
|
|
|
import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CacheDirectiveInfoExpirationProto;
|
|
@@ -185,6 +196,13 @@ public class PBHelper {
|
|
|
RegisterCommandProto.newBuilder().build();
|
|
|
private static final RegisterCommand REG_CMD = new RegisterCommand();
|
|
|
|
|
|
+ private static final AclEntryScope[] ACL_ENTRY_SCOPE_VALUES =
|
|
|
+ AclEntryScope.values();
|
|
|
+ private static final AclEntryType[] ACL_ENTRY_TYPE_VALUES =
|
|
|
+ AclEntryType.values();
|
|
|
+ private static final FsAction[] FSACTION_VALUES =
|
|
|
+ FsAction.values();
|
|
|
+
|
|
|
private PBHelper() {
|
|
|
/** Hidden constructor */
|
|
|
}
|
|
@@ -193,6 +211,10 @@ public class PBHelper {
|
|
|
return ByteString.copyFrom(bytes);
|
|
|
}
|
|
|
|
|
|
+ private static <T extends Enum<T>, U extends Enum<U>> U castEnum(T from, U[] to) {
|
|
|
+ return to[from.ordinal()];
|
|
|
+ }
|
|
|
+
|
|
|
public static NamenodeRole convert(NamenodeRoleProto role) {
|
|
|
switch (role) {
|
|
|
case NAMENODE:
|
|
@@ -717,8 +739,9 @@ public class PBHelper {
|
|
|
return REG_CMD;
|
|
|
case BlockIdCommand:
|
|
|
return PBHelper.convert(proto.getBlkIdCmd());
|
|
|
+ default:
|
|
|
+ return null;
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
public static BalancerBandwidthCommandProto convert(
|
|
@@ -1755,4 +1778,63 @@ public class PBHelper {
|
|
|
assert size >= 0;
|
|
|
return new ExactSizeInputStream(input, size);
|
|
|
}
|
|
|
+
|
|
|
+ private static AclEntryScopeProto convert(AclEntryScope v) {
|
|
|
+ return AclEntryScopeProto.valueOf(v.ordinal());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static AclEntryScope convert(AclEntryScopeProto v) {
|
|
|
+ return castEnum(v, ACL_ENTRY_SCOPE_VALUES);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static AclEntryTypeProto convert(AclEntryType e) {
|
|
|
+ return AclEntryTypeProto.valueOf(e.ordinal());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static AclEntryType convert(AclEntryTypeProto v) {
|
|
|
+ return castEnum(v, ACL_ENTRY_TYPE_VALUES);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static FsActionProto convert(FsAction v) {
|
|
|
+ return FsActionProto.valueOf(v.ordinal());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static FsAction convert(FsActionProto v) {
|
|
|
+ return castEnum(v, FSACTION_VALUES);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<AclEntryProto> convertAclEntryProto(
|
|
|
+ List<AclEntry> aclSpec) {
|
|
|
+ ArrayList<AclEntryProto> r = Lists.newArrayListWithCapacity(aclSpec.size());
|
|
|
+ for (AclEntry e : aclSpec) {
|
|
|
+ r.add(AclEntryProto.newBuilder().setType(convert(e.getType()))
|
|
|
+ .setName(e.getName()).setPermissions(convert(e.getPermission()))
|
|
|
+ .setScope(convert(e.getScope())).build());
|
|
|
+ }
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<AclEntry> convertAclEntry(List<AclEntryProto> aclSpec) {
|
|
|
+ ArrayList<AclEntry> r = Lists.newArrayListWithCapacity(aclSpec.size());
|
|
|
+ for (AclEntryProto e : aclSpec) {
|
|
|
+ r.add(new AclEntry.Builder().setType(convert(e.getType()))
|
|
|
+ .setName(e.getName()).setPermission(convert(e.getPermissions()))
|
|
|
+ .setScope(convert(e.getScope())).build());
|
|
|
+ }
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static AclStatus convert(GetAclStatusResponseProto e) {
|
|
|
+ AclStatusProto r = e.getResult();
|
|
|
+ return new AclStatus.Builder().owner(r.getOwner()).group(r.getGroup())
|
|
|
+ .stickyBit(r.getSticky())
|
|
|
+ .addEntries(convertAclEntry(r.getEntriesList())).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static GetAclStatusResponseProto convert(AclStatus e) {
|
|
|
+ AclStatusProto r = AclStatusProto.newBuilder().setOwner(e.getOwner())
|
|
|
+ .setGroup(e.getGroup()).setSticky(e.isStickyBit())
|
|
|
+ .addAllEntries(convertAclEntryProto(e.getEntries())).build();
|
|
|
+ return GetAclStatusResponseProto.newBuilder().setResult(r).build();
|
|
|
+ }
|
|
|
}
|