/** * Checks if the given path is properly formed. * * @param path The path to check * @throws InvalidPathException If the path is not properly formed */ public static void validatePath(String path) throws InvalidPathException { boolean invalid = (path == null || path.isEmpty()); if (!OSUtils.isWindows()) { invalid = (invalid || !path.startsWith(AlluxioURI.SEPARATOR)); } if (invalid) { throw new InvalidPathException(ExceptionMessage.PATH_INVALID.getMessage(path)); } }
private void traverseWithoutLocking() throws InvalidPathException { if (mExistingInodes.isEmpty()) { mExistingInodes.add(mRoot); } for (int i = mExistingInodes.size(); i < mPathComponents.length; i++) { Inode lastInode = mExistingInodes.get(i - 1); if (lastInode.isFile()) { throw new InvalidPathException(String.format( "Traversal failed for path %s. Component %s(%s) is a file, not a directory.", mUri, i - 1, lastInode.getName())); } Optional<Inode> nextInode = mInodeStore.getChild(lastInode.asDirectory(), mPathComponents[i]); if (!nextInode.isPresent()) { return; } mExistingInodes.add(nextInode.get()); } }
File dstFile = new File(dstPath.getPath()); if (dstFile.exists() && !dstFile.isDirectory()) { throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
@Override public MountPointInfo getMountPointInfo(AlluxioURI path) throws InvalidPathException { if (!mMountTable.isMountPoint(path)) { throw new InvalidPathException( ExceptionMessage.PATH_MUST_BE_MOUNT_POINT.getMessage(path)); } return getMountPointInfo(mMountTable.getMountTable().get(path.toString())); }
private void checkBucketIsAlluxioDirectory(String bucketPath) throws S3Exception { try { URIStatus status = mFileSystem.getStatus(new AlluxioURI(bucketPath)); if (!status.isFolder()) { throw new InvalidPathException("Bucket name is not a valid Alluxio directory."); } } catch (Exception e) { throw toBucketS3Exception(e, bucketPath); } }
/** * Creates a directory in the Alluxio filesystem space. It will not throw any exception if the * destination directory already exists. * * @param dstPath the {@link AlluxioURI} of the destination directory which will be created */ private void createDstDir(AlluxioURI dstPath) throws AlluxioException, IOException { try { mFileSystem.createDirectory(dstPath); } catch (FileAlreadyExistsException e) { // it's fine if the directory already exists } URIStatus dstStatus = mFileSystem.getStatus(dstPath); if (!dstStatus.isFolder()) { throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage()); } }
/** * Set the operation mode the given physical ufs. * * @param journalContext the journal context * @param ufsPath the physical ufs path (scheme and authority only) * @param ufsMode the ufs operation mode * @throws InvalidPathException if no managed ufs covers the given path */ public synchronized void setUfsMode(Supplier<JournalContext> journalContext, AlluxioURI ufsPath, UfsMode ufsMode) throws InvalidPathException { LOG.info("Set ufs mode for {} to {}", ufsPath, ufsMode); String root = ufsPath.getRootPath(); if (!mUfsRoots.contains(root)) { LOG.warn("No managed ufs for physical ufs path {}", root); throw new InvalidPathException(String.format("Unknown Ufs path %s", root)); } mState.applyAndJournal(journalContext, UpdateUfsModeEntry.newBuilder() .setUfsPath(ufsPath.getRootPath()) .setUfsMode(File.UfsMode.valueOf(ufsMode.name())) .build()); }
throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
/** * @return the parent of the target inode * @throws InvalidPathException if the parent inode is not a directory * @throws FileDoesNotExistException if the parent of the target does not exist */ public InodeDirectory getParentInodeDirectory() throws InvalidPathException, FileDoesNotExistException { Inode inode = getParentInodeOrNull(); if (inode == null) { throw new FileDoesNotExistException( ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(mUri.getParent())); } if (!inode.isDirectory()) { throw new InvalidPathException( ExceptionMessage.PATH_MUST_HAVE_VALID_PARENT.getMessage(mUri)); } return (InodeDirectory) inode; }
@Override public void createDirectory(AlluxioURI path, CreateDirectoryPOptions options) throws FileAlreadyExistsException, InvalidPathException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.createDirectory(path, options); LOG.debug("Created directory {}, options: {}", path.getPath(), options); } catch (AlreadyExistsException e) { throw new FileAlreadyExistsException(e.getMessage()); } catch (InvalidArgumentException e) { throw new InvalidPathException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
String mountedUfsPath = mountedUfsUri.getPath().isEmpty() ? "/" : mountedUfsUri.getPath(); if (PathUtils.hasPrefix(ufsPath, mountedUfsPath)) { throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER .getMessage(mountedUfsUri.toString(), ufsUri.toString())); throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER .getMessage(ufsUri.toString(), mountedUfsUri.toString()));
throw new InvalidPathException(String.format( "Error persisting directory. A file exists at the UFS location %s.", ufsUri));
Inode lastInode = mLockList.getLockedInodes().get(lastInodeIndex); if (!lastInode.isDirectory()) { throw new InvalidPathException(String.format( "Traversal failed for path %s. Component %s(%s) is a file, not a directory.", mUri, lastInodeIndex, lastInode.getName()));
throw new InvalidPathException("Failed to unmount " + inodePath.getUri() + ". Please ensure" + " the path is an existing mount point and not root.");
throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
throw new InvalidPathException(ExceptionMessage.ROOT_CANNOT_BE_RENAMED.getMessage()); throw new InvalidPathException(ExceptionMessage.RENAME_CANNOT_BE_TO_ROOT.getMessage()); if ((srcMount == null && dstMount != null) || (srcMount != null && dstMount == null) || ( srcMount != null && dstMount != null && !srcMount.equals(dstMount))) { throw new InvalidPathException(ExceptionMessage.RENAME_CANNOT_BE_ACROSS_MOUNTS .getMessage(srcInodePath.getUri(), dstInodePath.getUri())); throw new InvalidPathException( ExceptionMessage.RENAME_CANNOT_BE_ONTO_MOUNT_POINT.getMessage(dstInodePath.getUri())); throw new InvalidPathException(ExceptionMessage.RENAME_CANNOT_BE_TO_SUBDIRECTORY .getMessage(srcInodePath.getUri(), dstInodePath.getUri())); throw new InvalidPathException( ExceptionMessage.PATH_MUST_HAVE_VALID_PARENT.getMessage(srcInodePath.getUri())); throw new InvalidPathException( ExceptionMessage.PATH_MUST_HAVE_VALID_PARENT.getMessage(dstInodePath.getUri()));
throw new InvalidPathException( ExceptionMessage.MOUNT_POINT_ALREADY_EXISTS.getMessage(inodePath.getUri()));
throw new FileAlreadyExistsException(e.getMessage()); } catch (InvalidArgumentException e) { throw new InvalidPathException(e.getMessage()); } catch (UnavailableException e) { throw e;
throw new InvalidPathException("URI " + uri + " is already a sync point");
private void stopSyncAndJournal(RpcContext rpcContext, LockingScheme lockingScheme, LockedInodePath lockedInodePath) throws IOException, InvalidPathException { try (LockResource r = new LockResource(mSyncManager.getSyncManagerLock())) { MountTable.Resolution resolution = mSyncManager.resolveSyncPoint(lockedInodePath.getUri()); if (resolution == null) { throw new InvalidPathException(lockedInodePath.getUri() + " is not a sync point."); } AlluxioURI uri = lockedInodePath.getUri(); RemoveSyncPointEntry removeSyncPoint = File.RemoveSyncPointEntry.newBuilder() .setSyncpointPath(lockedInodePath.getUri().toString()) .setMountId(resolution.getMountId()) .build(); mSyncManager.applyAndJournal(rpcContext, removeSyncPoint); try { mSyncManager.stopSyncPostJournal(lockedInodePath.getUri()); } catch (Throwable e) { // revert state; AddSyncPointEntry addSyncPoint = File.AddSyncPointEntry.newBuilder() .setSyncpointPath(uri.toString()).build(); mSyncManager.applyAndJournal(rpcContext, addSyncPoint); mSyncManager.recoverFromStopSync(uri, resolution.getMountId()); throw e; } } }