/** * Returns the closest ancestor of the target inode (last inode in the full path). * * @return the closest ancestor inode * @throws FileDoesNotExistException if an ancestor does not exist */ public Inode getAncestorInode() throws FileDoesNotExistException { int ancestorIndex = mPathComponents.length - 2; if (ancestorIndex < 0) { throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(mUri)); } ancestorIndex = Math.min(ancestorIndex, mExistingInodes.size() - 1); return mExistingInodes.get(ancestorIndex); }
/** * @return the target inode * @throws FileDoesNotExistException if the target inode does not exist */ public Inode getInode() throws FileDoesNotExistException { Inode inode = getInodeOrNull(); if (inode == null) { throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(mUri)); } return inode; }
/** * Checks the {@link LoadMetadataPType} to determine whether or not to proceed in loading * metadata. This method assumes that the path does not exist in Alluxio namespace, and will * throw an exception if metadata should not be loaded. * * @param loadMetadataType the {@link LoadMetadataPType} to check * @param path the path that does not exist in Alluxio namespace (used for exception message) */ private void checkLoadMetadataOptions(LoadMetadataPType loadMetadataType, AlluxioURI path) throws FileDoesNotExistException { if (loadMetadataType == LoadMetadataPType.NEVER || (loadMetadataType == LoadMetadataPType.ONCE && mUfsAbsentPathCache.isAbsent(path))) { throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path)); } }
/** * Tells the mock to throw FileDoesNotExistException when the given path is queried. */ private void setPathToNotExist(String path) throws Exception { AlluxioURI uri = new AlluxioURI(path); when(mMockFileSystem.getStatus(uri)).thenThrow(new FileDoesNotExistException(uri)); when(mMockFileSystem.listStatus(uri)).thenThrow(new FileDoesNotExistException(uri)); } }
@Override protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(plainPath); if (status.isFolder()) { throw new FileDoesNotExistException( ExceptionMessage.PATH_MUST_BE_FILE.getMessage(plainPath.getPath())); } String str = calculateChecksum(plainPath); System.out.println("md5sum: " + str + "\n"); }
/** * @return the target inode as an {@link MutableInodeFile} * @throws FileDoesNotExistException if the target inode does not exist, or it is not a file */ public InodeFile getInodeFile() throws FileDoesNotExistException { Inode inode = getInode(); if (!inode.isFile()) { throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(mUri)); } return inode.asFile(); }
/** * Locks a path and throws an exception if the path does not exist. * * @param uri a uri to lock * @param lockPattern the pattern to lock with * @return a locked inode path for the uri */ public LockedInodePath lockFullInodePath(AlluxioURI uri, LockPattern lockPattern) throws InvalidPathException, FileDoesNotExistException { LockedInodePath inodePath = lockInodePath(uri, lockPattern); if (!inodePath.fullPathExists()) { inodePath.close(); throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(uri)); } return inodePath; }
/** * Locks a path and throws an exception if the path does not exist. * * @param id the inode id to lock * @param lockPattern the pattern to lock with * @return a locked inode path for the uri */ public LockedInodePath lockFullInodePath(long id, LockPattern lockPattern) throws FileDoesNotExistException { LockedInodePath inodePath = lockInodePathById(id, lockPattern); if (!inodePath.fullPathExists()) { inodePath.close(); throw new FileDoesNotExistException(ExceptionMessage.INODE_DOES_NOT_EXIST.getMessage(id)); } return inodePath; }
/** * Starts the active syncing process on an Alluxio path. * * @param path the path to sync */ @Override public void startSync(AlluxioURI path) throws FileDoesNotExistException, IOException, AlluxioException { FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.startSync(path); LOG.debug("Start syncing for {}", path.getPath()); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
/** * Stops the active syncing process on an Alluxio path. * @param path the path to stop syncing */ @Override public void stopSync(AlluxioURI path) throws FileDoesNotExistException, IOException, AlluxioException { FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.stopSync(path); LOG.debug("Stop syncing for {}", path.getPath()); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void free(AlluxioURI path, FreePOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.free(path, options); LOG.debug("Freed {}, options: {}", path.getPath(), options); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { URIStatus status = mFileSystem.getStatus(path); if (status.isFolder()) { throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path)); } OpenFilePOptions options = OpenFilePOptions.getDefaultInstance(); byte[] buf = new byte[Constants.MB]; try (FileInStream is = mFileSystem.openFile(path, options)) { int read = is.read(buf); while (read != -1) { System.out.write(buf, 0, read); read = is.read(buf); } } }
@Override public void setAcl(AlluxioURI path, SetAclAction action, List<AclEntry> entries, SetAclPOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.setAcl(path, action, entries, options); LOG.debug("Set ACL for {}, entries: {} options: {}", path.getPath(), entries, options); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void setAttribute(AlluxioURI path, SetAttributePOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.setAttribute(path, options); LOG.debug("Set attributes for {}, options: {}", path.getPath(), options); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
/** * Attempts to extend an existing {@link LockedInodePath} to reach the target inode (the last * inode for the full path). If the target inode does not exist, an exception will be thrown. * * @param inodePath the {@link LockedInodePath} to extend to the target inode * @throws InvalidPathException if the path is invalid * @throws FileDoesNotExistException if the target inode does not exist */ public void ensureFullInodePath(LockedInodePath inodePath) throws InvalidPathException, FileDoesNotExistException { if (inodePath.fullPathExists()) { return; } inodePath.traverse(); if (!inodePath.fullPathExists()) { throw new FileDoesNotExistException( ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(inodePath.getUri())); } }
@Override public URIStatus getStatus(AlluxioURI path, GetStatusPOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { return masterClient.getStatus(path, options); } catch (NotFoundException e) { throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path)); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
/** * @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 List<URIStatus> listStatus(AlluxioURI path, ListStatusPOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); // TODO(calvin): Fix the exception handling in the master try { return masterClient.listStatus(path, options); } catch (NotFoundException e) { throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path)); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void rename(AlluxioURI src, AlluxioURI dst, RenamePOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(src); checkUri(dst); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { // TODO(calvin): Update this code on the master side. masterClient.rename(src, dst, options); LOG.debug("Renamed {} to {}, options: {}", src.getPath(), dst.getPath(), options); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public FileInStream openFile(AlluxioURI path, OpenFilePOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); URIStatus status = getStatus(path); if (status.isFolder()) { throw new FileDoesNotExistException( ExceptionMessage.CANNOT_READ_DIRECTORY.getMessage(status.getName())); } InStreamOptions inStreamOptions = new InStreamOptions(status, options, mFsContext.getConf()); return new FileInStream(status, inStreamOptions, mFsContext); }