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 @@ -16,6 +16,9 @@
*/
package org.apache.hadoop.ozone.om;

import static org.apache.hadoop.ozone.OzoneAcl.AclScope.ACCESS;
import static org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType.VOLUME;
import static org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType.OZONE;
import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
import static org.mockito.Matchers.any;
Expand All @@ -24,6 +27,7 @@

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.hadoop.hdds.client.BlockID;
Expand All @@ -32,9 +36,13 @@
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
import org.apache.hadoop.ozone.security.acl.OzoneObj;
import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -318,6 +326,42 @@ public void testKeyOps() throws IOException {

}

@Test
public void testAclOperations() throws IOException {
try {
// Create a volume.
cluster.getClient().getObjectStore().createVolume("volumeacl");

OzoneObj volObj = new OzoneObjInfo.Builder().setVolumeName("volumeacl")
.setResType(VOLUME).setStoreType(OZONE).build();

// Test getAcl
List<OzoneAcl> acls = ozoneManager.getAcl(volObj);
MetricsRecordBuilder omMetrics = getMetrics("OMMetrics");
assertCounter("NumGetAcl", 1L, omMetrics);

// Test addAcl
ozoneManager.addAcl(volObj,
new OzoneAcl(IAccessAuthorizer.ACLIdentityType.USER, "ozoneuser",
IAccessAuthorizer.ACLType.ALL, ACCESS));
omMetrics = getMetrics("OMMetrics");
assertCounter("NumAddAcl", 1L, omMetrics);

// Test setAcl
ozoneManager.setAcl(volObj, acls);
omMetrics = getMetrics("OMMetrics");
assertCounter("NumSetAcl", 1L, omMetrics);

// Test removeAcl
ozoneManager.removeAcl(volObj, acls.get(0));
omMetrics = getMetrics("OMMetrics");
assertCounter("NumRemoveAcl", 1L, omMetrics);

} finally {
cluster.getClient().getObjectStore().deleteVolume("volumeacl");
}
}

/**
* Test volume operations with ignoring thrown exception.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public class OMMetrics {
private @Metric MutableCounterLong numOpenKeysSubmittedForDeletion;
private @Metric MutableCounterLong numOpenKeysDeleted;

private @Metric MutableCounterLong numAddAcl;
private @Metric MutableCounterLong numSetAcl;
private @Metric MutableCounterLong numGetAcl;
private @Metric MutableCounterLong numRemoveAcl;

// Failure Metrics
private @Metric MutableCounterLong numVolumeCreateFails;
private @Metric MutableCounterLong numVolumeUpdateFails;
Expand Down Expand Up @@ -560,6 +565,22 @@ public void incNumOpenKeyDeleteRequestFails() {
numOpenKeyDeleteRequestFails.incr();
}

public void incNumAddAcl() {
numAddAcl.incr();
}

public void incNumSetAcl() {
numSetAcl.incr();
}

public void incNumGetAcl() {
numGetAcl.incr();
}

public void incNumRemoveAcl() {
numRemoveAcl.incr();
}

@VisibleForTesting
public long getNumVolumeCreates() {
return numVolumeCreates.value();
Expand Down Expand Up @@ -832,6 +853,22 @@ public long getNumOpenKeyDeleteRequestFails() {
return numOpenKeyDeleteRequestFails.value();
}

public long getNumAddAcl() {
return numAddAcl.value();
}

public long getNumSetAcl() {
return numSetAcl.value();
}

public long getNumGetAcl() {
return numGetAcl.value();
}

public long getNumRemoveAcl() {
return numRemoveAcl.value();
}

public void unRegister() {
MetricsSystem ms = DefaultMetricsSystem.instance();
ms.unregisterSource(SOURCE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2986,6 +2986,7 @@ public boolean addAcl(OzoneObj obj, OzoneAcl acl) throws IOException {
checkAcls(obj.getResourceType(), obj.getStoreType(), ACLType.WRITE_ACL,
obj.getVolumeName(), obj.getBucketName(), obj.getKeyName());
}
metrics.incNumAddAcl();
switch (obj.getResourceType()) {
case VOLUME:
return volumeManager.addAcl(obj, acl);
Expand Down Expand Up @@ -3027,6 +3028,7 @@ public boolean removeAcl(OzoneObj obj, OzoneAcl acl) throws IOException {
checkAcls(obj.getResourceType(), obj.getStoreType(), ACLType.WRITE_ACL,
obj.getVolumeName(), obj.getBucketName(), obj.getKeyName());
}
metrics.incNumRemoveAcl();
switch (obj.getResourceType()) {
case VOLUME:
return volumeManager.removeAcl(obj, acl);
Expand Down Expand Up @@ -3069,6 +3071,7 @@ public boolean setAcl(OzoneObj obj, List<OzoneAcl> acls) throws IOException {
checkAcls(obj.getResourceType(), obj.getStoreType(), ACLType.WRITE_ACL,
obj.getVolumeName(), obj.getBucketName(), obj.getKeyName());
}
metrics.incNumSetAcl();
switch (obj.getResourceType()) {
case VOLUME:
return volumeManager.setAcl(obj, acls);
Expand Down Expand Up @@ -3108,6 +3111,7 @@ public List<OzoneAcl> getAcl(OzoneObj obj) throws IOException {
checkAcls(obj.getResourceType(), obj.getStoreType(), ACLType.READ_ACL,
obj.getVolumeName(), obj.getBucketName(), obj.getKeyName());
}
metrics.incNumGetAcl();
switch (obj.getResourceType()) {
case VOLUME:
return volumeManager.getAcl(obj);
Expand Down