HADOOP-2047 Add an '--master=X' and '--html' command-line parameters to shell

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@603824 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2007-12-13 05:43:59 +00:00
parent c0000537e7
commit f8a906f49f
3 changed files with 52 additions and 22 deletions

View File

@ -116,6 +116,7 @@ Trunk (unreleased changes)
HADOOP-2370 Allow column families with an unlimited number of versions HADOOP-2370 Allow column families with an unlimited number of versions
(Edward Yoon via Stack) (Edward Yoon via Stack)
HADOOP-2407 Keeping MapFile.Reader open is expensive: Part 2 HADOOP-2407 Keeping MapFile.Reader open is expensive: Part 2
HADOOP-2047 Add an '--master=X' and '--html' command-line parameters to shell
Release 0.15.1 Release 0.15.1
Branch 0.15 Branch 0.15

View File

@ -27,9 +27,11 @@ import jline.ConsoleReader;
import org.apache.hadoop.hbase.shell.Command; import org.apache.hadoop.hbase.shell.Command;
import org.apache.hadoop.hbase.shell.HelpCommand; import org.apache.hadoop.hbase.shell.HelpCommand;
import org.apache.hadoop.hbase.shell.ShellSecurityManager;
import org.apache.hadoop.hbase.shell.ReturnMsg; import org.apache.hadoop.hbase.shell.ReturnMsg;
import org.apache.hadoop.hbase.shell.ShellSecurityManager;
import org.apache.hadoop.hbase.shell.TableFormatter;
import org.apache.hadoop.hbase.shell.TableFormatterFactory; import org.apache.hadoop.hbase.shell.TableFormatterFactory;
import org.apache.hadoop.hbase.shell.formatter.HtmlTableFormatter;
import org.apache.hadoop.hbase.shell.generated.ParseException; import org.apache.hadoop.hbase.shell.generated.ParseException;
import org.apache.hadoop.hbase.shell.generated.Parser; import org.apache.hadoop.hbase.shell.generated.Parser;
import org.apache.hadoop.hbase.shell.generated.TokenMgrError; import org.apache.hadoop.hbase.shell.generated.TokenMgrError;
@ -37,11 +39,14 @@ import org.apache.hadoop.hbase.shell.generated.TokenMgrError;
/** /**
* An hbase shell. * An hbase shell.
* *
* @see <a href="http://wiki.apache.org/lucene-hadoop/Hbase/HbaseShell">HbaseShell</a> * @see <a
* href="http://wiki.apache.org/lucene-hadoop/Hbase/HbaseShell">HbaseShell</a>
*/ */
public class Shell { public class Shell {
/** audible keyboard bells */ /** audible keyboard bells */
public static final boolean DEFAULT_BELL_ENABLED = true; public static final boolean DEFAULT_BELL_ENABLED = true;
public static String MASTER_ADDRESS = null;
public static String HTML_OPTION = null;
/** Return the boolean value indicating whether end of command or not */ /** Return the boolean value indicating whether end of command or not */
static boolean isEndOfCommand(String line) { static boolean isEndOfCommand(String line) {
@ -57,36 +62,48 @@ public class Shell {
* @param watch true if execution time should be computed and returned * @param watch true if execution time should be computed and returned
* @param start start of time interval * @param start start of time interval
* @param end end of time interval * @param end end of time interval
* @return a string of code execution time. */ * @return a string of code execution time.
*/
public static String executeTime(boolean watch, long start, long end) { public static String executeTime(boolean watch, long start, long end) {
return watch? return watch ? " ("
" (" + String.format("%.2f", Double.valueOf((end - start) * 0.001)) + + String.format("%.2f", Double.valueOf((end - start) * 0.001)) + " sec)"
" sec)": : "";
"";
} }
/** /**
* Main method * Main method
*
* @param args not used * @param args not used
* @throws IOException * @throws IOException
*/ */
public static void main(String args[]) throws IOException { public static void main(String args[]) throws IOException {
argumentParsing(args);
HBaseConfiguration conf = new HBaseConfiguration(); HBaseConfiguration conf = new HBaseConfiguration();
ConsoleReader reader = new ConsoleReader(); ConsoleReader reader = new ConsoleReader();
System.setSecurityManager(new ShellSecurityManager()); System.setSecurityManager(new ShellSecurityManager());
reader.setBellEnabled(conf.getBoolean("hbaseshell.jline.bell.enabled", reader.setBellEnabled(conf.getBoolean("hbaseshell.jline.bell.enabled",
DEFAULT_BELL_ENABLED)); DEFAULT_BELL_ENABLED));
Writer out = new OutputStreamWriter(System.out, "UTF-8"); Writer out = new OutputStreamWriter(System.out, "UTF-8");
TableFormatterFactory tff = new TableFormatterFactory(out, conf); TableFormatter tableFormater = new TableFormatterFactory(out, conf).get();
HelpCommand help = new HelpCommand(out, tff.get()); if (MASTER_ADDRESS != null) {
if(args.length == 0) help.printVersion(); conf.set("hbase.master", MASTER_ADDRESS.substring(9, MASTER_ADDRESS.length()));
}
if (HTML_OPTION != null) {
tableFormater = new HtmlTableFormatter(out);
System.out.println("--html");
}
HelpCommand help = new HelpCommand(out, tableFormater);
if (args.length == 0 || !args[0].equals("7")) {
help.printVersion();
}
StringBuilder queryStr = new StringBuilder(); StringBuilder queryStr = new StringBuilder();
String extendedLine; String extendedLine;
while ((extendedLine = reader.readLine(getPrompt(queryStr))) != null) { while ((extendedLine = reader.readLine(getPrompt(queryStr))) != null) {
if (isEndOfCommand(extendedLine)) { if (isEndOfCommand(extendedLine)) {
queryStr.append(" " + extendedLine); queryStr.append(" " + extendedLine);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Parser parser = new Parser(queryStr.toString(), out, tff.get()); Parser parser = new Parser(queryStr.toString(), out, tableFormater);
ReturnMsg rs = null; ReturnMsg rs = null;
try { try {
Command cmd = parser.terminatedCommand(); Command cmd = parser.terminatedCommand();
@ -95,10 +112,12 @@ public class Shell {
} }
} catch (ParseException pe) { } catch (ParseException pe) {
String[] msg = pe.getMessage().split("[\n]"); String[] msg = pe.getMessage().split("[\n]");
System.out.println("Syntax error : Type 'help;' for usage.\nMessage : " + msg[0]); System.out.println("Syntax error : Type 'help;' for usage.\nMessage : "
+ msg[0]);
} catch (TokenMgrError te) { } catch (TokenMgrError te) {
String[] msg = te.getMessage().split("[\n]"); String[] msg = te.getMessage().split("[\n]");
System.out.println("Lexical error : Type 'help;' for usage.\nMessage : " + msg[0]); System.out.println("Lexical error : Type 'help;' for usage.\nMessage : "
+ msg[0]);
} }
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
@ -112,4 +131,14 @@ public class Shell {
} }
System.out.println(); System.out.println();
} }
private static void argumentParsing(String[] args) {
for (int i = 0; i < args.length; i++) {
if (args[i].toLowerCase().startsWith("--master:")) {
MASTER_ADDRESS = args[i];
} else if (args[i].toLowerCase().startsWith("--html")) {
HTML_OPTION = args[i];
}
}
}
} }

View File

@ -47,7 +47,7 @@ public class ShellSecurityManager extends SecurityManager {
// I didn't figure out How can catch the ExitException in shell main. // I didn't figure out How can catch the ExitException in shell main.
// So, I just Re-launching the shell. // So, I just Re-launching the shell.
Shell shell = new Shell(); Shell shell = new Shell();
String[] args = new String[] { String.valueOf(status) }; String[] args = new String[] { String.valueOf(7) };
try { try {
shell.main(args); shell.main(args);
} catch (IOException e) { } catch (IOException e) {