org.apache.hadoop.fs.XAttrSetFlag Java Examples

The following examples show how to use org.apache.hadoop.fs.XAttrSetFlag. 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: GoogleHadoopFileSystemXAttrsIntegrationTest.java    From hadoop-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void setXAttr_replace_fail() throws Exception {
  URI fileUri = GoogleCloudStorageFileSystemIntegrationTest.getTempFilePath();
  Path filePath = ghfsHelper.castAsHadoopPath(fileUri);
  ghfsHelper.writeFile(filePath, "obj-test-set-xattr-replace-fail", 1, /* overwrite= */ false);

  ghfs.setXAttr(filePath, "test-key", "value".getBytes(UTF_8));

  IOException e =
      assertThrows(
          IOException.class,
          () ->
              ghfs.setXAttr(
                  filePath, "test-key", "new".getBytes(UTF_8), EnumSet.of(XAttrSetFlag.CREATE)));
  assertThat(e).hasMessageThat().startsWith("REPLACE flag must be set to update XAttr");

  // Cleanup.
  assertThat(ghfs.delete(filePath, true)).isTrue();
}
 
Example #2
Source File: TestXAttrsWithHA.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #3
Source File: FSDirXAttrOp.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: TestXAttrsWithHA.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: NameNodeRpcServer.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: FSDirXAttrOp.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #7
Source File: NameNodeRpcServer.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: FSDirectory.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #9
Source File: FSDirectory.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #10
Source File: DFSClient.java    From big-c with Apache License 2.0 6 votes vote down vote up
public void setXAttr(String src, String name, byte[] value, 
    EnumSet<XAttrSetFlag> flag) throws IOException {
  checkOpen();
  TraceScope scope = getPathTraceScope("setXAttr", src);
  try {
    namenode.setXAttr(src, XAttrHelper.buildXAttr(name, value), flag);
  } catch (RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   FileNotFoundException.class,
                                   NSQuotaExceededException.class,
                                   SafeModeException.class,
                                   SnapshotAccessControlException.class,
                                   UnresolvedPathException.class);
  } finally {
    scope.close();
  }
}
 
Example #11
Source File: DFSClient.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public void setXAttr(String src, String name, byte[] value, 
    EnumSet<XAttrSetFlag> flag) throws IOException {
  checkOpen();
  TraceScope scope = getPathTraceScope("setXAttr", src);
  try {
    namenode.setXAttr(src, XAttrHelper.buildXAttr(name, value), flag);
  } catch (RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   FileNotFoundException.class,
                                   NSQuotaExceededException.class,
                                   SafeModeException.class,
                                   SnapshotAccessControlException.class,
                                   UnresolvedPathException.class);
  } finally {
    scope.close();
  }
}
 
Example #12
Source File: GoogleHadoopFileSystemXAttrsIntegrationTest.java    From hadoop-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void setXAttr_create_fail() throws Exception {
  URI fileUri = GoogleCloudStorageFileSystemIntegrationTest.getTempFilePath();
  Path filePath = ghfsHelper.castAsHadoopPath(fileUri);
  ghfsHelper.writeFile(filePath, "obj-test-set-xattr-create-fail", 1, /* overwrite= */ false);

  IOException e =
      assertThrows(
          IOException.class,
          () ->
              ghfs.setXAttr(
                  filePath, "test-key", "val".getBytes(UTF_8), EnumSet.of(XAttrSetFlag.REPLACE)));

  assertThat(e).hasMessageThat().startsWith("CREATE flag must be set to create XAttr");

  // Cleanup.
  assertThat(ghfs.delete(filePath, true)).isTrue();
}
 
Example #13
Source File: ClientNamenodeProtocolTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void setXAttr(String src, XAttr xAttr, EnumSet<XAttrSetFlag> flag)
    throws IOException {
  SetXAttrRequestProto req = SetXAttrRequestProto.newBuilder()
      .setSrc(src)
      .setXAttr(PBHelper.convertXAttrProto(xAttr))
      .setFlag(PBHelper.convert(flag))
      .build();
  try {
    rpcProxy.setXAttr(null, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #14
Source File: TestFSImageWithXAttr.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void testXAttr(boolean persistNamespace) throws IOException {
  Path path = new Path("/p");
  DistributedFileSystem fs = cluster.getFileSystem();
  fs.create(path).close();
  
  fs.setXAttr(path, name1, value1, EnumSet.of(XAttrSetFlag.CREATE));
  fs.setXAttr(path, name2, value2, EnumSet.of(XAttrSetFlag.CREATE));
  fs.setXAttr(path, name3, null, EnumSet.of(XAttrSetFlag.CREATE));
  
  restart(fs, persistNamespace);
  
  Map<String, byte[]> xattrs = fs.getXAttrs(path);
  Assert.assertEquals(xattrs.size(), 3);
  Assert.assertArrayEquals(value1, xattrs.get(name1));
  Assert.assertArrayEquals(value2, xattrs.get(name2));
  Assert.assertArrayEquals(value3, xattrs.get(name3));
  
  fs.setXAttr(path, name1, newValue1, EnumSet.of(XAttrSetFlag.REPLACE));
  
  restart(fs, persistNamespace);
  
  xattrs = fs.getXAttrs(path);
  Assert.assertEquals(xattrs.size(), 3);
  Assert.assertArrayEquals(newValue1, xattrs.get(name1));
  Assert.assertArrayEquals(value2, xattrs.get(name2));
  Assert.assertArrayEquals(value3, xattrs.get(name3));

  fs.removeXAttr(path, name1);
  fs.removeXAttr(path, name2);
  fs.removeXAttr(path, name3);

  restart(fs, persistNamespace);
  xattrs = fs.getXAttrs(path);
  Assert.assertEquals(xattrs.size(), 0);
}
 
Example #15
Source File: FSXAttrBaseTest.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Steps:
 * 1) Set xattrs on a file.
 * 2) Remove xattrs from that file.
 * 3) Save a checkpoint and restart NN.
 * 4) Set xattrs again on the same file.
 * 5) Remove xattrs from that file.
 * 6) Restart NN without saving a checkpoint.
 * 7) Set xattrs again on the same file.
 */
@Test(timeout = 120000)
public void testCleanupXAttrs() throws Exception {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  fs.setXAttr(path, name1, value1, EnumSet.of(XAttrSetFlag.CREATE));
  fs.setXAttr(path, name2, value2, EnumSet.of(XAttrSetFlag.CREATE));
  fs.removeXAttr(path, name1);
  fs.removeXAttr(path, name2);
  
  restart(true);
  initFileSystem();
  
  fs.setXAttr(path, name1, value1, EnumSet.of(XAttrSetFlag.CREATE));
  fs.setXAttr(path, name2, value2, EnumSet.of(XAttrSetFlag.CREATE));
  fs.removeXAttr(path, name1);
  fs.removeXAttr(path, name2);
  
  restart(false);
  initFileSystem();
  
  fs.setXAttr(path, name1, value1, EnumSet.of(XAttrSetFlag.CREATE));
  fs.setXAttr(path, name2, value2, EnumSet.of(XAttrSetFlag.CREATE));
  fs.removeXAttr(path, name1);
  fs.removeXAttr(path, name2);
  
  fs.setXAttr(path, name1, value1, EnumSet.of(XAttrSetFlag.CREATE));
  fs.setXAttr(path, name2, value2, EnumSet.of(XAttrSetFlag.CREATE));
  
  Map<String, byte[]> xattrs = fs.getXAttrs(path);
  Assert.assertEquals(xattrs.size(), 2);
  Assert.assertArrayEquals(value1, xattrs.get(name1));
  Assert.assertArrayEquals(value2, xattrs.get(name2));
}
 
Example #16
Source File: TestXAttrWithSnapshot.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Tests modifying xattrs on a directory that has been snapshotted
 */
@Test (timeout = 120000)
public void testModifyReadsCurrentState() throws Exception {
  // Init
  FileSystem.mkdirs(hdfs, path, FsPermission.createImmutable((short) 0700));
  SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
  hdfs.setXAttr(path, name1, value1);
  hdfs.setXAttr(path, name2, value2);

  // Verify that current path reflects xattrs, snapshot doesn't
  Map<String, byte[]> xattrs = hdfs.getXAttrs(path);
  assertEquals(xattrs.size(), 2);
  assertArrayEquals(value1, xattrs.get(name1));
  assertArrayEquals(value2, xattrs.get(name2));

  xattrs = hdfs.getXAttrs(snapshotPath);
  assertEquals(xattrs.size(), 0);

  // Modify each xattr and make sure it's reflected
  hdfs.setXAttr(path, name1, value2, EnumSet.of(XAttrSetFlag.REPLACE));
  xattrs = hdfs.getXAttrs(path);
  assertEquals(xattrs.size(), 2);
  assertArrayEquals(value2, xattrs.get(name1));
  assertArrayEquals(value2, xattrs.get(name2));

  hdfs.setXAttr(path, name2, value1, EnumSet.of(XAttrSetFlag.REPLACE));
  xattrs = hdfs.getXAttrs(path);
  assertEquals(xattrs.size(), 2);
  assertArrayEquals(value2, xattrs.get(name1));
  assertArrayEquals(value1, xattrs.get(name2));

  // Paranoia checks
  xattrs = hdfs.getXAttrs(snapshotPath);
  assertEquals(xattrs.size(), 0);

  hdfs.removeXAttr(path, name1);
  hdfs.removeXAttr(path, name2);
  xattrs = hdfs.getXAttrs(path);
  assertEquals(xattrs.size(), 0);
}
 
Example #17
Source File: ViewFileSystem.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void setXAttr(Path path, String name, byte[] value,
    EnumSet<XAttrSetFlag> flag) throws IOException {
  InodeTree.ResolveResult<FileSystem> res =
      fsState.resolve(getUriPath(path), true);
  res.targetFileSystem.setXAttr(res.remainingPath, name, value, flag);
}
 
Example #18
Source File: ViewFs.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void setXAttr(Path path, String name, byte[] value,
                     EnumSet<XAttrSetFlag> flag) throws IOException {
  InodeTree.ResolveResult<AbstractFileSystem> res =
      fsState.resolve(getUriPath(path), true);
  res.targetFileSystem.setXAttr(res.remainingPath, name, value, flag);
}
 
Example #19
Source File: GoogleHadoopFileSystemBase.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void setXAttr(Path path, String name, byte[] value, EnumSet<XAttrSetFlag> flags)
    throws IOException {
  logger.atFiner().log(
      "setXAttr(path: %s, name: %s, value %s, flags %s",
      path, name, lazy(() -> new String(value, UTF_8)), flags);
  checkNotNull(path, "path should not be null");
  checkNotNull(name, "name should not be null");
  checkArgument(flags != null && !flags.isEmpty(), "flags should not be null or empty");

  FileInfo fileInfo = getGcsFs().getFileInfo(getGcsPath(path));
  String xAttrKey = getXAttrKey(name);
  Map<String, byte[]> attributes = fileInfo.getAttributes();

  if (attributes.containsKey(xAttrKey) && !flags.contains(XAttrSetFlag.REPLACE)) {
    throw new IOException(
        String.format(
            "REPLACE flag must be set to update XAttr (name='%s', value='%s') for '%s'",
            name, new String(value, UTF_8), path));
  }
  if (!attributes.containsKey(xAttrKey) && !flags.contains(XAttrSetFlag.CREATE)) {
    throw new IOException(
        String.format(
            "CREATE flag must be set to create XAttr (name='%s', value='%s') for '%s'",
            name, new String(value, UTF_8), path));
  }

  UpdatableItemInfo updateInfo =
      new UpdatableItemInfo(
          fileInfo.getItemInfo().getResourceId(),
          ImmutableMap.of(xAttrKey, getXAttrValue(value)));
  getGcsFs().getGcs().updateItems(ImmutableList.of(updateInfo));
}
 
Example #20
Source File: GoogleHadoopFileSystemXAttrsIntegrationTest.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void setXAttr_throwsExceptionOnEmptyFlags() {
  URI fileUri = GoogleCloudStorageFileSystemIntegrationTest.getTempFilePath();
  Path filePath = ghfsHelper.castAsHadoopPath(fileUri);
  EnumSet<XAttrSetFlag> emptyFlags = EnumSet.noneOf(XAttrSetFlag.class);
  Throwable exception =
      assertThrows(
          java.lang.IllegalArgumentException.class,
          () -> ghfs.setXAttr(filePath, "test-key", "val".getBytes(UTF_8), emptyFlags));
  assertThat(exception).hasMessageThat().isEqualTo("flags should not be null or empty");
}
 
Example #21
Source File: FSXAttrBaseTest.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 120000)
public void testRenameFileWithXAttr() throws Exception {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  fs.setXAttr(path, name1, value1, EnumSet.of(XAttrSetFlag.CREATE));
  fs.setXAttr(path, name2, value2, EnumSet.of(XAttrSetFlag.CREATE));
  Path renamePath = new Path(path.toString() + "-rename");
  fs.rename(path, renamePath);
  Map<String, byte[]> xattrs = fs.getXAttrs(renamePath);
  Assert.assertEquals(xattrs.size(), 2);
  Assert.assertArrayEquals(value1, xattrs.get(name1));
  Assert.assertArrayEquals(value2, xattrs.get(name2));
  fs.removeXAttr(renamePath, name1);
  fs.removeXAttr(renamePath, name2);
}
 
Example #22
Source File: ViewFs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void setXAttr(Path path, String name, byte[] value,
                     EnumSet<XAttrSetFlag> flag) throws IOException {
  InodeTree.ResolveResult<AbstractFileSystem> res =
      fsState.resolve(getUriPath(path), true);
  res.targetFileSystem.setXAttr(res.remainingPath, name, value, flag);
}
 
Example #23
Source File: PBHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * The flag field in PB is a bitmask whose values are the same a the 
 * emum values of XAttrSetFlag
 */
public static int convert(EnumSet<XAttrSetFlag> flag) {
  int value = 0;
  if (flag.contains(XAttrSetFlag.CREATE)) {
    value |= XAttrSetFlagProto.XATTR_CREATE.getNumber();
  }
  if (flag.contains(XAttrSetFlag.REPLACE)) {
    value |= XAttrSetFlagProto.XATTR_REPLACE.getNumber();
  }
  return value;
}
 
Example #24
Source File: FSDirXAttrOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
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 #25
Source File: HttpFSFileSystem.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void setXAttr(Path f, String name, byte[] value,
    EnumSet<XAttrSetFlag> flag) throws IOException {
  Map<String, String> params = new HashMap<String, String>();
  params.put(OP_PARAM, Operation.SETXATTR.toString());
  params.put(XATTR_NAME_PARAM, name);
  if (value != null) {
    params.put(XATTR_VALUE_PARAM, 
        XAttrCodec.encodeValue(value, XAttrCodec.HEX));
  }
  params.put(XATTR_SET_FLAG_PARAM, EnumSetParam.toString(flag));
  HttpURLConnection conn = getConnection(Operation.SETXATTR.getMethod(),
      params, f, true);
  HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK);
}
 
Example #26
Source File: HadoopFileSystemWrapper.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void setXAttr(final Path path, final String name, final byte[] value, final EnumSet<XAttrSetFlag> flag) throws IOException {
  try (WaitRecorder recorder = OperatorStats.getWaitRecorder(operatorStats)) {
    underlyingFs.setXAttr(path, name, value, flag);
  } catch(FSError e) {
    throw propagateFSError(e);
  }
}
 
Example #27
Source File: FSDirAttrOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static void setDirStoragePolicy(
    FSDirectory fsd, INodeDirectory inode, byte policyId,
    int latestSnapshotId) throws IOException {
  List<XAttr> existingXAttrs = XAttrStorage.readINodeXAttrs(inode);
  XAttr xAttr = BlockStoragePolicySuite.buildXAttr(policyId);
  List<XAttr> newXAttrs = FSDirXAttrOp.setINodeXAttrs(fsd, existingXAttrs,
                                                      Arrays.asList(xAttr),
                                                      EnumSet.of(
                                                          XAttrSetFlag.CREATE,
                                                          XAttrSetFlag.REPLACE));
  XAttrStorage.updateINodeXAttrs(inode, newXAttrs, latestSnapshotId);
}
 
Example #28
Source File: FileSystemRMStateStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void setUnreadableBySuperuserXattrib(Path p)
        throws IOException {
  if (fs.getScheme().toLowerCase().contains("hdfs")
      && intermediateEncryptionEnabled
      && !fs.getXAttrs(p).containsKey(UNREADABLE_BY_SUPERUSER_XATTRIB)) {
    fs.setXAttr(p, UNREADABLE_BY_SUPERUSER_XATTRIB, null,
      EnumSet.of(XAttrSetFlag.CREATE));
  }
}
 
Example #29
Source File: FSOperations.java    From big-c with Apache License 2.0 5 votes vote down vote up
public FSSetXAttr(String path, String name, String encodedValue, 
    EnumSet<XAttrSetFlag> flag) throws IOException {
  this.path = new Path(path);
  this.name = name;
  this.value = XAttrCodec.decodeValue(encodedValue);
  this.flag = flag;
}
 
Example #30
Source File: WebHdfsFileSystem.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void setXAttr(Path p, String name, byte[] value, 
    EnumSet<XAttrSetFlag> flag) throws IOException {
  statistics.incrementWriteOps(1);
  final HttpOpParam.Op op = PutOpParam.Op.SETXATTR;
  if (value != null) {
    new FsPathRunner(op, p, new XAttrNameParam(name), new XAttrValueParam(
        XAttrCodec.encodeValue(value, XAttrCodec.HEX)), 
        new XAttrSetFlagParam(flag)).run();
  } else {
    new FsPathRunner(op, p, new XAttrNameParam(name), 
        new XAttrSetFlagParam(flag)).run();
  }
}