Java 类org.apache.hadoop.fs.Options 实例源码

项目:hadoop    文件:DFSClient.java   
/**
 * Rename file or directory.
 * @see ClientProtocol#rename2(String, String, Options.Rename...)
 */
public void rename(String src, String dst, Options.Rename... options)
    throws IOException {
  checkOpen();
  TraceScope scope = getSrcDstTraceScope("rename2", src, dst);
  try {
    namenode.rename2(src, dst, options);
  } catch(RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   DSQuotaExceededException.class,
                                   FileAlreadyExistsException.class,
                                   FileNotFoundException.class,
                                   ParentNotDirectoryException.class,
                                   SafeModeException.class,
                                   NSQuotaExceededException.class,
                                   UnresolvedPathException.class,
                                   SnapshotAccessControlException.class);
  } finally {
    scope.close();
  }
}
项目:hadoop    文件:NameNodeRpcServer.java   
@Override // ClientProtocol
public void rename2(String src, String dst, Options.Rename... options)
    throws IOException {
  checkNNStartup();
  if(stateChangeLog.isDebugEnabled()) {
    stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst);
  }
  if (!checkPathLength(dst)) {
    throw new IOException("rename: Pathname too long.  Limit "
        + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
  }
  CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
  if (cacheEntry != null && cacheEntry.isSuccess()) {
    return; // Return previous response
  }
  boolean success = false;
  try {
    namesystem.renameTo(src, dst, cacheEntry != null, options);
    success = true;
  } finally {
    RetryCache.setState(cacheEntry, success);
  }
  metrics.incrFilesRenamed();
}
项目:aliyun-oss-hadoop-fs    文件:DFSClient.java   
/**
 * Rename file or directory.
 * @see ClientProtocol#rename2(String, String, Options.Rename...)
 */
public void rename(String src, String dst, Options.Rename... options)
    throws IOException {
  checkOpen();
  try (TraceScope ignored = newSrcDstTraceScope("rename2", src, dst)) {
    namenode.rename2(src, dst, options);
  } catch (RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
        DSQuotaExceededException.class,
        QuotaByStorageTypeExceededException.class,
        FileAlreadyExistsException.class,
        FileNotFoundException.class,
        ParentNotDirectoryException.class,
        SafeModeException.class,
        NSQuotaExceededException.class,
        UnresolvedPathException.class,
        SnapshotAccessControlException.class);
  }
}
项目:aliyun-oss-hadoop-fs    文件:NameNodeRpcServer.java   
@Override // ClientProtocol
public void rename2(String src, String dst, Options.Rename... options)
    throws IOException {
  checkNNStartup();
  if(stateChangeLog.isDebugEnabled()) {
    stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst);
  }
  if (!checkPathLength(dst)) {
    throw new IOException("rename: Pathname too long.  Limit "
        + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
  }
  namesystem.checkOperation(OperationCategory.WRITE);
  CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
  if (cacheEntry != null && cacheEntry.isSuccess()) {
    return; // Return previous response
  }
  boolean success = false;
  try {
    namesystem.renameTo(src, dst, cacheEntry != null, options);
    success = true;
  } finally {
    RetryCache.setState(cacheEntry, success);
  }
  metrics.incrFilesRenamed();
}
项目:big-c    文件:DFSClient.java   
/**
 * Rename file or directory.
 * @see ClientProtocol#rename2(String, String, Options.Rename...)
 */
public void rename(String src, String dst, Options.Rename... options)
    throws IOException {
  checkOpen();
  TraceScope scope = getSrcDstTraceScope("rename2", src, dst);
  try {
    namenode.rename2(src, dst, options);
  } catch(RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   DSQuotaExceededException.class,
                                   FileAlreadyExistsException.class,
                                   FileNotFoundException.class,
                                   ParentNotDirectoryException.class,
                                   SafeModeException.class,
                                   NSQuotaExceededException.class,
                                   UnresolvedPathException.class,
                                   SnapshotAccessControlException.class);
  } finally {
    scope.close();
  }
}
项目:big-c    文件:NameNodeRpcServer.java   
@Override // ClientProtocol
public void rename2(String src, String dst, Options.Rename... options)
    throws IOException {
  checkNNStartup();
  if(stateChangeLog.isDebugEnabled()) {
    stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst);
  }
  if (!checkPathLength(dst)) {
    throw new IOException("rename: Pathname too long.  Limit "
        + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
  }
  CacheEntry cacheEntry = RetryCache.waitForCompletion(retryCache);
  if (cacheEntry != null && cacheEntry.isSuccess()) {
    return; // Return previous response
  }
  boolean success = false;
  try {
    namesystem.renameTo(src, dst, cacheEntry != null, options);
    success = true;
  } finally {
    RetryCache.setState(cacheEntry, success);
  }
  metrics.incrFilesRenamed();
}
项目:hadoop-2.6.0-cdh5.4.3    文件:DFSClient.java   
/**
 * Rename file or directory.
 * @see ClientProtocol#rename2(String, String, Options.Rename...)
 */
public void rename(String src, String dst, Options.Rename... options)
    throws IOException {
  checkOpen();
  try {
    namenode.rename2(src, dst, options);
  } catch(RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   DSQuotaExceededException.class,
                                   FileAlreadyExistsException.class,
                                   FileNotFoundException.class,
                                   ParentNotDirectoryException.class,
                                   SafeModeException.class,
                                   NSQuotaExceededException.class,
                                   UnresolvedPathException.class,
                                   SnapshotAccessControlException.class);
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSDirectory.java   
/**
 * @see #unprotectedRenameTo(String, String, long, Options.Rename...)
 */
void renameTo(String src, String dst, long mtime,
    BlocksMapUpdateInfo collectedBlocks, Options.Rename... options)
    throws FileAlreadyExistsException, FileNotFoundException,
    ParentNotDirectoryException, QuotaExceededException,
    UnresolvedLinkException, IOException {
  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* FSDirectory.renameTo: " + src
        + " to " + dst);
  }
  writeLock();
  try {
    if (unprotectedRenameTo(src, dst, mtime, collectedBlocks, options)) {
      namesystem.incrDeletedFileCount(1);
    }
  } finally {
    writeUnlock();
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSNamesystem.java   
private void renameToInternal(FSPermissionChecker pc, String src, 
    String dst, boolean logRetryCache, BlocksMapUpdateInfo collectedBlocks, 
    Options.Rename... options) throws IOException {
  assert hasWriteLock();
  if (isPermissionEnabled) {
    // Rename does not operates on link targets
    // Do not resolveLink when checking permissions of src and dst
    // Check write access to parent of src
    checkPermission(pc, src, false, null, FsAction.WRITE, null, null, false,
        false);
    // Check write access to ancestor of dst
    checkPermission(pc, dst, false, FsAction.WRITE, null, null, null, false,
        false);
  }

  waitForLoadingFSImage();
  long mtime = now();
  dir.renameTo(src, dst, mtime, collectedBlocks, options);
  getEditLog().logRename(src, dst, mtime, logRetryCache, options);
}
项目:hops    文件:ClientNamenodeProtocolServerSideTranslatorPB.java   
@Override
public Rename2ResponseProto rename2(RpcController controller,
    Rename2RequestProto req) throws ServiceException {

  try {
    Options.Rename[] options;
    if (req.hasKeepEncodingStatus() && req.getKeepEncodingStatus()) {
      options = new Rename[2];
      options[1] = Rename.KEEP_ENCODING_STATUS;
    } else {
      options = new Rename[1];
    }
    options[0] = req.getOverwriteDest() ? Rename.OVERWRITE : Rename.NONE;
    server.rename2(req.getSrc(), req.getDst(), options);
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_RENAME2_RESPONSE;
}
项目:apex-malhar    文件:FileSystemWAL.java   
private DataOutputStream getOutputStream(FileSystemWALPointer pointer) throws IOException
{
  Preconditions.checkArgument(outputStream == null, "output stream is not null");

  if (pointer.offset > 0 && (fileSystemWAL.fileContext.getDefaultFileSystem() instanceof LocalFs ||
      fileSystemWAL.fileContext.getDefaultFileSystem() instanceof RawLocalFs)) {
    //On local file system the stream is always closed and never flushed so we open it again in append mode if the
    //offset > 0. This block is entered only when appending to wal while writing on local fs.
    return fileSystemWAL.fileContext.create(new Path(fileSystemWAL.tempPartFiles.get(pointer.partNum)),
        EnumSet.of(CreateFlag.CREATE, CreateFlag.APPEND), Options.CreateOpts.CreateParent.createParent());
  }

  String partFile = fileSystemWAL.getPartFilePath(pointer.partNum);
  String tmpFilePath = createTmpFilePath(partFile);
  fileSystemWAL.tempPartFiles.put(pointer.partNum, tmpFilePath);

  Preconditions.checkArgument(pointer.offset == 0, "offset > 0");
  LOG.debug("open {} => {}", pointer.partNum, tmpFilePath);
  outputStream = fileSystemWAL.fileContext.create(new Path(tmpFilePath),
      EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE), Options.CreateOpts.CreateParent.createParent());
  return outputStream;
}
项目:apex-malhar    文件:IOUtilsTest.java   
private void testCopyPartialHelper(int dataSize, int offset, long size) throws IOException
  {
    FileUtils.deleteQuietly(new File("target/IOUtilsTest"));
    File file = new File("target/IOUtilsTest/testCopyPartial/input");
    createDataFile(file, dataSize);

    FileContext fileContext = FileContext.getFileContext();
    DataInputStream inputStream = fileContext.open(new Path(file.getAbsolutePath()));

    Path output = new Path("target/IOUtilsTest/testCopyPartial/output");
    DataOutputStream outputStream = fileContext.create(output, EnumSet
        .of(CreateFlag.CREATE, CreateFlag.OVERWRITE), Options.CreateOpts.CreateParent.createParent());

    if (offset == 0) {
      IOUtils.copyPartial(inputStream, size, outputStream);
    } else {
      IOUtils.copyPartial(inputStream, offset, size, outputStream);
    }

    outputStream.close();

    Assert.assertTrue("output exists", fileContext.util().exists(output));
    Assert.assertEquals("output size", size, fileContext.getFileStatus(output).getLen());
//    FileUtils.deleteQuietly(new File("target/IOUtilsTest"));
  }
项目:hadoop-plus    文件:DFSClient.java   
/**
 * Rename file or directory.
 * @see ClientProtocol#rename2(String, String, Options.Rename...)
 */
public void rename(String src, String dst, Options.Rename... options)
    throws IOException {
  checkOpen();
  try {
    namenode.rename2(src, dst, options);
  } catch(RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   DSQuotaExceededException.class,
                                   FileAlreadyExistsException.class,
                                   FileNotFoundException.class,
                                   ParentNotDirectoryException.class,
                                   SafeModeException.class,
                                   NSQuotaExceededException.class,
                                   UnresolvedPathException.class,
                                   SnapshotAccessControlException.class);
  }
}
项目:hadoop-plus    文件:FSDirectory.java   
/**
 * @see #unprotectedRenameTo(String, String, long, Options.Rename...)
 */
void renameTo(String src, String dst, boolean logRetryCache, 
    Options.Rename... options)
    throws FileAlreadyExistsException, FileNotFoundException,
    ParentNotDirectoryException, QuotaExceededException,
    UnresolvedLinkException, IOException {
  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* FSDirectory.renameTo: " + src
        + " to " + dst);
  }
  waitForReady();
  long now = now();
  writeLock();
  try {
    if (unprotectedRenameTo(src, dst, now, options)) {
      incrDeletedFileCount(1);
    }
  } finally {
    writeUnlock();
  }
  fsImage.getEditLog().logRename(src, dst, now, logRetryCache, options);
}
项目:hops    文件:NameNodeRpcServer.java   
@Override // ClientProtocol
public void rename2(String src, String dst, Options.Rename... options)
    throws IOException {
  if (stateChangeLog.isDebugEnabled()) {
    stateChangeLog.debug("*DIR* NameNode.rename: " + src + " to " + dst);
  }
  if (!checkPathLength(dst)) {
    throw new IOException(
        "rename: Pathname too long.  Limit " + MAX_PATH_LENGTH +
            " characters, " + MAX_PATH_DEPTH + " levels.");
  }

  if (namesystem.isLegacyRenameEnabled()) {
    namesystem.renameTo(src, dst, options);
  } else {
    namesystem.multiTransactionalRename(src, dst, options);
  }
  metrics.incrFilesRenamed();
}
项目:FlexMap    文件:DFSClient.java   
/**
 * Rename file or directory.
 * @see ClientProtocol#rename2(String, String, Options.Rename...)
 */
public void rename(String src, String dst, Options.Rename... options)
    throws IOException {
  checkOpen();
  try {
    namenode.rename2(src, dst, options);
  } catch(RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   DSQuotaExceededException.class,
                                   FileAlreadyExistsException.class,
                                   FileNotFoundException.class,
                                   ParentNotDirectoryException.class,
                                   SafeModeException.class,
                                   NSQuotaExceededException.class,
                                   UnresolvedPathException.class,
                                   SnapshotAccessControlException.class);
  }
}
项目:FlexMap    文件:FSDirectory.java   
/**
 * @see #unprotectedRenameTo(String, String, long, Options.Rename...)
 */
void renameTo(String src, String dst, long mtime,
    BlocksMapUpdateInfo collectedBlocks, Options.Rename... options)
    throws FileAlreadyExistsException, FileNotFoundException,
    ParentNotDirectoryException, QuotaExceededException,
    UnresolvedLinkException, IOException {
  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* FSDirectory.renameTo: " + src
        + " to " + dst);
  }
  writeLock();
  try {
    if (unprotectedRenameTo(src, dst, mtime, collectedBlocks, options)) {
      namesystem.incrDeletedFileCount(1);
    }
  } finally {
    writeUnlock();
  }
}
项目:FlexMap    文件:FSNamesystem.java   
private void renameToInternal(FSPermissionChecker pc, String src, 
    String dst, boolean logRetryCache, BlocksMapUpdateInfo collectedBlocks, 
    Options.Rename... options) throws IOException {
  assert hasWriteLock();
  if (isPermissionEnabled) {
    // Rename does not operates on link targets
    // Do not resolveLink when checking permissions of src and dst
    // Check write access to parent of src
    checkPermission(pc, src, false, null, FsAction.WRITE, null, null, false,
        false);
    // Check write access to ancestor of dst
    checkPermission(pc, dst, false, FsAction.WRITE, null, null, null, false,
        false);
  }

  waitForLoadingFSImage();
  long mtime = now();
  dir.renameTo(src, dst, mtime, collectedBlocks, options);
  getEditLog().logRename(src, dst, mtime, logRetryCache, options);
}
项目:embulk-output-hdfs    文件:HdfsClient.java   
public void renameDirectory(final Path src, final Path dst, final boolean trashIfExists)
{
    run(new Retryable<Void>()
    {
        @Override
        public Void call()
                throws Exception
        {
            if (fs.exists(dst)) {
                if (!trashIfExists) {
                    throw new DataException(String.format("Directory Exists: %s", dst.toString()));
                }
                logger.info("Move To Trash: {}", dst);
                if (!trash(dst)) {
                    throw new IllegalStateException(String.format("Failed to Move To Trash: %s", dst.toString()));
                }
            }
            FileContext.getFileContext(conf).rename(src, dst, Options.Rename.NONE);
            logger.debug("Rename: {} >>> {}", src, dst);
            return null;
        }
    });
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testCreateBase() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path dir = new Path(fsHome, "/someDir1/someDir2/someDir3");
    Path file = new Path(dir, "someFile");

    assertPathDoesNotExist(fs, file);

    FsPermission fsPerm = new FsPermission((short)644);

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(fsPerm));

    // Try to write something in file.
    os.write("abc".getBytes());

    os.close();

    // Check file status.
    FileStatus fileStatus = fs.getFileStatus(file);

    assertFalse(fileStatus.isDirectory());
    assertEquals(file, fileStatus.getPath());
    assertEquals(fsPerm, fileStatus.getPermission());
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testDeleteRecursively() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path someDir3 = new Path(fsHome, "/someDir1/someDir2/someDir3");

    FSDataOutputStream os = fs.create(someDir3, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    Path someDir2 = new Path(fsHome, "/someDir1/someDir2");

    assertTrue(fs.delete(someDir2, true));

    assertPathDoesNotExist(fs, someDir2);
    assertPathDoesNotExist(fs, someDir3);
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testDeleteRecursivelyFromRoot() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path someDir3 = new Path(fsHome, "/someDir1/someDir2/someDir3");

    FSDataOutputStream os = fs.create(someDir3, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    Path root = new Path(fsHome, "/");

    assertFalse(fs.delete(root, true));

    assertTrue(fs.delete(new Path(fsHome, "/someDir1"), true));

    assertPathDoesNotExist(fs, someDir3);
    assertPathDoesNotExist(fs, new Path(fsHome, "/someDir1/someDir2"));
    assertPathDoesNotExist(fs, new Path(fsHome, "/someDir1"));
    assertPathExists(fs, root);
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
@SuppressWarnings("OctalInteger")
public void testSetPermission() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path file = new Path(fsHome, "/tmp/my");

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    for (short i = 0; i <= 0777; i += 7) {
        FsPermission perm = new FsPermission(i);

        fs.setPermission(file, perm);

        assertEquals(perm, fs.getFileStatus(file).getPermission());
    }
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testSetOwnerCheckParametersPathIsNull() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    final Path file = new Path(fsHome, "/tmp/my");

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            fs.setOwner(null, "aUser", "aGroup");

            return null;
        }
    }, NullPointerException.class, "Ouch! Argument cannot be null: p");
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testSetOwnerCheckParametersUserIsNull() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    final Path file = new Path(fsHome, "/tmp/my");

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            fs.setOwner(file, null, "aGroup");

            return null;
        }
    }, NullPointerException.class, "Ouch! Argument cannot be null: username");
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testSetOwnerCheckParametersGroupIsNull() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    final Path file = new Path(fsHome, "/tmp/my");

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            fs.setOwner(file, "aUser", null);

            return null;
        }
    }, NullPointerException.class, "Ouch! Argument cannot be null: grpName");
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testSetOwner() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    final Path file = new Path(fsHome, "/tmp/my");

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    assertEquals(getClientFsUser(), fs.getFileStatus(file).getOwner());

    fs.setOwner(file, "aUser", "aGroup");

    assertEquals("aUser", fs.getFileStatus(file).getOwner());
    assertEquals("aGroup", fs.getFileStatus(file).getGroup());
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testSetOwnerCheckNonRecursiveness() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path file = new Path(fsHome, "/tmp/my");

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    Path tmpDir = new Path(fsHome, "/tmp");

    fs.setOwner(file, "fUser", "fGroup");
    fs.setOwner(tmpDir, "dUser", "dGroup");

    assertEquals("dUser", fs.getFileStatus(tmpDir).getOwner());
    assertEquals("dGroup", fs.getFileStatus(tmpDir).getGroup());

    assertEquals("fUser", fs.getFileStatus(file).getOwner());
    assertEquals("fGroup", fs.getFileStatus(file).getGroup());
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testOpenIfPathIsAlreadyOpened() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path file = new Path(fsHome, "someFile");

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    FSDataInputStream is1 = fs.open(file);
    FSDataInputStream is2 = fs.open(file);

    is1.close();
    is2.close();
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testOpen() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path file = new Path(fsHome, "someFile");

    int cnt = 2 * 1024;

    try (FSDataOutputStream out = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()))) {

        for (long i = 0; i < cnt; i++)
            out.writeLong(i);
    }

    assertEquals(getClientFsUser(), fs.getFileStatus(file).getOwner());

    try (FSDataInputStream in = fs.open(file, 1024)) {

        for (long i = 0; i < cnt; i++)
            assertEquals(i, in.readLong());
    }
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testAppendIfPathPointsToDirectory() throws Exception {
    final Path fsHome = new Path(primaryFsUri);
    final Path dir = new Path(fsHome, "/tmp");
    Path file = new Path(dir, "my");

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    GridTestUtils.assertThrowsInherited(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            return fs.create(new Path(fsHome, dir), EnumSet.of(CreateFlag.APPEND),
                Options.CreateOpts.perms(FsPermission.getDefault()));
        }
    }, IOException.class, null);
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testAppendIfFileIsAlreadyBeingOpenedToWrite() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    final Path file = new Path(fsHome, "someFile");

    FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    FSDataOutputStream appendOs = fs.create(file, EnumSet.of(CreateFlag.APPEND),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            return fs.create(file, EnumSet.of(CreateFlag.APPEND),
                Options.CreateOpts.perms(FsPermission.getDefault()));
        }
    }, IOException.class, null);

    appendOs.close();
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testRenameCheckParametersDstPathIsNull() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    final Path file = new Path(fsHome, "someFile");

    fs.create(file, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault())).close();

    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            fs.rename(file, null);

            return null;
        }
    }, NullPointerException.class, "Ouch! Argument cannot be null: f");
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testRenameFile() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path srcFile = new Path(fsHome, "/tmp/srcFile");
    Path dstFile = new Path(fsHome, "/tmp/dstFile");

    FSDataOutputStream os = fs.create(srcFile, EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    fs.rename(srcFile, dstFile);

    assertPathDoesNotExist(fs, srcFile);
    assertPathExists(fs, dstFile);
}
项目:ignite    文件:HadoopIgfs20FileSystemAbstractSelfTest.java   
/** @throws Exception If failed. */
public void testRenameDirectory() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    Path dir = new Path(fsHome, "/tmp/");
    Path newDir = new Path(fsHome, "/tmpNew/");

    FSDataOutputStream os = fs.create(new Path(dir, "myFile"), EnumSet.noneOf(CreateFlag.class),
        Options.CreateOpts.perms(FsPermission.getDefault()));

    os.close();

    fs.rename(dir, newDir);

    assertPathDoesNotExist(fs, dir);
    assertPathExists(fs, newDir);
}
项目:hops    文件:DFSClient.java   
/**
 * Rename file or directory.
 *
 * @see ClientProtocol#rename2(String, String, Options.Rename...)
 */
public void rename(final String src, final String dst,
    final Options.Rename... options) throws IOException {
  checkOpen();
  try {
    ClientActionHandler handler = new ClientActionHandler() {
      @Override
      public Object doAction(ClientProtocol namenode)
          throws RemoteException, IOException {
        namenode.rename2(src, dst, options);
        return null;
      }
    };
    doClientActionWithRetry(handler, "rename");
  } catch (RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
        DSQuotaExceededException.class, FileAlreadyExistsException.class,
        FileNotFoundException.class, ParentNotDirectoryException.class,
        SafeModeException.class, NSQuotaExceededException.class,
        UnresolvedPathException.class);
  }
}
项目:hadoop    文件:AggregatedLogFormat.java   
public LogWriter(final Configuration conf, final Path remoteAppLogFile,
    UserGroupInformation userUgi) throws IOException {
  try {
    this.fsDataOStream =
        userUgi.doAs(new PrivilegedExceptionAction<FSDataOutputStream>() {
          @Override
          public FSDataOutputStream run() throws Exception {
            fc = FileContext.getFileContext(remoteAppLogFile.toUri(), conf);
            fc.setUMask(APP_LOG_FILE_UMASK);
            return fc.create(
                remoteAppLogFile,
                EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE),
                new Options.CreateOpts[] {});
          }
        });
  } catch (InterruptedException e) {
    throw new IOException(e);
  }

  // Keys are not sorted: null arg
  // 256KB minBlockSize : Expected log size for each container too
  this.writer =
      new TFile.Writer(this.fsDataOStream, 256 * 1024, conf.get(
          YarnConfiguration.NM_LOG_AGG_COMPRESSION_TYPE,
          YarnConfiguration.DEFAULT_NM_LOG_AGG_COMPRESSION_TYPE), null, conf);
  //Write the version string
  writeVersion();
}
项目:hadoop    文件:WebHdfsFileSystem.java   
@SuppressWarnings("deprecation")
@Override
public void rename(final Path src, final Path dst,
    final Options.Rename... options) throws IOException {
  statistics.incrementWriteOps(1);
  final HttpOpParam.Op op = PutOpParam.Op.RENAME;
  new FsPathRunner(op, src,
      new DestinationParam(makeQualified(dst).toUri().getPath()),
      new RenameOptionSetParam(options)
  ).run();
}
项目:hadoop    文件:FSDirRenameOp.java   
/**
 * The new rename which has the POSIX semantic.
 */
static Map.Entry<BlocksMapUpdateInfo, HdfsFileStatus> renameToInt(
    FSDirectory fsd, final String srcArg, final String dstArg,
    boolean logRetryCache, Options.Rename... options)
    throws IOException {
  String src = srcArg;
  String dst = dstArg;
  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* NameSystem.renameTo: with options -" +
        " " + src + " to " + dst);
  }
  if (!DFSUtil.isValidName(dst)) {
    throw new InvalidPathException("Invalid name: " + dst);
  }
  final FSPermissionChecker pc = fsd.getPermissionChecker();

  byte[][] srcComponents = FSDirectory.getPathComponentsForReservedPath(src);
  byte[][] dstComponents = FSDirectory.getPathComponentsForReservedPath(dst);
  BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo();
  src = fsd.resolvePath(pc, src, srcComponents);
  dst = fsd.resolvePath(pc, dst, dstComponents);
  renameTo(fsd, pc, src, dst, collectedBlocks, logRetryCache, options);
  INodesInPath dstIIP = fsd.getINodesInPath(dst, false);
  HdfsFileStatus resultingStat = fsd.getAuditFileInfo(dstIIP);

  return new AbstractMap.SimpleImmutableEntry<>(
      collectedBlocks, resultingStat);
}
项目:hadoop    文件:FSDirRenameOp.java   
/**
 * @see {@link #unprotectedRenameTo(FSDirectory, String, String, INodesInPath,
 * INodesInPath, long, BlocksMapUpdateInfo, Options.Rename...)}
 */
static void renameTo(FSDirectory fsd, FSPermissionChecker pc, String src,
    String dst, BlocksMapUpdateInfo collectedBlocks, boolean logRetryCache,
    Options.Rename... options) throws IOException {
  final INodesInPath srcIIP = fsd.getINodesInPath4Write(src, false);
  final INodesInPath dstIIP = fsd.getINodesInPath4Write(dst, false);
  if (fsd.isPermissionEnabled()) {
    // Rename does not operate on link targets
    // Do not resolveLink when checking permissions of src and dst
    // Check write access to parent of src
    fsd.checkPermission(pc, srcIIP, false, null, FsAction.WRITE, null, null,
        false);
    // Check write access to ancestor of dst
    fsd.checkPermission(pc, dstIIP, false, FsAction.WRITE, null, null, null,
        false);
  }

  if (NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* FSDirectory.renameTo: " + src + " to "
        + dst);
  }
  final long mtime = Time.now();
  fsd.writeLock();
  try {
    if (unprotectedRenameTo(fsd, src, dst, srcIIP, dstIIP, mtime,
        collectedBlocks, options)) {
      FSDirDeleteOp.incrDeletedFileCount(1);
    }
  } finally {
    fsd.writeUnlock();
  }
  fsd.getEditLog().logRename(src, dst, mtime, logRetryCache, options);
}