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
(Edward Yoon via Stack)
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
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.HelpCommand;
import org.apache.hadoop.hbase.shell.ShellSecurityManager;
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.formatter.HtmlTableFormatter;
import org.apache.hadoop.hbase.shell.generated.ParseException;
import org.apache.hadoop.hbase.shell.generated.Parser;
import org.apache.hadoop.hbase.shell.generated.TokenMgrError;
@ -37,12 +39,15 @@ import org.apache.hadoop.hbase.shell.generated.TokenMgrError;
/**
* 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 {
/** audible keyboard bells */
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 */
static boolean isEndOfCommand(String line) {
return (line.lastIndexOf(';') > -1) ? true : false;
@ -57,50 +62,64 @@ public class Shell {
* @param watch true if execution time should be computed and returned
* @param start start 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) {
return watch?
" (" + String.format("%.2f", Double.valueOf((end - start) * 0.001)) +
" sec)":
"";
return watch ? " ("
+ String.format("%.2f", Double.valueOf((end - start) * 0.001)) + " sec)"
: "";
}
/**
* Main method
*
* @param args not used
* @throws IOException
*/
public static void main(String args[]) throws IOException {
public static void main(String args[]) throws IOException {
argumentParsing(args);
HBaseConfiguration conf = new HBaseConfiguration();
ConsoleReader reader = new ConsoleReader();
System.setSecurityManager(new ShellSecurityManager());
reader.setBellEnabled(conf.getBoolean("hbaseshell.jline.bell.enabled",
DEFAULT_BELL_ENABLED));
DEFAULT_BELL_ENABLED));
Writer out = new OutputStreamWriter(System.out, "UTF-8");
TableFormatterFactory tff = new TableFormatterFactory(out, conf);
HelpCommand help = new HelpCommand(out, tff.get());
if(args.length == 0) help.printVersion();
TableFormatter tableFormater = new TableFormatterFactory(out, conf).get();
if (MASTER_ADDRESS != null) {
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();
String extendedLine;
while ((extendedLine = reader.readLine(getPrompt(queryStr))) != null) {
if (isEndOfCommand(extendedLine)) {
queryStr.append(" " + extendedLine);
long start = System.currentTimeMillis();
Parser parser = new Parser(queryStr.toString(), out, tff.get());
Parser parser = new Parser(queryStr.toString(), out, tableFormater);
ReturnMsg rs = null;
try {
Command cmd = parser.terminatedCommand();
if (cmd != null) {
rs = cmd.execute(conf);
rs = cmd.execute(conf);
}
} catch (ParseException pe) {
} catch (ParseException pe) {
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) {
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();
if (rs != null && rs.getType() > -1)
System.out.println(rs.getMsg()
@ -112,4 +131,14 @@ public class Shell {
}
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.
// So, I just Re-launching the shell.
Shell shell = new Shell();
String[] args = new String[] { String.valueOf(status) };
String[] args = new String[] { String.valueOf(7) };
try {
shell.main(args);
} catch (IOException e) {