Skip to content

Commit

Permalink
Reflecting the user interface refactoring in the rest of the code base.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsimsa committed Sep 24, 2015
1 parent f1c31fb commit 0a3056a
Show file tree
Hide file tree
Showing 35 changed files with 641 additions and 519 deletions.
Expand Up @@ -19,12 +19,12 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;


import org.apache.thrift.TException;

import tachyon.TachyonURI; import tachyon.TachyonURI;
import tachyon.client.file.FileOutStream; import tachyon.client.file.FileOutStream;
import tachyon.client.file.TachyonFile; import tachyon.client.file.TachyonFile;
import tachyon.client.file.TachyonFileSystem; import tachyon.client.file.TachyonFileSystem;
import tachyon.client.options.OutStreamOptions;
import tachyon.exception.TachyonException;
import tachyon.thrift.FileInfo; import tachyon.thrift.FileInfo;


public final class TachyonFSTestUtils { public final class TachyonFSTestUtils {
Expand All @@ -39,7 +39,7 @@ public final class TachyonFSTestUtils {
* @throws IOException if <code>path</code> is invalid (e.g., illegal URI) * @throws IOException if <code>path</code> is invalid (e.g., illegal URI)
*/ */
public static TachyonFile createByteFile(TachyonFileSystem tfs, String fileName, public static TachyonFile createByteFile(TachyonFileSystem tfs, String fileName,
ClientOptions options, int len) throws IOException { OutStreamOptions options, int len) throws IOException {
return createByteFile(tfs, fileName, options.getTachyonStorageType(), return createByteFile(tfs, fileName, options.getTachyonStorageType(),
options.getUnderStorageType(), len, options.getBlockSize()); options.getUnderStorageType(), len, options.getBlockSize());
} }
Expand Down Expand Up @@ -76,8 +76,8 @@ public static TachyonFile createByteFile(TachyonFileSystem tfs, TachyonURI fileU
TachyonStorageType tachyonStorageType, UnderStorageType underStorageType, int len) TachyonStorageType tachyonStorageType, UnderStorageType underStorageType, int len)
throws IOException { throws IOException {
try { try {
ClientOptions options = OutStreamOptions options =
new ClientOptions.Builder(ClientContext.getConf()) new OutStreamOptions.Builder(ClientContext.getConf())
.setTachyonStorageType(tachyonStorageType).setUnderStorageType(underStorageType) .setTachyonStorageType(tachyonStorageType).setUnderStorageType(underStorageType)
.build(); .build();
FileOutStream os = tfs.getOutStream(fileURI, options); FileOutStream os = tfs.getOutStream(fileURI, options);
Expand All @@ -89,7 +89,7 @@ public static TachyonFile createByteFile(TachyonFileSystem tfs, TachyonURI fileU
os.write(arr); os.write(arr);
os.close(); os.close();
return tfs.open(fileURI); return tfs.open(fileURI);
} catch (TException e) { } catch (TachyonException e) {
throw new IOException(e.getMessage()); throw new IOException(e.getMessage());
} }
} }
Expand All @@ -110,8 +110,8 @@ public static TachyonFile createByteFile(TachyonFileSystem tfs, String fileName,
TachyonStorageType tachyonStorageType, UnderStorageType underStorageType, int len, TachyonStorageType tachyonStorageType, UnderStorageType underStorageType, int len,
long blockCapacityByte) throws IOException { long blockCapacityByte) throws IOException {
try { try {
ClientOptions options = OutStreamOptions options =
new ClientOptions.Builder(ClientContext.getConf()) new OutStreamOptions.Builder(ClientContext.getConf())
.setTachyonStorageType(tachyonStorageType).setUnderStorageType(underStorageType) .setTachyonStorageType(tachyonStorageType).setUnderStorageType(underStorageType)
.setBlockSize(blockCapacityByte).build(); .setBlockSize(blockCapacityByte).build();
FileOutStream os = tfs.getOutStream(new TachyonURI(fileName), options); FileOutStream os = tfs.getOutStream(new TachyonURI(fileName), options);
Expand All @@ -121,7 +121,7 @@ public static TachyonFile createByteFile(TachyonFileSystem tfs, String fileName,
} }
os.close(); os.close();
return tfs.open(new TachyonURI(fileName)); return tfs.open(new TachyonURI(fileName));
} catch (TException e) { } catch (TachyonException e) {
throw new IOException(e.getMessage()); throw new IOException(e.getMessage());
} }
} }
Expand All @@ -147,7 +147,7 @@ public static List<String> listFiles(TachyonFileSystem tfs, String path) throws
} }


return res; return res;
} catch (TException e) { } catch (TachyonException e) {
throw new IOException(e.getMessage()); throw new IOException(e.getMessage());
} }
} }
Expand Down
12 changes: 6 additions & 6 deletions clients/unshaded/src/main/java/tachyon/client/TachyonFile.java
Expand Up @@ -28,7 +28,10 @@
import tachyon.client.file.FileInStream; import tachyon.client.file.FileInStream;
import tachyon.client.file.FileOutStream; import tachyon.client.file.FileOutStream;
import tachyon.client.file.TachyonFileSystem; import tachyon.client.file.TachyonFileSystem;
import tachyon.client.options.InStreamOptions;
import tachyon.client.options.OutStreamOptions;
import tachyon.conf.TachyonConf; import tachyon.conf.TachyonConf;
import tachyon.exception.TachyonException;
import tachyon.thrift.BlockLocation; import tachyon.thrift.BlockLocation;
import tachyon.thrift.FileBlockInfo; import tachyon.thrift.FileBlockInfo;
import tachyon.thrift.FileDoesNotExistException; import tachyon.thrift.FileDoesNotExistException;
Expand Down Expand Up @@ -166,18 +169,15 @@ public FileInStream getInStream(ReadType readType) throws IOException {


FileInfo info = getUnCachedFileStatus(); FileInfo info = getUnCachedFileStatus();
TachyonURI uri = new TachyonURI(info.getPath()); TachyonURI uri = new TachyonURI(info.getPath());
ClientOptions.Builder optionsBuilder = new ClientOptions.Builder(mTachyonConf); InStreamOptions.Builder optionsBuilder = new InStreamOptions.Builder(mTachyonConf);
optionsBuilder.setBlockSize(info.getBlockSizeBytes());
if (readType.isCache()) { if (readType.isCache()) {
optionsBuilder.setTachyonStorageType(TachyonStorageType.STORE); optionsBuilder.setTachyonStorageType(TachyonStorageType.STORE);
} else { } else {
optionsBuilder.setTachyonStorageType(TachyonStorageType.NO_STORE); optionsBuilder.setTachyonStorageType(TachyonStorageType.NO_STORE);
} }
try { try {
return mTFS.getInStream(mTFS.open(uri), optionsBuilder.build()); return mTFS.getInStream(mTFS.open(uri), optionsBuilder.build());
} catch (InvalidPathException e) { } catch (TachyonException e) {
throw new IOException(e.getMessage());
} catch (FileDoesNotExistException e) {
throw new IOException(e.getMessage()); throw new IOException(e.getMessage());
} }
} }
Expand Down Expand Up @@ -259,7 +259,7 @@ public FileOutStream getOutStream(WriteType writeType) throws IOException {
} }


FileInfo info = getUnCachedFileStatus(); FileInfo info = getUnCachedFileStatus();
ClientOptions.Builder optionsBuilder = new ClientOptions.Builder(mTachyonConf); OutStreamOptions.Builder optionsBuilder = new OutStreamOptions.Builder(mTachyonConf);
optionsBuilder.setBlockSize(info.getBlockSizeBytes()); optionsBuilder.setBlockSize(info.getBlockSizeBytes());


if (writeType.isCache()) { if (writeType.isCache()) {
Expand Down
Expand Up @@ -16,14 +16,11 @@
package tachyon.client.file; package tachyon.client.file;


import java.io.IOException; import java.io.IOException;
import java.util.Optional;


import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;


import tachyon.Constants;
import tachyon.TachyonURI; import tachyon.TachyonURI;
import tachyon.annotation.PublicApi; import tachyon.annotation.PublicApi;
import tachyon.client.ClientOptions;
import tachyon.client.FileSystemMasterClient; import tachyon.client.FileSystemMasterClient;
import tachyon.client.options.CreateOptions; import tachyon.client.options.CreateOptions;
import tachyon.client.options.DeleteOptions; import tachyon.client.options.DeleteOptions;
Expand All @@ -36,11 +33,12 @@
import tachyon.conf.TachyonConf; import tachyon.conf.TachyonConf;
import tachyon.exception.TachyonException; import tachyon.exception.TachyonException;
import tachyon.exception.TachyonExceptionType; import tachyon.exception.TachyonExceptionType;
import tachyon.thrift.BlockInfoException;
import tachyon.thrift.DependencyDoesNotExistException; import tachyon.thrift.DependencyDoesNotExistException;
import tachyon.thrift.FileAlreadyExistException;
import tachyon.thrift.FileDoesNotExistException; import tachyon.thrift.FileDoesNotExistException;
import tachyon.thrift.FileInfo; import tachyon.thrift.FileInfo;
import org.slf4j.Logger; import tachyon.thrift.InvalidPathException;
import org.slf4j.LoggerFactory;


/** /**
* A TachyonFileSystem implementation including convenience methods as well as a streaming API to * A TachyonFileSystem implementation including convenience methods as well as a streaming API to
Expand All @@ -51,8 +49,6 @@
*/ */
@PublicApi @PublicApi
public class TachyonFileSystem extends AbstractTachyonFileSystem { public class TachyonFileSystem extends AbstractTachyonFileSystem {
private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE);

private static TachyonFileSystem sTachyonFileSystem; private static TachyonFileSystem sTachyonFileSystem;


public static final boolean RECURSIVE = true; public static final boolean RECURSIVE = true;
Expand All @@ -69,14 +65,26 @@ private TachyonFileSystem() {
} }


@Override @Override
public long create(TachyonURI path) { public long create(TachyonURI path) throws IOException, TachyonException {
return create(path, CreateOptions.defaults()); return create(path, CreateOptions.defaults());
} }


@Override @Override
public long create(TachyonURI path, CreateOptions options) { public long create(TachyonURI path, CreateOptions options) throws IOException, TachyonException {
throw new UnsupportedOperationException( FileSystemMasterClient masterClient = mContext.acquireMasterClient();
"create() is currently not supported, use getOutStream instead."); try {
long fileId =
masterClient.createFile(path.getPath(), options.getBlockSize(), options.isRecursive());
return fileId;
} catch (BlockInfoException e) {
throw new TachyonException(e.getMessage(), TachyonExceptionType.FILE_ALREADY_EXISTS);
} 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 @Override
Expand Down
Expand Up @@ -55,7 +55,11 @@ private CreateOptions(CreateOptions.Builder builder) {
mRecursive = builder.mRecursive; mRecursive = builder.mRecursive;
} }


public long getBlockSize() { return mBlockSize; } public long getBlockSize() {
return mBlockSize;
}


public boolean isRecursive() { return mRecursive; } public boolean isRecursive() {
return mRecursive;
}
} }
Expand Up @@ -45,5 +45,7 @@ private DeleteOptions(DeleteOptions.Builder builder) {
mRecursive = builder.mRecursive; mRecursive = builder.mRecursive;
} }


public boolean isRecursive() { return mRecursive; } public boolean isRecursive() {
return mRecursive;
}
} }
Expand Up @@ -45,5 +45,7 @@ private FreeOptions(FreeOptions.Builder builder) {
mRecursive = builder.mRecursive; mRecursive = builder.mRecursive;
} }


public boolean isRecursive() { return mRecursive; } public boolean isRecursive() {
return mRecursive;
}
} }
Expand Up @@ -45,5 +45,7 @@ private LoadOptions(LoadOptions.Builder builder) {
mRecursive = builder.mRecursive; mRecursive = builder.mRecursive;
} }


public boolean isRecursive() { return mRecursive; } public boolean isRecursive() {
return mRecursive;
}
} }
Expand Up @@ -45,5 +45,7 @@ private MkdirOptions(MkdirOptions.Builder builder) {
mRecursive = builder.mRecursive; mRecursive = builder.mRecursive;
} }


public boolean isRecursive() { return mRecursive; } public boolean isRecursive() {
return mRecursive;
}
} }
Expand Up @@ -40,23 +40,11 @@ public Builder(TachyonConf conf) {
* @param hostname the hostname to use * @param hostname the hostname to use
* @return the builder * @return the builder
*/ */
public Builder setLocation(String hostname) { public Builder setHostname(String hostname) {
mHostname = hostname; mHostname = hostname;
return this; 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 * @param tachyonStorageType the Tachyon storage type to use
* @return the builder * @return the builder
Expand Down Expand Up @@ -140,4 +128,9 @@ public UnderStorageType getUnderStorageType() {
public String getHostname() { public String getHostname() {
return mHostname; return mHostname;
} }

public InStreamOptions toInStreamOptions() {
return new InStreamOptions.Builder(new TachyonConf())
.setTachyonStorageType(mTachyonStorageType).build();
}
} }
Expand Up @@ -15,9 +15,10 @@


package tachyon.client.options; package tachyon.client.options;


import tachyon.conf.TachyonConf;
import java.util.Optional; import java.util.Optional;


import tachyon.conf.TachyonConf;

public class SetStateOptions { public class SetStateOptions {
public static class Builder { public static class Builder {
private Optional<Boolean> mPinned; private Optional<Boolean> mPinned;
Expand All @@ -26,8 +27,8 @@ public Builder(TachyonConf conf) {
mPinned = Optional.of(false); mPinned = Optional.of(false);
} }


public Builder setRecursive(boolean recursive) { public Builder setPinned(boolean pinned) {
mPinned = Optional.of(recursive); mPinned = Optional.of(pinned);
return this; return this;
} }


Expand All @@ -46,5 +47,7 @@ private SetStateOptions(SetStateOptions.Builder builder) {
mPinned = Optional.of(builder.mPinned.get()); mPinned = Optional.of(builder.mPinned.get());
} }


public Optional<Boolean> getPinned() { return mPinned; } public Optional<Boolean> getPinned() {
return mPinned;
}
} }
Expand Up @@ -16,6 +16,7 @@
package tachyon.exception; package tachyon.exception;


public enum TachyonExceptionType { public enum TachyonExceptionType {
BLOCK_INFO,
DEPENDENCY_DOES_NOT_EXIST, DEPENDENCY_DOES_NOT_EXIST,
FILE_DOES_NOT_EXIST, FILE_DOES_NOT_EXIST,
FILE_ALREADY_EXISTS, FILE_ALREADY_EXISTS,
Expand Down
6 changes: 4 additions & 2 deletions examples/src/main/java/tachyon/examples/BasicCheckpoint.java
Expand Up @@ -36,7 +36,9 @@
import tachyon.client.ClientOptions; import tachyon.client.ClientOptions;
import tachyon.client.file.FileInStream; import tachyon.client.file.FileInStream;
import tachyon.client.file.TachyonFileSystem; import tachyon.client.file.TachyonFileSystem;
import tachyon.client.options.OutStreamOptions;
import tachyon.conf.TachyonConf; import tachyon.conf.TachyonConf;
import tachyon.exception.TachyonException;
import tachyon.master.file.meta.DependencyType; import tachyon.master.file.meta.DependencyType;
import tachyon.util.CommonUtils; import tachyon.util.CommonUtils;
import tachyon.util.FormatUtils; import tachyon.util.FormatUtils;
Expand Down Expand Up @@ -99,7 +101,7 @@ private boolean readFile(TachyonFS tachyonClient) throws IOException {
return pass; return pass;
} }


private void writeFile(TachyonFS tachyonClient) throws IOException, TException { private void writeFile(TachyonFS tachyonClient) throws IOException, TachyonException {
for (int i = 0; i < mNumFiles; i ++) { for (int i = 0; i < mNumFiles; i ++) {
ByteBuffer buf = ByteBuffer.allocate(80); ByteBuffer buf = ByteBuffer.allocate(80);
buf.order(ByteOrder.nativeOrder()); buf.order(ByteOrder.nativeOrder());
Expand All @@ -109,7 +111,7 @@ private void writeFile(TachyonFS tachyonClient) throws IOException, TException {
buf.flip(); buf.flip();
TachyonURI filePath = new TachyonURI(mFileFolder + "/part-" + i); TachyonURI filePath = new TachyonURI(mFileFolder + "/part-" + i);
LOG.debug("Writing data to {}", filePath); LOG.debug("Writing data to {}", filePath);
OutputStream os = TachyonFileSystem.get().getOutStream(filePath, ClientOptions.defaults()); OutputStream os = TachyonFileSystem.get().getOutStream(filePath, OutStreamOptions.defaults());
os.write(buf.array()); os.write(buf.array());
os.close(); os.close();
} }
Expand Down

0 comments on commit 0a3056a

Please sign in to comment.