rakeshadr commented on a change in pull request #3249:
URL: https://github.com/apache/ozone/pull/3249#discussion_r840621576
##########
File path:
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMDirectoryCreateRequest.java
##########
@@ -104,8 +105,13 @@
}
public OMDirectoryCreateRequest(OMRequest omRequest,
- BucketLayout bucketLayout) {
+ BucketLayout bucketLayout)
+ throws OMException {
super(omRequest, bucketLayout);
+ if (!(this instanceof OMDirectoryCreateRequestWithFSO)) {
+ OMClientRequestUtils.checkOBSClientRequestPreconditions(
Review comment:
Thanks @JyotinderSingh for the patch. I would like to reduce the noise
by adding duplicate validation logic everywhere in the request classes.
How about to make the creator of the OMRequestClasses and do a validation
after the validateBucketAndVolume check like below:
Step-1)
```
OMKeyRequestFactory -> OMKeyRequestBucketLayoutAwareFactory
.......
......
omKeyRequest = new OMKeyRequestBucketLayoutAwareFactory()
.createRequest(keyArgs.getVolumeName(), keyArgs.getBucketName(),
omRequest, ozoneManager);
//
class OMKeyRequestBucketLayoutAwareFactory {
static HashMap<String, Class<? extends OMKeyRequest>>
omKeyReqClasses = new HashMap();
static {
omKeyReqClasses.put(
Type.CreateDirectory.toString() + BucketLayout.FILE_SYSTEM_OPTIMIZED,
OMDirectoryCreateRequestWithFSO.class);
omKeyReqClasses
.put(Type.CreateDirectory.toString(),
OMDirectoryCreateRequest.class);
omKeyReqClasses
.put(Type.CreateFile.toString() + BucketLayout.FILE_SYSTEM_OPTIMIZED,
OMFileCreateRequestWithFSO.class);
omKeyReqClasses.put(Type.CreateFile.toString(),
OMFileCreateRequest.class);
// TODO : Add all the command types to this map
}
public OMKeyRequest createRequest(String volName, String buckName,
OMRequest omRequest, OzoneManager ozoneManager)
throws IOException {
BucketLayout bucketLayout =
getBucketLayout(volName, buckName, ozoneManager);
String className = "";
if (bucketLayout.isFileSystemOptimized()) {
className =
omRequest.getCmdType().name() + BucketLayout.FILE_SYSTEM_OPTIMIZED;
} else {
className = omRequest.getCmdType().name();
}
try {
Constructor<? extends OMKeyRequest> declaredConstructor =
omKeyReqClasses.get(className)
.getDeclaredConstructor(OMRequest.class, BucketLayout.class);
return declaredConstructor.newInstance(omRequest, bucketLayout);
} catch (Exception e) {
throw new IOException(e);
// TODO: LOG the exception details.
// TODO: Use OMException.....with error code
}
}
```
Step-2) OmKeyRequest#validateBucketAndVolume()
Do below logic at the end of the method.
```
// Verifying the class attribute bucket layout with DB stored bucket
layout
OmBucketInfo bucketInfo =
omMetadataManager.getBucketTable().get(bucketKey);
OMClientRequestUtils
.checkClientRequestPreconditions(bucketInfo.getBucketLayout(),
getBucketLayout());
public final class OMClientRequestUtils {
private OMClientRequestUtils() {
}
public static void checkClientRequestPreconditions(
BucketLayout dbBucketLayout, BucketLayout reqClassBucketLayout)
throws OMException {
// Make sure class is called for the correct bucket layout.
if (dbBucketLayout.isFileSystemOptimized() !=
reqClassBucketLayout.isFileSystemOptimized()) {
throw new OMException(
"BucketLayout mismatches. DB BucketLayout: " + dbBucketLayout +
" and OMRequestClass BucketLayout: " + reqClassBucketLayout,
OMException.ResultCodes.INTERNAL_ERROR
);
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]