* The main method for the HBase rest server.
* @param args command-line arguments
* @throws Exception exception
*/
public static void main(String[] args) throws Exception {
Log LOG = LogFactory.getLog("RESTServer");
VersionInfo.logVersion();
Configuration conf = HBaseConfiguration.create();
// login the server principal (if using secure Hadoop)
UserProvider provider = UserProvider.instantiate(conf);
if (provider.isHadoopSecurityEnabled() && provider.isHBaseSecurityEnabled()) {
String machineName = Strings.domainNamePointerToHostName(
DNS.getDefaultHost(conf.get("hbase.rest.dns.interface", "default"),
conf.get("hbase.rest.dns.nameserver", "default")));
provider.login("hbase.rest.keytab.file", "hbase.rest.kerberos.principal",
machineName);
}
RESTServlet servlet = RESTServlet.getInstance(conf);
Options options = new Options();
options.addOption("p", "port", true, "Port to bind to [default: 8080]");
options.addOption("ro", "readonly", false, "Respond only to GET HTTP " +
"method requests [default: false]");
options.addOption(null, "infoport", true, "Port for web UI");
CommandLine commandLine = null;
try {
commandLine = new PosixParser().parse(options, args);
} catch (ParseException e) {
LOG.error("Could not parse: ", e);
printUsageAndExit(options, -1);
}
// check for user-defined port setting, if so override the conf
if (commandLine != null && commandLine.hasOption("port")) {
String val = commandLine.getOptionValue("port");
servlet.getConfiguration()
.setInt("hbase.rest.port", Integer.valueOf(val));
LOG.debug("port set to " + val);
}
// check if server should only process GET requests, if so override the conf
if (commandLine != null && commandLine.hasOption("readonly")) {
servlet.getConfiguration().setBoolean("hbase.rest.readonly", true);
LOG.debug("readonly set to true");
}
// check for user-defined info server port setting, if so override the conf
if (commandLine != null && commandLine.hasOption("infoport")) {
String val = commandLine.getOptionValue("infoport");
servlet.getConfiguration()
.setInt("hbase.rest.info.port", Integer.valueOf(val));
LOG.debug("Web UI port set to " + val);
}
@SuppressWarnings("unchecked")
List<String> remainingArgs = commandLine != null ?
commandLine.getArgList() : new ArrayList<String>();