gpt4 book ai didi

org.apache.hadoop.fs.XAttr类的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 03:14:40 29 4
gpt4 key购买 nike

本文整理了Java中org.apache.hadoop.fs.XAttr类的一些代码示例,展示了XAttr类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XAttr类的具体详情如下:
包路径:org.apache.hadoop.fs.XAttr
类名称:XAttr

XAttr介绍

[英]XAttr is the POSIX Extended Attribute model similar to that found in traditional Operating Systems. Extended Attributes consist of one or more name/value pairs associated with a file or directory. Five namespaces are defined: user, trusted, security, system and raw. 1) USER namespace attributes may be used by any user to store arbitrary information. Access permissions in this namespace are defined by a file directory's permission bits. For sticky directories, only the owner and privileged user can write attributes.
2) TRUSTED namespace attributes are only visible and accessible to privileged users. This namespace is available from both user space (filesystem API) and fs kernel.
3) SYSTEM namespace attributes are used by the fs kernel to store system objects. This namespace is only available in the fs kernel. It is not visible to users.
4) SECURITY namespace attributes are used by the fs kernel for security features. It is not visible to users.
5) RAW namespace attributes are used for internal system attributes that sometimes need to be exposed. Like SYSTEM namespace attributes they are not visible to the user except when getXAttr/getXAttrs is called on a file or directory in the /.reserved/raw HDFS directory hierarchy. These attributes can only be accessed by the superuser.
[中]XAttr是POSIX扩展属性模型,类似于传统操作系统中的属性模型。扩展属性由一个或多个与文件或目录关联的名称/值对组成。定义了五个名称空间:用户、受信任、安全、系统和原始。1) 任何用户都可以使用用户名称空间属性来存储任意信息。此命名空间中的访问权限由文件目录的权限位定义。对于粘性目录,只有所有者和特权用户可以写入属性。
2) 受信任的命名空间属性仅对特权用户可见和可访问。这个名称空间可以从用户空间(文件系统API)和fs内核获得。
3) fs内核使用系统名称空间属性来存储系统对象。此名称空间仅在fs内核中可用。它对用户不可见。
4) 安全命名空间属性由fs内核用于安全特性。它对用户不可见。
5) 原始名称空间属性用于有时需要公开的内部系统属性。与系统名称空间属性一样,它们对用户不可见,除非对/中的文件或目录调用getXAttr/getXAttrs。保留/原始HDFS目录层次结构。这些属性只能由超级用户访问。

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

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");
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

if (toSet.get(i).equalsIgnoreValue(toSet.get(j))) {
  throw new IOException("Cannot specify the same XAttr to be set " +
    "more than once");
if (existingXAttrs != null) {
 for (XAttr a : existingXAttrs) {
  if (a.equalsIgnoreValue(xAttr)) {
   exist = true;
   break;
XAttrSetFlag.validate(xAttr.getName(), exist, flag);
 boolean alreadySet = false;
 for (XAttr set : toSet) {
  if (set.equalsIgnoreValue(existing)) {
   alreadySet = true;
   break;

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

/**
 * Verifies that the combined size of the name and value of an xattr is within
 * the configured limit. Setting a limit of zero disables this check.
 */
private static void checkXAttrSize(FSDirectory fsd, XAttr xAttr) {
 int size = DFSUtil.string2Bytes(xAttr.getName()).length;
 if (xAttr.getValue() != null) {
  size += xAttr.getValue().length;
 }
 if (size > fsd.getXattrMaxSize()) {
  throw new HadoopIllegalArgumentException(
    "The XAttr is too big. The maximum combined size of the"
    + " name and value is " + fsd.getXattrMaxSize()
    + ", but the total size is " + size);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

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) {
  return;
 }
 if (XAttrHelper.getPrefixedName(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.getPrefixedName(xAttr));
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

if (aXAttr.getNameSpace() == search.getNameSpace()
  && aXAttr.getName().equals(search.getName())) {

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

private static Map<String, Object> toJsonMap(final XAttr xAttr,
  final XAttrCodec encoding) throws IOException {
 if (xAttr == null) {
  return null;
 }
 final Map<String, Object> m = new TreeMap<String, Object>();
 m.put("name", XAttrHelper.getPrefixedName(xAttr));
 m.put("value", xAttr.getValue() != null ?
   XAttrCodec.encodeValue(xAttr.getValue(), encoding) : null);
 return m;
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

private static boolean isUserVisible(XAttr xAttr) {
  XAttr.NameSpace ns = xAttr.getNameSpace();
  return ns == XAttr.NameSpace.USER || ns == XAttr.NameSpace.TRUSTED;
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

Event.MetadataUpdateEvent.MetadataType.XATTRS);
Assert.assertTrue(mue5.getxAttrs().size() == 1);
Assert.assertTrue(mue5.getxAttrs().get(0).getName().contains("field"));
Assert.assertTrue(!mue5.isxAttrsRemoved());
  Event.MetadataUpdateEvent.MetadataType.XATTRS);
Assert.assertTrue(mue6.getxAttrs().size() == 1);
Assert.assertTrue(mue6.getxAttrs().get(0).getName().contains("field"));
Assert.assertTrue(mue6.isxAttrsRemoved());

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

XAttr filter = it.next();
Preconditions.checkArgument(
  !KEYID_XATTR.equalsIgnoreValue(filter),
  "The encryption zone xattr should never be deleted.");
if (UNREADABLE_BY_SUPERUSER_XATTR.equalsIgnoreValue(filter)) {
 throw new AccessControlException("The xattr '" +
   SECURITY_XATTR_UNREADABLE_BY_SUPERUSER + "' can not be deleted.");
if (a.equalsIgnoreValue(filter)) {
 add = false;
 it.remove();

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs-client

public XAttr build() {
  return new XAttr(ns, name, value);
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

@Test
 public void testXAttrHashCode() {
  assertEquals(XATTR.hashCode(), XATTR1.hashCode());
  assertFalse(XATTR1.hashCode() == XATTR2.hashCode());
  assertFalse(XATTR2.hashCode() == XATTR3.hashCode());
  assertFalse(XATTR3.hashCode() == XATTR4.hashCode());
  assertFalse(XATTR4.hashCode() == XATTR5.hashCode());
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs-client

@Test
public void testXAttrEquals() {
 assertNotSame(XATTR1, XATTR2);
 assertNotSame(XATTR2, XATTR3);
 assertNotSame(XATTR3, XATTR4);
 assertNotSame(XATTR4, XATTR5);
 assertEquals(XATTR, XATTR1);
 assertEquals(XATTR1, XATTR1);
 assertEquals(XATTR2, XATTR2);
 assertEquals(XATTR3, XATTR3);
 assertEquals(XATTR4, XATTR4);
 assertEquals(XATTR5, XATTR5);
 assertFalse(XATTR1.equals(XATTR2));
 assertFalse(XATTR2.equals(XATTR3));
 assertFalse(XATTR3.equals(XATTR4));
 assertFalse(XATTR4.equals(XATTR5));
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

static int toInt(XAttr a) {
 int nid = SerialNumberManager.XATTR.getSerialNumber(a.getName());
 int nsOrd = a.getNameSpace().ordinal();
 long value = NS.BITS.combine(nsOrd & NS_MASK, 0L);
 value = NS_EXT.BITS.combine(nsOrd >>> NS_EXT_SHIFT, value);
 value = NAME.BITS.combine(nid, value);
 return (int)value;
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

public XAttrFeature(List<XAttr> xAttrs) {
 if (xAttrs != null && !xAttrs.isEmpty()) {
  List<XAttr> toPack = new ArrayList<XAttr>();
  ImmutableList.Builder<XAttr> b = null;
  for (XAttr attr : xAttrs) {
   if (attr.getValue() == null ||
     attr.getValue().length <= PACK_THRESHOLD) {
    toPack.add(attr);
   } else {
    if (b == null) {
     b = ImmutableList.builder();
    }
    b.add(attr);
   }
  }
  this.attrs = XAttrFormat.toBytes(toPack);
  if (b != null) {
   this.xAttrs = b.build();
  }
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

private void addEncryptionZone(INodeWithAdditionalFields inode,
  XAttrFeature xaf) {
 if (xaf == null) {
  return;
 }
 XAttr xattr = xaf.getXAttr(CRYPTO_XATTR_ENCRYPTION_ZONE);
 if (xattr == null) {
  return;
 }
 try {
  final HdfsProtos.ZoneEncryptionInfoProto ezProto =
    HdfsProtos.ZoneEncryptionInfoProto.parseFrom(xattr.getValue());
  ezManager.unprotectedAddEncryptionZone(inode.getId(),
    PBHelperClient.convert(ezProto.getSuite()),
    PBHelperClient.convert(ezProto.getCryptoProtocolVersion()),
    ezProto.getKeyName());
  if (ezProto.hasReencryptionProto()) {
   final ReencryptionInfoProto reProto = ezProto.getReencryptionProto();
   // inodes parents may not be loaded if this is done during fsimage
   // loading so cannot set full path now. Pass in null to indicate that.
   ezManager.getReencryptionStatus()
     .updateZoneStatus(inode.getId(), null, reProto);
  }
 } catch (InvalidProtocolBufferException e) {
  NameNode.LOG.warn("Error parsing protocol buffer of " +
    "EZ XAttr " + xattr.getName() + " dir:" + inode.getFullPathName());
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

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));
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

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 && isRawPath) {
    filteredXAttrs.add(xAttr);
   } else if (XAttrHelper.getPrefixedName(xAttr).
     equals(SECURITY_XATTR_UNREADABLE_BY_SUPERUSER)) {
    filteredXAttrs.add(xAttr);
   }
  }
  return filteredXAttrs;
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

/**
  * Get XAttr by name with prefix.
  * @param prefixedName xAttr name with prefix
  * @return the XAttr
  */
 public XAttr getXAttr(String prefixedName) {
  XAttr attr = XAttrFormat.getXAttr(attrs, prefixedName);
  if (attr == null && xAttrs != null) {
   XAttr toFind = XAttrHelper.buildXAttr(prefixedName);
   for (XAttr a : xAttrs) {
    if (a.equalsIgnoreValue(toFind)) {
     attr = a;
     break;
    }
   }
  }
  return attr;
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

public XAttr build() {
  return new XAttr(ns, name, value);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs-client

@Test
 public void testXAttrHashCode() {
  assertEquals(XATTR.hashCode(), XATTR1.hashCode());
  assertFalse(XATTR1.hashCode() == XATTR2.hashCode());
  assertFalse(XATTR2.hashCode() == XATTR3.hashCode());
  assertFalse(XATTR3.hashCode() == XATTR4.hashCode());
  assertFalse(XATTR4.hashCode() == XATTR5.hashCode());
 }
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com