ashishkumar50 commented on code in PR #12213:
URL: https://github.com/apache/ozone/pull/12213#discussion_r4797075141


##########
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.")

Review Comment:
   Please check if any of the parent command or inherited option uses "s" to 
avoid conflict? 



##########
hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/keys/PutKeyHandler.java:
##########
@@ -106,35 +125,60 @@ 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) {
+    String trimmed = value == null ? null : value.trim();
+    if (Strings.isNullOrEmpty(trimmed) || 
NULL_STORAGE_POLICY.equalsIgnoreCase(trimmed)) {
+      return null;
+    }
+    try {
+      return OzoneStoragePolicy.valueOf(trimmed.toUpperCase());
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgumentException("Invalid storage policy: " + value
+          + ". Allowed values are: HOT, WARM, COLD, or null.");
     }
   }
 
   private void async(
       File dataFile, OzoneBucket bucket,
       String keyName, Map<String, String> keyMetadata,
-      ReplicationConfig replicationConfig, int chunkSize)
+      ReplicationConfig replicationConfig, int chunkSize, StoragePolicy 
storagePolicy)
       throws IOException {
     if (isVerbose()) {
       out().println("API: async");
     }
     try (InputStream input = Files.newInputStream(dataFile.toPath());
-         OutputStream output = createOrReplaceKey(bucket, keyName, 
dataFile.length(), keyMetadata, replicationConfig)) {
+         OutputStream output = createOrReplaceKey(bucket, keyName, 
dataFile.length(), keyMetadata, replicationConfig,
+             storagePolicy)) {
       IOUtils.copyBytes(input, output, chunkSize);
     }
   }
 
   private OzoneOutputStream createOrReplaceKey(OzoneBucket bucket, String 
keyName,
-      long size, Map<String, String> keyMetadata, ReplicationConfig 
replicationConfig
-  ) throws IOException {
+      long size, Map<String, String> keyMetadata, ReplicationConfig 
replicationConfig,
+      StoragePolicy storagePolicy) throws IOException {
     if (expectedGeneration != null) {
       final long existingGeneration = expectedGeneration;
       Preconditions.checkArgument(existingGeneration > 0,
           "expectedGeneration must be positive, but was %s", 
existingGeneration);
       return bucket.rewriteKey(keyName, size, existingGeneration, 
replicationConfig, keyMetadata);
     }
 
-    return bucket.createKey(keyName, size, replicationConfig, keyMetadata);
+    return bucket.createKey(keyName, CreateKeyOptions.builder()

Review Comment:
   What happens when an existing key has an explicit `COLD` policy, but the 
user overwrites it without specifying --storage-policy in a bucket whose policy 
is `WARM`?
   Should the resulting key:
   1. Inherit `WARM` from the bucket?
   2. Retain the existing `COLD` policy?



-- 
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]

Reply via email to