Permalink
Browse files

Fixed issue 201:

    - Converted this to use joptsimple, to have better options and
      more reasonable defaults.
    - Took out references to shell in file and class names, as this
      is a tool rather than a shell.
  • Loading branch information...
1 parent 43f8921 commit 59d4b240986deaf7ef7ebd74ea076e0d3ae518cc @afeinberg afeinberg committed Jan 30, 2010
@@ -18,4 +18,4 @@
base_dir=$(dirname $0)/..
-$base_dir/bin/run-class.sh jline.ConsoleRunner voldemort.client.rebalance.RebalanceCommandShell $@
+$base_dir/bin/run-class.sh jline.ConsoleRunner voldemort.client.rebalance.RebalanceCLI $@
@@ -0,0 +1,59 @@
+package voldemort.client.rebalance;
+
+import java.io.File;
+import java.util.Set;
+
+import com.google.common.base.Joiner;
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+import voldemort.cluster.Cluster;
+import voldemort.utils.CmdUtils;
+import voldemort.xml.ClusterMapper;
+
+public class RebalanceCLI {
+ public static void main(String[] args) throws Exception {
+ OptionParser parser = new OptionParser();
+ parser.accepts("help", "print usage information");
+ parser.accepts("url", "[REQUIRED] bootstrap url")
+ .withRequiredArg()
+ .describedAs("boostrap-url");
+ parser.accepts("cluster", "path to target cluster xml config file.")
+ .withRequiredArg()
+ .describedAs("target-cluster.xml");
+ parser.accepts("parallelism", "number of rebalances to run in parallel. Default = 1")
+ .withRequiredArg()
+ .ofType(Integer.class)
+ .describedAs("parallelism");
+ parser.accepts("no-delete", "Do not delete after rebalancing");
+ OptionSet options = parser.parse(args);
+
+ if (options.has("help")) {
+ parser.printHelpOn(System.out);
+ System.exit(0);
+ }
+
+ Set<String> missing = CmdUtils.missing(options,
+ "cluster",
+ "url");
+ if (missing.size() > 0) {
+ System.err.println("Missing required arguments: " + Joiner.on(", ").join(missing));
+ parser.printHelpOn(System.err);
+ System.exit(1);
+ }
+
+ String bootstrapURL = (String) options.valueOf("url");
+ String targetClusterXML = (String) options.valueOf("cluster");
+ boolean deleteAfterRebalancing = !options.has("no-delete");
+ int maxParallelRebalancing = CmdUtils.valueOf(options, "parallelism", 1);
+
+ Cluster targetCluster = new ClusterMapper().readCluster(new File(targetClusterXML));
+
+ RebalanceClientConfig config = new RebalanceClientConfig();
+ config.setMaxParallelRebalancing(maxParallelRebalancing);
+ config.setDeleteAfterRebalancingEnabled(deleteAfterRebalancing);
+
+ RebalanceController rebalanceController = new RebalanceController(bootstrapURL, config);
+ rebalanceController.rebalance(targetCluster);
+ rebalanceController.stop();
+ }
+}
@@ -1,49 +0,0 @@
-package voldemort.client.rebalance;
-
-import java.io.File;
-
-import voldemort.cluster.Cluster;
-import voldemort.xml.ClusterMapper;
-
-public class RebalanceCommandShell {
-
- private static RebalanceController rebalanceClient;
- private static ClusterMapper clusterMapper = new ClusterMapper();
-
- private static void printUsage() {
- StringBuilder builder = new StringBuilder();
- builder.append("java RebalanceCommandShell bootstrapURL targetCluster.xml maxParallelRebalancing deleteAfterRebalancing\n");
- builder.append("Arguments:\n");
- builder.append("bootstrapUrl: bootstrap voldemort server url.(should point to a node in the cluster and not the new nodes)\n");
- builder.append("targetCluster.xml: The final desired cluster configuration.\n");
- builder.append("maxParallelRebalancing: maximum parallel transfers to start\n");
- builder.append("deleteAfterRebalancing: delete data from original nodes after transfering.\n");
-
- System.out.println(builder.toString());
- System.exit(0);
- }
-
- public static void main(String[] args) throws Exception {
- if(args.length != 4)
- printUsage();
-
- String bootstrapURL = args[0];
- Cluster targetCluster = clusterMapper.readCluster(new File(args[1]));
- int maxParallelRebalancing = Integer.parseInt(args[2]);
-
- if(!"true".equals(args[3]) && !"false".equals(args[3])) {
- printUsage();
- }
-
- boolean deleteAfterRebalancing = Boolean.parseBoolean(args[3]);
-
- RebalanceClientConfig config = new RebalanceClientConfig();
- config.setMaxParallelRebalancing(maxParallelRebalancing);
- config.setDeleteAfterRebalancingEnabled(deleteAfterRebalancing);
-
- rebalanceClient = new RebalanceController(bootstrapURL, config);
-
- rebalanceClient.rebalance(targetCluster);
- rebalanceClient.stop();
- }
-}

0 comments on commit 59d4b24

Please sign in to comment.