Search in sources :

Example 1 with OzoneAcl

use of org.apache.hadoop.ozone.OzoneAcl in project ozone by apache.

the class RpcClient method createVolume.

@Override
public void createVolume(String volumeName, VolumeArgs volArgs) throws IOException {
    verifyVolumeName(volumeName);
    Preconditions.checkNotNull(volArgs);
    verifyCountsQuota(volArgs.getQuotaInNamespace());
    verifySpaceQuota(volArgs.getQuotaInBytes());
    String admin = volArgs.getAdmin() == null ? ugi.getShortUserName() : volArgs.getAdmin();
    String owner = volArgs.getOwner() == null ? ugi.getShortUserName() : volArgs.getOwner();
    long quotaInNamespace = volArgs.getQuotaInNamespace();
    long quotaInBytes = volArgs.getQuotaInBytes();
    List<OzoneAcl> listOfAcls = new ArrayList<>();
    // User ACL
    listOfAcls.add(new OzoneAcl(ACLIdentityType.USER, owner, userRights, ACCESS));
    // Group ACLs of the User
    List<String> userGroups = Arrays.asList(UserGroupInformation.createRemoteUser(owner).getGroupNames());
    userGroups.stream().forEach((group) -> listOfAcls.add(new OzoneAcl(ACLIdentityType.GROUP, group, groupRights, ACCESS)));
    // ACLs from VolumeArgs
    if (volArgs.getAcls() != null) {
        listOfAcls.addAll(volArgs.getAcls());
    }
    OmVolumeArgs.Builder builder = OmVolumeArgs.newBuilder();
    builder.setVolume(volumeName);
    builder.setAdminName(admin);
    builder.setOwnerName(owner);
    builder.setQuotaInBytes(quotaInBytes);
    builder.setQuotaInNamespace(quotaInNamespace);
    builder.setUsedNamespace(0L);
    builder.addAllMetadata(volArgs.getMetadata());
    // Remove duplicates and add ACLs
    for (OzoneAcl ozoneAcl : listOfAcls.stream().distinct().collect(Collectors.toList())) {
        builder.addOzoneAcls(ozoneAcl);
    }
    if (volArgs.getQuotaInBytes() == 0) {
        LOG.info("Creating Volume: {}, with {} as owner.", volumeName, owner);
    } else {
        LOG.info("Creating Volume: {}, with {} as owner " + "and space quota set to {} bytes, counts quota set" + " to {}", volumeName, owner, quotaInBytes, quotaInNamespace);
    }
    ozoneManagerClient.createVolume(builder.build());
}
Also used : OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) ArrayList(java.util.ArrayList)

Example 2 with OzoneAcl

use of org.apache.hadoop.ozone.OzoneAcl in project ozone by apache.

the class TestOmMetrics method testAclMetricsInternal.

private void testAclMetricsInternal(ObjectStore objectStore, OzoneObj volObj, List<OzoneAcl> acls) throws IOException {
    // Test addAcl
    OMMetrics metrics = ozoneManager.getMetrics();
    long initialValue = metrics.getNumAddAcl();
    objectStore.addAcl(volObj, new OzoneAcl(IAccessAuthorizer.ACLIdentityType.USER, "ozoneuser", IAccessAuthorizer.ACLType.ALL, ACCESS));
    Assert.assertEquals(initialValue + 1, metrics.getNumAddAcl());
    // Test setAcl
    initialValue = metrics.getNumSetAcl();
    objectStore.setAcl(volObj, acls);
    Assert.assertEquals(initialValue + 1, metrics.getNumSetAcl());
    // Test removeAcl
    initialValue = metrics.getNumRemoveAcl();
    objectStore.removeAcl(volObj, acls.get(0));
    Assert.assertEquals(initialValue + 1, metrics.getNumRemoveAcl());
}
Also used : OzoneAcl(org.apache.hadoop.ozone.OzoneAcl)

Example 3 with OzoneAcl

use of org.apache.hadoop.ozone.OzoneAcl in project ozone by apache.

the class TestOzoneManagerHAWithACL method testSetPrefixAcl.

public void testSetPrefixAcl() throws Exception {
    OzoneBucket ozoneBucket = setupBucket();
    String remoteUserName = "remoteUser";
    String prefixName = RandomStringUtils.randomAlphabetic(5) + "/";
    OzoneAcl defaultUserAcl = new OzoneAcl(USER, remoteUserName, READ, DEFAULT);
    OzoneObj ozoneObj = OzoneObjInfo.Builder.newBuilder().setResType(OzoneObj.ResourceType.PREFIX).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName(ozoneBucket.getVolumeName()).setBucketName(ozoneBucket.getName()).setPrefixName(prefixName).build();
    testSetAcl(remoteUserName, ozoneObj, defaultUserAcl);
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OzoneObj(org.apache.hadoop.ozone.security.acl.OzoneObj) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl)

Example 4 with OzoneAcl

use of org.apache.hadoop.ozone.OzoneAcl in project ozone by apache.

the class TestOzoneManagerHAWithACL method testAddAcl.

private void testAddAcl(String remoteUserName, OzoneObj ozoneObj, OzoneAcl userAcl) throws Exception {
    ObjectStore objectStore = getObjectStore();
    boolean addAcl = objectStore.addAcl(ozoneObj, userAcl);
    Assert.assertTrue(addAcl);
    List<OzoneAcl> acls = objectStore.getAcl(ozoneObj);
    Assert.assertTrue(containsAcl(userAcl, acls));
    // Add an already existing acl.
    addAcl = objectStore.addAcl(ozoneObj, userAcl);
    Assert.assertFalse(addAcl);
    // Add an acl by changing acl type with same type, name and scope.
    userAcl = new OzoneAcl(USER, remoteUserName, WRITE, DEFAULT);
    addAcl = objectStore.addAcl(ozoneObj, userAcl);
    Assert.assertTrue(addAcl);
}
Also used : ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl)

Example 5 with OzoneAcl

use of org.apache.hadoop.ozone.OzoneAcl in project ozone by apache.

the class TestOzoneManagerHAWithACL method testAddKeyAcl.

public void testAddKeyAcl() throws Exception {
    OzoneBucket ozoneBucket = setupBucket();
    String remoteUserName = "remoteUser";
    OzoneAcl userAcl = new OzoneAcl(USER, remoteUserName, READ, DEFAULT);
    String key = createKey(ozoneBucket);
    OzoneObj ozoneObj = OzoneObjInfo.Builder.newBuilder().setResType(OzoneObj.ResourceType.KEY).setStoreType(OzoneObj.StoreType.OZONE).setVolumeName(ozoneBucket.getVolumeName()).setBucketName(ozoneBucket.getName()).setKeyName(key).build();
    testAddAcl(remoteUserName, ozoneObj, userAcl);
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OzoneObj(org.apache.hadoop.ozone.security.acl.OzoneObj) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl)

Aggregations

OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)101 Test (org.junit.Test)56 ArrayList (java.util.ArrayList)28 OzoneObj (org.apache.hadoop.ozone.security.acl.OzoneObj)26 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)25 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)23 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)20 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)18 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)18 BitSet (java.util.BitSet)12 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)12 IOException (java.io.IOException)11 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)10 ObjectStore (org.apache.hadoop.ozone.client.ObjectStore)8 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)8 ACLType (org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType)8 BucketArgs (org.apache.hadoop.ozone.client.BucketArgs)7 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)7 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)7 VolumeArgs (org.apache.hadoop.ozone.client.VolumeArgs)6