use of org.apache.helix.manager.zk.HelixManagerShutdownHook in project helix by apache.
the class ExampleProcess method main.
public static void main(String[] args) throws Exception {
String zkConnectString = "localhost:2181";
String clusterName = "storage-integration-cluster";
String instanceName = "localhost_8905";
String file = null;
String stateModelValue = "MasterSlave";
int delay = 0;
// false is for dev testing
boolean skipZeroArgs = true;
if (!skipZeroArgs || args.length > 0) {
CommandLine cmd = processCommandLineArgs(args);
zkConnectString = cmd.getOptionValue(zkServer);
clusterName = cmd.getOptionValue(cluster);
String host = cmd.getOptionValue(hostAddress);
String portString = cmd.getOptionValue(hostPort);
int port = Integer.parseInt(portString);
instanceName = host + "_" + port;
file = cmd.getOptionValue(configFile);
if (file != null) {
File f = new File(file);
if (!f.exists()) {
System.err.println("static config file doesn't exist");
System.exit(1);
}
}
stateModelValue = cmd.getOptionValue(stateModel);
if (cmd.hasOption(transDelay)) {
try {
delay = Integer.parseInt(cmd.getOptionValue(transDelay));
if (delay < 0) {
throw new Exception("delay must be positive");
}
} catch (Exception e) {
e.printStackTrace();
delay = 0;
}
}
}
// Espresso_driver.py will consume this
System.out.println("Starting Process with ZK:" + zkConnectString);
ExampleProcess process = new ExampleProcess(zkConnectString, clusterName, instanceName, file, stateModelValue, delay);
process.start();
Runtime.getRuntime().addShutdownHook(new HelixManagerShutdownHook(process.getManager()));
Thread.currentThread().join();
}
use of org.apache.helix.manager.zk.HelixManagerShutdownHook in project helix by apache.
the class HelixControllerMain method main.
public static void main(String[] args) throws Exception {
// read the config;
// check if the this process is the master wait indefinitely
// other approach is always process the events but when updating the zk
// check if this is master.
// This is difficult to get right
// get the clusters to manage
// for each cluster create a manager
// add the respective listeners for each manager
CommandLine cmd = processCommandLineArgs(args);
String zkConnectString = cmd.getOptionValue(zkServerAddress);
String clusterName = cmd.getOptionValue(cluster);
String controllerMode = STANDALONE;
String controllerName = null;
if (cmd.hasOption(mode)) {
controllerMode = cmd.getOptionValue(mode);
}
if (controllerMode.equalsIgnoreCase(DISTRIBUTED) && !cmd.hasOption(name)) {
throw new IllegalArgumentException("A unique cluster controller name is required in DISTRIBUTED mode");
}
controllerName = cmd.getOptionValue(name);
// Espresso_driver.py will consume this
logger.info("Cluster manager started, zkServer: " + zkConnectString + ", clusterName:" + clusterName + ", controllerName:" + controllerName + ", mode:" + controllerMode);
HelixManager manager = startHelixController(zkConnectString, clusterName, controllerName, controllerMode);
Runtime.getRuntime().addShutdownHook(new HelixManagerShutdownHook(manager));
try {
Thread.currentThread().join();
} catch (InterruptedException e) {
logger.info("controller:" + controllerName + ", " + Thread.currentThread().getName() + " interrupted");
} finally {
manager.disconnect();
}
}
Aggregations