Search in sources :

Example 16 with VolumeArgs

use of org.apache.hadoop.ozone.client.VolumeArgs in project ozone by apache.

the class TestOzoneManagerSnapshotProvider method testDownloadCheckpoint.

@Test
public void testDownloadCheckpoint() throws Exception {
    String userName = "user" + RandomStringUtils.randomNumeric(5);
    String adminName = "admin" + RandomStringUtils.randomNumeric(5);
    String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
    String bucketName = "bucket" + RandomStringUtils.randomNumeric(5);
    VolumeArgs createVolumeArgs = VolumeArgs.newBuilder().setOwner(userName).setAdmin(adminName).build();
    objectStore.createVolume(volumeName, createVolumeArgs);
    OzoneVolume retVolumeinfo = objectStore.getVolume(volumeName);
    retVolumeinfo.createBucket(bucketName);
    String leaderOMNodeId = OmFailoverProxyUtil.getFailoverProxyProvider(objectStore.getClientProxy()).getCurrentProxyOMNodeId();
    OzoneManager leaderOM = cluster.getOzoneManager(leaderOMNodeId);
    // Get a follower OM
    String followerNodeId = leaderOM.getPeerNodes().get(0).getNodeId();
    OzoneManager followerOM = cluster.getOzoneManager(followerNodeId);
    // Download latest checkpoint from leader OM to follower OM
    DBCheckpoint omSnapshot = followerOM.getOmSnapshotProvider().getOzoneManagerDBSnapshot(leaderOMNodeId);
    long leaderSnapshotIndex = leaderOM.getRatisSnapshotIndex();
    long downloadedSnapshotIndex = getDownloadedSnapshotIndex(omSnapshot);
    // The snapshot index downloaded from leader OM should match the ratis
    // snapshot index on the leader OM
    Assert.assertEquals("The snapshot index downloaded from leader OM does " + "not match its ratis snapshot index", leaderSnapshotIndex, downloadedSnapshotIndex);
}
Also used : OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) VolumeArgs(org.apache.hadoop.ozone.client.VolumeArgs) Test(org.junit.Test)

Example 17 with VolumeArgs

use of org.apache.hadoop.ozone.client.VolumeArgs in project ozone by apache.

the class TestRootedOzoneFileSystem method testNonPrivilegedUserMkdirCreateBucket.

@Test
public void testNonPrivilegedUserMkdirCreateBucket() throws IOException {
    // This test is only meaningful when ACL is enabled
    Assume.assumeTrue("ACL is not enabled. Skipping this test as it requires " + "ACL to be enabled to be meaningful.", enableAcl);
    // Sanity check
    Assert.assertTrue(cluster.getOzoneManager().getAclsEnabled());
    final String volume = "volume-for-test-get-bucket";
    // Create a volume as admin
    // Create volume "tmp" with world access. allow non-admin to create buckets
    ClientProtocol proxy = objectStore.getClientProxy();
    // Get default acl rights for user
    OzoneAclConfig aclConfig = conf.getObject(OzoneAclConfig.class);
    ACLType userRights = aclConfig.getUserDefaultRights();
    // Construct ACL for world access
    OzoneAcl aclWorldAccess = new OzoneAcl(ACLIdentityType.WORLD, "", userRights, ACCESS);
    // Construct VolumeArgs, set ACL to world access
    VolumeArgs volumeArgs = new VolumeArgs.Builder().setAcls(Collections.singletonList(aclWorldAccess)).build();
    proxy.createVolume(volume, volumeArgs);
    // Create a bucket as non-admin, should succeed
    final String bucket = "test-bucket-1";
    try {
        final Path myBucketPath = new Path(volume, bucket);
        // Have to prepend the root to bucket path here.
        // Otherwise, FS will automatically prepend user home directory path
        // which is not we want here.
        Assert.assertTrue(userOfs.mkdirs(new Path("/", myBucketPath)));
    } catch (IOException e) {
        Assert.fail("Should not have thrown exception when creating bucket as" + " a regular user here");
    }
    // Clean up
    proxy.deleteBucket(volume, bucket);
    proxy.deleteVolume(volume);
}
Also used : OzoneAclConfig(org.apache.hadoop.ozone.security.acl.OzoneAclConfig) Path(org.apache.hadoop.fs.Path) OFSPath(org.apache.hadoop.ozone.OFSPath) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) ACLType(org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType) VolumeArgs(org.apache.hadoop.ozone.client.VolumeArgs) IOException(java.io.IOException) ClientProtocol(org.apache.hadoop.ozone.client.protocol.ClientProtocol) Test(org.junit.Test)

Example 18 with VolumeArgs

use of org.apache.hadoop.ozone.client.VolumeArgs in project ozone by apache.

the class TestRootedOzoneFileSystem method testTempMount.

/*
   * OFS: Test /tmp mount behavior.
   */
@Test
public void testTempMount() throws IOException {
    // Prep
    // Use ClientProtocol to pass in volume ACL, ObjectStore won't do it
    ClientProtocol proxy = objectStore.getClientProxy();
    // Get default acl rights for user
    OzoneAclConfig aclConfig = conf.getObject(OzoneAclConfig.class);
    ACLType userRights = aclConfig.getUserDefaultRights();
    // Construct ACL for world access
    OzoneAcl aclWorldAccess = new OzoneAcl(ACLIdentityType.WORLD, "", userRights, ACCESS);
    // Construct VolumeArgs
    VolumeArgs volumeArgs = new VolumeArgs.Builder().setAcls(Collections.singletonList(aclWorldAccess)).setQuotaInNamespace(1000).setQuotaInBytes(Long.MAX_VALUE).build();
    // Sanity check
    Assert.assertNull(volumeArgs.getOwner());
    Assert.assertNull(volumeArgs.getAdmin());
    Assert.assertEquals(Long.MAX_VALUE, volumeArgs.getQuotaInBytes());
    Assert.assertEquals(1000, volumeArgs.getQuotaInNamespace());
    Assert.assertEquals(0, volumeArgs.getMetadata().size());
    Assert.assertEquals(1, volumeArgs.getAcls().size());
    // Create volume "tmp" with world access. allow non-admin to create buckets
    proxy.createVolume(OFSPath.OFS_MOUNT_TMP_VOLUMENAME, volumeArgs);
    OzoneVolume vol = objectStore.getVolume(OFSPath.OFS_MOUNT_TMP_VOLUMENAME);
    Assert.assertNotNull(vol);
    // Begin test
    String hashedUsername = OFSPath.getTempMountBucketNameOfCurrentUser();
    // Expect failure since temp bucket for current user is not created yet
    try {
        vol.getBucket(hashedUsername);
    } catch (OMException ex) {
        // Expect BUCKET_NOT_FOUND
        if (!ex.getResult().equals(BUCKET_NOT_FOUND)) {
            Assert.fail("Temp bucket for current user shouldn't have been created");
        }
    }
    // Write under /tmp/, OFS will create the temp bucket if not exist
    Path dir1 = new Path("/tmp/dir1");
    fs.mkdirs(dir1);
    try (FSDataOutputStream stream = ofs.create(new Path("/tmp/dir1/file1"))) {
        stream.write(1);
    }
    // Verify temp bucket creation
    OzoneBucket bucket = vol.getBucket(hashedUsername);
    Assert.assertNotNull(bucket);
    // Verify dir1 creation
    FileStatus[] fileStatuses = fs.listStatus(new Path("/tmp/"));
    Assert.assertEquals(1, fileStatuses.length);
    Assert.assertEquals("/tmp/dir1", fileStatuses[0].getPath().toUri().getPath());
    // Verify file1 creation
    FileStatus[] fileStatusesInDir1 = fs.listStatus(dir1);
    Assert.assertEquals(1, fileStatusesInDir1.length);
    Assert.assertEquals("/tmp/dir1/file1", fileStatusesInDir1[0].getPath().toUri().getPath());
    // Cleanup
    fs.delete(dir1, true);
    vol.deleteBucket(hashedUsername);
    proxy.deleteVolume(OFSPath.OFS_MOUNT_TMP_VOLUMENAME);
}
Also used : Path(org.apache.hadoop.fs.Path) OFSPath(org.apache.hadoop.ozone.OFSPath) FileStatus(org.apache.hadoop.fs.FileStatus) ACLType(org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType) VolumeArgs(org.apache.hadoop.ozone.client.VolumeArgs) OzoneAclConfig(org.apache.hadoop.ozone.security.acl.OzoneAclConfig) OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) ClientProtocol(org.apache.hadoop.ozone.client.protocol.ClientProtocol) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Test(org.junit.Test)

Aggregations

VolumeArgs (org.apache.hadoop.ozone.client.VolumeArgs)18 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)13 Test (org.junit.Test)12 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)6 ObjectStore (org.apache.hadoop.ozone.client.ObjectStore)5 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)4 IOException (java.io.IOException)3 ConnectException (java.net.ConnectException)2 Path (org.apache.hadoop.fs.Path)2 RemoteException (org.apache.hadoop.ipc.RemoteException)2 OFSPath (org.apache.hadoop.ozone.OFSPath)2 ClientProtocol (org.apache.hadoop.ozone.client.protocol.ClientProtocol)2 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)2 ACLType (org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType)2 OzoneAclConfig (org.apache.hadoop.ozone.security.acl.OzoneAclConfig)2 OzoneObj (org.apache.hadoop.ozone.security.acl.OzoneObj)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileStatus (org.apache.hadoop.fs.FileStatus)1