Java Code Examples for org.apache.hadoop.fs.XAttr#getValue()

The following examples show how to use org.apache.hadoop.fs.XAttr#getValue() . 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: XAttrHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source File: PBHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static List<XAttrProto> convertXAttrProto(
    List<XAttr> xAttrSpec) {
  if (xAttrSpec == null) {
    return Lists.newArrayListWithCapacity(0);
  }
  ArrayList<XAttrProto> xAttrs = Lists.newArrayListWithCapacity(
      xAttrSpec.size());
  for (XAttr a : xAttrSpec) {
    XAttrProto.Builder builder = XAttrProto.newBuilder();
    builder.setNamespace(convert(a.getNameSpace()));
    if (a.getName() != null) {
      builder.setName(a.getName());
    }
    if (a.getValue() != null) {
      builder.setValue(getByteString(a.getValue()));
    }
    xAttrs.add(builder.build());
  }
  return xAttrs;
}
 
Example 3
Source File: FSDirXAttrOp.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * 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) {
  if (fsd.getXattrMaxSize() == 0) {
    return;
  }
  int size = xAttr.getName().getBytes(Charsets.UTF_8).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);
  }
}
 
Example 4
Source File: XAttrPermissionFilter.java    From big-c with Apache License 2.0 6 votes vote down vote up
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 5
Source File: FSImageFormatPBINode.java    From big-c with Apache License 2.0 6 votes vote down vote up
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 6
Source File: FSEditLogOp.java    From big-c with Apache License 2.0 6 votes vote down vote up
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 7
Source File: XAttrHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * 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 8
Source File: PBHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static List<XAttrProto> convertXAttrProto(
    List<XAttr> xAttrSpec) {
  if (xAttrSpec == null) {
    return Lists.newArrayListWithCapacity(0);
  }
  ArrayList<XAttrProto> xAttrs = Lists.newArrayListWithCapacity(
      xAttrSpec.size());
  for (XAttr a : xAttrSpec) {
    XAttrProto.Builder builder = XAttrProto.newBuilder();
    builder.setNamespace(convert(a.getNameSpace()));
    if (a.getName() != null) {
      builder.setName(a.getName());
    }
    if (a.getValue() != null) {
      builder.setValue(getByteString(a.getValue()));
    }
    xAttrs.add(builder.build());
  }
  return xAttrs;
}
 
Example 9
Source File: FSDirXAttrOp.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * 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) {
  if (fsd.getXattrMaxSize() == 0) {
    return;
  }
  int size = xAttr.getName().getBytes(Charsets.UTF_8).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);
  }
}
 
Example 10
Source File: XAttrPermissionFilter.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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 11
Source File: FSImageFormatPBINode.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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 12
Source File: FSEditLogOp.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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 13
Source File: PBHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static XAttrProto convertXAttrProto(XAttr a) {
  XAttrProto.Builder builder = XAttrProto.newBuilder();
  builder.setNamespace(convert(a.getNameSpace()));
  if (a.getName() != null) {
    builder.setName(a.getName());
  }
  if (a.getValue() != null) {
    builder.setValue(getByteString(a.getValue()));
  }
  return builder.build();
}
 
Example 14
Source File: XAttrHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Get value of first xattr from <code>XAttr</code> list
 */
public static byte[] getFirstXAttrValue(List<XAttr> xAttrs) {
  byte[] value = null;
  XAttr xAttr = getFirstXAttr(xAttrs);
  if (xAttr != null) {
    value = xAttr.getValue();
    if (value == null) {
      value = new byte[0]; // xattr exists, but no value.
    }
  }
  return value;
}
 
Example 15
Source File: INodeDirectory.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public byte getLocalStoragePolicyID() {
  XAttrFeature f = getXAttrFeature();
  ImmutableList<XAttr> xattrs = f == null ? ImmutableList.<XAttr> of() : f
      .getXAttrs();
  for (XAttr xattr : xattrs) {
    if (BlockStoragePolicySuite.isStoragePolicyXAttr(xattr)) {
      return (xattr.getValue())[0];
    }
  }
  return ID_UNSPECIFIED;
}
 
Example 16
Source File: INodeDirectory.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public byte getLocalStoragePolicyID() {
  XAttrFeature f = getXAttrFeature();
  ImmutableList<XAttr> xattrs = f == null ? ImmutableList.<XAttr> of() : f
      .getXAttrs();
  for (XAttr xattr : xattrs) {
    if (BlockStoragePolicySuite.isStoragePolicyXAttr(xattr)) {
      return (xattr.getValue())[0];
    }
  }
  return ID_UNSPECIFIED;
}
 
Example 17
Source File: PBHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static XAttrProto convertXAttrProto(XAttr a) {
  XAttrProto.Builder builder = XAttrProto.newBuilder();
  builder.setNamespace(convert(a.getNameSpace()));
  if (a.getName() != null) {
    builder.setName(a.getName());
  }
  if (a.getValue() != null) {
    builder.setValue(getByteString(a.getValue()));
  }
  return builder.build();
}
 
Example 18
Source File: XAttrHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Get value of first xattr from <code>XAttr</code> list
 */
public static byte[] getFirstXAttrValue(List<XAttr> xAttrs) {
  byte[] value = null;
  XAttr xAttr = getFirstXAttr(xAttrs);
  if (xAttr != null) {
    value = xAttr.getValue();
    if (value == null) {
      value = new byte[0]; // xattr exists, but no value.
    }
  }
  return value;
}