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


##########
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.");
     }
   }
 
   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()
+        .setSize(size)
+        .setReplicationConfig(replicationConfig)
+        .setMetadata(keyMetadata)
+        .setStoragePolicy(storagePolicy)

Review Comment:
   Since you already have https://github.com/apache/ozone/pull/12179 ready, 
I’ll leave it up to you to decide whether to hold off or proceed. I’m happy 
with either approach as long as we have something moving forward in parallel.



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