Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ protected ObjectStore() {
proxy = null;
}

@VisibleForTesting
/**
* Returns the ClientProtocol of the ObjectStore.
*/
public ClientProtocol getClientProxy() {
return proxy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public TestRootedOzoneFileSystem(boolean setDefaultFs,
private static FileSystem fs;
private static RootedOzoneFileSystem ofs;
private static ObjectStore objectStore;
private static BasicRootedOzoneClientAdapterImpl adapter;
private static BasicRootedOzoneFileSystemHelper helper;
private static Trash trash;

private static String volumeName;
Expand Down Expand Up @@ -164,7 +164,7 @@ public static void init() throws Exception {
TrashPolicy.class);
trash = new Trash(conf);
ofs = (RootedOzoneFileSystem) fs;
adapter = (BasicRootedOzoneClientAdapterImpl) ofs.getAdapter();
helper = ofs.getHelper();
}

@AfterClass
Expand Down Expand Up @@ -696,7 +696,7 @@ private void listStatusRecursiveHelper(Path curPath, List<FileStatus> result)
*/
private List<FileStatus> callAdapterListStatus(String pathStr,
boolean recursive, String startPath, long numEntries) throws IOException {
return adapter.listStatus(pathStr, recursive, startPath, numEntries,
return helper.listStatus(pathStr, recursive, startPath, numEntries,
ofs.getUri(), ofs.getWorkingDirectory(), ofs.getUsername())
.stream().map(ofs::convertFileStatus).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ public void renameKey(String key, String newKeyName) throws IOException {
bucket.renameKey(key, newKeyName);
}

@Override
public void rename(String pathStr, String newPath) throws IOException {
throw new IOException("Please use renameKey instead for o3fs.");
}

/**
* Helper method to create an directory specified by key name in bucket.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public class BasicRootedOzoneFileSystem extends FileSystem {
private URI uri;
private String userName;
private Path workingDir;
private OzoneClientAdapter adapter;
private BasicRootedOzoneClientAdapterImpl adapterImpl;
// Using impl directly rather than OzoneClientAdapter in OFS.
private BasicRootedOzoneFileSystemHelper helper;

private static final String URI_EXCEPTION_TEXT =
"URL should be one of the following formats: " +
Expand Down Expand Up @@ -145,8 +145,8 @@ public void initialize(URI name, Configuration conf) throws IOException {
LOG.trace("Ozone URI for OFS initialization is " + uri);

ConfigurationSource source = getConfSource();
this.adapter = createAdapter(source, omHostOrServiceId, omPort);
this.adapterImpl = (BasicRootedOzoneClientAdapterImpl) this.adapter;
this.helper = new BasicRootedOzoneFileSystemHelper(
omHostOrServiceId, omPort, source);

try {
this.userName =
Expand All @@ -163,15 +163,10 @@ public void initialize(URI name, Configuration conf) throws IOException {
}
}

protected OzoneClientAdapter createAdapter(ConfigurationSource conf,
String omHost, int omPort) throws IOException {
return new BasicRootedOzoneClientAdapterImpl(omHost, omPort, conf);
}

@Override
public void close() throws IOException {
try {
adapter.close();
helper.close();
} finally {
super.close();
}
Expand All @@ -194,7 +189,7 @@ public FSDataInputStream open(Path path, int bufferSize) throws IOException {
LOG.trace("open() path: {}", path);
final String key = pathToKey(path);
return new FSDataInputStream(
new OzoneFSInputStream(adapter.readFile(key), statistics));
new OzoneFSInputStream(helper.readFile(key), statistics));
}

protected void incrementCounter(Statistic statistic) {
Expand Down Expand Up @@ -234,7 +229,7 @@ public FSDataOutputStream createNonRecursive(Path path,

private FSDataOutputStream createOutputStream(String key, short replication,
boolean overwrite, boolean recursive) throws IOException {
return new FSDataOutputStream(adapter.createFile(key,
return new FSDataOutputStream(helper.createFile(key,
replication, overwrite, recursive), statistics);
}

Expand All @@ -249,7 +244,6 @@ private class RenameIterator extends OzoneListingIterator {
private final String srcPath;
private final String dstPath;
private final OzoneBucket bucket;
private final BasicRootedOzoneClientAdapterImpl adapterImpl;

RenameIterator(Path srcPath, Path dstPath)
throws IOException {
Expand All @@ -259,16 +253,14 @@ private class RenameIterator extends OzoneListingIterator {
LOG.trace("rename from:{} to:{}", this.srcPath, this.dstPath);
// Initialize bucket here to reduce number of RPC calls
OFSPath ofsPath = new OFSPath(srcPath);
// TODO: Refactor later.
adapterImpl = (BasicRootedOzoneClientAdapterImpl) adapter;
this.bucket = adapterImpl.getBucket(ofsPath, false);
this.bucket = helper.getBucket(ofsPath, false);
}

@Override
boolean processKeyPath(List<String> keyPathList) throws IOException {
for (String keyPath : keyPathList) {
String newPath = dstPath.concat(keyPath.substring(srcPath.length()));
adapterImpl.rename(this.bucket, keyPath, newPath);
helper.rename(this.bucket, keyPath, newPath);
}
return true;
}
Expand Down Expand Up @@ -411,7 +403,6 @@ protected void rename(final Path src, final Path dst,
private class DeleteIterator extends OzoneListingIterator {
private final boolean recursive;
private final OzoneBucket bucket;
private final BasicRootedOzoneClientAdapterImpl adapterImpl;

DeleteIterator(Path f, boolean recursive)
throws IOException {
Expand All @@ -424,15 +415,13 @@ && listStatus(f).length != 0) {
}
// Initialize bucket here to reduce number of RPC calls
OFSPath ofsPath = new OFSPath(f);
// TODO: Refactor later.
adapterImpl = (BasicRootedOzoneClientAdapterImpl) adapter;
this.bucket = adapterImpl.getBucket(ofsPath, false);
this.bucket = helper.getBucket(ofsPath, false);
}

@Override
boolean processKeyPath(List<String> keyPathList) {
LOG.trace("Deleting keys: {}", keyPathList);
boolean succeed = adapterImpl.deleteObjects(this.bucket, keyPathList);
boolean succeed = helper.deleteObjects(this.bucket, keyPathList);
// if recursive delete is requested ignore the return value of
// deleteObject and issue deletes for other keys.
return recursive || succeed;
Expand Down Expand Up @@ -505,8 +494,7 @@ public boolean delete(Path f, boolean recursive) throws IOException {
String volumeName = ofsPath.getVolumeName();
if (recursive) {
// Delete all buckets first
OzoneVolume volume =
adapterImpl.getObjectStore().getVolume(volumeName);
OzoneVolume volume = helper.getVolumeDetails(volumeName);
Iterator<? extends OzoneBucket> it = volume.listBuckets("");
String prefixVolumePathStr = addTrailingSlashIfNeeded(f.toString());
while (it.hasNext()) {
Expand All @@ -516,7 +504,7 @@ public boolean delete(Path f, boolean recursive) throws IOException {
}
}
try {
adapterImpl.getObjectStore().deleteVolume(volumeName);
helper.deleteVolume(volumeName);
return true;
} catch (OMException ex) {
// volume is not empty
Expand All @@ -532,8 +520,7 @@ public boolean delete(Path f, boolean recursive) throws IOException {

// Handle delete bucket
if (ofsPath.isBucket()) {
OzoneVolume volume =
adapterImpl.getObjectStore().getVolume(ofsPath.getVolumeName());
OzoneVolume volume = helper.getVolumeDetails(ofsPath.getVolumeName());
try {
volume.deleteBucket(ofsPath.getBucketName());
return result;
Expand All @@ -549,7 +536,7 @@ public boolean delete(Path f, boolean recursive) throws IOException {

} else {
LOG.debug("delete: Path is a file: {}", f);
result = adapter.deleteObject(key);
result = helper.deleteObject(key);
}

if (result) {
Expand Down Expand Up @@ -586,7 +573,7 @@ private void createFakeDirectoryIfNecessary(Path f) throws IOException {
if (!key.isEmpty() && !o3Exists(f)) {
LOG.debug("Creating new fake directory at {}", f);
String dirKey = addTrailingSlashIfNeeded(key);
adapter.createDirectory(dirKey);
helper.createDirectory(dirKey);
}
}

Expand Down Expand Up @@ -619,7 +606,7 @@ public FileStatus[] listStatus(Path f) throws IOException {

do {
tmpStatusList =
adapter.listStatus(pathToKey(f), false, startPath,
helper.listStatus(pathToKey(f), false, startPath,
numEntries, uri, workingDir, getUsername())
.stream()
.map(this::convertFileStatus)
Expand Down Expand Up @@ -653,7 +640,7 @@ public Path getWorkingDirectory() {

@Override
public Token<?> getDelegationToken(String renewer) throws IOException {
return adapter.getDelegationToken(renewer);
return helper.getDelegationToken(renewer);
}

/**
Expand All @@ -664,7 +651,7 @@ public Token<?> getDelegationToken(String renewer) throws IOException {
*/
@Override
public String getCanonicalServiceName() {
return adapter.getCanonicalServiceName();
return helper.getCanonicalServiceName();
}

/**
Expand Down Expand Up @@ -697,7 +684,7 @@ public Path getTrashRoot(Path path) {
public Collection<FileStatus> getTrashRoots(boolean allUsers) {
// Since get all trash roots for one or more users requires listing all
// volumes and buckets, we will let adapter impl handle it.
return adapterImpl.getTrashRoots(allUsers, this);
return helper.getTrashRoots(allUsers, this);
}

/**
Expand All @@ -708,7 +695,7 @@ public Collection<FileStatus> getTrashRoots(boolean allUsers) {
* @throws IOException
*/
private boolean mkdir(Path path) throws IOException {
return adapter.createDirectory(pathToKey(path));
return helper.createDirectory(pathToKey(path));
}

@Override
Expand Down Expand Up @@ -742,7 +729,7 @@ public FileStatus getFileStatus(Path f) throws IOException {
FileStatus fileStatus = null;
try {
fileStatus = convertFileStatus(
adapter.getFileStatus(key, uri, qualifiedPath, getUsername()));
helper.getFileStatus(key, uri, qualifiedPath, getUsername()));
} catch (OMException ex) {
if (ex.getResult().equals(OMException.ResultCodes.KEY_NOT_FOUND) ||
ex.getResult().equals(OMException.ResultCodes.BUCKET_NOT_FOUND) ||
Expand All @@ -766,7 +753,7 @@ public BlockLocation[] getFileBlockLocations(FileStatus fileStatus,

@Override
public short getDefaultReplication() {
return adapter.getDefaultReplication();
return helper.getDefaultReplication();
}

@Override
Expand Down Expand Up @@ -912,7 +899,7 @@ private abstract class OzoneListingIterator {
if (status.isDirectory()) {
this.pathKey = addTrailingSlashIfNeeded(pathKey);
}
keyIterator = adapter.listKeys(pathKey);
keyIterator = helper.listKeys(pathKey);
}

/**
Expand Down Expand Up @@ -989,8 +976,8 @@ FileStatus getStatus() {
}
}

public OzoneClientAdapter getAdapter() {
return adapter;
public BasicRootedOzoneFileSystemHelper getHelper() {
return helper;
}

public boolean isEmpty(CharSequence cs) {
Expand Down
Loading