Skip to content

Commit

Permalink
HDDS-10394. Fix parameter number warning in om.helpers (#6271)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai authored Feb 26, 2024
1 parent 84c6e4d commit 50d43e8
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 404 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,37 @@
/**
* Lightweight OmKeyInfo class.
*/
public class BasicOmKeyInfo {

private String volumeName;
private String bucketName;
private String keyName;
private long dataSize;
private long creationTime;
private long modificationTime;
private ReplicationConfig replicationConfig;
private boolean isFile;

@SuppressWarnings("parameternumber")
public BasicOmKeyInfo(String volumeName, String bucketName, String keyName,
long dataSize, long creationTime, long modificationTime,
ReplicationConfig replicationConfig, boolean isFile) {
this.volumeName = volumeName;
this.bucketName = bucketName;
this.keyName = keyName;
this.dataSize = dataSize;
this.creationTime = creationTime;
this.modificationTime = modificationTime;
this.replicationConfig = replicationConfig;
this.isFile = isFile;
public final class BasicOmKeyInfo {

private final String volumeName;
private final String bucketName;
private final String keyName;
private final long dataSize;
private final long creationTime;
private final long modificationTime;
private final ReplicationConfig replicationConfig;
private final boolean isFile;

private BasicOmKeyInfo(Builder b) {
this.volumeName = b.volumeName;
this.bucketName = b.bucketName;
this.keyName = b.keyName;
this.dataSize = b.dataSize;
this.creationTime = b.creationTime;
this.modificationTime = b.modificationTime;
this.replicationConfig = b.replicationConfig;
this.isFile = b.isFile;
}

private BasicOmKeyInfo(OmKeyInfo b) {
this.volumeName = b.getVolumeName();
this.bucketName = b.getBucketName();
this.keyName = b.getKeyName();
this.dataSize = b.getDataSize();
this.creationTime = b.getCreationTime();
this.modificationTime = b.getModificationTime();
this.replicationConfig = b.getReplicationConfig();
this.isFile = b.isFile();
}

public String getVolumeName() {
Expand Down Expand Up @@ -139,8 +147,7 @@ public Builder setIsFile(boolean isFile) {
}

public BasicOmKeyInfo build() {
return new BasicOmKeyInfo(volumeName, bucketName, keyName, dataSize,
creationTime, modificationTime, replicationConfig, isFile);
return new BasicOmKeyInfo(this);
}
}

Expand Down Expand Up @@ -233,14 +240,6 @@ public int hashCode() {
}

public static BasicOmKeyInfo fromOmKeyInfo(OmKeyInfo omKeyInfo) {
return new BasicOmKeyInfo(
omKeyInfo.getVolumeName(),
omKeyInfo.getBucketName(),
omKeyInfo.getKeyName(),
omKeyInfo.getDataSize(),
omKeyInfo.getCreationTime(),
omKeyInfo.getModificationTime(),
omKeyInfo.getReplicationConfig(),
omKeyInfo.isFile());
return new BasicOmKeyInfo(omKeyInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.ozone.om.helpers;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

Expand Down Expand Up @@ -44,44 +45,40 @@ public final class OmBucketArgs extends WithMetadata implements Auditable {
/**
* Bucket Version flag.
*/
private Boolean isVersionEnabled;
private final Boolean isVersionEnabled;
/**
* Type of storage to be used for this bucket.
* [RAM_DISK, SSD, DISK, ARCHIVE]
*/
private StorageType storageType;
private final StorageType storageType;

/**
* Bucket encryption key info if encryption is enabled.
*/
private BucketEncryptionKeyInfo bekInfo;
private long quotaInBytes = OzoneConsts.QUOTA_RESET;
private long quotaInNamespace = OzoneConsts.QUOTA_RESET;
private boolean quotaInBytesSet = false;
private boolean quotaInNamespaceSet = false;
private DefaultReplicationConfig defaultReplicationConfig = null;
private final BucketEncryptionKeyInfo bekInfo;
private final long quotaInBytes;
private final long quotaInNamespace;
private final boolean quotaInBytesSet;
private final boolean quotaInNamespaceSet;
private final DefaultReplicationConfig defaultReplicationConfig;
/**
* Bucket Owner Name.
*/
private String ownerName;

/**
* Private constructor, constructed via builder.
* @param volumeName - Volume name.
* @param bucketName - Bucket name.
* @param isVersionEnabled - Bucket version flag.
* @param storageType - Storage type to be used.
*/
@SuppressWarnings("checkstyle:ParameterNumber")
private OmBucketArgs(String volumeName, String bucketName,
Boolean isVersionEnabled, StorageType storageType,
Map<String, String> metadata, String ownerName) {
this.volumeName = volumeName;
this.bucketName = bucketName;
this.isVersionEnabled = isVersionEnabled;
this.storageType = storageType;
setMetadata(metadata);
this.ownerName = ownerName;
private final String ownerName;

private OmBucketArgs(Builder b) {
setMetadata(b.metadata);
this.volumeName = b.volumeName;
this.bucketName = b.bucketName;
this.isVersionEnabled = b.isVersionEnabled;
this.storageType = b.storageType;
this.ownerName = b.ownerName;
this.defaultReplicationConfig = b.defaultReplicationConfig;
this.quotaInBytesSet = b.quotaInBytesSet;
this.quotaInBytes = quotaInBytesSet ? b.quotaInBytes : OzoneConsts.QUOTA_RESET;
this.quotaInNamespaceSet = b.quotaInNamespaceSet;
this.quotaInNamespace = quotaInNamespaceSet ? b.quotaInNamespace : OzoneConsts.QUOTA_RESET;
this.bekInfo = b.bekInfo;
}

/**
Expand Down Expand Up @@ -149,7 +146,6 @@ public boolean hasQuotaInNamespace() {

/**
* Returns Bucket default replication config.
* @return
*/
public DefaultReplicationConfig getDefaultReplicationConfig() {
return defaultReplicationConfig;
Expand All @@ -159,30 +155,6 @@ public BucketEncryptionKeyInfo getBucketEncryptionKeyInfo() {
return bekInfo;
}

/**
* Sets the Bucket default replication config.
*/
private void setDefaultReplicationConfig(
DefaultReplicationConfig defaultReplicationConfig) {
this.defaultReplicationConfig = defaultReplicationConfig;
}

private void setQuotaInBytes(long quotaInBytes) {
this.quotaInBytesSet = true;
this.quotaInBytes = quotaInBytes;
}

private void setQuotaInNamespace(long quotaInNamespace) {
this.quotaInNamespaceSet = true;
this.quotaInNamespace = quotaInNamespace;
}

@Deprecated
private void setBucketEncryptionKey(
BucketEncryptionKeyInfo bucketEncryptionKey) {
this.bekInfo = bucketEncryptionKey;
}

/**
* Returns Bucket Owner Name.
*
Expand Down Expand Up @@ -226,7 +198,7 @@ public static class Builder {
private String bucketName;
private Boolean isVersionEnabled;
private StorageType storageType;
private Map<String, String> metadata;
private final Map<String, String> metadata = new HashMap<>();
private boolean quotaInBytesSet = false;
private long quotaInBytes;
private boolean quotaInNamespaceSet = false;
Expand Down Expand Up @@ -259,12 +231,14 @@ public Builder setIsVersionEnabled(Boolean versionFlag) {

@Deprecated
public Builder setBucketEncryptionKey(BucketEncryptionKeyInfo info) {
this.bekInfo = info;
if (info == null || info.getKeyName() != null) {
this.bekInfo = info;
}
return this;
}

public Builder addMetadata(Map<String, String> metadataMap) {
this.metadata = metadataMap;
public Builder addAllMetadata(Map<String, String> map) {
metadata.putAll(map);
return this;
}

Expand Down Expand Up @@ -303,20 +277,7 @@ public Builder setOwnerName(String owner) {
public OmBucketArgs build() {
Preconditions.checkNotNull(volumeName);
Preconditions.checkNotNull(bucketName);
OmBucketArgs omBucketArgs =
new OmBucketArgs(volumeName, bucketName, isVersionEnabled,
storageType, metadata, ownerName);
omBucketArgs.setDefaultReplicationConfig(defaultReplicationConfig);
if (quotaInBytesSet) {
omBucketArgs.setQuotaInBytes(quotaInBytes);
}
if (quotaInNamespaceSet) {
omBucketArgs.setQuotaInNamespace(quotaInNamespace);
}
if (bekInfo != null && bekInfo.getKeyName() != null) {
omBucketArgs.setBucketEncryptionKey(bekInfo);
}
return omBucketArgs;
return new OmBucketArgs(this);
}
}

Expand Down Expand Up @@ -348,7 +309,7 @@ public BucketArgs getProtobuf() {
builder.setOwnerName(ownerName);
}

if (bekInfo != null && bekInfo.getKeyName() != null) {
if (bekInfo != null) {
builder.setBekInfo(OMPBHelper.convert(bekInfo));
}

Expand All @@ -357,39 +318,42 @@ public BucketArgs getProtobuf() {

/**
* Parses BucketInfo protobuf and creates OmBucketArgs.
* @param bucketArgs
* @return instance of OmBucketArgs
*/
public static OmBucketArgs getFromProtobuf(BucketArgs bucketArgs) {
OmBucketArgs omBucketArgs =
new OmBucketArgs(bucketArgs.getVolumeName(),
bucketArgs.getBucketName(),
bucketArgs.hasIsVersionEnabled() ?
bucketArgs.getIsVersionEnabled() : null,
bucketArgs.hasStorageType() ? StorageType.valueOf(
bucketArgs.getStorageType()) : null,
KeyValueUtil.getFromProtobuf(bucketArgs.getMetadataList()),
bucketArgs.hasOwnerName() ?
bucketArgs.getOwnerName() : null);
// OmBucketArgs ctor already has more arguments, so setting the default
// replication config separately.
final OmBucketArgs.Builder builder = newBuilder()
.setVolumeName(bucketArgs.getVolumeName())
.setBucketName(bucketArgs.getBucketName())
.addAllMetadata(KeyValueUtil.getFromProtobuf(bucketArgs.getMetadataList()));

if (bucketArgs.hasIsVersionEnabled()) {
builder.setIsVersionEnabled(bucketArgs.getIsVersionEnabled());
}
if (bucketArgs.hasStorageType()) {
builder.setStorageType(StorageType.valueOf(bucketArgs.getStorageType()));
}
if (bucketArgs.hasOwnerName()) {
builder.setOwnerName(bucketArgs.getOwnerName());
}

if (bucketArgs.hasDefaultReplicationConfig()) {
omBucketArgs.setDefaultReplicationConfig(
builder.setDefaultReplicationConfig(
DefaultReplicationConfig.fromProto(
bucketArgs.getDefaultReplicationConfig()));
}

if (bucketArgs.hasQuotaInBytes()) {
omBucketArgs.setQuotaInBytes(bucketArgs.getQuotaInBytes());
builder.setQuotaInBytes(bucketArgs.getQuotaInBytes());
}
if (bucketArgs.hasQuotaInNamespace()) {
omBucketArgs.setQuotaInNamespace(bucketArgs.getQuotaInNamespace());
builder.setQuotaInNamespace(bucketArgs.getQuotaInNamespace());
}

if (bucketArgs.hasBekInfo()) {
omBucketArgs.setBucketEncryptionKey(
builder.setBucketEncryptionKey(
OMPBHelper.convert(bucketArgs.getBekInfo()));
}
return omBucketArgs;

return builder.build();
}
}
Loading

0 comments on commit 50d43e8

Please sign in to comment.