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

The following examples show how to use org.apache.hadoop.fs.XAttr#equalsIgnoreValue() . 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: FSDirXAttrOp.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Filter XAttrs from a list of existing XAttrs. Removes matched XAttrs from
 * toFilter and puts them into filtered. Upon completion,
 * toFilter contains the filter XAttrs that were not found, while
 * fitleredXAttrs contains the XAttrs that were found.
 *
 * @param existingXAttrs Existing XAttrs to be filtered
 * @param toFilter XAttrs to filter from the existing XAttrs
 * @param filtered Return parameter, XAttrs that were filtered
 * @return List of XAttrs that does not contain filtered XAttrs
 */
@VisibleForTesting
static List<XAttr> filterINodeXAttrs(
    final List<XAttr> existingXAttrs, final List<XAttr> toFilter,
    final List<XAttr> filtered)
  throws AccessControlException {
  if (existingXAttrs == null || existingXAttrs.isEmpty() ||
      toFilter == null || toFilter.isEmpty()) {
    return existingXAttrs;
  }

  // Populate a new list with XAttrs that pass the filter
  List<XAttr> newXAttrs =
      Lists.newArrayListWithCapacity(existingXAttrs.size());
  for (XAttr a : existingXAttrs) {
    boolean add = true;
    for (ListIterator<XAttr> it = toFilter.listIterator(); it.hasNext()
        ;) {
      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();
        filtered.add(filter);
        break;
      }
    }
    if (add) {
      newXAttrs.add(a);
    }
  }

  return newXAttrs;
}
 
Example 2
Source File: FSDirXAttrOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Filter XAttrs from a list of existing XAttrs. Removes matched XAttrs from
 * toFilter and puts them into filtered. Upon completion,
 * toFilter contains the filter XAttrs that were not found, while
 * fitleredXAttrs contains the XAttrs that were found.
 *
 * @param existingXAttrs Existing XAttrs to be filtered
 * @param toFilter XAttrs to filter from the existing XAttrs
 * @param filtered Return parameter, XAttrs that were filtered
 * @return List of XAttrs that does not contain filtered XAttrs
 */
@VisibleForTesting
static List<XAttr> filterINodeXAttrs(
    final List<XAttr> existingXAttrs, final List<XAttr> toFilter,
    final List<XAttr> filtered)
  throws AccessControlException {
  if (existingXAttrs == null || existingXAttrs.isEmpty() ||
      toFilter == null || toFilter.isEmpty()) {
    return existingXAttrs;
  }

  // Populate a new list with XAttrs that pass the filter
  List<XAttr> newXAttrs =
      Lists.newArrayListWithCapacity(existingXAttrs.size());
  for (XAttr a : existingXAttrs) {
    boolean add = true;
    for (ListIterator<XAttr> it = toFilter.listIterator(); it.hasNext()
        ;) {
      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();
        filtered.add(filter);
        break;
      }
    }
    if (add) {
      newXAttrs.add(a);
    }
  }

  return newXAttrs;
}
 
Example 3
Source File: FSDirXAttrOp.java    From hadoop with Apache License 2.0 4 votes vote down vote up
static List<XAttr> setINodeXAttrs(
    FSDirectory fsd, final List<XAttr> existingXAttrs,
    final List<XAttr> toSet, final EnumSet<XAttrSetFlag> flag)
    throws IOException {
  // Check for duplicate XAttrs in toSet
  // We need to use a custom comparator, so using a HashSet is not suitable
  for (int i = 0; i < toSet.size(); i++) {
    for (int j = i + 1; j < toSet.size(); j++) {
      if (toSet.get(i).equalsIgnoreValue(toSet.get(j))) {
        throw new IOException("Cannot specify the same XAttr to be set " +
            "more than once");
      }
    }
  }

  // Count the current number of user-visible XAttrs for limit checking
  int userVisibleXAttrsNum = 0; // Number of user visible xAttrs

  // The XAttr list is copied to an exactly-sized array when it's stored,
  // so there's no need to size it precisely here.
  int newSize = (existingXAttrs != null) ? existingXAttrs.size() : 0;
  newSize += toSet.size();
  List<XAttr> xAttrs = Lists.newArrayListWithCapacity(newSize);

  // Check if the XAttr already exists to validate with the provided flag
  for (XAttr xAttr: toSet) {
    boolean exist = false;
    if (existingXAttrs != null) {
      for (XAttr a : existingXAttrs) {
        if (a.equalsIgnoreValue(xAttr)) {
          exist = true;
          break;
        }
      }
    }
    XAttrSetFlag.validate(xAttr.getName(), exist, flag);
    // add the new XAttr since it passed validation
    xAttrs.add(xAttr);
    if (isUserVisible(xAttr)) {
      userVisibleXAttrsNum++;
    }
  }

  // Add the existing xattrs back in, if they weren't already set
  if (existingXAttrs != null) {
    for (XAttr existing : existingXAttrs) {
      boolean alreadySet = false;
      for (XAttr set : toSet) {
        if (set.equalsIgnoreValue(existing)) {
          alreadySet = true;
          break;
        }
      }
      if (!alreadySet) {
        xAttrs.add(existing);
        if (isUserVisible(existing)) {
          userVisibleXAttrsNum++;
        }
      }
    }
  }

  if (userVisibleXAttrsNum > fsd.getInodeXAttrsLimit()) {
    throw new IOException("Cannot add additional XAttr to inode, "
        + "would exceed limit of " + fsd.getInodeXAttrsLimit());
  }

  return xAttrs;
}
 
Example 4
Source File: FSDirXAttrOp.java    From big-c with Apache License 2.0 4 votes vote down vote up
static List<XAttr> setINodeXAttrs(
    FSDirectory fsd, final List<XAttr> existingXAttrs,
    final List<XAttr> toSet, final EnumSet<XAttrSetFlag> flag)
    throws IOException {
  // Check for duplicate XAttrs in toSet
  // We need to use a custom comparator, so using a HashSet is not suitable
  for (int i = 0; i < toSet.size(); i++) {
    for (int j = i + 1; j < toSet.size(); j++) {
      if (toSet.get(i).equalsIgnoreValue(toSet.get(j))) {
        throw new IOException("Cannot specify the same XAttr to be set " +
            "more than once");
      }
    }
  }

  // Count the current number of user-visible XAttrs for limit checking
  int userVisibleXAttrsNum = 0; // Number of user visible xAttrs

  // The XAttr list is copied to an exactly-sized array when it's stored,
  // so there's no need to size it precisely here.
  int newSize = (existingXAttrs != null) ? existingXAttrs.size() : 0;
  newSize += toSet.size();
  List<XAttr> xAttrs = Lists.newArrayListWithCapacity(newSize);

  // Check if the XAttr already exists to validate with the provided flag
  for (XAttr xAttr: toSet) {
    boolean exist = false;
    if (existingXAttrs != null) {
      for (XAttr a : existingXAttrs) {
        if (a.equalsIgnoreValue(xAttr)) {
          exist = true;
          break;
        }
      }
    }
    XAttrSetFlag.validate(xAttr.getName(), exist, flag);
    // add the new XAttr since it passed validation
    xAttrs.add(xAttr);
    if (isUserVisible(xAttr)) {
      userVisibleXAttrsNum++;
    }
  }

  // Add the existing xattrs back in, if they weren't already set
  if (existingXAttrs != null) {
    for (XAttr existing : existingXAttrs) {
      boolean alreadySet = false;
      for (XAttr set : toSet) {
        if (set.equalsIgnoreValue(existing)) {
          alreadySet = true;
          break;
        }
      }
      if (!alreadySet) {
        xAttrs.add(existing);
        if (isUserVisible(existing)) {
          userVisibleXAttrsNum++;
        }
      }
    }
  }

  if (userVisibleXAttrsNum > fsd.getInodeXAttrsLimit()) {
    throw new IOException("Cannot add additional XAttr to inode, "
        + "would exceed limit of " + fsd.getInodeXAttrsLimit());
  }

  return xAttrs;
}