use of org.apache.hadoop.ozone.client.BucketArgs in project ozone by apache.
the class TestOzoneManagerHAMetadataOnly method testAllBucketOperations.
@Test
public void testAllBucketOperations() throws Exception {
String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
String bucketName = "volume" + RandomStringUtils.randomNumeric(5);
OzoneVolume retVolume = createAndCheckVolume(volumeName);
BucketArgs bucketArgs = BucketArgs.newBuilder().setStorageType(StorageType.DISK).setVersioning(true).build();
retVolume.createBucket(bucketName, bucketArgs);
OzoneBucket ozoneBucket = retVolume.getBucket(bucketName);
Assert.assertEquals(volumeName, ozoneBucket.getVolumeName());
Assert.assertEquals(bucketName, ozoneBucket.getName());
Assert.assertTrue(ozoneBucket.getVersioning());
Assert.assertEquals(StorageType.DISK, ozoneBucket.getStorageType());
Assert.assertFalse(ozoneBucket.getCreationTime().isAfter(Instant.now()));
// Change versioning to false
ozoneBucket.setVersioning(false);
ozoneBucket = retVolume.getBucket(bucketName);
Assert.assertFalse(ozoneBucket.getVersioning());
retVolume.deleteBucket(bucketName);
OzoneTestUtils.expectOmException(OMException.ResultCodes.BUCKET_NOT_FOUND, () -> retVolume.deleteBucket(bucketName));
}
use of org.apache.hadoop.ozone.client.BucketArgs in project ozone by apache.
the class TestRecursiveAclWithFSO method testKeyDeleteAndRenameWithoutPermission.
@Test
public void testKeyDeleteAndRenameWithoutPermission() throws Exception {
List<String> keys = new ArrayList<>();
// Create volumes with user1
OzoneClient client = cluster.getClient();
ObjectStore objectStore = client.getObjectStore();
/* r = READ, w = WRITE, c = CREATE, d = DELETE
l = LIST, a = ALL, n = NONE, x = READ_ACL, y = WRITE_ACL */
String aclWorldAll = "world::a";
createVolumeWithOwnerAndAcl(objectStore, "volume1", "user1", aclWorldAll);
// Login as user1, create directories and keys
UserGroupInformation.setLoginUser(user1);
client = cluster.getClient();
objectStore = client.getObjectStore();
OzoneVolume volume = objectStore.getVolume("volume1");
BucketArgs omBucketArgs = BucketArgs.newBuilder().setStorageType(StorageType.DISK).build();
// create bucket with user1
volume.createBucket("bucket1", omBucketArgs);
setBucketAcl(objectStore, volume.getName(), "bucket1", aclWorldAll);
OzoneBucket ozoneBucket = volume.getBucket("bucket1");
/**
* buck-1
* |
* a
* |
* ------------------------------------
* | | | |
* b1 b2 b3 file1
* ----- ------ -----
* | | | | | |
* c1 c2 d1 d2 e1 e2
* | | | | | |
* f1 f2 f3 -------- f5 f6
* | |
* d21 file2
* |
* f4
*
* Test Case 1 :
* Remove delete acl from file File2
* Try deleting b2
*
* Test case 2:
* Remove delete acl fro dir c2
* Try deleting b1
*
* Test case 3
* try deleting b3
*/
String keyf1 = "a/b1/c1/f1";
String keyf2 = "a/b1/c2/f2";
String keyf3 = "a/b2/d1/f3";
String keyf4 = "a/b2/d2/d21/f4";
String keyf5 = "/a/b3/e1/f5";
String keyf6 = "/a/b3/e2/f6";
String file1 = "a/" + "file" + RandomStringUtils.randomNumeric(5);
String file2 = "a/b2/d2/" + "file" + RandomStringUtils.randomNumeric(5);
keys.add(keyf1);
keys.add(keyf2);
keys.add(keyf3);
keys.add(keyf4);
keys.add(keyf5);
keys.add(keyf6);
keys.add(file1);
keys.add(file2);
createKeys(objectStore, ozoneBucket, keys);
// Test case 1
// Remove acls from file2
// Delete/Rename on directory a/b2 should throw permission denied
// (since file2 is a child)
removeAclsFromKey(objectStore, ozoneBucket, file2);
OzoneObj ozoneObj;
List<OzoneAcl> aclList1;
UserGroupInformation.setLoginUser(user2);
client = cluster.getClient();
objectStore = client.getObjectStore();
volume = objectStore.getVolume("volume1");
ozoneBucket = volume.getBucket("bucket1");
// perform delete
try {
ozoneBucket.deleteDirectory("a/b2", true);
Assert.fail("Should throw permission denied !");
} catch (OMException ome) {
// expect permission error
Assert.assertEquals("Permission check failed", OMException.ResultCodes.PERMISSION_DENIED, ome.getResult());
}
// perform rename
try {
ozoneBucket.renameKey("a/b2", "a/b2_renamed");
Assert.fail("Should throw permission denied !");
} catch (OMException ome) {
// expect permission error
Assert.assertEquals("Permission check failed", OMException.ResultCodes.PERMISSION_DENIED, ome.getResult());
}
// Test case 2
// Remove acl from directory c2, delete/rename a/b1 should throw
// permission denied since c2 is a subdirectory
UserGroupInformation.setLoginUser(user1);
removeAclsFromKey(objectStore, ozoneBucket, "a/b1/c2");
UserGroupInformation.setLoginUser(user2);
// perform delete
try {
ozoneBucket.deleteDirectory("a/b1", true);
Assert.fail("Should throw permission denied !");
} catch (OMException ome) {
// expect permission error
Assert.assertEquals("Permission check failed", OMException.ResultCodes.PERMISSION_DENIED, ome.getResult());
}
// perform rename
try {
ozoneBucket.renameKey("a/b1", "a/b1_renamed");
Assert.fail("Should throw permission denied !");
} catch (OMException ome) {
// expect permission error
Assert.assertEquals("Permission check failed", OMException.ResultCodes.PERMISSION_DENIED, ome.getResult());
}
// Test case 3
// delete b3 and this shouldn't throw exception because acls have not
// been removed from subpaths.
ozoneBucket.deleteDirectory("a/b3", true);
}
use of org.apache.hadoop.ozone.client.BucketArgs in project ozone by apache.
the class TestNSSummaryAdmin method createVolumeAndBuckets.
/**
* Create OBS and FSO buckets for the tests.
* @throws Exception
*/
private static void createVolumeAndBuckets() throws Exception {
store.createVolume(volumeName);
OzoneVolume volume = store.getVolume(volumeName);
// Create OBS bucket.
BucketArgs bucketArgsOBS = BucketArgs.newBuilder().setBucketLayout(BucketLayout.OBJECT_STORE).build();
volume.createBucket(bucketOBS, bucketArgsOBS);
// Create FSO bucket.
BucketArgs bucketArgsFSO = BucketArgs.newBuilder().setBucketLayout(BucketLayout.FILE_SYSTEM_OPTIMIZED).build();
volume.createBucket(bucketFSO, bucketArgsFSO);
}
use of org.apache.hadoop.ozone.client.BucketArgs in project ozone by apache.
the class TestDataUtil method createVolumeAndBucket.
public static OzoneBucket createVolumeAndBucket(MiniOzoneCluster cluster, String volumeName, String bucketName, BucketLayout bucketLayout) throws IOException {
String userName = "user" + RandomStringUtils.randomNumeric(5);
String adminName = "admin" + RandomStringUtils.randomNumeric(5);
OzoneClient client = cluster.getClient();
VolumeArgs volumeArgs = VolumeArgs.newBuilder().setAdmin(adminName).setOwner(userName).build();
ObjectStore objectStore = client.getObjectStore();
objectStore.createVolume(volumeName, volumeArgs);
OzoneVolume volume = objectStore.getVolume(volumeName);
BucketArgs omBucketArgs;
BucketArgs.Builder builder = BucketArgs.newBuilder();
builder.setStorageType(StorageType.DISK);
builder.setBucketLayout(bucketLayout);
omBucketArgs = builder.build();
volume.createBucket(bucketName, omBucketArgs);
return volume.getBucket(bucketName);
}
use of org.apache.hadoop.ozone.client.BucketArgs in project ozone by apache.
the class TestOzoneRpcClientAbstract method testDeletedKeyForGDPR.
/**
* Tests deletedKey for GDPR.
* 1. Create GDPR Enabled bucket.
* 2. Create a Key in this bucket so it gets encrypted via GDPRSymmetricKey.
* 3. Read key and validate the content/metadata is as expected because the
* readKey will decrypt using the GDPR Symmetric Key with details from KeyInfo
* Metadata.
* 4. Delete this key in GDPR enabled bucket
* 5. Confirm the deleted key metadata in deletedTable does not contain the
* GDPR encryption details (flag, secret, algorithm).
* @throws Exception
*/
@Test
public void testDeletedKeyForGDPR() throws Exception {
// Step 1
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();
String keyName = UUID.randomUUID().toString();
store.createVolume(volumeName);
OzoneVolume volume = store.getVolume(volumeName);
BucketArgs args = BucketArgs.newBuilder().addMetadata(OzoneConsts.GDPR_FLAG, "true").build();
volume.createBucket(bucketName, args);
OzoneBucket bucket = volume.getBucket(bucketName);
Assert.assertEquals(bucketName, bucket.getName());
Assert.assertNotNull(bucket.getMetadata());
Assert.assertEquals("true", bucket.getMetadata().get(OzoneConsts.GDPR_FLAG));
// Step 2
String text = "hello world";
Map<String, String> keyMetadata = new HashMap<>();
keyMetadata.put(OzoneConsts.GDPR_FLAG, "true");
OzoneOutputStream out = bucket.createKey(keyName, text.getBytes(UTF_8).length, RATIS, ONE, keyMetadata);
out.write(text.getBytes(UTF_8));
out.close();
// Step 3
OzoneKeyDetails key = bucket.getKey(keyName);
Assert.assertEquals(keyName, key.getName());
Assert.assertEquals("true", key.getMetadata().get(OzoneConsts.GDPR_FLAG));
Assert.assertEquals("AES", key.getMetadata().get(OzoneConsts.GDPR_ALGORITHM));
Assert.assertTrue(key.getMetadata().get(OzoneConsts.GDPR_SECRET) != null);
OzoneInputStream is = bucket.readKey(keyName);
byte[] fileContent = new byte[text.getBytes(UTF_8).length];
is.read(fileContent);
Assert.assertTrue(verifyRatisReplication(volumeName, bucketName, keyName, RATIS, ONE));
Assert.assertEquals(text, new String(fileContent, UTF_8));
// Step 4
bucket.deleteKey(keyName);
// Step 5
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
String objectKey = omMetadataManager.getOzoneKey(volumeName, bucketName, keyName);
RepeatedOmKeyInfo deletedKeys = omMetadataManager.getDeletedTable().get(objectKey);
if (deletedKeys != null) {
Map<String, String> deletedKeyMetadata = deletedKeys.getOmKeyInfoList().get(0).getMetadata();
Assert.assertFalse(deletedKeyMetadata.containsKey(OzoneConsts.GDPR_FLAG));
Assert.assertFalse(deletedKeyMetadata.containsKey(OzoneConsts.GDPR_SECRET));
Assert.assertFalse(deletedKeyMetadata.containsKey(OzoneConsts.GDPR_ALGORITHM));
}
}
Aggregations