sarvekshayr commented on code in PR #12213:
URL: https://github.com/apache/ozone/pull/12213#discussion_r4764859204
##########
hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/keys/PutKeyHandler.java:
##########
@@ -69,10 +73,25 @@ public class PutKeyHandler extends KeyHandler {
description = "Store key only if it already exists and its generation
matches the value provided")
private Long expectedGeneration;
+ @Option(names = {"--storage-policy", "-s"},
+ description = "Key StoragePolicy. Allowed values: HOT, WARM, COLD, null.
"
+ + "If not specified, the key inherits the StoragePolicy of the
bucket.")
+ private String storagePolicyStr;
+
+ private static final String NULL_STORAGE_POLICY = "null";
+
@Override
protected void execute(OzoneClient client, OzoneAddress address)
throws IOException {
+ StoragePolicy storagePolicy = parseStoragePolicy(storagePolicyStr);
+ // TODO(HDDS-16679): Streaming writes support StoragePolicy.
+ Preconditions.checkArgument(!(stream && storagePolicy != null),
+ "--storage-policy is not supported together with --stream");
+ // TODO(HDDS-17963): rewriteKey supports StoragePolicy.
+ Preconditions.checkArgument(!(expectedGeneration != null && storagePolicy
!= null),
+ "--storage-policy is not supported together with
--expected-generation");
Review Comment:
QQ: Will all three options work together in future?
##########
hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/keys/PutKeyHandler.java:
##########
@@ -106,35 +125,59 @@ protected void execute(OzoneClient client, OzoneAddress
address)
replicationConfig, chunkSize);
} else {
async(dataFile, bucket, keyName, keyMetadata,
- replicationConfig, chunkSize);
+ replicationConfig, chunkSize, storagePolicy);
+ }
+ }
+
+ /**
+ * Parse a user-supplied {@code --storage-policy} value into a {@link
StoragePolicy}. Returns {@code null} when the
+ * caller passed "null" (any case) or an empty value, so that the key
inherits the StoragePolicy of the bucket.
+ *
+ * @throws IllegalArgumentException if the value is not one of HOT, WARM,
COLD, or "null".
+ */
+ private static StoragePolicy parseStoragePolicy(String value) {
+ if (Strings.isNullOrEmpty(value) ||
NULL_STORAGE_POLICY.equalsIgnoreCase(value)) {
+ return null;
+ }
+ try {
+ return OzoneStoragePolicy.valueOf(value.toUpperCase());
Review Comment:
Should we trim whitespace from the storage policy input? Otherwise strings
like " COLD" or "COLD " will throw an exception:
```
java.lang.IllegalArgumentException: Invalid storage policy: COLD . Allowed
String values are: HOT, WARM, COLD, or null.
```
```suggestion
return OzoneStoragePolicy.valueOf(value.toUpperCase().trim());
```
##########
hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/keys/PutKeyHandler.java:
##########
@@ -106,35 +125,59 @@ protected void execute(OzoneClient client, OzoneAddress
address)
replicationConfig, chunkSize);
} else {
async(dataFile, bucket, keyName, keyMetadata,
- replicationConfig, chunkSize);
+ replicationConfig, chunkSize, storagePolicy);
+ }
+ }
+
+ /**
+ * Parse a user-supplied {@code --storage-policy} value into a {@link
StoragePolicy}. Returns {@code null} when the
+ * caller passed "null" (any case) or an empty value, so that the key
inherits the StoragePolicy of the bucket.
+ *
+ * @throws IllegalArgumentException if the value is not one of HOT, WARM,
COLD, or "null".
+ */
+ private static StoragePolicy parseStoragePolicy(String value) {
+ if (Strings.isNullOrEmpty(value) ||
NULL_STORAGE_POLICY.equalsIgnoreCase(value)) {
+ return null;
+ }
+ try {
+ return OzoneStoragePolicy.valueOf(value.toUpperCase());
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid storage policy: " + value
+ + ". Allowed String values are: HOT, WARM, COLD, or null.");
Review Comment:
nit:
```suggestion
+ ". Allowed values are: HOT, WARM, COLD, or null.");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]