dineshchitlangia commented on code in PR #963:
URL: https://github.com/apache/ozone/pull/963#discussion_r429695171


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/keys/CpKeyHandler.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ozone.shell.keys;
+
+import org.apache.hadoop.conf.StorageUnit;
+import org.apache.hadoop.hdds.client.ReplicationFactor;
+import org.apache.hadoop.hdds.client.ReplicationType;
+import org.apache.hadoop.io.IOUtils;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.client.OzoneClient;
+import org.apache.hadoop.ozone.client.OzoneClientException;
+import org.apache.hadoop.ozone.client.OzoneVolume;
+import org.apache.hadoop.ozone.shell.OzoneAddress;
+import org.apache.hadoop.ozone.shell.bucket.BucketHandler;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+import picocli.CommandLine.Parameters;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import static 
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CHUNK_SIZE_DEFAULT;
+import static 
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CHUNK_SIZE_KEY;
+import static org.apache.hadoop.ozone.OzoneConfigKeys.*;
+import static 
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION_TYPE_DEFAULT;
+
+/**
+ * Copy an existing key to another one.
+ */
+@Command(name = "cp",
+    description = "copies an existing key to another one")
+public class CpKeyHandler extends BucketHandler {
+
+  @Parameters(index = "1", arity = "1..1",
+      description = "The existing key to be renamed")
+  private String fromKey;
+
+  @Parameters(index = "2", arity = "1..1",
+      description = "The new desired name of the key")
+  private String toKey;
+
+  @Option(names = {"-r", "--replication"},
+      description = "Replication factor of the new key. (use ONE or THREE) "
+          + "Default is specified in the cluster-wide config.")
+  private ReplicationFactor replicationFactor;
+
+  @Option(names = {"-t", "--type"},
+      description = "Replication type of the new key. (use RATIS or " +
+          "STAND_ALONE) Default is specified in the cluster-wide config.")
+  private ReplicationType replicationType;
+
+  @Override
+  protected void execute(OzoneClient client, OzoneAddress address)
+      throws IOException, OzoneClientException {
+
+    String volumeName = address.getVolumeName();
+    String bucketName = address.getBucketName();
+
+    OzoneVolume vol = client.getObjectStore().getVolume(volumeName);
+    OzoneBucket bucket = vol.getBucket(bucketName);
+
+    if (replicationFactor == null) {
+      replicationFactor = ReplicationFactor.valueOf(
+          getConf().getInt(OZONE_REPLICATION, OZONE_REPLICATION_DEFAULT));
+    }
+
+    if (replicationType == null) {
+      replicationType = ReplicationType.valueOf(
+          getConf().get(OZONE_REPLICATION_TYPE,
+              OZONE_REPLICATION_TYPE_DEFAULT));
+    }
+
+    Map<String, String> keyMetadata = new HashMap<>();
+    String gdprEnabled = bucket.getMetadata().get(OzoneConsts.GDPR_FLAG);
+    if (Boolean.parseBoolean(gdprEnabled)) {
+      keyMetadata.put(OzoneConsts.GDPR_FLAG, Boolean.TRUE.toString());
+    }
+

Review Comment:
   Since we are assuming that the copy command is to copy a key within the same 
bucket, this GDPR piece of code won't cause any problem.
   Can we pls add comments in the javadoc to state the copykey  will only be 
copying keys within the same bucket?
   This will be a safeguard for users attempting to doing something like:
   `ozone sh key cp /vol1/bucket1/key1 /vol1/bucket5/newkey`



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