String[] kv = confOpt.split("=", 2);
if (kv.length == 2) {
conf.set(kv[0], kv[1]);
LOG.debug("-D configuration override: " + kv[0] + "=" + kv[1]);
} else {
throw new ParseException("-D option format invalid: " + confOpt);
}
}
}
// check if we are the backup master - override the conf if so
if (cmd.hasOption("backup")) {
conf.setBoolean(HConstants.MASTER_TYPE_BACKUP, true);
}
if (cmd.getArgList().contains("start")) {
try {
// Print out vm stats before starting up.
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
if (runtime != null) {
LOG.info("vmName=" + runtime.getVmName() + ", vmVendor=" +
runtime.getVmVendor() + ", vmVersion=" + runtime.getVmVersion());
LOG.info("vmInputArguments=" + runtime.getInputArguments());
}
// If 'local', defer to LocalHBaseCluster instance. Starts master
// and regionserver both in the one JVM.
if (LocalHBaseCluster.isLocal(conf)) {
final MiniZooKeeperCluster zooKeeperCluster =
new MiniZooKeeperCluster();
File zkDataPath = new File(conf.get("hbase.zookeeper.property.dataDir"));
int zkClientPort = conf.getInt("hbase.zookeeper.property.clientPort", 0);
if (zkClientPort == 0) {
throw new IOException("No config value for hbase.zookeeper.property.clientPort");
}
zooKeeperCluster.setTickTime(conf.getInt("hbase.zookeeper.property.tickTime", 3000));
zooKeeperCluster.setClientPort(zkClientPort);
int clientPort = zooKeeperCluster.startup(zkDataPath);
if (clientPort != zkClientPort) {
String errorMsg = "Couldnt start ZK at requested address of " +
zkClientPort + ", instead got: " + clientPort + ". Aborting. Why? " +
"Because clients (eg shell) wont be able to find this ZK quorum";
System.err.println(errorMsg);
throw new IOException(errorMsg);
}
conf.set("hbase.zookeeper.property.clientPort",
Integer.toString(clientPort));
// Need to have the zk cluster shutdown when master is shutdown.
// Run a subclass that does the zk cluster shutdown on its way out.
LocalHBaseCluster cluster = new LocalHBaseCluster(conf, 1,
LocalHMaster.class, HRegionServer.class);
((LocalHMaster)cluster.getMaster()).setZKCluster(zooKeeperCluster);
cluster.startup();
} else {
HMaster master = constructMaster(masterClass, conf);
if (master.shutdownRequested.get()) {
LOG.info("Won't bring the Master up as a shutdown is requested");
return;
}
master.start();
}
} catch (Throwable t) {
LOG.error("Failed to start master", t);
System.exit(-1);
}
} else if (cmd.getArgList().contains("stop")) {
HBaseAdmin adm = null;
try {
adm = new HBaseAdmin(conf);
} catch (MasterNotRunningException e) {
LOG.error("Master not running");
System.exit(0);
}
try {
adm.shutdown();
} catch (Throwable t) {
LOG.error("Failed to stop master", t);
System.exit(-1);
}
} else {
throw new ParseException("Unknown argument(s): " +
org.apache.commons.lang.StringUtils.join(cmd.getArgs(), " "));
}
} catch (ParseException e) {
LOG.error("Could not parse: ", e);
printUsageAndExit();