DRILL-246: Improve command line parsing for QuerySubmitter
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/251022f8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/251022f8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/251022f8 Branch: refs/heads/master Commit: 251022f8494e8f1efe3e2faaa38cbb686f330eb2 Parents: 8540450 Author: Steven Phillips <[email protected]> Authored: Thu Sep 12 20:13:15 2013 -0700 Committer: Steven Phillips <[email protected]> Committed: Fri Sep 20 15:11:34 2013 -0700 ---------------------------------------------------------------------- distribution/src/resources/submit_plan | 18 +------ .../drill/exec/client/QuerySubmitter.java | 52 ++++++++++++++++++-- 2 files changed, 49 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/251022f8/distribution/src/resources/submit_plan ---------------------------------------------------------------------- diff --git a/distribution/src/resources/submit_plan b/distribution/src/resources/submit_plan index fee1820..3c9184a 100755 --- a/distribution/src/resources/submit_plan +++ b/distribution/src/resources/submit_plan @@ -15,21 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -ARGS=(); -while [ $# -gt 0 ] -do - case "$1" in - -t) shift; - TYPE=$1;; - -zk) shift; - ZK=$1;; - -f) shift; - FILE=$1;; - *) ARGS+=($1);; - esac - shift -done - bin=`dirname "${BASH_SOURCE-$0}"` bin=`cd "$bin">/dev/null; pwd` @@ -64,7 +49,8 @@ CP=$DRILL_HOME/jars/*:$CP CP=$DRILL_HOME/lib/*:$CP CP=$DRILL_CONF_DIR:$CP +CP=$HADOOP_CLASSPATH:$CP DRILL_SHELL_JAVA_OPTS="$DRILL_SHELL_JAVA_OPTS -Dlog.path=$DRILL_LOG_DIR/submitter.log" -exec $JAVA $DRILL_SHELL_JAVA_OPTS $DRILL_JAVA_OPTS -cp $CP org.apache.drill.exec.client.QuerySubmitter $FILE $TYPE $ZK +exec $JAVA $DRILL_SHELL_JAVA_OPTS $DRILL_JAVA_OPTS -cp $CP org.apache.drill.exec.client.QuerySubmitter $@ http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/251022f8/exec/java-exec/src/main/java/org/apache/drill/exec/client/QuerySubmitter.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/client/QuerySubmitter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/client/QuerySubmitter.java index 2d5c105..835b9b5 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/client/QuerySubmitter.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/client/QuerySubmitter.java @@ -17,6 +17,10 @@ */ package org.apache.drill.exec.client; +import com.beust.jcommander.JCommander; +import com.beust.jcommander.Parameter; +import com.beust.jcommander.ParameterException; +import com.beust.jcommander.Parameters; import com.beust.jcommander.internal.Lists; import com.google.common.base.Charsets; import com.google.common.base.Stopwatch; @@ -52,16 +56,54 @@ public class QuerySubmitter { public static void main(String args[]) throws Exception { QuerySubmitter submitter = new QuerySubmitter(); - System.exit(submitter.submitQuery(args[0], args[1], args[2])); + Options o = new Options(); + JCommander jc = null; + try { + jc = new JCommander(o, args); + jc.setProgramName("./submit_plan"); + } catch (ParameterException e) { + System.out.println(e.getMessage()); + String[] valid = {"-f", "file", "-t", "physical"}; + new JCommander(o, valid).usage(); + System.exit(-1); + } + if (o.help) { + jc.usage(); + System.exit(0); + } + System.exit(submitter.submitQuery(o.location, o.planType, o.zk, o.local, o.bits)); + } + + static class Options { + @Parameter(names = {"-f"}, description = "file containing plan", required=true) + public String location = null; + + @Parameter(names = {"-t"}, description = "type of plan, logical/physical", required=true) + public String planType; + + @Parameter(names = {"-zk"}, description = "zookeeper connect string.", required=false) + public String zk = "localhost:2181"; + + @Parameter(names = {"-local"}, description = "run query in local mode", required=false) + public boolean local; + + @Parameter(names = "-bits", description = "number of drillbits to run. local mode only", required=false) + public int bits = 1; + + @Parameter(names = {"-h", "-help", "--help"}, description = "show usage", help=true) + public boolean help = false; } - public int submitQuery(String planLocation, String type, String zkQuorum) throws Exception { + public int submitQuery(String planLocation, String type, String zkQuorum, boolean local, int bits) throws Exception { DrillConfig config = DrillConfig.create(); DrillClient client; - if (zkQuorum.equals("local")) { + if (local) { RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); - Drillbit bit = new Drillbit(config, serviceSet); - bit.run(); + Drillbit[] drillbits = new Drillbit[bits]; + for (int i = 0; i < bits; i++) { + drillbits[i] = new Drillbit(config, serviceSet); + drillbits[i].run(); + } client = new DrillClient(config, serviceSet.getCoordinator()); } else { ZKClusterCoordinator clusterCoordinator = new ZKClusterCoordinator(config, zkQuorum);
