-
Notifications
You must be signed in to change notification settings - Fork 625
HDDS-6938. handle NPE when removing prefixAcl #3568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+72
−0
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f20757
HDDS-6938. handle NPE when removing prefixAcl of a non-set prefix
mohan3d 9fe1a62
HDDS-6938. add removePrefixAcl unittest
mohan3d bd42b66
HDDS-6938. fix style
mohan3d e2e83a5
HDDS-6938. get rid of useless variable
mohan3d d87be89
HDDS-6938. move removeAcl test to TestOMPrefixAclRequest
mohan3d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...er/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMPrefixRemoveAclRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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 org.apache.hadoop.ozone.om.request.key; | ||
|
|
||
| import org.apache.hadoop.ozone.OzoneAcl; | ||
| import org.apache.hadoop.ozone.om.PrefixManager; | ||
| import org.apache.hadoop.ozone.om.PrefixManagerImpl; | ||
| import org.apache.hadoop.ozone.om.request.OMRequestTestUtils; | ||
| import org.apache.hadoop.ozone.om.request.key.acl.prefix.OMPrefixAddAclRequest; | ||
| import org.apache.hadoop.ozone.om.request.key.acl.prefix.OMPrefixRemoveAclRequest; | ||
| import org.apache.hadoop.ozone.om.response.OMClientResponse; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.AddAclRequest; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RemoveAclRequest; | ||
| import org.apache.hadoop.ozone.security.acl.OzoneObj; | ||
| import org.apache.hadoop.ozone.security.acl.OzoneObjInfo; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * Tests Remove Prefix ACL requests. | ||
| */ | ||
| public class TestOMPrefixRemoveAclRequest extends TestOMKeyRequest { | ||
|
|
||
| @Test | ||
| public void testRemoveAclRequest() throws Exception { | ||
| PrefixManager prefixManager = new PrefixManagerImpl( | ||
| ozoneManager.getMetadataManager(), true); | ||
| when(ozoneManager.getPrefixManager()).thenReturn(prefixManager); | ||
|
|
||
| // Manually add volume, bucket and key to DB | ||
| OMRequestTestUtils.addVolumeAndBucketToDB(volumeName, bucketName, | ||
| omMetadataManager); | ||
| OMRequestTestUtils.addKeyToTable(false, false, volumeName, bucketName, | ||
| keyName, clientID, replicationType, replicationFactor, 1L, | ||
| omMetadataManager); | ||
|
|
||
| OzoneAcl acl = OzoneAcl.parseAcl("user:mohanad.elsafty:rwdlncxy[ACCESS]"); | ||
|
|
||
| // Create KeyAddAcl request | ||
| OMRequest originalRequest = createAddAclKeyRequest(acl); | ||
| OMPrefixAddAclRequest omKeyPrefixAclRequest = new OMPrefixAddAclRequest( | ||
| originalRequest); | ||
| omKeyPrefixAclRequest.preExecute(ozoneManager); | ||
| omKeyPrefixAclRequest.validateAndUpdateCache(ozoneManager, 2, | ||
| ozoneManagerDoubleBufferHelper); | ||
|
|
||
| // Remove existing prefix acl. | ||
| OMRequest validRemoveAclRequest = createRemoveAclKeyRequest(acl, keyName); | ||
| OMPrefixRemoveAclRequest omPrefixRemoveAclRequest1 = | ||
| new OMPrefixRemoveAclRequest(validRemoveAclRequest); | ||
| omPrefixRemoveAclRequest1.preExecute(ozoneManager); | ||
| OMClientResponse omClientResponse1 = omPrefixRemoveAclRequest1 | ||
| .validateAndUpdateCache(ozoneManager, 3, | ||
| ozoneManagerDoubleBufferHelper); | ||
| Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK, | ||
| omClientResponse1.getOMResponse().getStatus()); | ||
|
|
||
| // Remove non-existing prefix acl. | ||
| OMRequest invalidRemoveAclRequest = createRemoveAclKeyRequest(acl, keyName); | ||
| OMPrefixRemoveAclRequest omPrefixRemoveAclRequest2 = | ||
| new OMPrefixRemoveAclRequest(invalidRemoveAclRequest); | ||
| omPrefixRemoveAclRequest1.preExecute(ozoneManager); | ||
| OMClientResponse omClientResponse2 = omPrefixRemoveAclRequest2 | ||
| .validateAndUpdateCache(ozoneManager, 4, | ||
| ozoneManagerDoubleBufferHelper); | ||
| Assert.assertEquals(OzoneManagerProtocolProtos.Status.PREFIX_NOT_FOUND, | ||
| omClientResponse2.getOMResponse().getStatus()); | ||
| } | ||
|
|
||
| private OMRequest createAddAclKeyRequest(OzoneAcl acl) { | ||
| OzoneObj obj = OzoneObjInfo.Builder.newBuilder() | ||
| .setBucketName(bucketName) | ||
| .setVolumeName(volumeName) | ||
| .setKeyName(keyName) | ||
| .setResType(OzoneObj.ResourceType.PREFIX) | ||
| .setStoreType(OzoneObj.StoreType.OZONE) | ||
| .build(); | ||
|
|
||
| AddAclRequest addAclRequest = AddAclRequest.newBuilder() | ||
| .setObj(OzoneObj.toProtobuf(obj)) | ||
| .setAcl(OzoneAcl.toProtobuf(acl)) | ||
| .build(); | ||
|
|
||
| return OMRequest.newBuilder().setClientId(UUID.randomUUID().toString()) | ||
| .setCmdType(OzoneManagerProtocolProtos.Type.AddAcl) | ||
| .setAddAclRequest(addAclRequest) | ||
| .build(); | ||
| } | ||
|
|
||
| private OMRequest createRemoveAclKeyRequest(OzoneAcl acl, String key) { | ||
| OzoneObj obj = OzoneObjInfo.Builder.newBuilder() | ||
| .setBucketName(bucketName) | ||
| .setVolumeName(volumeName) | ||
| .setKeyName(key) | ||
| .setResType(OzoneObj.ResourceType.PREFIX) | ||
| .setStoreType(OzoneObj.StoreType.OZONE) | ||
| .build(); | ||
|
|
||
| RemoveAclRequest removeAclRequest = RemoveAclRequest.newBuilder() | ||
| .setObj(OzoneObj.toProtobuf(obj)) | ||
| .setAcl(OzoneAcl.toProtobuf(acl)) | ||
| .build(); | ||
|
|
||
| return OMRequest.newBuilder().setClientId(UUID.randomUUID().toString()) | ||
| .setCmdType(OzoneManagerProtocolProtos.Type.RemoveAcl) | ||
| .setRemoveAclRequest(removeAclRequest) | ||
| .build(); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a new test class for this?
Can't we adjust it in some existing class? like
TestOMPrefixAclRequest?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, I thought it would be cleaner to have corresponding testing class for RemoveAcl. Yeah it can be done their as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change is in
OMPrefixAclRequest.javaand if we have a corresponding test classTestOMPrefixAclRequestbetter to add tests there only unless there are issues doing so.
Not very convinced with having one-one test class for each use case. Better keep all the related tests in one place only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ayushtkn updated accordingly.