Repository: hadoop
Updated Branches:
  refs/heads/HDFS-7240 58cdb715f -> 2dc48b7f1


HDFS-10202. ozone : Add key commands to CLI. Contributed by Anu Engineer.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/2dc48b7f
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/2dc48b7f
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/2dc48b7f

Branch: refs/heads/HDFS-7240
Commit: 2dc48b7f1e90f9b457bd8e80cb33b923ec34f459
Parents: 58cdb71
Author: Chris Nauroth <cnaur...@apache.org>
Authored: Fri Mar 25 09:50:58 2016 -0700
Committer: Chris Nauroth <cnaur...@apache.org>
Committed: Fri Mar 25 09:50:58 2016 -0700

----------------------------------------------------------------------
 .../src/main/conf/log4j.properties              |  24 ++++
 .../apache/hadoop/ozone/web/ozShell/Shell.java  | 107 ++++++++++++++--
 .../web/ozShell/bucket/InfoBucketHandler.java   |   2 +-
 .../web/ozShell/bucket/UpdateBucketHandler.java |  98 +++++++++++++++
 .../web/ozShell/keys/DeleteKeyHandler.java      |  95 +++++++++++++++
 .../ozone/web/ozShell/keys/GetKeyHandler.java   | 122 +++++++++++++++++++
 .../ozone/web/ozShell/keys/InfoKeyHandler.java  |  93 ++++++++++++++
 .../ozone/web/ozShell/keys/ListKeyHandler.java  | 105 ++++++++++++++++
 .../ozone/web/ozShell/keys/PutKeyHandler.java   | 110 +++++++++++++++++
 9 files changed, 748 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/2dc48b7f/hadoop-common-project/hadoop-common/src/main/conf/log4j.properties
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/conf/log4j.properties 
b/hadoop-common-project/hadoop-common/src/main/conf/log4j.properties
index dc7e705..e1cc73a 100644
--- a/hadoop-common-project/hadoop-common/src/main/conf/log4j.properties
+++ b/hadoop-common-project/hadoop-common/src/main/conf/log4j.properties
@@ -308,3 +308,27 @@ 
log4j.appender.EWMA=org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender
 log4j.appender.EWMA.cleanupInterval=${yarn.ewma.cleanupInterval}
 log4j.appender.EWMA.messageAgeLimitSeconds=${yarn.ewma.messageAgeLimitSeconds}
 log4j.appender.EWMA.maxUniqueMessages=${yarn.ewma.maxUniqueMessages}
+
+#
+# Add a logger for ozone that is separate from the Datanode.
+#
+log4j.logger.org.apache.hadoop.ozone=DEBUG,OZONE,FILE
+
+# Do not log into datanode logs. Remove this line to have single log.
+log4j.additivity.org.apache.hadoop.ozone=false
+
+# For development purposes, log both to console and log file.
+log4j.appender.OZONE=org.apache.log4j.ConsoleAppender
+log4j.appender.OZONE.Threshold=info
+log4j.appender.OZONE.layout=org.apache.log4j.PatternLayout
+log4j.appender.OZONE.layout.ConversionPattern=%d{ISO8601} [%t] %-5p \
+ %X{component} %X{function} %X{resource} %X{user} %X{request} - %m%n
+
+# Real ozone logger that writes to ozone.log
+log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.FILE.File=${hadoop.log.dir}/ozone.log
+log4j.appender.FILE.Threshold=debug
+log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.FILE.layout.ConversionPattern=%d{ISO8601} [%t] %-5p \
+(%F:%L) %X{function} %X{resource} %X{user} %X{request} - \
+%m%n

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2dc48b7f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java
index 6fc42a0..7a8dd4d 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/Shell.java
@@ -23,9 +23,16 @@ import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.ozone.web.exceptions.OzoneException;
+import org.apache.hadoop.ozone.web.ozShell.bucket.UpdateBucketHandler;
+import org.apache.hadoop.ozone.web.ozShell.keys.DeleteKeyHandler;
+import org.apache.hadoop.ozone.web.ozShell.keys.GetKeyHandler;
+import org.apache.hadoop.ozone.web.ozShell.keys.InfoKeyHandler;
+import org.apache.hadoop.ozone.web.ozShell.keys.ListKeyHandler;
+import org.apache.hadoop.ozone.web.ozShell.keys.PutKeyHandler;
 import org.apache.hadoop.ozone.web.ozShell.volume.CreateVolumeHandler;
 import org.apache.hadoop.ozone.web.ozShell.volume.DeleteVolumeHandler;
 import org.apache.hadoop.ozone.web.ozShell.volume.InfoVolumeHandler;
@@ -72,6 +79,15 @@ public class Shell extends Configured implements Tool {
   public static final String INFO_BUCKET = "infoBucket";
   public static final String ADD_ACLS = "addAcl";
   public static final String REMOVE_ACLS = "removeAcl";
+  // TODO : Support versioning and StorageType for buckets
+
+  //Object related command line arguments
+  public static final String PUT_KEY = "putKey";
+  public static final String GET_KEY = "getKey";
+  public static final String INFO_KEY = "infoKey";
+  public static final String DELETE_KEY = "deleteKey";
+  public static final String LIST_KEY = "listKey";
+  public static final String FILE = "file";
 
   /**
    * Main for the ozShell Command handling.
@@ -118,6 +134,7 @@ public class Shell extends Configured implements Tool {
     Options opts = new Options();
     addVolumeCommands(opts);
     addBucketCommands(opts);
+    addKeyCommands(opts);
     return opts;
   }
 
@@ -131,8 +148,14 @@ public class Shell extends Configured implements Tool {
    */
   private CommandLine parseArgs(String[] argv, Options opts)
       throws org.apache.commons.cli.ParseException {
-    BasicParser parser = new BasicParser();
-    return parser.parse(opts, argv);
+    try {
+      BasicParser parser = new BasicParser();
+      return parser.parse(opts, argv);
+    } catch (ParseException ex) {
+      System.out.printf(ex.getMessage());
+    }
+
+    return null;
   }
 
 
@@ -195,10 +218,8 @@ public class Shell extends Configured implements Tool {
    */
   private void addBucketCommands(Options opts) {
     Option createBucket = new Option(CREATE_BUCKET, true,
-        "creates a bucket in a given volume.\n" +
-            "\t For example : hdfs oz " +
-            "-createBucket " +
-            "<volumeName/bucketName>");
+        "creates a bucket in a given volume." +
+        "For example: hdfs oz -createBucket <bucketURI>");
     opts.addOption(createBucket);
 
     Option infoBucket =
@@ -210,9 +231,56 @@ public class Shell extends Configured implements Tool {
     opts.addOption(deleteBucket);
 
     Option listBucket =
-        new Option(LIST_BUCKET, true, "Lists the buckets in a volume.");
+        new Option(LIST_BUCKET, true, "lists the buckets in a volume.");
     opts.addOption(listBucket);
 
+    Option updateBucket =
+        new Option(UPDATE_BUCKET, true, "allows changing bucket attributes.\n" 
+
+            " For example: hdfs oz -updateBucket <bucketURI> " +
+            "-addAcl user:frodo:rw");
+    opts.addOption(updateBucket);
+
+    Option addAcl =
+        new Option(ADD_ACLS, true, "allows user to add acls to a bucket.");
+    opts.addOption(addAcl);
+
+    Option removeAcl =
+        new Option(REMOVE_ACLS, true, "allows user to remove acls from a " +
+            "bucket.");
+    opts.addOption(removeAcl);
+
+  }
+
+  /**
+   * All key commands.
+   *
+   * @param opts - options
+   */
+  private void addKeyCommands(Options opts) {
+    Option putKey =
+        new Option(PUT_KEY, true, "creates or overwrites an existing key");
+    opts.addOption(putKey);
+
+    Option deleteKey =
+        new Option(DELETE_KEY, true, "deletes an existing key");
+    opts.addOption(deleteKey);
+
+    Option infoKey =
+        new Option(INFO_KEY, true, "returns information about an existing 
key");
+    opts.addOption(infoKey);
+
+    Option listKey =
+        new Option(LIST_KEY, true, "list all keys in a given bucket");
+    opts.addOption(listKey);
+
+    Option getKey =
+        new Option(GET_KEY, true, "Gets a specific key from ozone server.");
+    opts.addOption(getKey);
+
+    Option fileArgument =
+        new Option(FILE, true, "Data file path");
+    opts.addOption(fileArgument);
+
   }
 
   /**
@@ -269,6 +337,31 @@ public class Shell extends Configured implements Tool {
         handler = new ListBucketHandler();
       }
 
+      if(cmd.hasOption(Shell.UPDATE_BUCKET)){
+        handler = new UpdateBucketHandler();
+      }
+
+      //Key Functions
+
+      if(cmd.hasOption(Shell.PUT_KEY)) {
+        handler = new PutKeyHandler();
+      }
+
+      if(cmd.hasOption(Shell.DELETE_KEY)) {
+        handler = new DeleteKeyHandler();
+      }
+
+      if(cmd.hasOption(Shell.INFO_KEY)) {
+        handler = new InfoKeyHandler();
+      }
+
+      if(cmd.hasOption(Shell.LIST_KEY)) {
+        handler = new ListKeyHandler();
+      }
+
+      if(cmd.hasOption(Shell.GET_KEY)) {
+        handler = new GetKeyHandler();
+      }
 
       if (handler != null) {
         handler.execute(cmd);

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2dc48b7f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
index 6694768..e930cba 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/InfoBucketHandler.java
@@ -64,7 +64,7 @@ public class InfoBucketHandler extends Handler {
 
     if (path.getNameCount() < 2) {
       throw new OzoneClientException(
-          "volume and bucket name required in delete Bucket");
+          "volume and bucket name required in info Bucket");
     }
 
     volumeName = path.getName(0).toString();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2dc48b7f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/UpdateBucketHandler.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/UpdateBucketHandler.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/UpdateBucketHandler.java
new file mode 100644
index 0000000..c79cfff
--- /dev/null
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/bucket/UpdateBucketHandler.java
@@ -0,0 +1,98 @@
+/*
+ * 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.web.ozShell.bucket;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.hadoop.ozone.web.client.OzoneBucket;
+import org.apache.hadoop.ozone.web.client.OzoneClientException;
+import org.apache.hadoop.ozone.web.client.OzoneVolume;
+import org.apache.hadoop.ozone.web.exceptions.OzoneException;
+import org.apache.hadoop.ozone.web.ozShell.Handler;
+import org.apache.hadoop.ozone.web.ozShell.Shell;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Allows users to add and remove acls and from a bucket.
+ */
+public class UpdateBucketHandler extends Handler {
+  private String volumeName;
+  private String bucketName;
+  private String rootName;
+
+  @Override
+  protected void execute(CommandLine cmd)
+      throws IOException, OzoneException, URISyntaxException {
+    if (!cmd.hasOption(Shell.UPDATE_BUCKET)) {
+      throw new OzoneClientException(
+          "Incorrect call : updateBucket is missing");
+    }
+
+    String ozoneURIString = cmd.getOptionValue(Shell.UPDATE_BUCKET);
+    URI ozoneURI = verifyURI(ozoneURIString);
+    Path path = Paths.get(ozoneURI.getPath());
+
+    if (path.getNameCount() < 2) {
+      throw new OzoneClientException(
+          "volume and bucket name required in update bucket");
+    }
+
+    volumeName = path.getName(0).toString();
+    bucketName = path.getName(1).toString();
+
+    if (cmd.hasOption(Shell.VERBOSE)) {
+      System.out.printf("Volume Name : %s%n", volumeName);
+      System.out.printf("Bucket Name : %s%n", bucketName);
+    }
+
+    if (cmd.hasOption(Shell.RUNAS)) {
+      rootName = "hdfs";
+    } else {
+      rootName = System.getProperty("user.name");
+    }
+
+    client.setEndPointURI(ozoneURI);
+    client.setUserAuth(rootName);
+
+    OzoneVolume vol = client.getVolume(volumeName);
+    if (cmd.hasOption(Shell.ADD_ACLS)) {
+      String aclString = cmd.getOptionValue(Shell.ADD_ACLS);
+      String[] aclArray = aclString.split(",");
+      vol.addAcls(bucketName, aclArray);
+    }
+
+    if (cmd.hasOption(Shell.REMOVE_ACLS)) {
+      String aclString = cmd.getOptionValue(Shell.REMOVE_ACLS);
+      String[] aclArray = aclString.split(",");
+      vol.removeAcls(bucketName, aclArray);
+    }
+
+    OzoneBucket bucket = vol.getBucket(bucketName);
+
+    ObjectMapper mapper = new ObjectMapper();
+    Object json =
+        mapper.readValue(bucket.getBucketInfo().toJsonString(), Object.class);
+    System.out.printf("%s%n", mapper.writerWithDefaultPrettyPrinter()
+        .writeValueAsString(json));
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2dc48b7f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/DeleteKeyHandler.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/DeleteKeyHandler.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/DeleteKeyHandler.java
new file mode 100644
index 0000000..a75b331
--- /dev/null
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/DeleteKeyHandler.java
@@ -0,0 +1,95 @@
+/*
+ * 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.web.ozShell.keys;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.hadoop.ozone.web.client.OzoneBucket;
+import org.apache.hadoop.ozone.web.client.OzoneClientException;
+import org.apache.hadoop.ozone.web.client.OzoneVolume;
+import org.apache.hadoop.ozone.web.exceptions.OzoneException;
+import org.apache.hadoop.ozone.web.ozShell.Handler;
+import org.apache.hadoop.ozone.web.ozShell.Shell;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Executes Delete Key.
+ */
+public class DeleteKeyHandler extends Handler {
+  private String userName;
+  private String volumeName;
+  private String bucketName;
+  private String keyName;
+
+  /**
+   * Executes the Client Calls.
+   *
+   * @param cmd - CommandLine
+   * @throws IOException
+   * @throws OzoneException
+   * @throws URISyntaxException
+   */
+  @Override
+  protected void execute(CommandLine cmd)
+      throws IOException, OzoneException, URISyntaxException {
+    if (!cmd.hasOption(Shell.DELETE_KEY)) {
+      throw new OzoneClientException("Incorrect call : deleteKey is missing");
+    }
+
+
+    if (cmd.hasOption(Shell.USER)) {
+      userName = cmd.getOptionValue(Shell.USER);
+    } else {
+      userName = System.getProperty("user.name");
+    }
+
+
+    String ozoneURIString = cmd.getOptionValue(Shell.DELETE_KEY);
+    URI ozoneURI = verifyURI(ozoneURIString);
+    Path path = Paths.get(ozoneURI.getPath());
+    if (path.getNameCount() < 3) {
+      throw new OzoneClientException(
+          "volume/bucket/key name required in deleteKey");
+    }
+
+    volumeName = path.getName(0).toString();
+    bucketName = path.getName(1).toString();
+    keyName = path.getName(2).toString();
+
+
+    if (cmd.hasOption(Shell.VERBOSE)) {
+      System.out.printf("Volume Name : %s%n", volumeName);
+      System.out.printf("Bucket Name : %s%n", bucketName);
+      System.out.printf("Key Name : %s%n", keyName);
+    }
+
+    client.setEndPointURI(ozoneURI);
+    client.setUserAuth(userName);
+
+
+    OzoneVolume vol = client.getVolume(volumeName);
+    OzoneBucket bucket = vol.createBucket(bucketName);
+    bucket.deleteKey(keyName);
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2dc48b7f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java
new file mode 100644
index 0000000..f0b207f
--- /dev/null
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/GetKeyHandler.java
@@ -0,0 +1,122 @@
+/*
+ * 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.web.ozShell.keys;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.hadoop.ozone.web.client.OzoneBucket;
+import org.apache.hadoop.ozone.web.client.OzoneClientException;
+import org.apache.hadoop.ozone.web.client.OzoneVolume;
+import org.apache.hadoop.ozone.web.exceptions.OzoneException;
+import org.apache.hadoop.ozone.web.ozShell.Handler;
+import org.apache.hadoop.ozone.web.ozShell.Shell;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Gets an existing key.
+ */
+public class GetKeyHandler extends Handler {
+  private String userName;
+  private String volumeName;
+  private String bucketName;
+  private String keyName;
+
+
+  /**
+   * Executes the Client Calls.
+   *
+   * @param cmd - CommandLine
+   *
+   * @throws IOException
+   * @throws OzoneException
+   * @throws URISyntaxException
+   */
+  @Override
+  protected void execute(CommandLine cmd)
+      throws IOException, OzoneException, URISyntaxException {
+    if (!cmd.hasOption(Shell.GET_KEY)) {
+      throw new OzoneClientException("Incorrect call : getKey is missing");
+    }
+
+    if (!cmd.hasOption(Shell.FILE)) {
+      throw new OzoneClientException(
+          "get key needs a file path to download to");
+    }
+
+    if (cmd.hasOption(Shell.USER)) {
+      userName = cmd.getOptionValue(Shell.USER);
+    } else {
+      userName = System.getProperty("user.name");
+    }
+
+
+    String ozoneURIString = cmd.getOptionValue(Shell.GET_KEY);
+    URI ozoneURI = verifyURI(ozoneURIString);
+    Path path = Paths.get(ozoneURI.getPath());
+    if (path.getNameCount() < 3) {
+      throw new OzoneClientException(
+          "volume/bucket/key name required in putKey");
+    }
+
+    volumeName = path.getName(0).toString();
+    bucketName = path.getName(1).toString();
+    keyName = path.getName(2).toString();
+
+
+    if (cmd.hasOption(Shell.VERBOSE)) {
+      System.out.printf("Volume Name : %s%n", volumeName);
+      System.out.printf("Bucket Name : %s%n", bucketName);
+      System.out.printf("Key Name : %s%n", keyName);
+    }
+
+
+    String fileName = cmd.getOptionValue(Shell.FILE);
+    Path dataFilePath = Paths.get(fileName);
+    File dataFile = new File(fileName);
+
+
+    if (dataFile.exists()) {
+      throw new OzoneClientException(fileName +
+                                         "exists. Download will overwrite an " 
+
+                                         "existing file. Aborting.");
+    }
+
+    client.setEndPointURI(ozoneURI);
+    client.setUserAuth(userName);
+
+
+    OzoneVolume vol = client.getVolume(volumeName);
+    OzoneBucket bucket = vol.getBucket(bucketName);
+    bucket.getKey(keyName, dataFilePath);
+
+    if(cmd.hasOption(Shell.VERBOSE)) {
+      FileInputStream stream = new FileInputStream(dataFile);
+      String hash = DigestUtils.md5Hex(stream);
+      System.out.printf("Downloaded file hash : %s%n", hash);
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2dc48b7f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/InfoKeyHandler.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/InfoKeyHandler.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/InfoKeyHandler.java
new file mode 100644
index 0000000..ac77f61
--- /dev/null
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/InfoKeyHandler.java
@@ -0,0 +1,93 @@
+/*
+ * 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.web.ozShell.keys;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.hadoop.ozone.web.client.OzoneClientException;
+import org.apache.hadoop.ozone.web.exceptions.OzoneException;
+import org.apache.hadoop.ozone.web.ozShell.Handler;
+import org.apache.hadoop.ozone.web.ozShell.Shell;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Executes Info Object.
+ */
+public class InfoKeyHandler extends Handler {
+  private String userName;
+  private String volumeName;
+  private String bucketName;
+  private String keyName;
+
+  /**
+   * Executes the Client Calls.
+   *
+   * @param cmd - CommandLine
+   * @throws IOException
+   * @throws OzoneException
+   * @throws URISyntaxException
+   */
+  @Override
+  protected void execute(CommandLine cmd)
+      throws IOException, OzoneException, URISyntaxException {
+    if (!cmd.hasOption(Shell.INFO_KEY)) {
+      throw new OzoneClientException("Incorrect call : infoKey is missing");
+    }
+
+
+    if (cmd.hasOption(Shell.USER)) {
+      userName = cmd.getOptionValue(Shell.USER);
+    } else {
+      userName = System.getProperty("user.name");
+    }
+
+
+    String ozoneURIString = cmd.getOptionValue(Shell.INFO_KEY);
+    URI ozoneURI = verifyURI(ozoneURIString);
+    Path path = Paths.get(ozoneURI.getPath());
+    if (path.getNameCount() < 3) {
+      throw new OzoneClientException(
+          "volume/bucket/key name required in infoKey");
+    }
+
+    volumeName = path.getName(0).toString();
+    bucketName = path.getName(1).toString();
+    keyName = path.getName(2).toString();
+
+
+    if (cmd.hasOption(Shell.VERBOSE)) {
+      System.out.printf("Volume Name : %s%n", volumeName);
+      System.out.printf("Bucket Name : %s%n", bucketName);
+      System.out.printf("Key Name : %s%n", keyName);
+    }
+
+    client.setEndPointURI(ozoneURI);
+    client.setUserAuth(userName);
+
+
+//    OzoneVolume vol = client.getVolume(volumeName);
+//    OzoneBucket bucket = vol.createBucket(bucketName);
+
+    throw new OzoneClientException("Not supported yet");
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2dc48b7f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/ListKeyHandler.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/ListKeyHandler.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/ListKeyHandler.java
new file mode 100644
index 0000000..5f04cd0
--- /dev/null
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/ListKeyHandler.java
@@ -0,0 +1,105 @@
+/*
+ * 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.web.ozShell.keys;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.hadoop.ozone.web.client.OzoneBucket;
+import org.apache.hadoop.ozone.web.client.OzoneClientException;
+import org.apache.hadoop.ozone.web.client.OzoneKey;
+import org.apache.hadoop.ozone.web.client.OzoneVolume;
+import org.apache.hadoop.ozone.web.exceptions.OzoneException;
+import org.apache.hadoop.ozone.web.ozShell.Handler;
+import org.apache.hadoop.ozone.web.ozShell.Shell;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+/**
+ * Executes List Keys.
+ */
+public class ListKeyHandler extends Handler {
+  private String userName;
+  private String volumeName;
+  private String bucketName;
+
+  /**
+   * Executes the Client Calls.
+   *
+   * @param cmd - CommandLine
+   * @throws IOException
+   * @throws OzoneException
+   * @throws URISyntaxException
+   */
+  @Override
+  protected void execute(CommandLine cmd)
+      throws IOException, OzoneException, URISyntaxException {
+
+    if (!cmd.hasOption(Shell.LIST_KEY)) {
+      throw new OzoneClientException("Incorrect call : listKey is missing");
+    }
+
+    String ozoneURIString = cmd.getOptionValue(Shell.LIST_KEY);
+    URI ozoneURI = verifyURI(ozoneURIString);
+    Path path = Paths.get(ozoneURI.getPath());
+    if (path.getNameCount() < 2) {
+      throw new OzoneClientException("volume/bucket is required in listKey");
+    }
+
+    volumeName = path.getName(0).toString();
+    bucketName = path.getName(1).toString();
+
+
+    if (cmd.hasOption(Shell.VERBOSE)) {
+      System.out.printf("Volume Name : %s%n", volumeName);
+      System.out.printf("bucket Name : %s%n", bucketName);
+    }
+
+    if (cmd.hasOption(Shell.USER)) {
+      userName = cmd.getOptionValue(Shell.USER);
+    } else {
+      userName = System.getProperty("user.name");
+    }
+
+
+    client.setEndPointURI(ozoneURI);
+    client.setUserAuth(userName);
+
+
+    OzoneVolume vol = client.getVolume(volumeName);
+    OzoneBucket bucket = vol.getBucket(bucketName);
+    List<OzoneKey> keys = bucket.listKeys();
+
+    ObjectMapper mapper = new ObjectMapper();
+
+
+    for (OzoneKey key : keys) {
+      Object json =
+          mapper.readValue(key.getObjectInfo().toJsonString(), Object.class);
+      System.out.printf("%s%n", mapper.writerWithDefaultPrettyPrinter()
+          .writeValueAsString(json));
+    }
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2dc48b7f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/PutKeyHandler.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/PutKeyHandler.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/PutKeyHandler.java
new file mode 100644
index 0000000..513787d
--- /dev/null
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/ozShell/keys/PutKeyHandler.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.web.ozShell.keys;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.hadoop.ozone.web.client.OzoneBucket;
+import org.apache.hadoop.ozone.web.client.OzoneClientException;
+import org.apache.hadoop.ozone.web.client.OzoneVolume;
+import org.apache.hadoop.ozone.web.exceptions.OzoneException;
+import org.apache.hadoop.ozone.web.ozShell.Handler;
+import org.apache.hadoop.ozone.web.ozShell.Shell;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Puts a file into an ozone bucket.
+ */
+public class PutKeyHandler extends Handler {
+  private String userName;
+  private String volumeName;
+  private String bucketName;
+  private String keyName;
+
+  /**
+   * Executes the Client Calls.
+   *
+   * @param cmd - CommandLine
+   * @throws IOException
+   * @throws OzoneException
+   * @throws URISyntaxException
+   */
+  @Override
+  protected void execute(CommandLine cmd)
+      throws IOException, OzoneException, URISyntaxException {
+    if (!cmd.hasOption(Shell.PUT_KEY)) {
+      throw new OzoneClientException("Incorrect call : putKey is missing");
+    }
+
+    if (!cmd.hasOption(Shell.FILE)) {
+      throw new OzoneClientException("put key needs a file to put");
+    }
+
+    if (cmd.hasOption(Shell.USER)) {
+      userName = cmd.getOptionValue(Shell.USER);
+    } else {
+      userName = System.getProperty("user.name");
+    }
+
+    String ozoneURIString = cmd.getOptionValue(Shell.PUT_KEY);
+    URI ozoneURI = verifyURI(ozoneURIString);
+    Path path = Paths.get(ozoneURI.getPath());
+    if (path.getNameCount() < 3) {
+      throw new OzoneClientException(
+          "volume/bucket/key name required in putKey");
+    }
+
+    volumeName = path.getName(0).toString();
+    bucketName = path.getName(1).toString();
+    keyName = path.getName(2).toString();
+
+
+    if (cmd.hasOption(Shell.VERBOSE)) {
+      System.out.printf("Volume Name : %s%n", volumeName);
+      System.out.printf("Bucket Name : %s%n", bucketName);
+      System.out.printf("Key Name : %s%n", keyName);
+    }
+
+
+    String fileName = cmd.getOptionValue(Shell.FILE);
+    File dataFile = new File(fileName);
+
+    if (cmd.hasOption(Shell.VERBOSE)) {
+      FileInputStream stream = new FileInputStream(dataFile);
+      String hash = DigestUtils.md5Hex(stream);
+      System.out.printf("File Hash : %s%n", hash);
+      stream.close();
+    }
+
+    client.setEndPointURI(ozoneURI);
+    client.setUserAuth(userName);
+
+    OzoneVolume vol = client.getVolume(volumeName);
+    OzoneBucket bucket = vol.getBucket(bucketName);
+    bucket.putKey(keyName, dataFile);
+  }
+
+}

Reply via email to