1919
2020import com .google .common .annotations .VisibleForTesting ;
2121import com .google .common .collect .ImmutableList ;
22+ import com .google .common .collect .ImmutableMap ;
2223import jakarta .annotation .Nonnull ;
2324import java .util .ArrayList ;
24- import java .util .HashMap ;
2525import java .util .LinkedHashMap ;
2626import java .util .List ;
2727import java .util .Map ;
3636 * Args for key. Client use this to specify key's attributes on key creation
3737 * (putKey()).
3838 */
39- public final class OmKeyArgs implements Auditable {
39+ public final class OmKeyArgs extends WithMetadata implements Auditable {
4040 private final String volumeName ;
4141 private final String bucketName ;
4242 private final String keyName ;
@@ -47,14 +47,13 @@ public final class OmKeyArgs implements Auditable {
4747 private final boolean isMultipartKey ;
4848 private final String multipartUploadID ;
4949 private final int multipartUploadPartNumber ;
50- private final Map <String , String > metadata ;
5150 private final boolean sortDatanodesInPipeline ;
5251 private final ImmutableList <OzoneAcl > acls ;
5352 private final boolean latestVersionLocation ;
5453 private final boolean recursive ;
5554 private final boolean headOp ;
5655 private final boolean forceUpdateContainerCacheFromSCM ;
57- private final Map <String , String > tags ;
56+ private final ImmutableMap <String , String > tags ;
5857 // expectedDataGeneration, when used in key creation indicates that a
5958 // key with the same keyName should exist with the given generation.
6059 // For a key commit to succeed, the original key should still be present with the
@@ -64,6 +63,7 @@ public final class OmKeyArgs implements Auditable {
6463 private Long expectedDataGeneration = null ;
6564
6665 private OmKeyArgs (Builder b ) {
66+ super (b );
6767 this .volumeName = b .volumeName ;
6868 this .bucketName = b .bucketName ;
6969 this .keyName = b .keyName ;
@@ -73,15 +73,14 @@ private OmKeyArgs(Builder b) {
7373 this .isMultipartKey = b .isMultipartKey ;
7474 this .multipartUploadID = b .multipartUploadID ;
7575 this .multipartUploadPartNumber = b .multipartUploadPartNumber ;
76- this .metadata = b .metadata ;
7776 this .acls = b .acls .build ();
7877 this .sortDatanodesInPipeline = b .sortDatanodesInPipeline ;
7978 this .latestVersionLocation = b .latestVersionLocation ;
8079 this .recursive = b .recursive ;
8180 this .headOp = b .headOp ;
8281 this .forceUpdateContainerCacheFromSCM = b .forceUpdateContainerCacheFromSCM ;
8382 this .ownerName = b .ownerName ;
84- this .tags = b .tags ;
83+ this .tags = b .tags . build () ;
8584 this .expectedDataGeneration = b .expectedDataGeneration ;
8685 }
8786
@@ -129,10 +128,6 @@ public void setDataSize(long size) {
129128 dataSize = size ;
130129 }
131130
132- public Map <String , String > getMetadata () {
133- return metadata ;
134- }
135-
136131 public void setLocationInfoList (List <OmKeyLocationInfo > locationInfoList ) {
137132 this .locationInfoList = locationInfoList ;
138133 }
@@ -220,7 +215,7 @@ public KeyArgs toProtobuf() {
220215 /**
221216 * Builder class of OmKeyArgs.
222217 */
223- public static class Builder {
218+ public static class Builder extends WithMetadata . Builder {
224219 private String volumeName ;
225220 private String bucketName ;
226221 private String keyName ;
@@ -231,14 +226,13 @@ public static class Builder {
231226 private boolean isMultipartKey ;
232227 private String multipartUploadID ;
233228 private int multipartUploadPartNumber ;
234- private final Map <String , String > metadata = new HashMap <>();
235229 private boolean sortDatanodesInPipeline ;
236230 private boolean latestVersionLocation ;
237231 private final AclListBuilder acls ;
238232 private boolean recursive ;
239233 private boolean headOp ;
240234 private boolean forceUpdateContainerCacheFromSCM ;
241- private final Map <String , String > tags = new HashMap <>() ;
235+ private final MapBuilder <String , String > tags ;
242236 private Long expectedDataGeneration = null ;
243237
244238 public Builder () {
@@ -247,9 +241,11 @@ public Builder() {
247241
248242 private Builder (AclListBuilder acls ) {
249243 this .acls = acls ;
244+ this .tags = MapBuilder .empty ();
250245 }
251246
252247 public Builder (OmKeyArgs obj ) {
248+ super (obj );
253249 this .volumeName = obj .volumeName ;
254250 this .bucketName = obj .bucketName ;
255251 this .keyName = obj .keyName ;
@@ -267,8 +263,7 @@ public Builder(OmKeyArgs obj) {
267263 this .forceUpdateContainerCacheFromSCM =
268264 obj .forceUpdateContainerCacheFromSCM ;
269265 this .expectedDataGeneration = obj .expectedDataGeneration ;
270- this .metadata .putAll (obj .metadata );
271- this .tags .putAll (obj .tags );
266+ this .tags = MapBuilder .of (obj .tags );
272267 this .acls = AclListBuilder .of (obj .acls );
273268 }
274269
@@ -287,6 +282,10 @@ public Builder setKeyName(String key) {
287282 return this ;
288283 }
289284
285+ public String getKeyName () {
286+ return keyName ;
287+ }
288+
290289 public Builder setOwnerName (String owner ) {
291290 this .ownerName = owner ;
292291 return this ;
@@ -297,6 +296,10 @@ public Builder setDataSize(long size) {
297296 return this ;
298297 }
299298
299+ public long getDataSize () {
300+ return dataSize ;
301+ }
302+
300303 public Builder setReplicationConfig (ReplicationConfig replConfig ) {
301304 this .replicationConfig = replConfig ;
302305 return this ;
@@ -307,6 +310,10 @@ public Builder setLocationInfoList(List<OmKeyLocationInfo> locationInfos) {
307310 return this ;
308311 }
309312
313+ public List <OmKeyLocationInfo > getLocationInfoList () {
314+ return locationInfoList ;
315+ }
316+
310317 public Builder setAcls (List <OzoneAcl > listOfAcls ) {
311318 this .acls .addAll (listOfAcls );
312319 return this ;
@@ -317,6 +324,10 @@ public Builder setIsMultipartKey(boolean isMultipart) {
317324 return this ;
318325 }
319326
327+ public boolean getIsMultipartKey () {
328+ return isMultipartKey ;
329+ }
330+
320331 public Builder setMultipartUploadID (String uploadID ) {
321332 this .multipartUploadID = uploadID ;
322333 return this ;
@@ -327,20 +338,22 @@ public Builder setMultipartUploadPartNumber(int multipartUploadPartNumber) {
327338 return this ;
328339 }
329340
341+ @ Override
330342 public Builder addMetadata (String key , String value ) {
331- this . metadata . put (key , value );
343+ super . addMetadata (key , value );
332344 return this ;
333345 }
334346
347+ @ Override
335348 public Builder addAllMetadata (Map <String , String > metadatamap ) {
336- this . metadata . putAll (metadatamap );
349+ super . addAllMetadata (metadatamap );
337350 return this ;
338351 }
339352
340353 public Builder addAllMetadataGdpr (Map <String , String > metadatamap ) {
341354 addAllMetadata (metadatamap );
342- if (Boolean .parseBoolean (metadata .get (OzoneConsts .GDPR_FLAG ))) {
343- GDPRSymmetricKey .newDefaultInstance ().acceptKeyDetails (metadata :: put );
355+ if (metadatamap != null && Boolean .parseBoolean (metadatamap .get (OzoneConsts .GDPR_FLAG ))) {
356+ GDPRSymmetricKey .newDefaultInstance ().acceptKeyDetails (this :: addMetadata );
344357 }
345358 return this ;
346359 }
0 commit comments