[GitHub] [hadoop-ozone] dineshchitlangia commented on a change in pull request #963: HDDS-3646. Add a copy command to copy key to a new one.

2020-05-24 Thread GitBox


dineshchitlangia commented on a change in pull request #963:
URL: https://github.com/apache/hadoop-ozone/pull/963#discussion_r429726622



##
File path: 
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/keys/CopyKeyHandler.java
##
@@ -89,17 +89,11 @@ protected void execute(OzoneClient client, OzoneAddress 
address)
   OZONE_REPLICATION_TYPE_DEFAULT));
 }
 
-Map keyMetadata = new HashMap<>();
-String gdprEnabled = bucket.getMetadata().get(OzoneConsts.GDPR_FLAG);
-if (Boolean.parseBoolean(gdprEnabled)) {
-  keyMetadata.put(OzoneConsts.GDPR_FLAG, Boolean.TRUE.toString());
-}
-
 int chunkSize = (int) getConf().getStorageSize(OZONE_SCM_CHUNK_SIZE_KEY,
 OZONE_SCM_CHUNK_SIZE_DEFAULT, StorageUnit.BYTES);
 try (InputStream input = bucket.readKey(fromKey);
- OutputStream output = bucket.createKey(toKey, 0,
- replicationType, replicationFactor, keyMetadata)) {
+ OutputStream output = bucket.createKey(toKey, input.available(),
+ replicationType, replicationFactor, bucket.getMetadata())) {

Review comment:
   Your previous code was fine. The bucket metadata object may have 
properties that may not be needed for the key. So, if we copy the bucket 
metadata to be saved as key metadata, that is basically the piece of data which 
is mostly irrelevant for the key.
   
   So you can replace `bucket.getMetadata()` with `keyMetadata`.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org



[GitHub] [hadoop-ozone] dineshchitlangia commented on a change in pull request #963: HDDS-3646. Add a copy command to copy key to a new one.

2020-05-24 Thread GitBox


dineshchitlangia commented on a change in pull request #963:
URL: https://github.com/apache/hadoop-ozone/pull/963#discussion_r429695171



##
File path: 
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 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 in 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 copy will only for 
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`

##
File path: 
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 

[GitHub] [hadoop-ozone] dineshchitlangia commented on a change in pull request #963: HDDS-3646. Add a copy command to copy key to a new one.

2020-05-24 Thread GitBox


dineshchitlangia commented on a change in pull request #963:
URL: https://github.com/apache/hadoop-ozone/pull/963#discussion_r429693826



##
File path: 
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;

Review comment:
   Redundant import statements.
   Avoid using * and instead import the specific classes/members needed.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org