|
@@ -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);
|