use of org.apache.hadoop.ozone.om.helpers.OmKeyInfo.Builder in project ozone by apache.
the class GeneratorOm method addDirectoryKey.
private void addDirectoryKey(String keyName, BatchOperation omKeyTableBatchOperation) throws IOException {
OmKeyInfo l3DirInfo = new Builder().setVolumeName(volumeName).setBucketName(bucketName).setKeyName(keyName).setDataSize(0).setCreationTime(System.currentTimeMillis()).setModificationTime(System.currentTimeMillis()).setReplicationConfig(RatisReplicationConfig.getInstance(ReplicationFactor.ONE)).build();
omKeyTable.putWithBatch(omKeyTableBatchOperation, "/" + volumeName + "/" + bucketName + "/" + keyName, l3DirInfo);
}
use of org.apache.hadoop.ozone.om.helpers.OmKeyInfo.Builder in project ozone by apache.
the class TestOmKeyInfo method createdAndTest.
private void createdAndTest(boolean isMPU) {
OmKeyInfo key = new Builder().setKeyName("key1").setBucketName("bucket").setVolumeName("vol1").setCreationTime(Time.now()).setModificationTime(Time.now()).setDataSize(100L).setReplicationConfig(RatisReplicationConfig.getInstance(ReplicationFactor.THREE)).addMetadata("key1", "value1").addMetadata("key2", "value2").setOmKeyLocationInfos(Collections.singletonList(createOmKeyLocationInfoGroup(isMPU))).build();
OmKeyInfo cloneKey = key.copyObject();
// Because for OmKeyLocationInfoGroup we have not implemented equals()
// method, so it checks only references.
Assert.assertNotEquals(key, cloneKey);
// Check each version content here.
Assert.assertEquals(key.getKeyLocationVersions().size(), cloneKey.getKeyLocationVersions().size());
// Check blocks for each version.
for (int i = 0; i < key.getKeyLocationVersions().size(); i++) {
OmKeyLocationInfoGroup orig = key.getKeyLocationVersions().get(i);
OmKeyLocationInfoGroup clone = key.getKeyLocationVersions().get(i);
Assert.assertEquals(orig.isMultipartKey(), clone.isMultipartKey());
Assert.assertEquals(orig.getVersion(), clone.getVersion());
Assert.assertEquals(orig.getLocationList().size(), clone.getLocationList().size());
for (int j = 0; j < orig.getLocationList().size(); j++) {
OmKeyLocationInfo origLocationInfo = orig.getLocationList().get(j);
OmKeyLocationInfo cloneLocationInfo = clone.getLocationList().get(j);
Assert.assertEquals(origLocationInfo, cloneLocationInfo);
}
}
key.setAcls(Arrays.asList(new OzoneAcl(IAccessAuthorizer.ACLIdentityType.USER, "user1", IAccessAuthorizer.ACLType.WRITE, ACCESS)));
// Change acls and check.
Assert.assertNotEquals(key, cloneKey);
Assert.assertNotEquals(key.getAcls(), cloneKey.getAcls());
// clone now again
cloneKey = key.copyObject();
Assert.assertEquals(key.getAcls(), cloneKey.getAcls());
}
use of org.apache.hadoop.ozone.om.helpers.OmKeyInfo.Builder in project ozone by apache.
the class GeneratorOm method writeOmData.
private void writeOmData(long l, BlockID blockId, BatchOperation omKeyTableBatchOperation) throws IOException {
List<OmKeyLocationInfo> omkl = new ArrayList<>();
omkl.add(new OmKeyLocationInfo.Builder().setBlockID(blockId).setLength(getKeySize()).setOffset(0).build());
OmKeyLocationInfoGroup infoGroup = new OmKeyLocationInfoGroup(0, omkl);
long l4n = l % 1_000;
long l3n = l / 1_000 % 1_000;
long l2n = l / 1_000_000 % 1_000;
long l1n = l / 1_000_000_000 % 1_000;
String level3 = "L3-" + l3n;
String level2 = "L2-" + l2n;
String level1 = "L1-" + l1n;
if (l2n == 0 && l3n == 0 && l4n == 0) {
// create l1 directory
addDirectoryKey(level1 + "/", omKeyTableBatchOperation);
}
if (l3n == 0 && l4n == 0) {
// create l2 directory
addDirectoryKey(level1 + "/" + level2 + "/", omKeyTableBatchOperation);
}
if (l4n == 0) {
// create l3 directory
addDirectoryKey(level1 + "/" + level2 + "/" + level3 + "/", omKeyTableBatchOperation);
}
String keyName = "/vol1/bucket1/" + level1 + "/" + level2 + "/" + level3 + "/key" + l;
OmKeyInfo keyInfo = new Builder().setVolumeName(volumeName).setBucketName(bucketName).setKeyName(level1 + "/" + level2 + "/" + level3 + "/key" + l).setDataSize(getKeySize()).setCreationTime(System.currentTimeMillis()).setModificationTime(System.currentTimeMillis()).setReplicationConfig(StandaloneReplicationConfig.getInstance(ReplicationFactor.THREE)).addOmKeyLocationInfoGroup(infoGroup).build();
omKeyTable.putWithBatch(omKeyTableBatchOperation, keyName, keyInfo);
}
Aggregations