use of org.apache.hadoop.ozone.client.VolumeArgs in project ozone by apache.
the class TestOzoneManagerHA method createKeyTest.
protected void createKeyTest(boolean checkSuccess) throws Exception {
String userName = "user" + RandomStringUtils.randomNumeric(5);
String adminName = "admin" + RandomStringUtils.randomNumeric(5);
String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
VolumeArgs createVolumeArgs = VolumeArgs.newBuilder().setOwner(userName).setAdmin(adminName).build();
try {
getObjectStore().createVolume(volumeName, createVolumeArgs);
OzoneVolume retVolumeinfo = getObjectStore().getVolume(volumeName);
Assert.assertTrue(retVolumeinfo.getName().equals(volumeName));
Assert.assertTrue(retVolumeinfo.getOwner().equals(userName));
Assert.assertTrue(retVolumeinfo.getAdmin().equals(adminName));
String bucketName = UUID.randomUUID().toString();
String keyName = UUID.randomUUID().toString();
retVolumeinfo.createBucket(bucketName);
OzoneBucket ozoneBucket = retVolumeinfo.getBucket(bucketName);
Assert.assertTrue(ozoneBucket.getName().equals(bucketName));
Assert.assertTrue(ozoneBucket.getVolumeName().equals(volumeName));
String value = "random data";
OzoneOutputStream ozoneOutputStream = ozoneBucket.createKey(keyName, value.length(), ReplicationType.RATIS, ReplicationFactor.ONE, new HashMap<>());
ozoneOutputStream.write(value.getBytes(UTF_8), 0, value.length());
ozoneOutputStream.close();
OzoneInputStream ozoneInputStream = ozoneBucket.readKey(keyName);
byte[] fileContent = new byte[value.getBytes(UTF_8).length];
ozoneInputStream.read(fileContent);
Assert.assertEquals(value, new String(fileContent, UTF_8));
} catch (ConnectException | RemoteException e) {
if (!checkSuccess) {
// last running OM as it would fail to get a quorum.
if (e instanceof RemoteException) {
GenericTestUtils.assertExceptionContains("OMNotLeaderException", e);
}
} else {
throw e;
}
}
}
use of org.apache.hadoop.ozone.client.VolumeArgs in project ozone by apache.
the class TestOzoneManagerHA method setupBucket.
protected OzoneBucket setupBucket() throws Exception {
String userName = "user" + RandomStringUtils.randomNumeric(5);
String adminName = "admin" + RandomStringUtils.randomNumeric(5);
String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
VolumeArgs createVolumeArgs = VolumeArgs.newBuilder().setOwner(userName).setAdmin(adminName).build();
objectStore.createVolume(volumeName, createVolumeArgs);
OzoneVolume retVolumeinfo = objectStore.getVolume(volumeName);
Assert.assertTrue(retVolumeinfo.getName().equals(volumeName));
Assert.assertTrue(retVolumeinfo.getOwner().equals(userName));
Assert.assertTrue(retVolumeinfo.getAdmin().equals(adminName));
String bucketName = UUID.randomUUID().toString();
retVolumeinfo.createBucket(bucketName);
OzoneBucket ozoneBucket = retVolumeinfo.getBucket(bucketName);
Assert.assertTrue(ozoneBucket.getName().equals(bucketName));
Assert.assertTrue(ozoneBucket.getVolumeName().equals(volumeName));
return ozoneBucket;
}
use of org.apache.hadoop.ozone.client.VolumeArgs 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.VolumeArgs in project ozone by apache.
the class TestOzoneRpcClientAbstract method testSetVolumeQuotaIllegal.
@Test
public void testSetVolumeQuotaIllegal() throws Exception {
String volumeName = UUID.randomUUID().toString();
VolumeArgs volumeArgs = VolumeArgs.newBuilder().addMetadata("key1", "val1").setQuotaInNamespace(0).setQuotaInBytes(0).build();
LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for quota", () -> store.createVolume(volumeName, volumeArgs));
store.createVolume(volumeName);
// test volume set quota 0
LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for space quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("0GB", "10")));
LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for namespace quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("10GB", "0")));
// The unit should be legal.
LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("1TEST", "1000")));
// The setting value cannot be greater than LONG.MAX_VALUE BYTES.
LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("9223372036854775808 B", "1000")));
// The value cannot be negative.
LambdaTestUtils.intercept(IllegalArgumentException.class, "Invalid values for space quota", () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota("-10GB", "1000")));
}
use of org.apache.hadoop.ozone.client.VolumeArgs in project ozone by apache.
the class TestOzoneRpcClientAbstract method testCreateVolumeWithMetadata.
@Test
public void testCreateVolumeWithMetadata() throws IOException, OzoneClientException {
String volumeName = UUID.randomUUID().toString();
VolumeArgs volumeArgs = VolumeArgs.newBuilder().addMetadata("key1", "val1").build();
store.createVolume(volumeName, volumeArgs);
OzoneVolume volume = store.getVolume(volumeName);
Assert.assertEquals(OzoneConsts.QUOTA_RESET, volume.getQuotaInNamespace());
Assert.assertEquals(OzoneConsts.QUOTA_RESET, volume.getQuotaInBytes());
Assert.assertEquals("val1", volume.getMetadata().get("key1"));
Assert.assertEquals(volumeName, volume.getName());
}
Aggregations