Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -28,6 +28,7 @@
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.om.PrefixManagerImpl;
import org.apache.hadoop.ozone.om.PrefixManagerImpl.OMPrefixAclOpResult;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.OmPrefixInfo;
import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
import org.apache.hadoop.ozone.om.request.OMClientRequest;
Expand Down Expand Up @@ -105,6 +106,11 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
}

omPrefixInfo = operationResult.getOmPrefixInfo();
if (omPrefixInfo == null) {
throw new OMException(
"No prefix info for the prefix path: " + prefixPath,
OMException.ResultCodes.PREFIX_NOT_FOUND);
}
omPrefixInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());

// As for remove acl list, for a prefix if after removing acl from
Expand Down
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

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

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.java and if we have a corresponding test class TestOMPrefixAclRequest
better 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ayushtkn updated accordingly.

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();
}

}