Search in sources :

Example 16 with OmBucketInfo

use of org.apache.hadoop.ozone.om.helpers.OmBucketInfo in project ozone by apache.

the class TestBucketManagerImpl method testDeleteNonEmptyBucket.

@Test
@Ignore("Bucket Manager does not use cache, Disable it for now.")
public void testDeleteNonEmptyBucket() throws Exception {
    thrown.expectMessage("Bucket is not empty");
    OmMetadataManagerImpl metaMgr = createSampleVol();
    BucketManager bucketManager = new BucketManagerImpl(metaMgr);
    OmBucketInfo bucketInfo = OmBucketInfo.newBuilder().setVolumeName("sampleVol").setBucketName("bucketOne").build();
    bucketManager.createBucket(bucketInfo);
    // Create keys in bucket
    metaMgr.getKeyTable(getBucketLayout()).put("/sampleVol/bucketOne/key_one", new OmKeyInfo.Builder().setBucketName("bucketOne").setVolumeName("sampleVol").setKeyName("key_one").setReplicationConfig(StandaloneReplicationConfig.getInstance(ReplicationFactor.ONE)).build());
    metaMgr.getKeyTable(getBucketLayout()).put("/sampleVol/bucketOne/key_two", new OmKeyInfo.Builder().setBucketName("bucketOne").setVolumeName("sampleVol").setKeyName("key_two").setReplicationConfig(StandaloneReplicationConfig.getInstance(ReplicationFactor.ONE)).build());
    try {
        bucketManager.deleteBucket("sampleVol", "bucketOne");
    } catch (OMException omEx) {
        Assert.assertEquals(ResultCodes.BUCKET_NOT_EMPTY, omEx.getResult());
        throw omEx;
    }
    metaMgr.getStore().close();
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with OmBucketInfo

use of org.apache.hadoop.ozone.om.helpers.OmBucketInfo in project ozone by apache.

the class TestBucketManagerImpl method testCreateBucket.

@Test
@Ignore("Bucket Manager does not use cache, Disable it for now.")
public void testCreateBucket() throws Exception {
    OmMetadataManagerImpl metaMgr = createSampleVol();
    KeyProviderCryptoExtension kmsProvider = Mockito.mock(KeyProviderCryptoExtension.class);
    String testBekName = "key1";
    String testCipherName = "AES/CTR/NoPadding";
    KeyProvider.Metadata mockMetadata = Mockito.mock(KeyProvider.Metadata.class);
    Mockito.when(kmsProvider.getMetadata(testBekName)).thenReturn(mockMetadata);
    Mockito.when(mockMetadata.getCipher()).thenReturn(testCipherName);
    BucketManager bucketManager = new BucketManagerImpl(metaMgr, kmsProvider);
    OmBucketInfo bucketInfo = OmBucketInfo.newBuilder().setVolumeName("sampleVol").setBucketName("bucketOne").setBucketEncryptionKey(new BucketEncryptionKeyInfo.Builder().setKeyName("key1").build()).build();
    bucketManager.createBucket(bucketInfo);
    Assert.assertNotNull(bucketManager.getBucketInfo("sampleVol", "bucketOne"));
    OmBucketInfo bucketInfoRead = bucketManager.getBucketInfo("sampleVol", "bucketOne");
    Assert.assertTrue(bucketInfoRead.getEncryptionKeyInfo().getKeyName().equals(bucketInfo.getEncryptionKeyInfo().getKeyName()));
    metaMgr.getStore().close();
}
Also used : KeyProvider(org.apache.hadoop.crypto.key.KeyProvider) OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) KeyProviderCryptoExtension(org.apache.hadoop.crypto.key.KeyProviderCryptoExtension) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with OmBucketInfo

use of org.apache.hadoop.ozone.om.helpers.OmBucketInfo in project ozone by apache.

the class TestBucketManagerImpl method testGetBucketInfo.

@Test
public void testGetBucketInfo() throws Exception {
    final String volumeName = "sampleVol";
    final String bucketName = "bucketOne";
    OmMetadataManagerImpl metaMgr = createSampleVol();
    BucketManager bucketManager = new BucketManagerImpl(metaMgr);
    // Check exception thrown when volume does not exist
    try {
        bucketManager.getBucketInfo(volumeName, bucketName);
        Assert.fail("Should have thrown OMException");
    } catch (OMException omEx) {
        Assert.assertEquals("getBucketInfo() should have thrown " + "VOLUME_NOT_FOUND as the parent volume is not created!", ResultCodes.VOLUME_NOT_FOUND, omEx.getResult());
    }
    OmBucketInfo bucketInfo = OmBucketInfo.newBuilder().setVolumeName(volumeName).setBucketName(bucketName).setStorageType(StorageType.DISK).setIsVersionEnabled(false).build();
    // Note: the helper method createBucket() in this scope won't create the
    // parent volume DB entry. In order to verify getBucketInfo's behavior, we
    // need to create the volume entry in DB manually.
    OmVolumeArgs args = OmVolumeArgs.newBuilder().setVolume(volumeName).setAdminName("bilbo").setOwnerName("bilbo").build();
    OMRequestTestUtils.addVolumeToOM(metaMgr, args);
    // Create bucket
    createBucket(metaMgr, bucketInfo);
    // Check exception thrown when bucket does not exist
    try {
        bucketManager.getBucketInfo(volumeName, "bucketNotExist");
        Assert.fail("Should have thrown OMException");
    } catch (OMException omEx) {
        Assert.assertEquals("getBucketInfo() should have thrown " + "BUCKET_NOT_FOUND as the parent volume exists but bucket " + "doesn't!", ResultCodes.BUCKET_NOT_FOUND, omEx.getResult());
    }
    OmBucketInfo result = bucketManager.getBucketInfo(volumeName, bucketName);
    Assert.assertEquals(volumeName, result.getVolumeName());
    Assert.assertEquals(bucketName, result.getBucketName());
    Assert.assertEquals(StorageType.DISK, result.getStorageType());
    Assert.assertFalse(result.getIsVersionEnabled());
    metaMgr.getStore().close();
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Test(org.junit.Test)

Example 19 with OmBucketInfo

use of org.apache.hadoop.ozone.om.helpers.OmBucketInfo in project ozone by apache.

the class TestBucketManagerImpl method testSetBucketPropertyChangeStorageType.

@Test
@Ignore("Bucket Manager does not use cache, Disable it for now.")
public void testSetBucketPropertyChangeStorageType() throws Exception {
    OmMetadataManagerImpl metaMgr = createSampleVol();
    BucketManager bucketManager = new BucketManagerImpl(metaMgr);
    OmBucketInfo bucketInfo = OmBucketInfo.newBuilder().setVolumeName("sampleVol").setBucketName("bucketOne").setStorageType(StorageType.DISK).build();
    createBucket(metaMgr, bucketInfo);
    OmBucketInfo result = bucketManager.getBucketInfo("sampleVol", "bucketOne");
    Assert.assertEquals(StorageType.DISK, result.getStorageType());
    OmBucketArgs bucketArgs = OmBucketArgs.newBuilder().setVolumeName("sampleVol").setBucketName("bucketOne").setStorageType(StorageType.SSD).build();
    bucketManager.setBucketProperty(bucketArgs);
    OmBucketInfo updatedResult = bucketManager.getBucketInfo("sampleVol", "bucketOne");
    Assert.assertEquals(StorageType.SSD, updatedResult.getStorageType());
    metaMgr.getStore().close();
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OmBucketArgs(org.apache.hadoop.ozone.om.helpers.OmBucketArgs) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with OmBucketInfo

use of org.apache.hadoop.ozone.om.helpers.OmBucketInfo in project ozone by apache.

the class TestBucketManagerImpl method testCreateAlreadyExistingBucket.

@Test
@Ignore("Bucket Manager does not use cache, Disable it for now.")
public void testCreateAlreadyExistingBucket() throws Exception {
    thrown.expectMessage("Bucket already exist");
    OmMetadataManagerImpl metaMgr = createSampleVol();
    try {
        BucketManager bucketManager = new BucketManagerImpl(metaMgr);
        OmBucketInfo bucketInfo = OmBucketInfo.newBuilder().setVolumeName("sampleVol").setBucketName("bucketOne").build();
        bucketManager.createBucket(bucketInfo);
        bucketManager.createBucket(bucketInfo);
    } catch (OMException omEx) {
        Assert.assertEquals(ResultCodes.BUCKET_ALREADY_EXISTS, omEx.getResult());
        throw omEx;
    } finally {
        metaMgr.getStore().close();
    }
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)138 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)43 IOException (java.io.IOException)38 Test (org.junit.Test)35 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)34 ArrayList (java.util.ArrayList)33 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)33 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)28 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)24 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)16 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)16 RepeatedOmKeyInfo (org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo)14 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)14 Path (java.nio.file.Path)12 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)12 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)11 OmDirectoryInfo (org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo)11 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)11 KeyArgs (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs)11 OmMultipartKeyInfo (org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo)10