Skip to content

Commit 64b7f01

Browse files
ivandika3jojochuang
authored andcommitted
HDDS-10435. Support S3 object tags for existing requests (apache#6607)
1 parent cbc8797 commit 64b7f01

File tree

35 files changed

+1071
-102
lines changed

35 files changed

+1071
-102
lines changed

hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneManagerVersion.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public enum OzoneManagerVersion implements ComponentVersion {
4040
LIGHTWEIGHT_LIST_KEYS(4, "OzoneManager version that supports lightweight"
4141
+ " listKeys API."),
4242

43+
OBJECT_TAG(5, "OzoneManager version that supports object tags"),
44+
4345
FUTURE_VERSION(-1, "Used internally in the client when the server side is "
4446
+ " newer and an unknown server version has arrived to the client.");
4547

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import java.time.Instant;
5555
import java.util.ArrayList;
5656
import java.util.Collections;
57-
import java.util.HashMap;
5857
import java.util.Iterator;
5958
import java.util.List;
6059
import java.util.Map;
@@ -431,7 +430,7 @@ public void setEncryptionKey(String bekName) throws IOException {
431430
public OzoneOutputStream createKey(String key, long size)
432431
throws IOException {
433432
return createKey(key, size, defaultReplication,
434-
new HashMap<>());
433+
Collections.emptyMap());
435434
}
436435

437436
/**
@@ -459,15 +458,35 @@ public OzoneOutputStream createKey(String key, long size,
459458
* @param key Name of the key to be created.
460459
* @param size Size of the data the key will point to.
461460
* @param replicationConfig Replication configuration.
461+
* @param keyMetadata Custom key metadata.
462462
* @return OzoneOutputStream to which the data has to be written.
463463
* @throws IOException
464464
*/
465465
public OzoneOutputStream createKey(String key, long size,
466466
ReplicationConfig replicationConfig,
467467
Map<String, String> keyMetadata)
468468
throws IOException {
469+
return this.createKey(key, size, replicationConfig, keyMetadata, Collections.emptyMap());
470+
}
471+
472+
/**
473+
* Creates a new key in the bucket.
474+
*
475+
* @param key Name of the key to be created.
476+
* @param size Size of the data the key will point to.
477+
* @param replicationConfig Replication configuration.
478+
* @param keyMetadata Custom key metadata.
479+
* @param tags Tags used for S3 object tags
480+
* @return OzoneOutputStream to which the data has to be written.
481+
* @throws IOException
482+
*/
483+
public OzoneOutputStream createKey(String key, long size,
484+
ReplicationConfig replicationConfig,
485+
Map<String, String> keyMetadata,
486+
Map<String, String> tags)
487+
throws IOException {
469488
return proxy
470-
.createKey(volumeName, name, key, size, replicationConfig, keyMetadata);
489+
.createKey(volumeName, name, key, size, replicationConfig, keyMetadata, tags);
471490
}
472491

473492
/**
@@ -491,6 +510,7 @@ public OzoneDataStreamOutput createStreamKey(String key, long size)
491510
* @param key Name of the key to be created.
492511
* @param size Size of the data the key will point to.
493512
* @param replicationConfig Replication configuration.
513+
* @param keyMetadata Custom key metadata.
494514
* @return OzoneDataStreamOutput to which the data has to be written.
495515
* @throws IOException
496516
*/
@@ -500,8 +520,28 @@ public OzoneDataStreamOutput createStreamKey(String key, long size,
500520
if (replicationConfig == null) {
501521
replicationConfig = defaultReplication;
502522
}
523+
return this.createStreamKey(key, size, replicationConfig, keyMetadata,
524+
Collections.emptyMap());
525+
}
526+
527+
/**
528+
* Creates a new key in the bucket.
529+
*
530+
* @param key Name of the key to be created.
531+
* @param size Size of the data the key will point to.
532+
* @param replicationConfig Replication configuration.
533+
* @param keyMetadata Custom key metadata.
534+
* @return OzoneDataStreamOutput to which the data has to be written.
535+
* @throws IOException
536+
*/
537+
public OzoneDataStreamOutput createStreamKey(String key, long size,
538+
ReplicationConfig replicationConfig, Map<String, String> keyMetadata,
539+
Map<String, String> tags) throws IOException {
540+
if (replicationConfig == null) {
541+
replicationConfig = defaultReplication;
542+
}
503543
return proxy.createStreamKey(volumeName, name, key, size,
504-
replicationConfig, keyMetadata);
544+
replicationConfig, keyMetadata, tags);
505545
}
506546

507547
/**
@@ -659,11 +699,12 @@ public void renameKeys(Map<String, String> keyMap)
659699

660700
/**
661701
* Initiate multipart upload for a specified key.
662-
* @param keyName
663-
* @param type
664-
* @param factor
702+
* @param keyName Name of the key to be created when the multipart upload is completed.
703+
* @param type Replication type to be used.
704+
* @param factor Replication factor of the key.
665705
* @return OmMultipartInfo
666706
* @throws IOException
707+
* @deprecated Use {@link OzoneBucket#initiateMultipartUpload(String, ReplicationConfig)} instead.
667708
*/
668709
@Deprecated
669710
public OmMultipartInfo initiateMultipartUpload(String keyName,
@@ -676,6 +717,10 @@ public OmMultipartInfo initiateMultipartUpload(String keyName,
676717

677718
/**
678719
* Initiate multipart upload for a specified key.
720+
* @param keyName Name of the key to be created when the multipart upload is completed.
721+
* @param config Replication config.
722+
* @return OmMultipartInfo
723+
* @throws IOException
679724
*/
680725
public OmMultipartInfo initiateMultipartUpload(String keyName,
681726
ReplicationConfig config)
@@ -685,11 +730,32 @@ public OmMultipartInfo initiateMultipartUpload(String keyName,
685730

686731
/**
687732
* Initiate multipart upload for a specified key.
733+
* @param keyName Name of the key to be created when the multipart upload is completed.
734+
* @param config Replication config.
735+
* @param metadata Custom key metadata.
736+
* @return OmMultipartInfo
737+
* @throws IOException
688738
*/
689739
public OmMultipartInfo initiateMultipartUpload(String keyName,
690740
ReplicationConfig config, Map<String, String> metadata)
691741
throws IOException {
692-
return proxy.initiateMultipartUpload(volumeName, name, keyName, config, metadata);
742+
return initiateMultipartUpload(keyName, config, metadata, Collections.emptyMap());
743+
}
744+
745+
/**
746+
* Initiate multipart upload for a specified key.
747+
* @param keyName Name of the key to be created when the multipart upload is completed.
748+
* @param config Replication config.
749+
* @param metadata Custom key metadata.
750+
* @param tags Tags used for S3 object tags.
751+
* @return OmMultipartInfo
752+
* @throws IOException
753+
*/
754+
public OmMultipartInfo initiateMultipartUpload(String keyName,
755+
ReplicationConfig config, Map<String, String> metadata,
756+
Map<String, String> tags)
757+
throws IOException {
758+
return proxy.initiateMultipartUpload(volumeName, name, keyName, config, metadata, tags);
693759
}
694760

695761
/**
@@ -1311,7 +1377,8 @@ private static OzoneKey toOzoneKey(OzoneFileStatusLight status) {
13111377
keyInfo.getReplicationConfig(),
13121378
metadata,
13131379
keyInfo.isFile(),
1314-
keyInfo.getOwnerName());
1380+
keyInfo.getOwnerName(),
1381+
Collections.emptyMap());
13151382
}
13161383

13171384

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneKey.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public class OzoneKey {
6363

6464
private ReplicationConfig replicationConfig;
6565

66-
private Map<String, String> metadata = new HashMap<>();
66+
private final Map<String, String> metadata = new HashMap<>();
67+
68+
private final Map<String, String> tags = new HashMap<>();
6769

6870
/**
6971
* Indicator if key is a file.
@@ -94,10 +96,12 @@ public OzoneKey(String volumeName, String bucketName,
9496
public OzoneKey(String volumeName, String bucketName,
9597
String keyName, long size, long creationTime,
9698
long modificationTime, ReplicationConfig replicationConfig,
97-
Map<String, String> metadata, boolean isFile, String owner) {
99+
Map<String, String> metadata, boolean isFile, String owner,
100+
Map<String, String> tags) {
98101
this(volumeName, bucketName, keyName, size, creationTime,
99102
modificationTime, replicationConfig, isFile, owner);
100103
this.metadata.putAll(metadata);
104+
this.tags.putAll(tags);
101105
}
102106

103107
/**
@@ -163,10 +167,24 @@ public Instant getModificationTime() {
163167
return modificationTime;
164168
}
165169

170+
/**
171+
* Returns the metadata of the key.
172+
*
173+
* @return key metadata.
174+
*/
166175
public Map<String, String> getMetadata() {
167176
return metadata;
168177
}
169178

179+
/**
180+
* Returns the tags of the key.
181+
*
182+
* @return key tags.
183+
*/
184+
public Map<String, String> getTags() {
185+
return tags;
186+
}
187+
170188
public void setMetadata(Map<String, String> metadata) {
171189
this.metadata.putAll(metadata);
172190
}
@@ -205,7 +223,8 @@ public static OzoneKey fromKeyInfo(OmKeyInfo keyInfo) {
205223
return new OzoneKey(keyInfo.getVolumeName(), keyInfo.getBucketName(),
206224
keyInfo.getKeyName(), keyInfo.getDataSize(), keyInfo.getCreationTime(),
207225
keyInfo.getModificationTime(), keyInfo.getReplicationConfig(),
208-
keyInfo.getMetadata(), keyInfo.isFile(), keyInfo.getOwnerName());
226+
keyInfo.getMetadata(), keyInfo.isFile(), keyInfo.getOwnerName(),
227+
keyInfo.getTags());
209228
}
210229

211230
}

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneKeyDetails.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public OzoneKeyDetails(String volumeName, String bucketName, String keyName,
5353
Map<String, String> metadata,
5454
FileEncryptionInfo feInfo,
5555
CheckedSupplier<OzoneInputStream, IOException> contentSupplier,
56-
boolean isFile, String owner) {
56+
boolean isFile, String owner, Map<String, String> tags) {
5757
super(volumeName, bucketName, keyName, size, creationTime,
58-
modificationTime, replicationConfig, metadata, isFile, owner);
58+
modificationTime, replicationConfig, metadata, isFile, owner, tags);
5959
this.ozoneKeyLocations = ozoneKeyLocations;
6060
this.feInfo = feInfo;
6161
this.contentSupplier = contentSupplier;

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/protocol/ClientProtocol.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ List<OzoneBucket> listBuckets(String volumeName, String bucketPrefix,
329329
* @param size Size of the data
330330
* @param metadata Custom key value metadata
331331
* @return {@link OzoneOutputStream}
332-
*
332+
* @deprecated Use {@link ClientProtocol#createKey(String, String, String, long, ReplicationConfig, Map)} instead.
333333
*/
334334
@Deprecated
335335
OzoneOutputStream createKey(String volumeName, String bucketName,
@@ -344,7 +344,7 @@ OzoneOutputStream createKey(String volumeName, String bucketName,
344344
* @param bucketName Name of the Bucket
345345
* @param keyName Name of the Key
346346
* @param size Size of the data
347-
* @param metadata custom key value metadata
347+
* @param metadata Custom key value metadata
348348
* @return {@link OzoneOutputStream}
349349
*
350350
*/
@@ -353,6 +353,22 @@ OzoneOutputStream createKey(String volumeName, String bucketName,
353353
Map<String, String> metadata)
354354
throws IOException;
355355

356+
/**
357+
* Writes a key in an existing bucket.
358+
* @param volumeName Name of the Volume
359+
* @param bucketName Name of the Bucket
360+
* @param keyName Name of the Key
361+
* @param size Size of the data
362+
* @param metadata Custom key value metadata
363+
* @param tags Tags used for S3 object tags
364+
* @return {@link OzoneOutputStream}
365+
*
366+
*/
367+
OzoneOutputStream createKey(String volumeName, String bucketName,
368+
String keyName, long size, ReplicationConfig replicationConfig,
369+
Map<String, String> metadata, Map<String, String> tags)
370+
throws IOException;
371+
356372
/**
357373
* Writes a key in an existing bucket.
358374
* @param volumeName Name of the Volume
@@ -368,6 +384,22 @@ OzoneDataStreamOutput createStreamKey(String volumeName, String bucketName,
368384
Map<String, String> metadata)
369385
throws IOException;
370386

387+
/**
388+
* Writes a key in an existing bucket.
389+
* @param volumeName Name of the Volume
390+
* @param bucketName Name of the Bucket
391+
* @param keyName Name of the Key
392+
* @param size Size of the data
393+
* @param metadata custom key value metadata
394+
* @param tags Tags used for S3 object tags
395+
* @return {@link OzoneDataStreamOutput}
396+
*
397+
*/
398+
OzoneDataStreamOutput createStreamKey(String volumeName, String bucketName,
399+
String keyName, long size, ReplicationConfig replicationConfig,
400+
Map<String, String> metadata, Map<String, String> tags)
401+
throws IOException;
402+
371403
/**
372404
* Reads a key from an existing bucket.
373405
* @param volumeName Name of the Volume
@@ -535,6 +567,22 @@ OmMultipartInfo initiateMultipartUpload(String volumeName, String
535567
Map<String, String> metadata)
536568
throws IOException;
537569

570+
/**
571+
* Initiate Multipart upload.
572+
* @param volumeName Name of the Volume
573+
* @param bucketName Name of the Bucket
574+
* @param keyName Name of the Key
575+
* @param replicationConfig Replication config
576+
* @param metadata Custom key value metadata
577+
* @param tags Tags used for S3 object tags
578+
* @return {@link OmMultipartInfo}
579+
* @throws IOException
580+
*/
581+
OmMultipartInfo initiateMultipartUpload(String volumeName, String
582+
bucketName, String keyName, ReplicationConfig replicationConfig,
583+
Map<String, String> metadata, Map<String, String> tags)
584+
throws IOException;
585+
538586
/**
539587
* Create a part key for a multipart upload key.
540588
* @param volumeName

0 commit comments

Comments
 (0)