This is an automated email from the ASF dual-hosted git repository.
captainzmc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new b3b0538597 HDDS-4223. Optimize the construction method of OzoneVolume
and OzoneBucket. (#4262)
b3b0538597 is described below
commit b3b05385975bcbf576b11a55881055c96fdf1eac
Author: Hongbing Wang <[email protected]>
AuthorDate: Thu Feb 16 17:07:01 2023 +0800
HDDS-4223. Optimize the construction method of OzoneVolume and OzoneBucket.
(#4262)
Co-authored-by: wanghongbing <[email protected]>
---
.../apache/hadoop/ozone/client/OzoneBucket.java | 332 ++++++++++-----------
.../apache/hadoop/ozone/client/OzoneVolume.java | 232 +++++++-------
.../apache/hadoop/ozone/client/rpc/RpcClient.java | 162 +++++-----
.../hadoop/ozone/client/ObjectStoreStub.java | 17 +-
.../hadoop/ozone/client/OzoneBucketStub.java | 78 +++--
.../hadoop/ozone/client/OzoneVolumeStub.java | 86 +++++-
6 files changed, 495 insertions(+), 412 deletions(-)
diff --git
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java
index 19bbfbeef1..2aa051ff84 100644
---
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java
+++
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java
@@ -19,7 +19,6 @@
package org.apache.hadoop.ozone.client;
import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -48,7 +47,6 @@ import org.apache.hadoop.ozone.om.helpers.WithMetadata;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.security.acl.OzoneObj;
import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
-import org.apache.hadoop.util.Time;
import java.io.IOException;
import java.time.Instant;
@@ -151,188 +149,45 @@ public class OzoneBucket extends WithMetadata {
*/
private String owner;
- private OzoneBucket(ConfigurationSource conf, String volumeName,
- String bucketName, ClientProtocol proxy) {
- Preconditions.checkNotNull(proxy, "Client proxy is not set.");
- this.volumeName = volumeName;
- this.name = bucketName;
-
+ protected OzoneBucket(Builder builder) {
+ this.metadata = builder.metadata;
+ this.proxy = builder.proxy;
+ this.volumeName = builder.volumeName;
+ this.name = builder.name; // bucket name
// Bucket level replication is not configured by default.
- this.defaultReplication = null;
-
- this.proxy = proxy;
- this.ozoneObj = OzoneObjInfo.Builder.newBuilder()
- .setBucketName(bucketName)
- .setVolumeName(volumeName)
- .setResType(OzoneObj.ResourceType.BUCKET)
- .setStoreType(OzoneObj.StoreType.OZONE).build();
- }
-
- @SuppressWarnings("parameternumber")
- public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
- String volumeName, String bucketName, StorageType storageType,
- Boolean versioning, long creationTime, Map<String, String> metadata,
- String encryptionKeyName,
- String sourceVolume, String sourceBucket) {
- this(conf, volumeName, bucketName, proxy);
- this.storageType = storageType;
- this.versioning = versioning;
- this.listCacheSize = HddsClientUtils.getListCacheSize(conf);
- this.creationTime = Instant.ofEpochMilli(creationTime);
- this.metadata = metadata;
- this.encryptionKeyName = encryptionKeyName;
- this.sourceVolume = sourceVolume;
- this.sourceBucket = sourceBucket;
- modificationTime = Instant.now();
- if (modificationTime.isBefore(this.creationTime)) {
- modificationTime = Instant.ofEpochSecond(
- this.creationTime.getEpochSecond(), this.creationTime.getNano());
+ this.defaultReplication = builder.defaultReplicationConfig != null ?
+ builder.defaultReplicationConfig.getReplicationConfig() : null;
+ this.storageType = builder.storageType;
+ this.versioning = builder.versioning;
+ if (builder.conf != null) {
+ this.listCacheSize = HddsClientUtils.getListCacheSize(builder.conf);
}
- }
-
- @SuppressWarnings("parameternumber")
- public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
- String volumeName, String bucketName, StorageType storageType,
- Boolean versioning, long creationTime, long modificationTime,
- Map<String, String> metadata, String encryptionKeyName,
- String sourceVolume, String sourceBucket) {
- this(conf, proxy, volumeName, bucketName, storageType, versioning,
- creationTime, metadata, encryptionKeyName, sourceVolume, sourceBucket);
- this.modificationTime = Instant.ofEpochMilli(modificationTime);
- }
-
- @SuppressWarnings("parameternumber")
- public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
- String volumeName, String bucketName, StorageType storageType,
- Boolean versioning, long creationTime, long modificationTime,
- Map<String, String> metadata, String encryptionKeyName,
- String sourceVolume, String sourceBucket, long usedBytes,
- long usedNamespace, long quotaInBytes, long quotaInNamespace) {
- this(conf, proxy, volumeName, bucketName, storageType, versioning,
- creationTime, metadata, encryptionKeyName, sourceVolume, sourceBucket);
- this.usedBytes = usedBytes;
- this.usedNamespace = usedNamespace;
- this.modificationTime = Instant.ofEpochMilli(modificationTime);
- this.quotaInBytes = quotaInBytes;
- this.quotaInNamespace = quotaInNamespace;
- }
-
- @SuppressWarnings("parameternumber")
- public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
- String volumeName, String bucketName, StorageType storageType,
- Boolean versioning, long creationTime, long modificationTime,
- Map<String, String> metadata, String encryptionKeyName,
- String sourceVolume, String sourceBucket, long usedBytes,
- long usedNamespace, long quotaInBytes, long quotaInNamespace,
- BucketLayout bucketLayout) {
- this(conf, proxy, volumeName, bucketName, storageType, versioning,
- creationTime, modificationTime, metadata, encryptionKeyName,
- sourceVolume, sourceBucket, usedBytes, usedNamespace, quotaInBytes,
- quotaInNamespace);
- this.bucketLayout = bucketLayout;
- }
-
- @SuppressWarnings("parameternumber")
- public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
- String volumeName, String bucketName, StorageType storageType,
- Boolean versioning, long creationTime, long modificationTime,
- Map<String, String> metadata, String encryptionKeyName,
- String sourceVolume, String sourceBucket, long usedBytes,
- long usedNamespace, long quotaInBytes, long quotaInNamespace,
- BucketLayout bucketLayout, String owner,
- DefaultReplicationConfig defaultReplicationConfig) {
- this(conf, proxy, volumeName, bucketName, storageType, versioning,
- creationTime, modificationTime, metadata, encryptionKeyName,
- sourceVolume, sourceBucket, usedBytes, usedNamespace, quotaInBytes,
- quotaInNamespace, bucketLayout, owner);
- this.bucketLayout = bucketLayout;
- if (defaultReplicationConfig != null) {
- defaultReplication = defaultReplicationConfig.getReplicationConfig();
+ this.usedBytes = builder.usedBytes;
+ this.usedNamespace = builder.usedNamespace;
+ this.creationTime = Instant.ofEpochMilli(builder.creationTime);
+ if (builder.modificationTime != 0) {
+ this.modificationTime = Instant.ofEpochMilli(builder.modificationTime);
} else {
- // Bucket level replication is not configured by default.
- this.defaultReplication = null;
- }
- }
-
- @SuppressWarnings("checkstyle:ParameterNumber")
- public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
- String volumeName, String bucketName, StorageType storageType,
- Boolean versioning, long creationTime, long modificationTime,
- Map<String, String> metadata, String encryptionKeyName,
- String sourceVolume, String sourceBucket, long usedBytes,
- long usedNamespace, long quotaInBytes, long quotaInNamespace,
- BucketLayout bucketLayout, String owner) {
- this(conf, proxy, volumeName, bucketName, storageType, versioning,
- creationTime, modificationTime, metadata, encryptionKeyName,
- sourceVolume, sourceBucket, usedBytes, usedNamespace, quotaInBytes,
- quotaInNamespace, bucketLayout);
- this.owner = owner;
- }
-
- /**
- * Constructs OzoneBucket instance.
- * @param conf Configuration object.
- * @param proxy ClientProtocol proxy.
- * @param volumeName Name of the volume the bucket belongs to.
- * @param bucketName Name of the bucket.
- * @param storageType StorageType of the bucket.
- * @param versioning versioning status of the bucket.
- * @param creationTime creation time of the bucket.
- */
- @SuppressWarnings("parameternumber")
- public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
- String volumeName, String bucketName, StorageType storageType,
- Boolean versioning, long creationTime, Map<String, String> metadata) {
- this(conf, volumeName, bucketName, proxy);
- this.storageType = storageType;
- this.versioning = versioning;
- this.listCacheSize = HddsClientUtils.getListCacheSize(conf);
- this.creationTime = Instant.ofEpochMilli(creationTime);
- this.metadata = metadata;
- modificationTime = Instant.now();
- if (modificationTime.isBefore(this.creationTime)) {
- modificationTime = Instant.ofEpochSecond(
- this.creationTime.getEpochSecond(), this.creationTime.getNano());
+ modificationTime = Instant.now();
+ if (modificationTime.isBefore(this.creationTime)) {
+ modificationTime = Instant.ofEpochSecond(
+ this.creationTime.getEpochSecond(), this.creationTime.getNano());
+ }
}
- }
-
- /**
- * @param modificationTime modification time of the bucket.
- */
- @SuppressWarnings("parameternumber")
- public OzoneBucket(ConfigurationSource conf, ClientProtocol proxy,
- String volumeName, String bucketName, StorageType storageType,
- Boolean versioning, long creationTime, long modificationTime,
- Map<String, String> metadata) {
- this(conf, proxy, volumeName, bucketName, storageType, versioning,
- creationTime, metadata);
- this.modificationTime = Instant.ofEpochMilli(modificationTime);
- }
-
- @VisibleForTesting
- @SuppressWarnings("parameternumber")
- OzoneBucket(String volumeName, String name,
- ReplicationConfig defaultReplication,
- StorageType storageType,
- Boolean versioning, long creationTime) {
- this.proxy = null;
- this.volumeName = volumeName;
- this.name = name;
- this.defaultReplication = defaultReplication;
- this.storageType = storageType;
- this.versioning = versioning;
- this.creationTime = Instant.ofEpochMilli(creationTime);
+ this.encryptionKeyName = builder.encryptionKeyName;
this.ozoneObj = OzoneObjInfo.Builder.newBuilder()
.setBucketName(name)
.setVolumeName(volumeName)
.setResType(OzoneObj.ResourceType.BUCKET)
.setStoreType(OzoneObj.StoreType.OZONE).build();
- long modifiedTime = Time.now();
- if (modifiedTime < creationTime) {
- this.modificationTime = Instant.ofEpochMilli(creationTime);
- } else {
- this.modificationTime = Instant.ofEpochMilli(modifiedTime);
+ this.sourceVolume = builder.sourceVolume;
+ this.sourceBucket = builder.sourceBucket;
+ this.quotaInBytes = builder.quotaInBytes;
+ this.quotaInNamespace = builder.quotaInNamespace;
+ if (builder.bucketLayout != null) {
+ this.bucketLayout = builder.bucketLayout;
}
+ this.owner = builder.owner;
}
/**
@@ -1034,6 +889,135 @@ public class OzoneBucket extends WithMetadata {
return result;
}
+ public static Builder newBuilder(ConfigurationSource conf,
+ ClientProtocol proxy) {
+ Preconditions.checkNotNull(proxy, "Client proxy is not set.");
+ return new Builder(conf, proxy);
+ }
+
+ /**
+ * Inner builder for OzoneBucket.
+ */
+ public static class Builder {
+ private Map<String, String> metadata;
+ private ConfigurationSource conf;
+ private ClientProtocol proxy;
+ private String volumeName;
+ private String name;
+ private DefaultReplicationConfig defaultReplicationConfig;
+ private StorageType storageType;
+ private Boolean versioning;
+ private long usedBytes;
+ private long usedNamespace;
+ private long creationTime;
+ private long modificationTime;
+ private String encryptionKeyName;
+ private String sourceVolume;
+ private String sourceBucket;
+ private long quotaInBytes;
+ private long quotaInNamespace;
+ private BucketLayout bucketLayout;
+ private String owner;
+
+ protected Builder() {
+ }
+
+ private Builder(ConfigurationSource conf, ClientProtocol proxy) {
+ this.conf = conf;
+ this.proxy = proxy;
+ }
+
+ public Builder setMetadata(Map<String, String> metadata) {
+ this.metadata = metadata;
+ return this;
+ }
+
+ public Builder setVolumeName(String volumeName) {
+ this.volumeName = volumeName;
+ return this;
+ }
+
+ public Builder setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder setDefaultReplicationConfig(
+ DefaultReplicationConfig defaultReplicationConfig) {
+ this.defaultReplicationConfig = defaultReplicationConfig;
+ return this;
+ }
+
+ public Builder setStorageType(StorageType storageType) {
+ this.storageType = storageType;
+ return this;
+ }
+
+ public Builder setVersioning(Boolean versioning) {
+ this.versioning = versioning;
+ return this;
+ }
+
+ public Builder setUsedBytes(long usedBytes) {
+ this.usedBytes = usedBytes;
+ return this;
+ }
+
+ public Builder setUsedNamespace(long usedNamespace) {
+ this.usedNamespace = usedNamespace;
+ return this;
+ }
+
+ public Builder setCreationTime(long creationTime) {
+ this.creationTime = creationTime;
+ return this;
+ }
+
+ public Builder setModificationTime(long modificationTime) {
+ this.modificationTime = modificationTime;
+ return this;
+ }
+
+ public Builder setEncryptionKeyName(String encryptionKeyName) {
+ this.encryptionKeyName = encryptionKeyName;
+ return this;
+ }
+
+ public Builder setSourceVolume(String sourceVolume) {
+ this.sourceVolume = sourceVolume;
+ return this;
+ }
+
+ public Builder setSourceBucket(String sourceBucket) {
+ this.sourceBucket = sourceBucket;
+ return this;
+ }
+
+ public Builder setQuotaInBytes(long quotaInBytes) {
+ this.quotaInBytes = quotaInBytes;
+ return this;
+ }
+
+ public Builder setQuotaInNamespace(long quotaInNamespace) {
+ this.quotaInNamespace = quotaInNamespace;
+ return this;
+ }
+
+ public Builder setBucketLayout(BucketLayout bucketLayout) {
+ this.bucketLayout = bucketLayout;
+ return this;
+ }
+
+ public Builder setOwner(String owner) {
+ this.owner = owner;
+ return this;
+ }
+
+ public OzoneBucket build() {
+ return new OzoneBucket(this);
+ }
+ }
+
/**
* An Iterator to iterate over {@link OzoneKey} list.
*/
diff --git
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java
index 2acf709ac9..60665c7f28 100644
---
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java
+++
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java
@@ -20,7 +20,6 @@ package org.apache.hadoop.ozone.client;
import java.io.IOException;
import java.time.Instant;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -34,7 +33,6 @@ import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
import org.apache.hadoop.ozone.om.helpers.WithMetadata;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import org.apache.hadoop.ozone.security.acl.OzoneObj;
import org.apache.hadoop.ozone.security.acl.OzoneObjInfo;
@@ -107,126 +105,34 @@ public class OzoneVolume extends WithMetadata {
*/
private long refCount;
- /**
- * Constructs OzoneVolume instance.
- * @param conf Configuration object.
- * @param proxy ClientProtocol proxy.
- * @param name Name of the volume.
- * @param admin Volume admin.
- * @param owner Volume owner.
- * @param quotaInBytes Volume quota in bytes.
- * @param creationTime creation time of the volume
- * @param acls ACLs associated with the volume.
- * @param metadata custom key value metadata.
- */
- @SuppressWarnings("parameternumber")
- public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
- String name, String admin, String owner, long quotaInBytes,
- long quotaInNamespace, long creationTime, List<OzoneAcl> acls,
- Map<String, String> metadata) {
- Preconditions.checkNotNull(proxy, "Client proxy is not set.");
- this.proxy = proxy;
- this.name = name;
- this.admin = admin;
- this.owner = owner;
- this.quotaInBytes = quotaInBytes;
- this.quotaInNamespace = quotaInNamespace;
- this.creationTime = Instant.ofEpochMilli(creationTime);
- this.acls = acls;
- this.listCacheSize = HddsClientUtils.getListCacheSize(conf);
- this.metadata = metadata;
- modificationTime = Instant.now();
- if (modificationTime.isBefore(this.creationTime)) {
- modificationTime = Instant.ofEpochSecond(
- this.creationTime.getEpochSecond(), this.creationTime.getNano());
+ protected OzoneVolume(Builder builder) {
+ this.metadata = builder.metadata;
+ this.proxy = builder.proxy;
+ this.name = builder.name;
+ this.admin = builder.admin;
+ this.owner = builder.owner;
+ this.quotaInBytes = builder.quotaInBytes;
+ this.quotaInNamespace = builder.quotaInNamespace;
+ this.usedNamespace = builder.usedNamespace;
+ this.creationTime = Instant.ofEpochMilli(builder.creationTime);
+ if (builder.modificationTime != 0) {
+ this.modificationTime = Instant.ofEpochMilli(builder.modificationTime);
+ } else {
+ modificationTime = Instant.now();
+ if (modificationTime.isBefore(this.creationTime)) {
+ modificationTime = Instant.ofEpochSecond(
+ this.creationTime.getEpochSecond(), this.creationTime.getNano());
+ }
+ }
+ this.acls = builder.acls;
+ if (builder.conf != null) {
+ this.listCacheSize = HddsClientUtils.getListCacheSize(builder.conf);
}
this.ozoneObj = OzoneObjInfo.Builder.newBuilder()
.setVolumeName(name)
.setResType(OzoneObj.ResourceType.VOLUME)
.setStoreType(OzoneObj.StoreType.OZONE).build();
- }
-
- /**
- * @param refCount volume reference count.
- */
- @SuppressWarnings("parameternumber")
- public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
- String name, String admin, String owner, long quotaInBytes,
- long quotaInNamespace, long usedNamespace, long creationTime,
- long modificationTime, List<OzoneAcl> acls,
- Map<String, String> metadata, long refCount) {
- this(conf, proxy, name, admin, owner, quotaInBytes, quotaInNamespace,
- usedNamespace, creationTime, modificationTime, acls, metadata);
- this.refCount = refCount;
- }
-
- /**
- * @param modificationTime modification time of the volume.
- */
- @SuppressWarnings("parameternumber")
- public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
- String name, String admin, String owner, long quotaInBytes,
- long quotaInNamespace, long usedNamespace, long creationTime,
- long modificationTime, List<OzoneAcl> acls,
- Map<String, String> metadata) {
- this(conf, proxy, name, admin, owner, quotaInBytes, quotaInNamespace,
- creationTime, acls, metadata);
- this.modificationTime = Instant.ofEpochMilli(modificationTime);
- this.usedNamespace = usedNamespace;
- }
-
- @SuppressWarnings("parameternumber")
- public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
- String name, String admin, String owner, long quotaInBytes,
- long quotaInNamespace, long creationTime, List<OzoneAcl> acls) {
- this(conf, proxy, name, admin, owner, quotaInBytes, quotaInNamespace,
- creationTime, acls, new HashMap<>());
- modificationTime = Instant.now();
- if (modificationTime.isBefore(this.creationTime)) {
- modificationTime = Instant.ofEpochSecond(
- this.creationTime.getEpochSecond(), this.creationTime.getNano());
- }
- }
-
- @SuppressWarnings("parameternumber")
- public OzoneVolume(ConfigurationSource conf, ClientProtocol proxy,
- String name, String admin, String owner, long quotaInBytes,
- long quotaInNamespace, long usedNamespace, long creationTime,
- long modificationTime, List<OzoneAcl> acls) {
- this(conf, proxy, name, admin, owner, quotaInBytes, quotaInNamespace,
- creationTime, acls);
- this.modificationTime = Instant.ofEpochMilli(modificationTime);
- this.usedNamespace = usedNamespace;
- }
-
- @VisibleForTesting
- protected OzoneVolume(String name, String admin, String owner,
- long quotaInBytes, long quotaInNamespace, long creationTime,
- List<OzoneAcl> acls) {
- this.proxy = null;
- this.name = name;
- this.admin = admin;
- this.owner = owner;
- this.quotaInBytes = quotaInBytes;
- this.quotaInNamespace = quotaInNamespace;
- this.creationTime = Instant.ofEpochMilli(creationTime);
- this.acls = acls;
- this.metadata = new HashMap<>();
- modificationTime = Instant.now();
- if (modificationTime.isBefore(this.creationTime)) {
- modificationTime = Instant.ofEpochSecond(
- this.creationTime.getEpochSecond(), this.creationTime.getNano());
- }
- }
-
- @SuppressWarnings("parameternumber")
- @VisibleForTesting
- protected OzoneVolume(String name, String admin, String owner,
- long quotaInBytes, long quotaInNamespace, long creationTime,
- long modificationTime, List<OzoneAcl> acls) {
- this(name, admin, owner, quotaInBytes, quotaInNamespace, creationTime,
- acls);
- this.modificationTime = Instant.ofEpochMilli(modificationTime);
+ this.refCount = builder.refCount;
}
/**
@@ -475,6 +381,98 @@ public class OzoneVolume extends WithMetadata {
return refCount;
}
+ public static Builder newBuilder(ConfigurationSource conf,
+ ClientProtocol proxy) {
+ Preconditions.checkNotNull(proxy, "Client proxy is not set.");
+ return new Builder(conf, proxy);
+ }
+
+ /**
+ * Inner builder for OzoneVolume.
+ */
+ public static class Builder {
+ private Map<String, String> metadata;
+ private ConfigurationSource conf;
+ private ClientProtocol proxy;
+ private String name;
+ private String admin;
+ private String owner;
+ private long quotaInBytes;
+ private long quotaInNamespace;
+ private long usedNamespace;
+ private long creationTime;
+ private long modificationTime;
+ private List<OzoneAcl> acls;
+ private long refCount;
+
+ protected Builder() {
+ }
+
+ private Builder(ConfigurationSource conf, ClientProtocol proxy) {
+ this.conf = conf;
+ this.proxy = proxy;
+ }
+
+ public Builder setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder setAdmin(String admin) {
+ this.admin = admin;
+ return this;
+ }
+
+ public Builder setOwner(String owner) {
+ this.owner = owner;
+ return this;
+ }
+
+ public Builder setQuotaInBytes(long quotaInBytes) {
+ this.quotaInBytes = quotaInBytes;
+ return this;
+ }
+
+ public Builder setQuotaInNamespace(long quotaInNamespace) {
+ this.quotaInNamespace = quotaInNamespace;
+ return this;
+ }
+
+ public Builder setUsedNamespace(long usedNamespace) {
+ this.usedNamespace = usedNamespace;
+ return this;
+ }
+
+ public Builder setCreationTime(long creationTime) {
+ this.creationTime = creationTime;
+ return this;
+ }
+
+ public Builder setModificationTime(long modificationTime) {
+ this.modificationTime = modificationTime;
+ return this;
+ }
+
+ public Builder setAcls(List<OzoneAcl> acls) {
+ this.acls = acls;
+ return this;
+ }
+
+ public Builder setRefCount(long refCount) {
+ this.refCount = refCount;
+ return this;
+ }
+
+ public Builder setMetadata(Map<String, String> metadata) {
+ this.metadata = metadata;
+ return this;
+ }
+
+ public OzoneVolume build() {
+ return new OzoneVolume(this);
+ }
+ }
+
/**
* An Iterator to iterate over {@link OzoneBucket} list.
*/
diff --git
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
index 1fb59567e1..128ad4fe68 100644
---
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
+++
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
@@ -535,20 +535,19 @@ public class RpcClient implements ClientProtocol {
}
public OzoneVolume buildOzoneVolume(OmVolumeArgs volume) {
- return new OzoneVolume(
- conf,
- this,
- volume.getVolume(),
- volume.getAdminName(),
- volume.getOwnerName(),
- volume.getQuotaInBytes(),
- volume.getQuotaInNamespace(),
- volume.getUsedNamespace(),
- volume.getCreationTime(),
- volume.getModificationTime(),
- volume.getAcls(),
- volume.getMetadata(),
- volume.getRefCount());
+ return OzoneVolume.newBuilder(conf, this)
+ .setName(volume.getVolume())
+ .setAdmin(volume.getAdminName())
+ .setOwner(volume.getOwnerName())
+ .setQuotaInBytes(volume.getQuotaInBytes())
+ .setQuotaInNamespace(volume.getQuotaInNamespace())
+ .setUsedNamespace(volume.getUsedNamespace())
+ .setCreationTime(volume.getCreationTime())
+ .setModificationTime(volume.getModificationTime())
+ .setAcls(volume.getAcls())
+ .setMetadata(volume.getMetadata())
+ .setRefCount(volume.getRefCount())
+ .build();
}
@Override
@@ -570,18 +569,18 @@ public class RpcClient implements ClientProtocol {
List<OmVolumeArgs> volumes = ozoneManagerClient.listAllVolumes(
volumePrefix, prevVolume, maxListResult);
- return volumes.stream().map(volume -> new OzoneVolume(
- conf,
- this,
- volume.getVolume(),
- volume.getAdminName(),
- volume.getOwnerName(),
- volume.getQuotaInBytes(),
- volume.getQuotaInNamespace(),
- volume.getUsedNamespace(),
- volume.getCreationTime(),
- volume.getModificationTime(),
- volume.getAcls()))
+ return volumes.stream().map(volume ->
+ OzoneVolume.newBuilder(conf, this)
+ .setName(volume.getVolume())
+ .setAdmin(volume.getAdminName())
+ .setOwner(volume.getOwnerName())
+ .setQuotaInBytes(volume.getQuotaInBytes())
+ .setQuotaInNamespace(volume.getQuotaInNamespace())
+ .setUsedNamespace(volume.getUsedNamespace())
+ .setCreationTime(volume.getCreationTime())
+ .setModificationTime(volume.getModificationTime())
+ .setAcls(volume.getAcls())
+ .build())
.collect(Collectors.toList());
}
@@ -592,19 +591,19 @@ public class RpcClient implements ClientProtocol {
List<OmVolumeArgs> volumes = ozoneManagerClient.listVolumeByUser(
user, volumePrefix, prevVolume, maxListResult);
- return volumes.stream().map(volume -> new OzoneVolume(
- conf,
- this,
- volume.getVolume(),
- volume.getAdminName(),
- volume.getOwnerName(),
- volume.getQuotaInBytes(),
- volume.getQuotaInNamespace(),
- volume.getUsedNamespace(),
- volume.getCreationTime(),
- volume.getModificationTime(),
- volume.getAcls(),
- volume.getMetadata()))
+ return volumes.stream().map(volume ->
+ OzoneVolume.newBuilder(conf, this)
+ .setName(volume.getVolume())
+ .setAdmin(volume.getAdminName())
+ .setOwner(volume.getOwnerName())
+ .setQuotaInBytes(volume.getQuotaInBytes())
+ .setQuotaInNamespace(volume.getQuotaInNamespace())
+ .setUsedNamespace(volume.getUsedNamespace())
+ .setCreationTime(volume.getCreationTime())
+ .setModificationTime(volume.getModificationTime())
+ .setAcls(volume.getAcls())
+ .setMetadata(volume.getMetadata())
+ .build())
.collect(Collectors.toList());
}
@@ -1171,28 +1170,26 @@ public class RpcClient implements ClientProtocol {
verifyBucketName(bucketName);
OmBucketInfo bucketInfo =
ozoneManagerClient.getBucketInfo(volumeName, bucketName);
- return new OzoneBucket(
- conf,
- this,
- bucketInfo.getVolumeName(),
- bucketInfo.getBucketName(),
- bucketInfo.getStorageType(),
- bucketInfo.getIsVersionEnabled(),
- bucketInfo.getCreationTime(),
- bucketInfo.getModificationTime(),
- bucketInfo.getMetadata(),
- bucketInfo.getEncryptionKeyInfo() != null ? bucketInfo
- .getEncryptionKeyInfo().getKeyName() : null,
- bucketInfo.getSourceVolume(),
- bucketInfo.getSourceBucket(),
- bucketInfo.getUsedBytes(),
- bucketInfo.getUsedNamespace(),
- bucketInfo.getQuotaInBytes(),
- bucketInfo.getQuotaInNamespace(),
- bucketInfo.getBucketLayout(),
- bucketInfo.getOwner(),
- bucketInfo.getDefaultReplicationConfig()
- );
+ return OzoneBucket.newBuilder(conf, this)
+ .setVolumeName(bucketInfo.getVolumeName())
+ .setName(bucketInfo.getBucketName())
+ .setStorageType(bucketInfo.getStorageType())
+ .setVersioning(bucketInfo.getIsVersionEnabled())
+ .setCreationTime(bucketInfo.getCreationTime())
+ .setModificationTime(bucketInfo.getModificationTime())
+ .setMetadata(bucketInfo.getMetadata())
+ .setEncryptionKeyName(bucketInfo.getEncryptionKeyInfo() != null ?
+ bucketInfo.getEncryptionKeyInfo().getKeyName() : null)
+ .setSourceVolume(bucketInfo.getSourceVolume())
+ .setSourceBucket(bucketInfo.getSourceBucket())
+ .setUsedBytes(bucketInfo.getUsedBytes())
+ .setUsedNamespace(bucketInfo.getUsedNamespace())
+ .setQuotaInBytes(bucketInfo.getQuotaInBytes())
+ .setQuotaInNamespace(bucketInfo.getQuotaInNamespace())
+ .setBucketLayout(bucketInfo.getBucketLayout())
+ .setOwner(bucketInfo.getOwner())
+ .setDefaultReplicationConfig(bucketInfo.getDefaultReplicationConfig())
+ .build();
}
@Override
@@ -1202,27 +1199,28 @@ public class RpcClient implements ClientProtocol {
List<OmBucketInfo> buckets = ozoneManagerClient.listBuckets(
volumeName, prevBucket, bucketPrefix, maxListResult);
- return buckets.stream().map(bucket -> new OzoneBucket(
- conf,
- this,
- bucket.getVolumeName(),
- bucket.getBucketName(),
- bucket.getStorageType(),
- bucket.getIsVersionEnabled(),
- bucket.getCreationTime(),
- bucket.getModificationTime(),
- bucket.getMetadata(),
- bucket.getEncryptionKeyInfo() != null ? bucket
- .getEncryptionKeyInfo().getKeyName() : null,
- bucket.getSourceVolume(),
- bucket.getSourceBucket(),
- bucket.getUsedBytes(),
- bucket.getUsedNamespace(),
- bucket.getQuotaInBytes(),
- bucket.getQuotaInNamespace(),
- bucket.getBucketLayout(),
- bucket.getOwner(),
- bucket.getDefaultReplicationConfig()))
+ return buckets.stream().map(bucket ->
+ OzoneBucket.newBuilder(conf, this)
+ .setVolumeName(bucket.getVolumeName())
+ .setName(bucket.getBucketName())
+ .setStorageType(bucket.getStorageType())
+ .setVersioning(bucket.getIsVersionEnabled())
+ .setCreationTime(bucket.getCreationTime())
+ .setModificationTime(bucket.getModificationTime())
+ .setMetadata(bucket.getMetadata())
+ .setEncryptionKeyName(bucket.getEncryptionKeyInfo() != null ?
+ bucket.getEncryptionKeyInfo().getKeyName() : null)
+ .setSourceVolume(bucket.getSourceVolume())
+ .setSourceBucket(bucket.getSourceBucket())
+ .setUsedBytes(bucket.getUsedBytes())
+ .setUsedNamespace(bucket.getUsedNamespace())
+ .setQuotaInBytes(bucket.getQuotaInBytes())
+ .setQuotaInNamespace(bucket.getQuotaInNamespace())
+ .setBucketLayout(bucket.getBucketLayout())
+ .setOwner(bucket.getOwner())
+ .setDefaultReplicationConfig(
+ bucket.getDefaultReplicationConfig())
+ .build())
.collect(Collectors.toList());
}
diff --git
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/ObjectStoreStub.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/ObjectStoreStub.java
index 5124cad526..a4ab45740f 100644
---
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/ObjectStoreStub.java
+++
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/ObjectStoreStub.java
@@ -61,14 +61,15 @@ public class ObjectStoreStub extends ObjectStore {
@Override
public void createVolume(String volumeName, VolumeArgs volumeArgs) {
- OzoneVolumeStub volume =
- new OzoneVolumeStub(volumeName,
- volumeArgs.getAdmin(),
- volumeArgs.getOwner(),
- volumeArgs.getQuotaInBytes(),
- volumeArgs.getQuotaInNamespace(),
- Time.now(),
- volumeArgs.getAcls());
+ OzoneVolumeStub volume = OzoneVolumeStub.newBuilder()
+ .setName(volumeName)
+ .setAdmin(volumeArgs.getAdmin())
+ .setOwner(volumeArgs.getOwner())
+ .setQuotaInBytes(volumeArgs.getQuotaInBytes())
+ .setQuotaInNamespace(volumeArgs.getQuotaInNamespace())
+ .setCreationTime(Time.now())
+ .setAcls(volumeArgs.getAcls())
+ .build();
volumes.put(volumeName, volume);
}
diff --git
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/OzoneBucketStub.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/OzoneBucketStub.java
index a150e50ebb..1972fb7646 100644
---
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/OzoneBucketStub.java
+++
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/OzoneBucketStub.java
@@ -32,6 +32,7 @@ import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.hadoop.hdds.client.DefaultReplicationConfig;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationFactor;
@@ -64,29 +65,66 @@ public class OzoneBucketStub extends OzoneBucket {
private ArrayList<OzoneAcl> aclList = new ArrayList<>();
private ReplicationConfig replicationConfig;
- /**
- * Constructs OzoneBucket instance.
- *
- * @param volumeName Name of the volume the bucket belongs to.
- * @param bucketName Name of the bucket.
- * @param storageType StorageType of the bucket.
- * @param versioning versioning status of the bucket.
- * @param creationTime creation time of the bucket.
- */
- public OzoneBucketStub(
- String volumeName,
- String bucketName,
- StorageType storageType, Boolean versioning,
- long creationTime) {
- super(volumeName,
- bucketName,
- RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE),
- storageType,
- versioning,
- creationTime);
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public OzoneBucketStub(Builder b) {
+ super(b);
this.replicationConfig = super.getReplicationConfig();
}
+ /**
+ * Inner builder for OzoneBucketStub.
+ */
+ public static final class Builder extends OzoneBucket.Builder {
+
+ private Builder() {
+ }
+
+ @Override
+ public Builder setVolumeName(String volumeName) {
+ super.setVolumeName(volumeName);
+ return this;
+ }
+
+ @Override
+ public Builder setName(String name) {
+ super.setName(name);
+ return this;
+ }
+
+ @Override
+ public Builder setDefaultReplicationConfig(
+ DefaultReplicationConfig defaultReplicationConfig) {
+ super.setDefaultReplicationConfig(defaultReplicationConfig);
+ return this;
+ }
+
+ @Override
+ public Builder setStorageType(StorageType storageType) {
+ super.setStorageType(storageType);
+ return this;
+ }
+
+ @Override
+ public Builder setVersioning(Boolean versioning) {
+ super.setVersioning(versioning);
+ return this;
+ }
+
+ @Override
+ public Builder setCreationTime(long creationTime) {
+ super.setCreationTime(creationTime);
+ return this;
+ }
+
+ @Override
+ public OzoneBucketStub build() {
+ return new OzoneBucketStub(this);
+ }
+ }
+
@Override
public OzoneOutputStream createKey(String key, long size) throws IOException
{
return createKey(key, size,
diff --git
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/OzoneVolumeStub.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/OzoneVolumeStub.java
index 55a7191ac3..9fab5a181b 100644
---
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/OzoneVolumeStub.java
+++
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/OzoneVolumeStub.java
@@ -27,7 +27,10 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import org.apache.hadoop.hdds.client.DefaultReplicationConfig;
+import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.protocol.StorageType;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.util.Time;
@@ -41,11 +44,68 @@ public class OzoneVolumeStub extends OzoneVolume {
private ArrayList<OzoneAcl> aclList = new ArrayList<>();
- public OzoneVolumeStub(String name, String admin, String owner,
- long quotaInBytes, long quotaInNamespace, long creationTime,
- List<OzoneAcl> acls) {
- super(name, admin, owner, quotaInBytes, quotaInNamespace, creationTime,
- acls);
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ public OzoneVolumeStub(Builder b) {
+ super(b);
+ }
+
+ /**
+ * Inner builder for OzoneVolumeStub.
+ */
+ public static final class Builder extends OzoneVolume.Builder {
+
+ private Builder() {
+ }
+
+ @Override
+ public Builder setName(String name) {
+ super.setName(name);
+ return this;
+ }
+
+ @Override
+ public Builder setAdmin(String admin) {
+ super.setAdmin(admin);
+ return this;
+ }
+
+ @Override
+ public Builder setOwner(String owner) {
+ super.setOwner(owner);
+ return this;
+ }
+
+ @Override
+ public Builder setQuotaInBytes(long quotaInBytes) {
+ super.setQuotaInBytes(quotaInBytes);
+ return this;
+ }
+
+ @Override
+ public Builder setQuotaInNamespace(long quotaInNamespace) {
+ super.setQuotaInNamespace(quotaInNamespace);
+ return this;
+ }
+
+ @Override
+ public Builder setCreationTime(long creationTime) {
+ super.setCreationTime(creationTime);
+ return this;
+ }
+
+ @Override
+ public Builder setAcls(List<OzoneAcl> acls) {
+ super.setAcls(acls);
+ return this;
+ }
+
+ @Override
+ public OzoneVolumeStub build() {
+ return new OzoneVolumeStub(this);
+ }
}
@Override
@@ -58,12 +118,16 @@ public class OzoneVolumeStub extends OzoneVolume {
@Override
public void createBucket(String bucketName, BucketArgs bucketArgs) {
- buckets.put(bucketName, new OzoneBucketStub(
- getName(),
- bucketName,
- bucketArgs.getStorageType(),
- bucketArgs.getVersioning(),
- Time.now()));
+ buckets.put(bucketName, OzoneBucketStub.newBuilder()
+ .setVolumeName(getName())
+ .setName(bucketName)
+ .setDefaultReplicationConfig(new DefaultReplicationConfig(
+ RatisReplicationConfig.getInstance(
+ HddsProtos.ReplicationFactor.THREE)))
+ .setStorageType(bucketArgs.getStorageType())
+ .setVersioning(bucketArgs.getVersioning())
+ .setCreationTime(Time.now())
+ .build());
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]