diff --git a/clients/unshaded/src/main/java/tachyon/client/file/AbstractTachyonFileSystem.java b/clients/unshaded/src/main/java/tachyon/client/file/AbstractTachyonFileSystem.java index 6de47530b30a..b086b39f8382 100644 --- a/clients/unshaded/src/main/java/tachyon/client/file/AbstractTachyonFileSystem.java +++ b/clients/unshaded/src/main/java/tachyon/client/file/AbstractTachyonFileSystem.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.util.List; +import java.util.Optional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,7 +26,13 @@ import tachyon.TachyonURI; import tachyon.annotation.PublicApi; import tachyon.client.FileSystemMasterClient; -import tachyon.thrift.BlockInfoException; +import tachyon.client.options.DeleteOptions; +import tachyon.client.options.FreeOptions; +import tachyon.client.options.LoadOptions; +import tachyon.client.options.MkdirOptions; +import tachyon.client.options.SetStateOptions; +import tachyon.exception.TachyonException; +import tachyon.exception.TachyonExceptionType; import tachyon.thrift.FileAlreadyExistException; import tachyon.thrift.FileDoesNotExistException; import tachyon.thrift.FileInfo; @@ -51,19 +58,6 @@ protected AbstractTachyonFileSystem() { mContext = FileSystemContext.INSTANCE; } - @Override - public long create(TachyonURI path, long blockSize, boolean recursive) throws - BlockInfoException, FileAlreadyExistException, InvalidPathException, IOException { - FileSystemMasterClient masterClient = mContext.acquireMasterClient(); - try { - long fileId = masterClient.createFile(path.getPath(), blockSize, recursive); - LOG.info("Created file " + path + " with file ID: " + fileId); - return fileId; - } finally { - mContext.releaseMasterClient(masterClient); - } - } - /** * {@inheritDoc} * @@ -74,13 +68,14 @@ public long create(TachyonURI path, long blockSize, boolean recursive) throws * current readers have relinquished their locks. */ @Override - public void delete(TachyonFile file, boolean recursive) throws FileDoesNotExistException, - IOException { + public void delete(TachyonFile file, DeleteOptions options) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { - masterClient.deleteFile(file.getFileId(), recursive); + masterClient.deleteFile(file.getFileId(), options.isRecursive()); LOG.info( "Deleted file " + file.getFileId() + " from both Tachyon Storage and under file system"); + } catch (FileDoesNotExistException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.FILE_DOES_NOT_EXIST); } finally { mContext.releaseMasterClient(masterClient); } @@ -92,12 +87,13 @@ public void delete(TachyonFile file, boolean recursive) throws FileDoesNotExistE * This method is asynchronous and will be propagated to the workers through their heartbeats. */ @Override - public void free(TachyonFile file, boolean recursive) throws FileDoesNotExistException, - IOException { + public void free(TachyonFile file, FreeOptions options) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { - masterClient.free(file.getFileId(), recursive); + masterClient.free(file.getFileId(), options.isRecursive()); LOG.info("Removed file " + file.getFileId() + " from Tachyon Storage"); + } catch (FileDoesNotExistException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.FILE_DOES_NOT_EXIST); } finally { mContext.releaseMasterClient(masterClient); } @@ -110,7 +106,7 @@ public void free(TachyonFile file, boolean recursive) throws FileDoesNotExistExc * path are possibly inconsistent. */ @Override - public FileInfo getInfo(TachyonFile file) throws IOException { + public FileInfo getInfo(TachyonFile file) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { return masterClient.getFileInfo(file.getFileId()); @@ -128,10 +124,12 @@ public FileInfo getInfo(TachyonFile file) throws IOException { * path are possibly inconsistent. */ @Override - public List listStatus(TachyonFile file) throws FileDoesNotExistException, IOException { + public List listStatus(TachyonFile file) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { return masterClient.getFileInfoList(file.getFileId()); + } catch (FileDoesNotExistException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.FILE_DOES_NOT_EXIST); } finally { mContext.releaseMasterClient(masterClient); } @@ -145,73 +143,83 @@ public List listStatus(TachyonFile file) throws FileDoesNotExistExcept * example the load command of the Tachyon Shell. */ @Override - public long loadFileInfoFromUfs(TachyonURI path, TachyonURI ufsPath, boolean recursive) - throws FileDoesNotExistException, IOException { + public long load(TachyonURI path, TachyonURI ufsPath, LoadOptions options) throws IOException, + TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { - long fileId = masterClient.loadFileInfoFromUfs(path.getPath(), ufsPath.toString(), recursive); - LOG.info( - "Loaded file " + path.getPath() + " from " + ufsPath + (recursive ? " recursively" : "")); + long fileId = + masterClient.loadFileInfoFromUfs(path.getPath(), ufsPath.toString(), + options.isRecursive()); + LOG.info("Loaded file " + path.getPath() + " from " + ufsPath + + (options.isRecursive() ? " recursively" : "")); return fileId; + } catch (FileDoesNotExistException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.FILE_DOES_NOT_EXIST); } finally { mContext.releaseMasterClient(masterClient); } } @Override - public boolean mkdirs(TachyonURI path, boolean recursive) throws InvalidPathException, - IOException, FileAlreadyExistException { + public boolean mkdir(TachyonURI path, MkdirOptions options) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { - boolean result = masterClient.createDirectory(path.getPath(), recursive); + boolean result = masterClient.createDirectory(path.getPath(), options.isRecursive()); if (result) { LOG.info("Created directory " + path.getPath()); } return result; + } catch (FileAlreadyExistException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.FILE_ALREADY_EXISTS); + } catch (InvalidPathException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.INVALID_PATH); } finally { mContext.releaseMasterClient(masterClient); } } @Override - public TachyonFile open(TachyonURI path) throws InvalidPathException, IOException { + public TachyonFile open(TachyonURI path) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { return new TachyonFile(masterClient.getFileId(path.getPath())); + } catch (InvalidPathException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.INVALID_PATH); } finally { mContext.releaseMasterClient(masterClient); } } - /** - * {@inheritDoc} - * - * The pin status is propagated asynchronously from this method call on the worker heartbeats. - */ @Override - public void setPin(TachyonFile file, boolean pinned) throws FileDoesNotExistException, - IOException { + public boolean rename(TachyonFile src, TachyonURI dst) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { - masterClient.setPinned(file.getFileId(), pinned); - LOG.info(pinned ? "Pinned" : "Unpinned" + " file " + file.getFileId()); + boolean result = masterClient.renameFile(src.getFileId(), dst.getPath()); + if (result) { + LOG.info("Renamed file " + src.getFileId() + " to " + dst.getPath()); + } + return result; + } catch (FileDoesNotExistException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.FILE_DOES_NOT_EXIST); } finally { mContext.releaseMasterClient(masterClient); } } @Override - public boolean rename(TachyonFile src, TachyonURI dst) throws FileDoesNotExistException, - IOException { + public void setState(TachyonFile file, SetStateOptions options) throws IOException, + TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); - try { - boolean result = masterClient.renameFile(src.getFileId(), dst.getPath()); - if (result) { - LOG.info("Renamed file " + src.getFileId() + " to " + dst.getPath()); + Optional pinned = options.getPinned(); + if (pinned.isPresent()) { + try { + masterClient.setPinned(file.getFileId(), pinned.get()); + LOG.info(pinned.get() ? "Pinned" : "Unpinned" + " file " + file.getFileId()); + } catch (FileDoesNotExistException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.FILE_DOES_NOT_EXIST); + } finally { + mContext.releaseMasterClient(masterClient); } - return result; - } finally { - mContext.releaseMasterClient(masterClient); } } } diff --git a/clients/unshaded/src/main/java/tachyon/client/file/FileInStream.java b/clients/unshaded/src/main/java/tachyon/client/file/FileInStream.java index dc2a0ba9fe4e..3a13bc1d1e3b 100644 --- a/clients/unshaded/src/main/java/tachyon/client/file/FileInStream.java +++ b/clients/unshaded/src/main/java/tachyon/client/file/FileInStream.java @@ -28,15 +28,14 @@ import tachyon.annotation.PublicApi; import tachyon.client.BoundedStream; import tachyon.client.ClientContext; -import tachyon.client.ClientOptions; import tachyon.client.Seekable; import tachyon.client.TachyonStorageType; import tachyon.client.block.BlockInStream; import tachyon.client.block.BufferedBlockOutStream; import tachyon.client.block.LocalBlockInStream; +import tachyon.client.options.InStreamOptions; import tachyon.master.block.BlockId; import tachyon.thrift.FileInfo; -import tachyon.thrift.NetAddress; import tachyon.util.network.NetworkAddressUtils; /** @@ -84,7 +83,7 @@ public final class FileInStream extends InputStream implements BoundedStream, Se * @param info the file information * @param options the client options */ - public FileInStream(FileInfo info, ClientOptions options) { + public FileInStream(FileInfo info, InStreamOptions options) { mBlockSize = info.getBlockSizeBytes(); mFileLength = info.getLength(); mBlockIds = info.getBlockIds(); @@ -228,7 +227,7 @@ private void checkAndAdvanceBlockInStream() throws IOException { try { // TODO(calvin): Specify the location to be local. mCurrentCacheStream = - mContext.getTachyonBlockStore().getOutStream(currentBlockId, -1, + mContext.getTachyonBlockStore().getOutStream(currentBlockId, -1, NetworkAddressUtils.getLocalHostName(ClientContext.getConf())); } catch (IOException ioe) { LOG.warn("Failed to get TachyonStore stream, the block " + currentBlockId @@ -288,7 +287,7 @@ private void seekBlockInStream(long newPos) throws IOException { if (mPos % mBlockSize == 0 && mShouldCacheCurrentBlock) { try { mCurrentCacheStream = - mContext.getTachyonBlockStore().getOutStream(currentBlockId, -1, + mContext.getTachyonBlockStore().getOutStream(currentBlockId, -1, NetworkAddressUtils.getLocalHostName(ClientContext.getConf())); } catch (IOException ioe) { LOG.warn("Failed to write to TachyonStore stream, block " + getCurrentBlockId() diff --git a/clients/unshaded/src/main/java/tachyon/client/file/FileOutStream.java b/clients/unshaded/src/main/java/tachyon/client/file/FileOutStream.java index 05b11f2f06c1..3a241d9eeea9 100644 --- a/clients/unshaded/src/main/java/tachyon/client/file/FileOutStream.java +++ b/clients/unshaded/src/main/java/tachyon/client/file/FileOutStream.java @@ -30,12 +30,12 @@ import tachyon.annotation.PublicApi; import tachyon.client.Cancelable; import tachyon.client.ClientContext; -import tachyon.client.ClientOptions; import tachyon.client.FileSystemMasterClient; import tachyon.client.TachyonStorageType; import tachyon.client.UnderStorageType; import tachyon.client.block.BlockStoreContext; import tachyon.client.block.BufferedBlockOutStream; +import tachyon.client.options.OutStreamOptions; import tachyon.underfs.UnderFileSystem; import tachyon.util.io.PathUtils; import tachyon.worker.WorkerClient; @@ -74,7 +74,7 @@ public final class FileOutStream extends OutputStream implements Cancelable { * @param options the client options * @throws IOException if an I/O error occurs */ - public FileOutStream(long fileId, ClientOptions options) throws IOException { + public FileOutStream(long fileId, OutStreamOptions options) throws IOException { mFileId = fileId; mBlockSize = options.getBlockSize(); mTachyonStorageType = options.getTachyonStorageType(); diff --git a/clients/unshaded/src/main/java/tachyon/client/file/TachyonFileSystem.java b/clients/unshaded/src/main/java/tachyon/client/file/TachyonFileSystem.java index b5006e2472c3..ba705f659b4c 100644 --- a/clients/unshaded/src/main/java/tachyon/client/file/TachyonFileSystem.java +++ b/clients/unshaded/src/main/java/tachyon/client/file/TachyonFileSystem.java @@ -16,19 +16,31 @@ package tachyon.client.file; import java.io.IOException; +import java.util.Optional; import com.google.common.base.Preconditions; +import tachyon.Constants; import tachyon.TachyonURI; import tachyon.annotation.PublicApi; import tachyon.client.ClientOptions; import tachyon.client.FileSystemMasterClient; -import tachyon.thrift.BlockInfoException; +import tachyon.client.options.CreateOptions; +import tachyon.client.options.DeleteOptions; +import tachyon.client.options.FreeOptions; +import tachyon.client.options.InStreamOptions; +import tachyon.client.options.LoadOptions; +import tachyon.client.options.MkdirOptions; +import tachyon.client.options.OutStreamOptions; +import tachyon.client.options.SetStateOptions; +import tachyon.conf.TachyonConf; +import tachyon.exception.TachyonException; +import tachyon.exception.TachyonExceptionType; import tachyon.thrift.DependencyDoesNotExistException; -import tachyon.thrift.FileAlreadyExistException; import tachyon.thrift.FileDoesNotExistException; import tachyon.thrift.FileInfo; -import tachyon.thrift.InvalidPathException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A TachyonFileSystem implementation including convenience methods as well as a streaming API to @@ -39,6 +51,7 @@ */ @PublicApi public class TachyonFileSystem extends AbstractTachyonFileSystem { + private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE); private static TachyonFileSystem sTachyonFileSystem; @@ -55,87 +68,38 @@ private TachyonFileSystem() { super(); } - /** - * Create is not supported in StreamingTachyonFileSystem. Files should only be written once. - * Use getOutStream instead to create files. - */ @Override - public long create(TachyonURI path, long blockSize, boolean recursive) { - throw new UnsupportedOperationException("Create is not supported, use getOutStream instead."); + public long create(TachyonURI path) { + return create(path, CreateOptions.defaults()); } - /** - * Convenience method for {@link #createEmptyFile(TachyonURI, ClientOptions)} with default - * client options. - * - * @param path the Tachyon path of the file - * @return the fileId of the created file - * @throws InvalidPathException if the provided path is invalid - * @throws FileAlreadyExistException if the file being written to already exists - * @throws BlockInfoException if the provided block size is invalid - * @throws IOException if the master cannot create the file. - */ - public long createEmptyFile(TachyonURI path) throws IOException, InvalidPathException, - FileAlreadyExistException, BlockInfoException { - ClientOptions options = ClientOptions.defaults(); - return createEmptyFile(path, options); - } - - /** - * Creates a zero byte file in Tachyon with the specified options. This is the same as calling - * {@link #getOutStream} and then immediately closing the stream. - * - * @param path the Tachyon path of the file - * @param options the set of options specific to this operation - * @return the fileId of the created file - * @throws InvalidPathException if the provided path is invalid - * @throws FileAlreadyExistException if the file being written to already exists - * @throws BlockInfoException if the provided block size is invalid - * @throws IOException if the master cannot create the file. - */ - public long createEmptyFile(TachyonURI path, ClientOptions options) throws IOException, - InvalidPathException, FileAlreadyExistException, BlockInfoException { - long fileId = super.create(path, options.getBlockSize(), true); - new FileOutStream(fileId, options).close(); - return fileId; + @Override + public long create(TachyonURI path, CreateOptions options) { + throw new UnsupportedOperationException( + "create() is currently not supported, use getOutStream instead."); } - /** - * Convenience method for delete without recursive set. This is the same as calling delete(file, - * false). - * - * @param file the handler for the file to delete recursively - * @throws FileDoesNotExistException if the file does not exist in Tachyon space - * @throws IOException if the master cannot delete the file - */ - public void delete(TachyonFile file) throws FileDoesNotExistException, IOException { - delete(file, !RECURSIVE); + @Override + public void delete(TachyonFile file) throws IOException, TachyonException { + delete(file, DeleteOptions.defaults()); } - /** - * Convenience method for free without recursive set. This is the same as calling free(file, - * false). - * - * @param file the handler for the file to free recursively - * @throws FileDoesNotExistException if the file does not exist in Tachyon space - * @throws IOException if the master cannot delete the file - */ - public void free(TachyonFile file) throws FileDoesNotExistException, - IOException { - free(file, !RECURSIVE); + @Override + public void free(TachyonFile file) throws IOException, TachyonException { + free(file, FreeOptions.defaults()); } /** - * Convenience method for {@link #getInStream(TachyonFile, ClientOptions)} with default client + * Convenience method for {@link #getInStream(TachyonFile, InStreamOptions)} with default * options. * * @param file the handler for the file to read * @return an input stream to read the file - * @throws FileDoesNotExistException if the file does not exist - * @throws IOException if the stream cannot be opened for some other reason + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - public FileInStream getInStream(TachyonFile file) throws FileDoesNotExistException, IOException { - return getInStream(file, ClientOptions.defaults()); + public FileInStream getInStream(TachyonFile file) throws IOException, TachyonException { + return getInStream(file, InStreamOptions.defaults()); } /** @@ -146,31 +110,27 @@ public FileInStream getInStream(TachyonFile file) throws FileDoesNotExistExcepti * @param file the handler for the file to read * @param options the set of options specific to this operation. * @return an input stream to read the file - * @throws FileDoesNotExistException if the file does not exist - * @throws IOException if the stream cannot be opened for some other reason + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - public FileInStream getInStream(TachyonFile file, ClientOptions options) throws IOException, - FileDoesNotExistException { + public FileInStream getInStream(TachyonFile file, InStreamOptions options) throws IOException, + TachyonException { FileInfo info = getInfo(file); Preconditions.checkState(!info.isIsFolder(), "Cannot read from a folder"); return new FileInStream(info, options); } /** - * Convenience method for {@link #getOutStream(TachyonURI, ClientOptions)} with default client + * Convenience method for {@link #getOutStream(TachyonURI, OutStreamOptions)} with default client * options. * * @param path the Tachyon path of the file * @return an output stream to write the file - * @throws InvalidPathException if the provided path is invalid - * @throws FileAlreadyExistException if the file being written to already exists - * @throws BlockInfoException if the provided block size is invalid - * @throws IOException if the file already exists or if the stream cannot be opened + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - public FileOutStream getOutStream(TachyonURI path) throws IOException, InvalidPathException, - FileAlreadyExistException, BlockInfoException { - ClientOptions options = ClientOptions.defaults(); - return getOutStream(path, options); + public FileOutStream getOutStream(TachyonURI path) throws IOException, TachyonException { + return getOutStream(path, OutStreamOptions.defaults()); } /** @@ -182,91 +142,67 @@ public FileOutStream getOutStream(TachyonURI path) throws IOException, InvalidPa * @param path the Tachyon path of the file * @param options the set of options specific to this operation * @return an output stream to write the file - * @throws InvalidPathException if the provided path is invalid - * @throws FileAlreadyExistException if the file being written to already exists - * @throws BlockInfoException if the provided block size is invalid - * @throws IOException if the file already exists or if the stream cannot be opened + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - public FileOutStream getOutStream(TachyonURI path, ClientOptions options) throws IOException, - InvalidPathException, FileAlreadyExistException, BlockInfoException { - long fileId = super.create(path, options.getBlockSize(), true); + public FileOutStream getOutStream(TachyonURI path, OutStreamOptions options) throws IOException, + TachyonException { + CreateOptions createOptions = + (new CreateOptions.Builder(new TachyonConf())).setBlockSize(options.getBlockSize()) + .setRecursive(true).build(); + long fileId = create(path, createOptions); return new FileOutStream(fileId, options); } /** - * Alternative way to get a FileOutStream to a file that has already been created. This should - * not be used. Deprecated in version v0.8 and will be removed in v0.9. + * Alternative way to get a FileOutStream to a file that has already been created. This should not + * be used. Deprecated in version v0.8 and will be removed in v0.9. * - * @see #getOutStream(TachyonURI path, ClientOptions options) + * @see #getOutStream(TachyonURI path, OutStreamOptions options) */ // TODO(calvin): We should remove this when the TachyonFS code is fully deprecated. @Deprecated - public FileOutStream getOutStream(long fileId, ClientOptions options) throws IOException { + public FileOutStream getOutStream(long fileId, OutStreamOptions options) throws IOException { return new FileOutStream(fileId, options); } - /** - * Convenience method for mkdirs with recursive set. - * - * @param path the Tachyon path of the folder to create recursively - * @return true if the directory is created - * @throws FileAlreadyExistException if the path already exists or a parent is a file - * @throws InvalidPathException if the path is invalid - * @throws IOException if the master cannot create the folder - */ - // TODO(calvin,jiri): Consider renaming to mkdir - public boolean mkdirs(TachyonURI path) throws FileAlreadyExistException, InvalidPathException, - IOException { - return mkdirs(path, !RECURSIVE); + @Override + public long load(TachyonURI path, TachyonURI ufsPath) throws IOException, TachyonException { + return load(path, ufsPath, LoadOptions.defaults()); } - /** - * Sets the pin status of a file. The file's pin status will be true regardless of whether or - * not it was pinned previously. Pinning a file prevents any of its blocks from being evicted, - * but does not load the blocks into memory. The blocks must be loaded through another means, - * for example the load command in the shell. Calling this method is equivalent to calling - * setPin(file, true). - * - * @param file the handler for the file to pin - * @throws FileDoesNotExistException if the file does not exist - * @throws IOException if the master fails to pin the file - */ - public void pin(TachyonFile file) throws FileDoesNotExistException, IOException { - setPin(file, true); + @Override + public boolean mkdir(TachyonURI path) throws IOException, TachyonException { + return mkdir(path, MkdirOptions.defaults()); } // TODO: Move this to lineage client - public void reportLostFile(TachyonFile file) throws IOException, FileDoesNotExistException { + public void reportLostFile(TachyonFile file) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { masterClient.reportLostFile(file.getFileId()); + } catch (FileDoesNotExistException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.FILE_DOES_NOT_EXIST); } finally { mContext.releaseMasterClient(masterClient); } } // TODO: Move this to lineage client - public void requestFilesInDependency(int depId) throws IOException, - DependencyDoesNotExistException { + public void requestFilesInDependency(int depId) throws IOException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { masterClient.requestFilesInDependency(depId); + } catch (DependencyDoesNotExistException e) { + throw new TachyonException(e.getMessage(), TachyonExceptionType.DEPENDENCY_DOES_NOT_EXIST); } finally { mContext.releaseMasterClient(masterClient); } } - /** - * Unsets the pin status of a file. The file's pin status will be false regardless of - * whether or not it was pinned previously. Unpinning a file makes it eligible for eviction, - * but the file will not be evicted from Tachyon space until the eviction policy deems it - * necessary. Calling this method is equivalent to calling setPin(file, false). - * - * @param file the handler for the file to unpin - * @throws FileDoesNotExistException if the file does not exist - * @throws IOException if the master fails to unpin the file - */ - public void unpin(TachyonFile file) throws FileDoesNotExistException, IOException { - setPin(file, false); + + @Override + public void setState(TachyonFile file) throws IOException, TachyonException { + setState(file, SetStateOptions.defaults()); } } diff --git a/clients/unshaded/src/main/java/tachyon/client/file/TachyonFileSystemCore.java b/clients/unshaded/src/main/java/tachyon/client/file/TachyonFileSystemCore.java index b999c576da87..9ad502838de9 100644 --- a/clients/unshaded/src/main/java/tachyon/client/file/TachyonFileSystemCore.java +++ b/clients/unshaded/src/main/java/tachyon/client/file/TachyonFileSystemCore.java @@ -20,11 +20,14 @@ import tachyon.TachyonURI; import tachyon.annotation.PublicApi; -import tachyon.thrift.BlockInfoException; -import tachyon.thrift.FileAlreadyExistException; -import tachyon.thrift.FileDoesNotExistException; +import tachyon.client.options.CreateOptions; +import tachyon.client.options.DeleteOptions; +import tachyon.client.options.FreeOptions; +import tachyon.client.options.LoadOptions; +import tachyon.client.options.MkdirOptions; +import tachyon.client.options.SetStateOptions; +import tachyon.exception.TachyonException; import tachyon.thrift.FileInfo; -import tachyon.thrift.InvalidPathException; /** * User facing interface for the Tachyon File System client APIs. File refers to any type of inode, @@ -34,90 +37,85 @@ interface TachyonFileSystemCore { /** - * Creates a file with the provided block size as the standard block size of the file. If the - * file's parent directories do not exist, they will be created if the recursive flag is set. + * Creates a file. * * @param path the path of the file to create in Tachyon space - * @param blockSize the block size in bytes, must be greater than 0 - * @param recursive whether or not to create parent directories if required * @return the file id that identifies the newly created file - * @throws BlockInfoException if the block size is less than or equal to 0 - * @throws FileAlreadyExistException if the path already exists as a file in Tachyon - * @throws InvalidPathException if the path is not a valid Tachyon path - * @throws IOException if the master is unable to create the file + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - long create(TachyonURI path, long blockSize, boolean recursive) throws BlockInfoException, - FileAlreadyExistException, InvalidPathException, IOException; + long create(TachyonURI path) throws IOException, TachyonException; + + long create(TachyonURI path, CreateOptions options) throws IOException, TachyonException; /** - * Deletes a file. If the file is a folder, its contents will be deleted recursively if the - * flag is set. + * Deletes a file or a directory. * * @param file the handler of the file to delete. - * @param recursive whether or not to delete all contents in a non empty folder - * @throws FileDoesNotExistException if the given file does not exist - * @throws IOException if the master is unable to delete the file + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - void delete(TachyonFile file, boolean recursive) throws FileDoesNotExistException, IOException; + void delete(TachyonFile file) throws IOException, TachyonException; + + void delete(TachyonFile file, DeleteOptions options) throws IOException, TachyonException; /** - * Removes the file from Tachyon Storage. The underlying under storage system file will not be - * removed. If the file is a folder, its contents will be freed recursively if the flag is set. + * Removes the file from Tachyon, but not from UFS in case it exists there. * * @param file the handler for the file - * @param recursive whether or not to free all contents in a non empty folder - * @throws FileDoesNotExistException if the file does not exist - * @throws IOException if the master is unable to free the file for some other reason + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - void free(TachyonFile file, boolean recursive) throws FileDoesNotExistException, IOException; + void free(TachyonFile file) throws IOException, TachyonException; + + void free(TachyonFile file, FreeOptions options) throws IOException, TachyonException; /** * Gets the {@link FileInfo} object that represents the metadata of a Tachyon file. * * @param file the handler for the file. * @return the FileInfo of the file, null if the file does not exist. - * @throws IOException if the master cannot retrieve the file's metadata for some other reason + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - FileInfo getInfo(TachyonFile file) throws IOException; + FileInfo getInfo(TachyonFile file) throws IOException, TachyonException; /** - * If the file is a folder, returns the {@link FileInfo} of all the direct entries in it. + * If the file is a directory, returns the {@link FileInfo} of all the direct entries in it. * Otherwise returns the {@link FileInfo} for the file. * * @param file the handler for the file * @return a list of FileInfos representing the files which are children of the given file - * @throws FileDoesNotExistException if the file does not exist - * @throws IOException if the master cannot retrieve the file status for some other reason + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - List listStatus(TachyonFile file) throws FileDoesNotExistException, IOException; + List listStatus(TachyonFile file) throws IOException, TachyonException; /** - * Adds metadata about a file in the under storage system to Tachyon. Only metadata will be - * updated and no data will be transferred. + * Loads metadata about a file in UFS to Tachyon. No data will be transferred. * * @param path the path to create the file in Tachyon - * @param ufsPath the under storage system path of the file that will back the Tachyon file - * @param recursive if true, the parent directories to the file in Tachyon will be created + * @param ufsPath the UFS path of the file that will back the Tachyon file * @return the file id of the resulting file in Tachyon - * @throws FileDoesNotExistException if there is no file at the given path - * @throws IOException if the Tachyon path is invalid or the ufsPath does not exist + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - long loadFileInfoFromUfs(TachyonURI path, TachyonURI ufsPath, boolean recursive) - throws FileDoesNotExistException, IOException; + long load(TachyonURI path, TachyonURI ufsPath) throws IOException, TachyonException; + + long load(TachyonURI path, TachyonURI ufsPath, LoadOptions options) throws IOException, + TachyonException; /** - * Creates a folder. If the parent folders do not exist, they will be created automatically if - * the recursive flag is set. + * Creates a directory. * * @param path the handler for the file - * @param recursive whether or not to create the parent folders that do not exist - * @return true if the folder is created successfully or already existing, false otherwise. - * @throws FileAlreadyExistException if there is already a file at the given path - * @throws InvalidPathException if the provided path is invalid - * @throws IOException if the master cannot create the folder under the specified path + * @return true if the directory is created successfully or already existing, false otherwise + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - boolean mkdirs(TachyonURI path, boolean recursive) throws FileAlreadyExistException, - InvalidPathException, IOException; + boolean mkdir(TachyonURI path) throws IOException, TachyonException; + + boolean mkdir(TachyonURI path, MkdirOptions options) throws IOException, TachyonException; /** * Resolves a {@link TachyonURI} to a {@link TachyonFile} which is used as the file handler for @@ -125,29 +123,30 @@ boolean mkdirs(TachyonURI path, boolean recursive) throws FileAlreadyExistExcept * * @param path the path of the file, this should be in Tachyon space * @return a TachyonFile which acts as a file handler for the path - * @throws InvalidPathException if the provided path is invalid - * @throws IOException if the path does not exist in Tachyon space + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - TachyonFile open(TachyonURI path) throws InvalidPathException, IOException; + TachyonFile open(TachyonURI path) throws IOException, TachyonException; /** - * Renames an existing file in Tachyon space to another path in Tachyon space. + * Renames an existing Tachyon file to another Tachyon path in Tachyon. * - * @param src The file handler for the source file - * @param dst The path of the destination file, this path should not exist + * @param src the file handler for the source file + * @param dst the path of the destination file, this path should not exist * @return true if successful, false otherwise - * @throws FileDoesNotExistException if the source file does not exist - * @throws IOException if the destination already exists or is invalid + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - boolean rename(TachyonFile src, TachyonURI dst) throws FileDoesNotExistException, IOException; + boolean rename(TachyonFile src, TachyonURI dst) throws IOException, TachyonException; /** - * Sets the pin status of a file. A pinned file will never be evicted for any reason. + * Sets the state of a file. * * @param file the file handler for the file to pin - * @param pinned true to pin the file, false to unpin it - * @throws FileDoesNotExistException if the file to be pinned does not exist - * @throws IOException if an error occurs during the pin operation + * @throws IOException if a non-Tachyon exception occurs + * @throws TachyonException if a Tachyon exception occurs */ - void setPin(TachyonFile file, boolean pinned) throws FileDoesNotExistException, IOException; + void setState(TachyonFile file) throws IOException, TachyonException; + + void setState(TachyonFile file, SetStateOptions options) throws IOException, TachyonException; } diff --git a/clients/unshaded/src/main/java/tachyon/client/options/CreateOptions.java b/clients/unshaded/src/main/java/tachyon/client/options/CreateOptions.java new file mode 100644 index 000000000000..79dde71d932d --- /dev/null +++ b/clients/unshaded/src/main/java/tachyon/client/options/CreateOptions.java @@ -0,0 +1,61 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.client.options; + +import tachyon.Constants; +import tachyon.conf.TachyonConf; + +public class CreateOptions { + public static class Builder { + private long mBlockSize; + private boolean mRecursive; + + public Builder(TachyonConf conf) { + mBlockSize = conf.getBytes(Constants.USER_DEFAULT_BLOCK_SIZE_BYTE); + mRecursive = false; + } + + public Builder setBlockSize(long blockSize) { + mBlockSize = blockSize; + return this; + } + + public Builder setRecursive(boolean recursive) { + mRecursive = recursive; + return this; + } + + public CreateOptions build() { + return new CreateOptions(this); + } + } + + public static CreateOptions defaults() { + return new Builder(new TachyonConf()).build(); + } + + private final long mBlockSize; + private final boolean mRecursive; + + private CreateOptions(CreateOptions.Builder builder) { + mBlockSize = builder.mBlockSize; + mRecursive = builder.mRecursive; + } + + public long getBlockSize() { return mBlockSize; } + + public boolean isRecursive() { return mRecursive; } +} diff --git a/clients/unshaded/src/main/java/tachyon/client/options/DeleteOptions.java b/clients/unshaded/src/main/java/tachyon/client/options/DeleteOptions.java new file mode 100644 index 000000000000..b05c8e5c6a3f --- /dev/null +++ b/clients/unshaded/src/main/java/tachyon/client/options/DeleteOptions.java @@ -0,0 +1,49 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.client.options; + +import tachyon.conf.TachyonConf; + +public class DeleteOptions { + public static class Builder { + private boolean mRecursive; + + public Builder(TachyonConf conf) { + mRecursive = false; + } + + public Builder setRecursive(boolean recursive) { + mRecursive = recursive; + return this; + } + + public DeleteOptions build() { + return new DeleteOptions(this); + } + } + + public static DeleteOptions defaults() { + return new Builder(new TachyonConf()).build(); + } + + private final boolean mRecursive; + + private DeleteOptions(DeleteOptions.Builder builder) { + mRecursive = builder.mRecursive; + } + + public boolean isRecursive() { return mRecursive; } +} diff --git a/clients/unshaded/src/main/java/tachyon/client/options/FreeOptions.java b/clients/unshaded/src/main/java/tachyon/client/options/FreeOptions.java new file mode 100644 index 000000000000..8c1999c3a3d1 --- /dev/null +++ b/clients/unshaded/src/main/java/tachyon/client/options/FreeOptions.java @@ -0,0 +1,49 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.client.options; + +import tachyon.conf.TachyonConf; + +public class FreeOptions { + public static class Builder { + private boolean mRecursive; + + public Builder(TachyonConf conf) { + mRecursive = false; + } + + public Builder setRecursive(boolean recursive) { + mRecursive = recursive; + return this; + } + + public FreeOptions build() { + return new FreeOptions(this); + } + } + + public static FreeOptions defaults() { + return new Builder(new TachyonConf()).build(); + } + + private final boolean mRecursive; + + private FreeOptions(FreeOptions.Builder builder) { + mRecursive = builder.mRecursive; + } + + public boolean isRecursive() { return mRecursive; } +} diff --git a/clients/unshaded/src/main/java/tachyon/client/options/InStreamOptions.java b/clients/unshaded/src/main/java/tachyon/client/options/InStreamOptions.java new file mode 100644 index 000000000000..44fcdd28f90c --- /dev/null +++ b/clients/unshaded/src/main/java/tachyon/client/options/InStreamOptions.java @@ -0,0 +1,70 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.client.options; + +import tachyon.Constants; +import tachyon.client.TachyonStorageType; +import tachyon.conf.TachyonConf; + +public class InStreamOptions { + public static class Builder { + private TachyonStorageType mTachyonStorageType; + + public Builder(TachyonConf conf) { + mTachyonStorageType = + conf.getEnum(Constants.USER_DEFAULT_TACHYON_STORAGE_TYPE, TachyonStorageType.class); + } + + /** + * @param tachyonStorageType the Tachyon storage type to use + * @return the builder + */ + public Builder setTachyonStorageType(TachyonStorageType tachyonStorageType) { + mTachyonStorageType = tachyonStorageType; + return this; + } + + /** + * Builds a new instance of ClientOptions + * + * @return a ClientOptions instance + */ + public InStreamOptions build() { + return new InStreamOptions(this); + } + } + + private final TachyonStorageType mTachyonStorageType; + + /** + * @return the default ClientOptions + */ + public static InStreamOptions defaults() { + return new Builder(new TachyonConf()).build(); + } + + private InStreamOptions(InStreamOptions.Builder builder) { + mTachyonStorageType = builder.mTachyonStorageType; + } + + + /** + * @return the cache type + */ + public TachyonStorageType getTachyonStorageType() { + return mTachyonStorageType; + } +} diff --git a/clients/unshaded/src/main/java/tachyon/client/options/LoadOptions.java b/clients/unshaded/src/main/java/tachyon/client/options/LoadOptions.java new file mode 100644 index 000000000000..ebf5f67662de --- /dev/null +++ b/clients/unshaded/src/main/java/tachyon/client/options/LoadOptions.java @@ -0,0 +1,49 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.client.options; + +import tachyon.conf.TachyonConf; + +public class LoadOptions { + public static class Builder { + private boolean mRecursive; + + public Builder(TachyonConf conf) { + mRecursive = false; + } + + public Builder setRecursive(boolean recursive) { + mRecursive = recursive; + return this; + } + + public LoadOptions build() { + return new LoadOptions(this); + } + } + + public static LoadOptions defaults() { + return new Builder(new TachyonConf()).build(); + } + + private final boolean mRecursive; + + private LoadOptions(LoadOptions.Builder builder) { + mRecursive = builder.mRecursive; + } + + public boolean isRecursive() { return mRecursive; } +} diff --git a/clients/unshaded/src/main/java/tachyon/client/options/MkdirOptions.java b/clients/unshaded/src/main/java/tachyon/client/options/MkdirOptions.java new file mode 100644 index 000000000000..f6e776d080bd --- /dev/null +++ b/clients/unshaded/src/main/java/tachyon/client/options/MkdirOptions.java @@ -0,0 +1,49 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.client.options; + +import tachyon.conf.TachyonConf; + +public class MkdirOptions { + public static class Builder { + private boolean mRecursive; + + public Builder(TachyonConf conf) { + mRecursive = false; + } + + public Builder setRecursive(boolean recursive) { + mRecursive = recursive; + return this; + } + + public MkdirOptions build() { + return new MkdirOptions(this); + } + } + + public static MkdirOptions defaults() { + return new Builder(new TachyonConf()).build(); + } + + private final boolean mRecursive; + + private MkdirOptions(MkdirOptions.Builder builder) { + mRecursive = builder.mRecursive; + } + + public boolean isRecursive() { return mRecursive; } +} diff --git a/clients/unshaded/src/main/java/tachyon/client/options/OutStreamOptions.java b/clients/unshaded/src/main/java/tachyon/client/options/OutStreamOptions.java new file mode 100644 index 000000000000..8430b7e357d2 --- /dev/null +++ b/clients/unshaded/src/main/java/tachyon/client/options/OutStreamOptions.java @@ -0,0 +1,143 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.client.options; + +import tachyon.Constants; +import tachyon.client.TachyonStorageType; +import tachyon.client.UnderStorageType; +import tachyon.conf.TachyonConf; + +public class OutStreamOptions { + public static class Builder { + private long mBlockSize; + private TachyonStorageType mTachyonStorageType; + private UnderStorageType mUnderStorageType; + private String mHostname; + + public Builder(TachyonConf conf) { + mBlockSize = conf.getBytes(Constants.USER_DEFAULT_BLOCK_SIZE_BYTE); + mTachyonStorageType = + conf.getEnum(Constants.USER_DEFAULT_TACHYON_STORAGE_TYPE, TachyonStorageType.class); + mUnderStorageType = + conf.getEnum(Constants.USER_DEFAULT_UNDER_STORAGE_TYPE, UnderStorageType.class); + mHostname = null; + } + + /** + * @param hostname the hostname to use + * @return the builder + */ + public Builder setLocation(String hostname) { + mHostname = hostname; + return this; + } + + /** + * @param tachyonStorageType the Tachyon storage type to use + * @param underStorageType the under storage type to use + * @return the builder + */ + public Builder setStorageTypes(TachyonStorageType tachyonStorageType, UnderStorageType + underStorageType) { + mTachyonStorageType = tachyonStorageType; + mUnderStorageType = underStorageType; + return this; + } + + /** + * @param tachyonStorageType the Tachyon storage type to use + * @return the builder + */ + public Builder setTachyonStorageType(TachyonStorageType tachyonStorageType) { + mTachyonStorageType = tachyonStorageType; + return this; + } + + /** + * @param underStorageType the under storage type to use + * @return the builder + */ + public Builder setUnderStorageType(UnderStorageType underStorageType) { + mUnderStorageType = underStorageType; + return this; + } + + /** + * @param blockSize the block size to use + * @return the builder + */ + public Builder setBlockSize(long blockSize) { + mBlockSize = blockSize; + return this; + } + + /** + * Builds a new instance of ClientOptions + * + * @return a ClientOptions instance + */ + public OutStreamOptions build() { + return new OutStreamOptions(this); + } + } + + private final long mBlockSize; + private final TachyonStorageType mTachyonStorageType; + private final UnderStorageType mUnderStorageType; + private final String mHostname; + + /** + * @return the default ClientOptions + */ + public static OutStreamOptions defaults() { + return new Builder(new TachyonConf()).build(); + } + + private OutStreamOptions(OutStreamOptions.Builder builder) { + mBlockSize = builder.mBlockSize; + mTachyonStorageType = builder.mTachyonStorageType; + mUnderStorageType = builder.mUnderStorageType; + mHostname = builder.mHostname; + } + + /** + * @return the block size + */ + public long getBlockSize() { + return mBlockSize; + } + + /** + * @return the cache type + */ + public TachyonStorageType getTachyonStorageType() { + return mTachyonStorageType; + } + + /** + * @return the under storage type + */ + public UnderStorageType getUnderStorageType() { + return mUnderStorageType; + } + + /** + * @return the hostname + */ + public String getHostname() { + return mHostname; + } +} diff --git a/clients/unshaded/src/main/java/tachyon/client/options/SetStateOptions.java b/clients/unshaded/src/main/java/tachyon/client/options/SetStateOptions.java new file mode 100644 index 000000000000..563f44c7fc73 --- /dev/null +++ b/clients/unshaded/src/main/java/tachyon/client/options/SetStateOptions.java @@ -0,0 +1,50 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.client.options; + +import tachyon.conf.TachyonConf; +import java.util.Optional; + +public class SetStateOptions { + public static class Builder { + private Optional mPinned; + + public Builder(TachyonConf conf) { + mPinned = Optional.of(false); + } + + public Builder setRecursive(boolean recursive) { + mPinned = Optional.of(recursive); + return this; + } + + public SetStateOptions build() { + return new SetStateOptions(this); + } + } + + public static SetStateOptions defaults() { + return new Builder(new TachyonConf()).build(); + } + + private final Optional mPinned; + + private SetStateOptions(SetStateOptions.Builder builder) { + mPinned = Optional.of(builder.mPinned.get()); + } + + public Optional getPinned() { return mPinned; } +} diff --git a/common/src/main/java/tachyon/exception/TachyonException.java b/common/src/main/java/tachyon/exception/TachyonException.java new file mode 100644 index 000000000000..d394420848b4 --- /dev/null +++ b/common/src/main/java/tachyon/exception/TachyonException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.exception; + +public class TachyonException extends Exception { + private TachyonExceptionType mType; + + public TachyonException(String message, TachyonExceptionType type) { + super(message); + mType = type; + } + + public TachyonException(String message, Throwable cause, TachyonExceptionType type) { + super(message, cause); + mType = type; + } + + public TachyonExceptionType getType() { + return mType; + } +} diff --git a/common/src/main/java/tachyon/exception/TachyonExceptionType.java b/common/src/main/java/tachyon/exception/TachyonExceptionType.java new file mode 100644 index 000000000000..77556daf8d8e --- /dev/null +++ b/common/src/main/java/tachyon/exception/TachyonExceptionType.java @@ -0,0 +1,23 @@ +/* + * Licensed to the University of California, Berkeley under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package tachyon.exception; + +public enum TachyonExceptionType { + DEPENDENCY_DOES_NOT_EXIST, + FILE_DOES_NOT_EXIST, + FILE_ALREADY_EXISTS, + INVALID_PATH, +}