@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); AlluxioURI srcPath = new AlluxioURI(args[0]); AlluxioURI dstPath = new AlluxioURI(args[1]); mFileSystem.rename(srcPath, dstPath); System.out.println("Renamed " + srcPath + " to " + dstPath); return 0; }
/** * Renames a path. * * @param oldPath the source path in the FS * @param newPath the destination path in the FS * @return 0 on success, a negative value on error */ @Override public int rename(String oldPath, String newPath) { final AlluxioURI oldUri = mPathResolverCache.getUnchecked(oldPath); final AlluxioURI newUri = mPathResolverCache.getUnchecked(newPath); LOG.trace("rename({}, {}) [Alluxio: {}, {}]", oldPath, newPath, oldUri, newUri); try { mFileSystem.rename(oldUri, newUri); synchronized (mOpenFiles) { if (mOpenFiles.contains(PATH_INDEX, oldPath)) { OpenFileEntry oe = mOpenFiles.getFirstByField(PATH_INDEX, oldPath); oe.setPath(newPath); } } } catch (Throwable t) { LOG.error("Failed to rename {} to {}", oldPath, newPath, t); return AlluxioFuseUtils.getErrorCode(t); } return 0; }
@Override public void apply(FileSystem fs) throws Exception { Utils.createFile(fs, SRC); fs.rename(SRC, DST); fs.createDirectory(new AlluxioURI("/renameDir/a/b"), CreateDirectoryPOptions.newBuilder().setRecursive(true).build()); fs.rename(new AlluxioURI("/renameDir/a"), new AlluxioURI("/renameDir/c")); }
AlluxioURI dstPath = new AlluxioURI(HadoopUtils.getPathWithoutScheme(dst)); try { mFileSystem.rename(srcPath, dstPath); } catch (FileDoesNotExistException e) { LOG.warn("rename failed: {}", e.getMessage()); mFileSystem.rename(srcPath, dstPath); } catch (IOException | AlluxioException e2) { LOG.error("Failed to rename {} to {}", src, dst, e2);
/** * Tests for the {@link BaseFileSystem#rename(AlluxioURI, AlluxioURI, RenamePOptions)} * method. */ @Test public void rename() throws Exception { AlluxioURI src = new AlluxioURI("/file"); AlluxioURI dst = new AlluxioURI("/file2"); RenamePOptions renameOptions = RenamePOptions.getDefaultInstance(); doNothing().when(mFileSystemMasterClient).rename(src, dst, renameOptions); mFileSystem.rename(src, dst, renameOptions); verify(mFileSystemMasterClient).rename(src, dst, renameOptions); }
/** * Ensures that an exception is propagated successfully when renaming a file. */ @Test public void renameException() throws Exception { AlluxioURI src = new AlluxioURI("/file"); AlluxioURI dst = new AlluxioURI("/file2"); RenamePOptions renameOptions = RenamePOptions.getDefaultInstance(); doThrow(EXCEPTION).when(mFileSystemMasterClient).rename(src, dst, renameOptions); try { mFileSystem.rename(src, dst, renameOptions); fail(SHOULD_HAVE_PROPAGATED_MESSAGE); } catch (Exception e) { assertSame(EXCEPTION, e); } }
sFileSystem.rename(testURI, new AlluxioURI(testURI + "-rename"));
AlluxioURI dstPath = new AlluxioURI(HadoopUtils.getPathWithoutScheme(dst)); try { mFileSystem.rename(srcPath, dstPath); } catch (FileDoesNotExistException e) { LOG.warn("rename failed: {}", e.getMessage()); mFileSystem.rename(srcPath, dstPath); } catch (IOException | AlluxioException e2) { LOG.error("Failed to rename {} to {}", src, dst, e2);
mFileSystem.rename(srcPath, dstPath); return true; } catch (IOException e) {
sFileSystem.rename(testURI, new AlluxioURI(testURI + "-rename"));