org.apache.hadoop.fs.XAttr Java Examples
The following examples show how to use
org.apache.hadoop.fs.XAttr.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestJsonUtil.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testToXAttrMap() throws IOException { String jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}"; ObjectReader reader = new ObjectMapper().reader(Map.class); Map<?, ?> json = reader.readValue(jsonString); XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a1").setValue(XAttrCodec.decodeValue("0x313233")).build(); XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a2").setValue(XAttrCodec.decodeValue("0x313131")).build(); List<XAttr> xAttrs = Lists.newArrayList(); xAttrs.add(xAttr1); xAttrs.add(xAttr2); Map<String, byte[]> xAttrMap = XAttrHelper.buildXAttrMap(xAttrs); Map<String, byte[]> parsedXAttrMap = JsonUtil.toXAttrs(json); Assert.assertEquals(xAttrMap.size(), parsedXAttrMap.size()); Iterator<Entry<String, byte[]>> iter = xAttrMap.entrySet().iterator(); while(iter.hasNext()) { Entry<String, byte[]> entry = iter.next(); Assert.assertArrayEquals(entry.getValue(), parsedXAttrMap.get(entry.getKey())); } }
Example #2
Source File: TestJsonUtil.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testToJsonFromXAttrs() throws IOException { String jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}"; XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a1").setValue(XAttrCodec.decodeValue("0x313233")).build(); XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a2").setValue(XAttrCodec.decodeValue("0x313131")).build(); List<XAttr> xAttrs = Lists.newArrayList(); xAttrs.add(xAttr1); xAttrs.add(xAttr2); Assert.assertEquals(jsonString, JsonUtil.toJsonString(xAttrs, XAttrCodec.HEX)); }
Example #3
Source File: TestJsonUtil.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testToXAttrMap() throws IOException { String jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}"; ObjectReader reader = new ObjectMapper().reader(Map.class); Map<?, ?> json = reader.readValue(jsonString); XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a1").setValue(XAttrCodec.decodeValue("0x313233")).build(); XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a2").setValue(XAttrCodec.decodeValue("0x313131")).build(); List<XAttr> xAttrs = Lists.newArrayList(); xAttrs.add(xAttr1); xAttrs.add(xAttr2); Map<String, byte[]> xAttrMap = XAttrHelper.buildXAttrMap(xAttrs); Map<String, byte[]> parsedXAttrMap = JsonUtil.toXAttrs(json); Assert.assertEquals(xAttrMap.size(), parsedXAttrMap.size()); Iterator<Entry<String, byte[]>> iter = xAttrMap.entrySet().iterator(); while(iter.hasNext()) { Entry<String, byte[]> entry = iter.next(); Assert.assertArrayEquals(entry.getValue(), parsedXAttrMap.get(entry.getKey())); } }
Example #4
Source File: NameNodeRpcServer.java From big-c with Apache License 2.0 | 6 votes |
@Override // ClientProtocol public void setXAttr(String src, XAttr xAttr, EnumSet<XAttrSetFlag> flag) throws IOException { checkNNStartup(); CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache); if (cacheEntry != null && cacheEntry.isSuccess()) { return; // Return previous response } boolean success = false; try { namesystem.setXAttr(src, xAttr, flag, cacheEntry != null); success = true; } finally { RetryCache.setState(cacheEntry, success); } }
Example #5
Source File: XAttrHelper.java From hadoop with Apache License 2.0 | 6 votes |
/** * Build xattr map from <code>XAttr</code> list, the key is * xattr name with prefix, and value is xattr value. */ public static Map<String, byte[]> buildXAttrMap(List<XAttr> xAttrs) { if (xAttrs == null) { return null; } Map<String, byte[]> xAttrMap = Maps.newHashMap(); for (XAttr xAttr : xAttrs) { String name = getPrefixName(xAttr); byte[] value = xAttr.getValue(); if (value == null) { value = new byte[0]; } xAttrMap.put(name, value); } return xAttrMap; }
Example #6
Source File: XAttrPermissionFilter.java From big-c with Apache License 2.0 | 6 votes |
static void checkPermissionForApi(FSPermissionChecker pc, XAttr xAttr, boolean isRawPath) throws AccessControlException { final boolean isSuperUser = pc.isSuperUser(); if (xAttr.getNameSpace() == XAttr.NameSpace.USER || (xAttr.getNameSpace() == XAttr.NameSpace.TRUSTED && isSuperUser)) { return; } if (xAttr.getNameSpace() == XAttr.NameSpace.RAW && isRawPath && isSuperUser) { return; } if (XAttrHelper.getPrefixName(xAttr). equals(SECURITY_XATTR_UNREADABLE_BY_SUPERUSER)) { if (xAttr.getValue() != null) { throw new AccessControlException("Attempt to set a value for '" + SECURITY_XATTR_UNREADABLE_BY_SUPERUSER + "'. Values are not allowed for this xattr."); } return; } throw new AccessControlException("User doesn't have permission for xattr: " + XAttrHelper.getPrefixName(xAttr)); }
Example #7
Source File: FSDirXAttrOp.java From big-c with Apache License 2.0 | 6 votes |
static List<XAttr> listXAttrs( FSDirectory fsd, String src) throws IOException { FSDirXAttrOp.checkXAttrsConfigFlag(fsd); final FSPermissionChecker pc = fsd.getPermissionChecker(); final boolean isRawPath = FSDirectory.isReservedRawName(src); byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src); src = fsd.resolvePath(pc, src, pathComponents); final INodesInPath iip = fsd.getINodesInPath(src, true); if (fsd.isPermissionEnabled()) { /* To access xattr names, you need EXECUTE in the owning directory. */ fsd.checkParentAccess(pc, iip, FsAction.EXECUTE); } final List<XAttr> all = FSDirXAttrOp.getXAttrs(fsd, src); return XAttrPermissionFilter. filterXAttrsForApi(pc, all, isRawPath); }
Example #8
Source File: FSEditLogOp.java From big-c with Apache License 2.0 | 6 votes |
private static void appendXAttrsToXml(ContentHandler contentHandler, List<XAttr> xAttrs) throws SAXException { for (XAttr xAttr: xAttrs) { contentHandler.startElement("", "", "XATTR", new AttributesImpl()); XMLUtils.addSaxString(contentHandler, "NAMESPACE", xAttr.getNameSpace().toString()); XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName()); if (xAttr.getValue() != null) { try { XMLUtils.addSaxString(contentHandler, "VALUE", XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX)); } catch (IOException e) { throw new SAXException(e); } } contentHandler.endElement("", "", "XATTR"); } }
Example #9
Source File: XAttrPermissionFilter.java From big-c with Apache License 2.0 | 6 votes |
static List<XAttr> filterXAttrsForApi(FSPermissionChecker pc, List<XAttr> xAttrs, boolean isRawPath) { assert xAttrs != null : "xAttrs can not be null"; if (xAttrs.isEmpty()) { return xAttrs; } List<XAttr> filteredXAttrs = Lists.newArrayListWithCapacity(xAttrs.size()); final boolean isSuperUser = pc.isSuperUser(); for (XAttr xAttr : xAttrs) { if (xAttr.getNameSpace() == XAttr.NameSpace.USER) { filteredXAttrs.add(xAttr); } else if (xAttr.getNameSpace() == XAttr.NameSpace.TRUSTED && isSuperUser) { filteredXAttrs.add(xAttr); } else if (xAttr.getNameSpace() == XAttr.NameSpace.RAW && isSuperUser && isRawPath) { filteredXAttrs.add(xAttr); } else if (XAttrHelper.getPrefixName(xAttr). equals(SECURITY_XATTR_UNREADABLE_BY_SUPERUSER)) { filteredXAttrs.add(xAttr); } } return filteredXAttrs; }
Example #10
Source File: FSEditLogOp.java From hadoop with Apache License 2.0 | 6 votes |
private static void appendXAttrsToXml(ContentHandler contentHandler, List<XAttr> xAttrs) throws SAXException { for (XAttr xAttr: xAttrs) { contentHandler.startElement("", "", "XATTR", new AttributesImpl()); XMLUtils.addSaxString(contentHandler, "NAMESPACE", xAttr.getNameSpace().toString()); XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName()); if (xAttr.getValue() != null) { try { XMLUtils.addSaxString(contentHandler, "VALUE", XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX)); } catch (IOException e) { throw new SAXException(e); } } contentHandler.endElement("", "", "XATTR"); } }
Example #11
Source File: FSDirXAttrOp.java From big-c with Apache License 2.0 | 6 votes |
/** * Set xattr for a file or directory. * * @param src * - path on which it sets the xattr * @param xAttr * - xAttr details to set * @param flag * - xAttrs flags * @throws IOException */ static HdfsFileStatus setXAttr( FSDirectory fsd, String src, XAttr xAttr, EnumSet<XAttrSetFlag> flag, boolean logRetryCache) throws IOException { checkXAttrsConfigFlag(fsd); checkXAttrSize(fsd, xAttr); FSPermissionChecker pc = fsd.getPermissionChecker(); XAttrPermissionFilter.checkPermissionForApi( pc, xAttr, FSDirectory.isReservedRawName(src)); byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src); src = fsd.resolvePath(pc, src, pathComponents); List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1); xAttrs.add(xAttr); INodesInPath iip; fsd.writeLock(); try { iip = fsd.getINodesInPath4Write(src); checkXAttrChangeAccess(fsd, iip, xAttr, pc); unprotectedSetXAttrs(fsd, src, xAttrs, flag); } finally { fsd.writeUnlock(); } fsd.getEditLog().logSetXAttrs(src, xAttrs, logRetryCache); return fsd.getAuditFileInfo(iip); }
Example #12
Source File: TestXAttrsWithHA.java From hadoop with Apache License 2.0 | 6 votes |
/** * Test that xattrs are properly tracked by the standby */ @Test(timeout = 60000) public void testXAttrsTrackedOnStandby() throws Exception { fs.create(path).close(); fs.setXAttr(path, name1, value1, EnumSet.of(XAttrSetFlag.CREATE)); fs.setXAttr(path, name2, value2, EnumSet.of(XAttrSetFlag.CREATE)); HATestUtil.waitForStandbyToCatchUp(nn0, nn1); List<XAttr> xAttrs = nn1.getRpcServer().getXAttrs("/file", null); assertEquals(2, xAttrs.size()); cluster.shutdownNameNode(0); // Failover the current standby to active. cluster.shutdownNameNode(0); cluster.transitionToActive(1); Map<String, byte[]> xattrs = fs.getXAttrs(path); Assert.assertEquals(xattrs.size(), 2); Assert.assertArrayEquals(value1, xattrs.get(name1)); Assert.assertArrayEquals(value2, xattrs.get(name2)); fs.delete(path, true); }
Example #13
Source File: XAttrPermissionFilter.java From hadoop with Apache License 2.0 | 6 votes |
static List<XAttr> filterXAttrsForApi(FSPermissionChecker pc, List<XAttr> xAttrs, boolean isRawPath) { assert xAttrs != null : "xAttrs can not be null"; if (xAttrs.isEmpty()) { return xAttrs; } List<XAttr> filteredXAttrs = Lists.newArrayListWithCapacity(xAttrs.size()); final boolean isSuperUser = pc.isSuperUser(); for (XAttr xAttr : xAttrs) { if (xAttr.getNameSpace() == XAttr.NameSpace.USER) { filteredXAttrs.add(xAttr); } else if (xAttr.getNameSpace() == XAttr.NameSpace.TRUSTED && isSuperUser) { filteredXAttrs.add(xAttr); } else if (xAttr.getNameSpace() == XAttr.NameSpace.RAW && isSuperUser && isRawPath) { filteredXAttrs.add(xAttr); } else if (XAttrHelper.getPrefixName(xAttr). equals(SECURITY_XATTR_UNREADABLE_BY_SUPERUSER)) { filteredXAttrs.add(xAttr); } } return filteredXAttrs; }
Example #14
Source File: XAttrPermissionFilter.java From hadoop with Apache License 2.0 | 6 votes |
static void checkPermissionForApi(FSPermissionChecker pc, XAttr xAttr, boolean isRawPath) throws AccessControlException { final boolean isSuperUser = pc.isSuperUser(); if (xAttr.getNameSpace() == XAttr.NameSpace.USER || (xAttr.getNameSpace() == XAttr.NameSpace.TRUSTED && isSuperUser)) { return; } if (xAttr.getNameSpace() == XAttr.NameSpace.RAW && isRawPath && isSuperUser) { return; } if (XAttrHelper.getPrefixName(xAttr). equals(SECURITY_XATTR_UNREADABLE_BY_SUPERUSER)) { if (xAttr.getValue() != null) { throw new AccessControlException("Attempt to set a value for '" + SECURITY_XATTR_UNREADABLE_BY_SUPERUSER + "'. Values are not allowed for this xattr."); } return; } throw new AccessControlException("User doesn't have permission for xattr: " + XAttrHelper.getPrefixName(xAttr)); }
Example #15
Source File: FSEditLogOp.java From big-c with Apache License 2.0 | 6 votes |
private static List<XAttr> readXAttrsFromXml(Stanza st) throws InvalidXmlException { if (!st.hasChildren("XATTR")) { return null; } List<Stanza> stanzas = st.getChildren("XATTR"); List<XAttr> xattrs = Lists.newArrayListWithCapacity(stanzas.size()); for (Stanza a: stanzas) { XAttr.Builder builder = new XAttr.Builder(); builder.setNameSpace(XAttr.NameSpace.valueOf(a.getValue("NAMESPACE"))). setName(a.getValue("NAME")); String v = a.getValueOrNull("VALUE"); if (v != null) { try { builder.setValue(XAttrCodec.decodeValue(v)); } catch (IOException e) { throw new InvalidXmlException(e.toString()); } } xattrs.add(builder.build()); } return xattrs; }
Example #16
Source File: NameNodeRpcServer.java From hadoop with Apache License 2.0 | 6 votes |
@Override // ClientProtocol public void setXAttr(String src, XAttr xAttr, EnumSet<XAttrSetFlag> flag) throws IOException { checkNNStartup(); CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache); if (cacheEntry != null && cacheEntry.isSuccess()) { return; // Return previous response } boolean success = false; try { namesystem.setXAttr(src, xAttr, flag, cacheEntry != null); success = true; } finally { RetryCache.setState(cacheEntry, success); } }
Example #17
Source File: FSImageFormatPBINode.java From hadoop with Apache License 2.0 | 6 votes |
private static XAttrFeatureProto.Builder buildXAttrs(XAttrFeature f, final SaverContext.DeduplicationMap<String> stringMap) { XAttrFeatureProto.Builder b = XAttrFeatureProto.newBuilder(); for (XAttr a : f.getXAttrs()) { XAttrCompactProto.Builder xAttrCompactBuilder = XAttrCompactProto. newBuilder(); int nsOrd = a.getNameSpace().ordinal(); Preconditions.checkArgument(nsOrd < 8, "Too many namespaces."); int v = ((nsOrd & XATTR_NAMESPACE_MASK) << XATTR_NAMESPACE_OFFSET) | ((stringMap.getId(a.getName()) & XATTR_NAME_MASK) << XATTR_NAME_OFFSET); v |= (((nsOrd >> 2) & XATTR_NAMESPACE_EXT_MASK) << XATTR_NAMESPACE_EXT_OFFSET); xAttrCompactBuilder.setName(v); if (a.getValue() != null) { xAttrCompactBuilder.setValue(PBHelper.getByteString(a.getValue())); } b.addXAttrs(xAttrCompactBuilder.build()); } return b; }
Example #18
Source File: FSDirectory.java From hadoop with Apache License 2.0 | 6 votes |
/** * Set the FileEncryptionInfo for an INode. */ void setFileEncryptionInfo(String src, FileEncryptionInfo info) throws IOException { // Make the PB for the xattr final HdfsProtos.PerFileEncryptionInfoProto proto = PBHelper.convertPerFileEncInfo(info); final byte[] protoBytes = proto.toByteArray(); final XAttr fileEncryptionAttr = XAttrHelper.buildXAttr(CRYPTO_XATTR_FILE_ENCRYPTION_INFO, protoBytes); final List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1); xAttrs.add(fileEncryptionAttr); writeLock(); try { FSDirXAttrOp.unprotectedSetXAttrs(this, src, xAttrs, EnumSet.of(XAttrSetFlag.CREATE)); } finally { writeUnlock(); } }
Example #19
Source File: FSEditLogOp.java From hadoop with Apache License 2.0 | 6 votes |
private static List<XAttr> readXAttrsFromXml(Stanza st) throws InvalidXmlException { if (!st.hasChildren("XATTR")) { return null; } List<Stanza> stanzas = st.getChildren("XATTR"); List<XAttr> xattrs = Lists.newArrayListWithCapacity(stanzas.size()); for (Stanza a: stanzas) { XAttr.Builder builder = new XAttr.Builder(); builder.setNameSpace(XAttr.NameSpace.valueOf(a.getValue("NAMESPACE"))). setName(a.getValue("NAME")); String v = a.getValueOrNull("VALUE"); if (v != null) { try { builder.setValue(XAttrCodec.decodeValue(v)); } catch (IOException e) { throw new InvalidXmlException(e.toString()); } } xattrs.add(builder.build()); } return xattrs; }
Example #20
Source File: XAttrHelper.java From big-c with Apache License 2.0 | 5 votes |
/** * Build <code>XAttr</code> list from xattr name list. */ public static List<XAttr> buildXAttrs(List<String> names) { if (names == null || names.isEmpty()) { throw new HadoopIllegalArgumentException("XAttr names can not be " + "null or empty."); } List<XAttr> xAttrs = Lists.newArrayListWithCapacity(names.size()); for (String name : names) { xAttrs.add(buildXAttr(name, null)); } return xAttrs; }
Example #21
Source File: XAttrStorage.java From big-c with Apache License 2.0 | 5 votes |
/** * Update xattrs of inode. * <p/> * Must be called while holding the FSDirectory write lock. * * @param inode INode to update * @param xAttrs to update xAttrs. * @param snapshotId id of the latest snapshot of the inode */ public static void updateINodeXAttrs(INode inode, List<XAttr> xAttrs, int snapshotId) throws QuotaExceededException { if (xAttrs == null || xAttrs.isEmpty()) { if (inode.getXAttrFeature() != null) { inode.removeXAttrFeature(snapshotId); } return; } // Dedupe the xAttr name and save them into a new interned list List<XAttr> internedXAttrs = Lists.newArrayListWithCapacity(xAttrs.size()); for (XAttr xAttr : xAttrs) { final String name = xAttr.getName(); String internedName = internedNames.get(name); if (internedName == null) { internedName = name; internedNames.put(internedName, internedName); } XAttr internedXAttr = new XAttr.Builder() .setName(internedName) .setNameSpace(xAttr.getNameSpace()) .setValue(xAttr.getValue()) .build(); internedXAttrs.add(internedXAttr); } // Save the list of interned xattrs ImmutableList<XAttr> newXAttrs = ImmutableList.copyOf(internedXAttrs); if (inode.getXAttrFeature() != null) { inode.removeXAttrFeature(snapshotId); } inode.addXAttrFeature(new XAttrFeature(newXAttrs), snapshotId); }
Example #22
Source File: FSEditLog.java From hadoop with Apache License 2.0 | 5 votes |
void logRemoveXAttrs(String src, List<XAttr> xAttrs, boolean toLogRpcIds) { final RemoveXAttrOp op = RemoveXAttrOp.getInstance(); op.src = src; op.xAttrs = xAttrs; logRpcIds(op, toLogRpcIds); logEdit(op); }
Example #23
Source File: XAttrPermissionFilter.java From big-c with Apache License 2.0 | 5 votes |
static void checkPermissionForApi(FSPermissionChecker pc, List<XAttr> xAttrs, boolean isRawPath) throws AccessControlException { Preconditions.checkArgument(xAttrs != null); if (xAttrs.isEmpty()) { return; } for (XAttr xAttr : xAttrs) { checkPermissionForApi(pc, xAttr, isRawPath); } }
Example #24
Source File: DFSClient.java From big-c with Apache License 2.0 | 5 votes |
public byte[] getXAttr(String src, String name) throws IOException { checkOpen(); TraceScope scope = getPathTraceScope("getXAttr", src); try { final List<XAttr> xAttrs = XAttrHelper.buildXAttrAsList(name); final List<XAttr> result = namenode.getXAttrs(src, xAttrs); return XAttrHelper.getFirstXAttrValue(result); } catch(RemoteException re) { throw re.unwrapRemoteException(AccessControlException.class, FileNotFoundException.class, UnresolvedPathException.class); } finally { scope.close(); } }
Example #25
Source File: FSImageLoader.java From hadoop with Apache License 2.0 | 5 votes |
private List<XAttr> getXAttrList(String path) throws IOException { long id = lookup(path); FsImageProto.INodeSection.INode inode = fromINodeId(id); switch (inode.getType()) { case FILE: return FSImageFormatPBINode.Loader.loadXAttrs( inode.getFile().getXAttrs(), stringTable); case DIRECTORY: return FSImageFormatPBINode.Loader.loadXAttrs(inode.getDirectory() .getXAttrs(), stringTable); default: return null; } }
Example #26
Source File: XAttrHelper.java From big-c with Apache License 2.0 | 5 votes |
/** * Get first xattr from <code>XAttr</code> list */ public static XAttr getFirstXAttr(List<XAttr> xAttrs) { if (xAttrs != null && !xAttrs.isEmpty()) { return xAttrs.get(0); } return null; }
Example #27
Source File: FSDirXAttrOp.java From big-c with Apache License 2.0 | 5 votes |
private static List<XAttr> getXAttrs(FSDirectory fsd, String src) throws IOException { String srcs = FSDirectory.normalizePath(src); fsd.readLock(); try { INodesInPath iip = fsd.getINodesInPath(srcs, true); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getPathSnapshotId(); return XAttrStorage.readINodeXAttrs(fsd.getAttributes(src, inode.getLocalNameBytes(), inode, snapshotId)); } finally { fsd.readUnlock(); } }
Example #28
Source File: XAttrHelper.java From big-c with Apache License 2.0 | 5 votes |
/** * Build <code>XAttr</code> from name with prefix and value. * Name can not be null. Value can be null. The name and prefix * are validated. * Both name and namespace are case sensitive. */ public static XAttr buildXAttr(String name, byte[] value) { Preconditions.checkNotNull(name, "XAttr name cannot be null."); final int prefixIndex = name.indexOf("."); if (prefixIndex < 3) {// Prefix length is at least 3. throw new HadoopIllegalArgumentException("An XAttr name must be " + "prefixed with user/trusted/security/system/raw, followed by a '.'"); } else if (prefixIndex == name.length() - 1) { throw new HadoopIllegalArgumentException("XAttr name cannot be empty."); } NameSpace ns; final String prefix = name.substring(0, prefixIndex); if (StringUtils.equalsIgnoreCase(prefix, NameSpace.USER.toString())) { ns = NameSpace.USER; } else if ( StringUtils.equalsIgnoreCase(prefix, NameSpace.TRUSTED.toString())) { ns = NameSpace.TRUSTED; } else if ( StringUtils.equalsIgnoreCase(prefix, NameSpace.SYSTEM.toString())) { ns = NameSpace.SYSTEM; } else if ( StringUtils.equalsIgnoreCase(prefix, NameSpace.SECURITY.toString())) { ns = NameSpace.SECURITY; } else if ( StringUtils.equalsIgnoreCase(prefix, NameSpace.RAW.toString())) { ns = NameSpace.RAW; } else { throw new HadoopIllegalArgumentException("An XAttr name must be " + "prefixed with user/trusted/security/system/raw, followed by a '.'"); } XAttr xAttr = (new XAttr.Builder()).setNameSpace(ns).setName(name. substring(prefixIndex + 1)).setValue(value).build(); return xAttr; }
Example #29
Source File: FSDirXAttrOp.java From hadoop with Apache License 2.0 | 5 votes |
static INode unprotectedSetXAttrs( FSDirectory fsd, final String src, final List<XAttr> xAttrs, final EnumSet<XAttrSetFlag> flag) throws IOException { assert fsd.hasWriteLock(); INodesInPath iip = fsd.getINodesInPath4Write(FSDirectory.normalizePath(src), true); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<XAttr> existingXAttrs = XAttrStorage.readINodeXAttrs(inode); List<XAttr> newXAttrs = setINodeXAttrs(fsd, existingXAttrs, xAttrs, flag); final boolean isFile = inode.isFile(); for (XAttr xattr : newXAttrs) { final String xaName = XAttrHelper.getPrefixName(xattr); /* * If we're adding the encryption zone xattr, then add src to the list * of encryption zones. */ if (CRYPTO_XATTR_ENCRYPTION_ZONE.equals(xaName)) { final HdfsProtos.ZoneEncryptionInfoProto ezProto = HdfsProtos.ZoneEncryptionInfoProto.parseFrom(xattr.getValue()); fsd.ezManager.addEncryptionZone(inode.getId(), PBHelper.convert(ezProto.getSuite()), PBHelper.convert( ezProto.getCryptoProtocolVersion()), ezProto.getKeyName()); } if (!isFile && SECURITY_XATTR_UNREADABLE_BY_SUPERUSER.equals(xaName)) { throw new IOException("Can only set '" + SECURITY_XATTR_UNREADABLE_BY_SUPERUSER + "' on a file."); } } XAttrStorage.updateINodeXAttrs(inode, newXAttrs, snapshotId); return inode; }
Example #30
Source File: DistCpUtils.java From big-c with Apache License 2.0 | 5 votes |
/** * Converts a FileStatus to a CopyListingFileStatus. If preserving ACLs, * populates the CopyListingFileStatus with the ACLs. If preserving XAttrs, * populates the CopyListingFileStatus with the XAttrs. * * @param fileSystem FileSystem containing the file * @param fileStatus FileStatus of file * @param preserveAcls boolean true if preserving ACLs * @param preserveXAttrs boolean true if preserving XAttrs * @param preserveRawXAttrs boolean true if preserving raw.* XAttrs * @throws IOException if there is an I/O error */ public static CopyListingFileStatus toCopyListingFileStatus( FileSystem fileSystem, FileStatus fileStatus, boolean preserveAcls, boolean preserveXAttrs, boolean preserveRawXAttrs) throws IOException { CopyListingFileStatus copyListingFileStatus = new CopyListingFileStatus(fileStatus); if (preserveAcls) { FsPermission perm = fileStatus.getPermission(); if (perm.getAclBit()) { List<AclEntry> aclEntries = fileSystem.getAclStatus( fileStatus.getPath()).getEntries(); copyListingFileStatus.setAclEntries(aclEntries); } } if (preserveXAttrs || preserveRawXAttrs) { Map<String, byte[]> srcXAttrs = fileSystem.getXAttrs(fileStatus.getPath()); if (preserveXAttrs && preserveRawXAttrs) { copyListingFileStatus.setXAttrs(srcXAttrs); } else { Map<String, byte[]> trgXAttrs = Maps.newHashMap(); final String rawNS = StringUtils.toLowerCase(XAttr.NameSpace.RAW.name()); for (Map.Entry<String, byte[]> ent : srcXAttrs.entrySet()) { final String xattrName = ent.getKey(); if (xattrName.startsWith(rawNS)) { if (preserveRawXAttrs) { trgXAttrs.put(xattrName, ent.getValue()); } } else if (preserveXAttrs) { trgXAttrs.put(xattrName, ent.getValue()); } } copyListingFileStatus.setXAttrs(trgXAttrs); } } return copyListingFileStatus; }