Search in sources :

Example 1 with Builder

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);
}
Also used : Builder(org.apache.hadoop.ozone.om.helpers.OmKeyInfo.Builder) DBStoreBuilder(org.apache.hadoop.hdds.utils.db.DBStoreBuilder) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo)

Example 2 with Builder

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());
}
Also used : OzoneAcl(org.apache.hadoop.ozone.OzoneAcl) Builder(org.apache.hadoop.ozone.om.helpers.OmKeyInfo.Builder)

Example 3 with Builder

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);
}
Also used : OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) Builder(org.apache.hadoop.ozone.om.helpers.OmKeyInfo.Builder) DBStoreBuilder(org.apache.hadoop.hdds.utils.db.DBStoreBuilder) ArrayList(java.util.ArrayList) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OmKeyLocationInfo(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)

Aggregations

Builder (org.apache.hadoop.ozone.om.helpers.OmKeyInfo.Builder)3 DBStoreBuilder (org.apache.hadoop.hdds.utils.db.DBStoreBuilder)2 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)2 ArrayList (java.util.ArrayList)1 OzoneAcl (org.apache.hadoop.ozone.OzoneAcl)1 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)1 OmKeyLocationInfoGroup (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup)1