|
@@ -54,6 +54,7 @@ import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_OWN
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_PERMISSIONS;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_QUOTA;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_REPLICATION;
|
|
|
+import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SET_XATTRS;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_START_LOG_SEGMENT;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_SYMLINK;
|
|
|
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.OP_TIMES;
|
|
@@ -79,12 +80,14 @@ import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
|
import org.apache.hadoop.fs.ChecksumException;
|
|
|
import org.apache.hadoop.fs.Options.Rename;
|
|
|
+import org.apache.hadoop.fs.XAttrCodec;
|
|
|
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.FsAction;
|
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.apache.hadoop.fs.permission.PermissionStatus;
|
|
|
+import org.apache.hadoop.fs.XAttr;
|
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.DeprecatedUTF8;
|
|
|
import org.apache.hadoop.hdfs.protocol.Block;
|
|
@@ -95,6 +98,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
|
|
import org.apache.hadoop.hdfs.protocol.LayoutVersion;
|
|
|
import org.apache.hadoop.hdfs.protocol.LayoutVersion.Feature;
|
|
|
import org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEditLogProto;
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.XAttrProtos.XAttrEditLogProto;
|
|
|
import org.apache.hadoop.hdfs.protocolPB.PBHelper;
|
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
|
import org.apache.hadoop.hdfs.util.XMLUtils;
|
|
@@ -186,6 +190,7 @@ public abstract class FSEditLogOp {
|
|
|
OP_ROLLING_UPGRADE_START, "start"));
|
|
|
inst.put(OP_ROLLING_UPGRADE_FINALIZE, new RollingUpgradeOp(
|
|
|
OP_ROLLING_UPGRADE_FINALIZE, "finalize"));
|
|
|
+ inst.put(OP_SET_XATTRS, new SetXAttrsOp());
|
|
|
}
|
|
|
|
|
|
public FSEditLogOp get(FSEditLogOpCodes opcode) {
|
|
@@ -3490,6 +3495,51 @@ public abstract class FSEditLogOp {
|
|
|
return builder.toString();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ static class SetXAttrsOp extends FSEditLogOp {
|
|
|
+ List<XAttr> xAttrs = Lists.newArrayList();
|
|
|
+ String src;
|
|
|
+
|
|
|
+ private SetXAttrsOp() {
|
|
|
+ super(OP_SET_XATTRS);
|
|
|
+ }
|
|
|
+
|
|
|
+ static SetXAttrsOp getInstance() {
|
|
|
+ return new SetXAttrsOp();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ void readFields(DataInputStream in, int logVersion) throws IOException {
|
|
|
+ XAttrEditLogProto p = XAttrEditLogProto.parseDelimitedFrom(in);
|
|
|
+ src = p.getSrc();
|
|
|
+ xAttrs = PBHelper.convertXAttrs(p.getXAttrsList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void writeFields(DataOutputStream out) throws IOException {
|
|
|
+ XAttrEditLogProto.Builder b = XAttrEditLogProto.newBuilder();
|
|
|
+ if (src != null) {
|
|
|
+ b.setSrc(src);
|
|
|
+ }
|
|
|
+ b.addAllXAttrs(PBHelper.convertXAttrProto(xAttrs));
|
|
|
+ b.build().writeDelimitedTo(out);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void toXml(ContentHandler contentHandler) throws SAXException {
|
|
|
+ XMLUtils.addSaxString(contentHandler, "SRC", src);
|
|
|
+ appendXAttrsToXml(contentHandler, xAttrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ void fromXml(Stanza st) throws InvalidXmlException {
|
|
|
+ src = st.getValue("SRC");
|
|
|
+ xAttrs = readXAttrsFromXml(st);
|
|
|
+ if (xAttrs == null) {
|
|
|
+ xAttrs = Lists.newArrayList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
static class SetAclOp extends FSEditLogOp {
|
|
|
List<AclEntry> aclEntries = Lists.newArrayList();
|
|
@@ -4106,4 +4156,43 @@ public abstract class FSEditLogOp {
|
|
|
}
|
|
|
return aclEntries;
|
|
|
}
|
|
|
+
|
|
|
+ private static void appendXAttrsToXml(ContentHandler contentHandler,
|
|
|
+ List<XAttr> xAttrs) throws SAXException {
|
|
|
+ for (XAttr a : xAttrs) {
|
|
|
+ contentHandler.startElement("", "", "XATTR", new AttributesImpl());
|
|
|
+ XMLUtils.addSaxString(contentHandler, "NAMESPACE",
|
|
|
+ a.getNameSpace().toString());
|
|
|
+ XMLUtils.addSaxString(contentHandler, "NAME", a.getName());
|
|
|
+ try {
|
|
|
+ XMLUtils.addSaxString(contentHandler, "VALUE",
|
|
|
+ XAttrCodec.encodeValue(a.getValue(), XAttrCodec.HEX));
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new SAXException(e);
|
|
|
+ }
|
|
|
+ contentHandler.endElement("", "", "XATTR");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<XAttr> readXAttrsFromXml(Stanza st)
|
|
|
+ throws InvalidXmlException {
|
|
|
+ List<XAttr> xAttrs = Lists.newArrayList();
|
|
|
+ if (!st.hasChildren("XATTR")) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<Stanza> stanzas = st.getChildren("XATTR");
|
|
|
+ for (Stanza s : stanzas) {
|
|
|
+ XAttr a = new XAttr.Builder()
|
|
|
+ .setNameSpace(XAttr.NameSpace.valueOf(s.getValue("NAMESPACE")))
|
|
|
+ .setName(s.getValue("NAME"))
|
|
|
+ .setValue(XAttrCodec.decodeValue(s.getValue("VALUE"))).build();
|
|
|
+ xAttrs.add(a);
|
|
|
+ }
|
|
|
+ return xAttrs;
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new InvalidXmlException(e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|