Skip to content
Merged
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 @@ -106,8 +106,7 @@ public Void call() throws Exception {
if (duResponse.get("status").equals("PATH_NOT_FOUND")) {
printPathNotFound();
} else {
if (parent.isObjectStoreBucket(path) ||
!parent.bucketIsPresentInThePath(path)) {
if (parent.isNotValidBucketOrOBSBucket(path)) {
printBucketReminder();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public Void call() throws Exception {
} else if (distResponse.get("status").equals("TYPE_NOT_APPLICABLE")) {
printTypeNA("File Size Distribution");
} else {
if (parent.isObjectStoreBucket(path) ||
!parent.bucketIsPresentInThePath(path)) {
if (parent.isNotValidBucketOrOBSBucket(path)) {
printBucketReminder();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

import java.io.IOException;
import java.util.HashSet;
import java.util.Objects;

import static org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_ADDRESS_DEFAULT;
import static org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_ADDRESS_KEY;
Expand Down Expand Up @@ -86,86 +85,46 @@ public Class<?> getParentType() {
return OzoneAdmin.class;
}

public boolean isFileSystemOptimizedBucket(String path) throws IOException {
OFSPath ofsPath = new OFSPath(path,
OzoneConfiguration.of(getOzoneConfig()));

OzoneClient ozoneClient = OzoneClientFactory.getRpcClient(getOzoneConfig());
ObjectStore objectStore = ozoneClient.getObjectStore();

try {
OzoneBucket bucket = objectStore.getVolume(ofsPath.getVolumeName())
.getBucket(ofsPath.getBucketName());

// Resolve the bucket layout in case this is a Link Bucket.
BucketLayout resolvedBucketLayout =
OzoneClientUtils.resolveLinkBucketLayout(bucket, objectStore,
new HashSet<>());

return resolvedBucketLayout.isFileSystemOptimized();
} catch (IOException e) {
System.out.println(
"Bucket layout couldn't be verified for path: " + ofsPath +
". Exception: " + e);
return false;
}
}

public boolean isObjectStoreBucket(String path) throws IOException {
OFSPath ofsPath = new OFSPath(path,
OzoneConfiguration.of(getOzoneConfig()));

private boolean isObjectStoreBucket(OzoneBucket bucket, ObjectStore objectStore) {
boolean enableFileSystemPaths = getOzoneConfig()
.getBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS_DEFAULT);

OzoneClient ozoneClient = OzoneClientFactory.getRpcClient(getOzoneConfig());
ObjectStore objectStore = ozoneClient.getObjectStore();

try {
OzoneBucket bucket = objectStore.getVolume(ofsPath.getVolumeName())
.getBucket(ofsPath.getBucketName());

// Resolve the bucket layout in case this is a Link Bucket.
BucketLayout resolvedBucketLayout =
OzoneClientUtils.resolveLinkBucketLayout(bucket, objectStore,
new HashSet<>());

return resolvedBucketLayout.isObjectStore(enableFileSystemPaths);
} catch (IOException e) {
System.out.println(
"Bucket layout couldn't be verified for path: " + ofsPath +
". Exception: " + e);
"Bucket layout couldn't be resolved. Exception thrown: " + e);
return false;
}
}

/**
* Checking if the bucket is part of the path.
* Checks if bucket is OBS bucket or if bucket is part of the path.
* Return false if path is root, just a volume or invalid.
* Returns false if bucket is part of path but not a OBS bucket.
* @param path
* @return true if the bucket
* is not part of the given path.
* @return true if bucket is OBS bucket or not part of provided path.
* @throws IOException
*/
public boolean bucketIsPresentInThePath(String path) throws IOException {
public boolean isNotValidBucketOrOBSBucket(String path) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that for every command, this check is preceded by a check to whether the path exists. Therefore, there is no issue of a NPException.

OFSPath ofsPath = new OFSPath(path,
OzoneConfiguration.of(getOzoneConfig()));

OzoneClient ozoneClient = OzoneClientFactory.getRpcClient(getOzoneConfig());
ObjectStore objectStore = ozoneClient.getObjectStore();

try {
try (OzoneClient ozoneClient = OzoneClientFactory.getRpcClient(getOzoneConfig())) {
ObjectStore objectStore = ozoneClient.getObjectStore();
// Checks if the bucket is part of the path.
OzoneBucket bucket = objectStore.getVolume(ofsPath.getVolumeName())
.getBucket(ofsPath.getBucketName());

return Objects.nonNull(bucket);
return isObjectStoreBucket(bucket, objectStore);
} catch (IOException e) {
System.out.println(
"Bucket layout couldn't be verified for path: " + ofsPath +
". Exception: " + e);
return false;
}
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public Void call() throws Exception {
} else if (quotaResponse.get("status").equals("TYPE_NOT_APPLICABLE")) {
printTypeNA("Quota");
} else {
if (parent.isObjectStoreBucket(path) ||
!parent.bucketIsPresentInThePath(path)) {
if (parent.isNotValidBucketOrOBSBucket(path)) {
printBucketReminder();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public Void call() throws Exception {
if (summaryResponse.get("status").equals("PATH_NOT_FOUND")) {
printPathNotFound();
} else {
if (parent.isObjectStoreBucket(path) ||
!parent.bucketIsPresentInThePath(path)) {
if (parent.isNotValidBucketOrOBSBucket(path)) {
printBucketReminder();
}

Expand Down