Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -596,57 +596,80 @@ public static OmBucketInfo getFromProtobuf(BucketInfo bucketInfo) {
}

/**
* Parses BucketInfo protobuf and creates OmBucketInfo.
* @param bucketInfo
* @return instance of OmBucketInfo
* Create a builder from the given proto.
* @param includeLargeFields Omitted the large fields: acl, metadata, beinfo.
*/
public static OmBucketInfo getFromProtobuf(BucketInfo bucketInfo,
BucketLayout buckLayout) {
Builder obib = OmBucketInfo.newBuilder()
public static Builder newBuilder(BucketInfo bucketInfo, boolean includeLargeFields) {
Builder builder = OmBucketInfo.newBuilder()
.setVolumeName(bucketInfo.getVolumeName())
.setBucketName(bucketInfo.getBucketName())
.setAcls(bucketInfo.getAclsList().stream().map(
OzoneAcl::fromProtobuf).collect(Collectors.toList()))
.setIsVersionEnabled(bucketInfo.getIsVersionEnabled())
.setStorageType(StorageType.valueOf(bucketInfo.getStorageType()))
.setCreationTime(bucketInfo.getCreationTime())
.setUsedBytes(bucketInfo.getUsedBytes())
.setModificationTime(bucketInfo.getModificationTime())
.setQuotaInBytes(bucketInfo.getQuotaInBytes())
.setUsedNamespace(bucketInfo.getUsedNamespace())
.setQuotaInNamespace(bucketInfo.getQuotaInNamespace());
if (buckLayout != null) {
obib.setBucketLayout(buckLayout);
} else if (bucketInfo.getBucketLayout() != null) {
obib.setBucketLayout(
BucketLayout.fromProto(bucketInfo.getBucketLayout()));
.setBucketName(bucketInfo.getBucketName());

if (includeLargeFields) {
// acl
builder.setAcls(bucketInfo.getAclsList().stream().map(
OzoneAcl::fromProtobuf).collect(Collectors.toList()));
}
if (bucketInfo.hasDefaultReplicationConfig()) {
obib.setDefaultReplicationConfig(
DefaultReplicationConfig.fromProto(
bucketInfo.getDefaultReplicationConfig()));
builder.setIsVersionEnabled(bucketInfo.getIsVersionEnabled())
.setStorageType(StorageType.valueOf(bucketInfo.getStorageType()))
.setCreationTime(bucketInfo.getCreationTime());
if (includeLargeFields) {
// metadata
builder.addAllMetadata(KeyValueUtil.getFromProtobuf(bucketInfo.getMetadataList()));

if (bucketInfo.hasBeinfo()) {
// beinfo
builder.setBucketEncryptionKey(OMPBHelper.convert(bucketInfo.getBeinfo()));
}
}

if (bucketInfo.hasObjectID()) {
obib.setObjectID(bucketInfo.getObjectID());
builder.setObjectID(bucketInfo.getObjectID());
}
if (bucketInfo.hasUpdateID()) {
obib.setUpdateID(bucketInfo.getUpdateID());
}
if (bucketInfo.getMetadataList() != null) {
obib.addAllMetadata(KeyValueUtil
.getFromProtobuf(bucketInfo.getMetadataList()));
}
if (bucketInfo.hasBeinfo()) {
obib.setBucketEncryptionKey(OMPBHelper.convert(bucketInfo.getBeinfo()));
builder.setUpdateID(bucketInfo.getUpdateID());
}
builder.setModificationTime(bucketInfo.getModificationTime());
if (bucketInfo.hasSourceVolume()) {
obib.setSourceVolume(bucketInfo.getSourceVolume());
builder.setSourceVolume(bucketInfo.getSourceVolume());
}
if (bucketInfo.hasSourceBucket()) {
obib.setSourceBucket(bucketInfo.getSourceBucket());
builder.setSourceBucket(bucketInfo.getSourceBucket());
}
builder.setUsedBytes(bucketInfo.getUsedBytes())
.setQuotaInBytes(bucketInfo.getQuotaInBytes())
.setQuotaInNamespace(bucketInfo.getQuotaInNamespace())
.setUsedNamespace(bucketInfo.getUsedNamespace());

if (bucketInfo.hasBucketLayout()) {
builder.setBucketLayout(BucketLayout.fromProto(bucketInfo.getBucketLayout()));
}
if (bucketInfo.hasOwner()) {
obib.setOwner(bucketInfo.getOwner());
builder.setOwner(bucketInfo.getOwner());
}
if (bucketInfo.hasDefaultReplicationConfig()) {
builder.setDefaultReplicationConfig(
DefaultReplicationConfig.fromProto(bucketInfo.getDefaultReplicationConfig()));
}
return builder;
}

/**
* Creates an {@link OmBucketInfo} instance from the given {@link BucketInfo} protobuf,
* optionally overriding the {@link BucketLayout}.
* <p>
* This method deserializes all fields including ACLs from the protobuf.
*
* @param bucketInfo The protobuf {@link BucketInfo} received from Ozone Manager.
* @param buckLayout The {@link BucketLayout} to override in the resulting {@link OmBucketInfo}.
* If null, the layout from the protobuf is retained.
* @return An {@link OmBucketInfo} instance built from the provided protobuf,
* with the specified bucket layout if provided.
*/
public static OmBucketInfo getFromProtobuf(BucketInfo bucketInfo,
BucketLayout buckLayout) {
Builder obib = OmBucketInfo.newBuilder(bucketInfo, true);
if (buckLayout != null) {
obib.setBucketLayout(buckLayout);
}
return obib.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,34 +208,43 @@ public DirectoryInfo getProtobuf() {
return pib.build();
}

/**
* Parses DirectoryInfo protobuf and creates OmPrefixInfo.
* @param dirInfo
* @return instance of OmDirectoryInfo
*/
public static OmDirectoryInfo getFromProtobuf(DirectoryInfo dirInfo) {
public static Builder newBuilder(DirectoryInfo dirInfo, boolean includeLargeFields) {
OmDirectoryInfo.Builder opib = OmDirectoryInfo.newBuilder()
.setName(dirInfo.getName())
.setCreationTime(dirInfo.getCreationTime())
.setModificationTime(dirInfo.getModificationTime())
.setAcls(OzoneAclUtil.fromProtobuf(dirInfo.getAclsList()));
if (dirInfo.getMetadataList() != null) {
opib.addAllMetadata(KeyValueUtil
.getFromProtobuf(dirInfo.getMetadataList()));
.setName(dirInfo.getName())
.setCreationTime(dirInfo.getCreationTime())
.setModificationTime(dirInfo.getModificationTime());

if (includeLargeFields) {
if (dirInfo.getMetadataList() != null) {
opib.addAllMetadata(KeyValueUtil.getFromProtobuf(dirInfo.getMetadataList()));
}
opib.setAcls(OzoneAclUtil.fromProtobuf(dirInfo.getAclsList()));
}
if (dirInfo.hasObjectID()) {
opib.setObjectID(dirInfo.getObjectID());
}
if (dirInfo.hasParentID()) {
opib.setParentObjectID(dirInfo.getParentID());
}
if (dirInfo.hasUpdateID()) {
opib.setUpdateID(dirInfo.getUpdateID());
}
if (dirInfo.hasParentID()) {
opib.setParentObjectID(dirInfo.getParentID());
}
if (dirInfo.hasOwnerName()) {
opib.setOwner(dirInfo.getOwnerName());
}
return opib.build();
return opib;
}

/**
* Creates an {@link OmDirectoryInfo} instance from the given {@link DirectoryInfo} protobuf.
* <p>
* This method deserializes all fields, including ACLs, from the provided protobuf message.
*
* @param dirInfo The {@link DirectoryInfo} protobuf received from Ozone Manager.
* @return An {@link OmDirectoryInfo} instance fully constructed from the protobuf.
*/
public static OmDirectoryInfo getFromProtobuf(DirectoryInfo dirInfo) {
return OmDirectoryInfo.newBuilder(dirInfo, true).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ private KeyInfo getProtobuf(boolean ignorePipeline, String fullKeyName,
return kb.build();
}

public static OmKeyInfo getFromProtobuf(KeyInfo keyInfo) {
public static Builder newBuilder(KeyInfo keyInfo, boolean includeLargeFields) {
if (keyInfo == null) {
return null;
}
Expand All @@ -745,18 +745,19 @@ public static OmKeyInfo getFromProtobuf(KeyInfo keyInfo) {
.setVolumeName(keyInfo.getVolumeName())
.setBucketName(keyInfo.getBucketName())
.setKeyName(keyInfo.getKeyName())
.setOmKeyLocationInfos(omKeyLocationInfos)
.setDataSize(keyInfo.getDataSize())
.setCreationTime(keyInfo.getCreationTime())
.setModificationTime(keyInfo.getModificationTime())
.setOmKeyLocationInfos(omKeyLocationInfos)
.setReplicationConfig(ReplicationConfig
.fromProto(keyInfo.getType(), keyInfo.getFactor(),
keyInfo.getEcReplicationConfig()))
.addAllMetadata(KeyValueUtil.getFromProtobuf(keyInfo.getMetadataList()))
.addAllTags(KeyValueUtil.getFromProtobuf(keyInfo.getTagsList()))
.setFileEncryptionInfo(keyInfo.hasFileEncryptionInfo() ?
OMPBHelper.convert(keyInfo.getFileEncryptionInfo()) : null)
.setAcls(OzoneAclUtil.fromProtobuf(keyInfo.getAclsList()));
keyInfo.getEcReplicationConfig()));
builder.setCreationTime(keyInfo.getCreationTime())
.setModificationTime(keyInfo.getModificationTime());
if (includeLargeFields) {
builder.addAllMetadata(KeyValueUtil.getFromProtobuf(keyInfo.getMetadataList()))
.setFileEncryptionInfo(keyInfo.hasFileEncryptionInfo() ?
OMPBHelper.convert(keyInfo.getFileEncryptionInfo()) : null)
.setAcls(OzoneAclUtil.fromProtobuf(keyInfo.getAclsList()));
}
if (keyInfo.hasObjectID()) {
builder.setObjectID(keyInfo.getObjectID());
}
Expand All @@ -766,24 +767,31 @@ public static OmKeyInfo getFromProtobuf(KeyInfo keyInfo) {
if (keyInfo.hasParentID()) {
builder.setParentObjectID(keyInfo.getParentID());
}
if (keyInfo.hasFileChecksum()) {
FileChecksum fileChecksum = OMPBHelper.convert(keyInfo.getFileChecksum());
builder.setFileChecksum(fileChecksum);
if (includeLargeFields) {
if (keyInfo.hasFileChecksum()) {
FileChecksum fileChecksum = OMPBHelper.convert(keyInfo.getFileChecksum());
builder.setFileChecksum(fileChecksum);
}
}

if (keyInfo.hasIsFile()) {
builder.setFile(keyInfo.getIsFile());
}
if (keyInfo.hasExpectedDataGeneration()) {
builder.setExpectedDataGeneration(keyInfo.getExpectedDataGeneration());
}

if (keyInfo.hasOwnerName()) {
builder.setOwnerName(keyInfo.getOwnerName());
}
if (includeLargeFields) {
builder.addAllTags(KeyValueUtil.getFromProtobuf(keyInfo.getTagsList()));
if (keyInfo.hasExpectedDataGeneration()) {
builder.setExpectedDataGeneration(keyInfo.getExpectedDataGeneration());
}
}
// not persisted to DB. FileName will be filtered out from keyName
builder.setFileName(OzoneFSUtils.getFileName(keyInfo.getKeyName()));
return builder.build();
return builder;
}

public static OmKeyInfo getFromProtobuf(KeyInfo keyInfo) {
return OmKeyInfo.newBuilder(keyInfo, true).build();
}

@Override
Expand Down
Loading