Exemple #1
0
        /// <summary>Create a new encryption zone.</summary>
        /// <remarks>
        /// Create a new encryption zone.
        /// <p/>
        /// Called while holding the FSDirectory lock.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        internal virtual XAttr CreateEncryptionZone(string src, CipherSuite suite, CryptoProtocolVersion
                                                    version, string keyName)
        {
            System.Diagnostics.Debug.Assert(dir.HasWriteLock());
            INodesInPath srcIIP = dir.GetINodesInPath4Write(src, false);

            if (dir.IsNonEmptyDirectory(srcIIP))
            {
                throw new IOException("Attempt to create an encryption zone for a non-empty directory."
                                      );
            }
            if (srcIIP != null && srcIIP.GetLastINode() != null && !srcIIP.GetLastINode().IsDirectory
                    ())
            {
                throw new IOException("Attempt to create an encryption zone for a file.");
            }
            EncryptionZoneManager.EncryptionZoneInt ezi = GetEncryptionZoneForPath(srcIIP);
            if (ezi != null)
            {
                throw new IOException("Directory " + src + " is already in an " + "encryption zone. ("
                                      + GetFullPathName(ezi) + ")");
            }
            HdfsProtos.ZoneEncryptionInfoProto proto = PBHelper.Convert(suite, version, keyName
                                                                        );
            XAttr ezXAttr = XAttrHelper.BuildXAttr(HdfsServerConstants.CryptoXattrEncryptionZone
                                                   , proto.ToByteArray());
            IList <XAttr> xattrs = Lists.NewArrayListWithCapacity(1);

            xattrs.AddItem(ezXAttr);
            // updating the xattr will call addEncryptionZone,
            // done this way to handle edit log loading
            FSDirXAttrOp.UnprotectedSetXAttrs(dir, src, xattrs, EnumSet.Of(XAttrSetFlag.Create
                                                                           ));
            return(ezXAttr);
        }
        public static XAttr BuildXAttr(byte policyId)
        {
            string name = BuildXAttrName();

            return(XAttrHelper.BuildXAttr(name, new byte[] { policyId }));
        }