use of com.netflix.exhibitor.core.config.zookeeper.ZookeeperConfigProvider in project exhibitor by soabase.
the class ExhibitorCreator method getZookeeperProvider.
private ConfigProvider getZookeeperProvider(CommandLine commandLine, String useHostname, Properties defaultProperties) throws Exception {
String connectString = commandLine.getOptionValue(ZOOKEEPER_CONFIG_INITIAL_CONNECT_STRING);
String path = commandLine.getOptionValue(ZOOKEEPER_CONFIG_BASE_PATH);
String retrySpec = commandLine.getOptionValue(ZOOKEEPER_CONFIG_RETRY, DEFAULT_ZOOKEEPER_CONFIG_RETRY);
if ((path == null) || (connectString == null)) {
log.error("Both " + ZOOKEEPER_CONFIG_INITIAL_CONNECT_STRING + " and " + ZOOKEEPER_CONFIG_BASE_PATH + " are required when the configtype is zookeeper");
return null;
}
try {
PathUtils.validatePath(path);
} catch (IllegalArgumentException e) {
log.error("Invalid " + ZOOKEEPER_CONFIG_BASE_PATH + ": " + path);
return null;
}
String[] retryParts = retrySpec.split("\\:");
if (retryParts.length != 2) {
log.error("Bad " + ZOOKEEPER_CONFIG_RETRY + " value: " + retrySpec);
return null;
}
int baseSleepTimeMs;
int maxRetries;
try {
baseSleepTimeMs = Integer.parseInt(retryParts[0]);
maxRetries = Integer.parseInt(retryParts[1]);
} catch (NumberFormatException e) {
log.error("Bad " + ZOOKEEPER_CONFIG_RETRY + " value: " + retrySpec);
return null;
}
int exhibitorPort;
try {
exhibitorPort = commandLine.hasOption(ZOOKEEPER_CONFIG_EXHIBITOR_PORT) ? Integer.parseInt(commandLine.getOptionValue(ZOOKEEPER_CONFIG_EXHIBITOR_PORT)) : 0;
} catch (NumberFormatException e) {
log.error("Bad " + ZOOKEEPER_CONFIG_EXHIBITOR_PORT + " value: " + commandLine.getOptionValue(ZOOKEEPER_CONFIG_EXHIBITOR_PORT));
return null;
}
int pollingMs;
try {
pollingMs = Integer.parseInt(commandLine.getOptionValue(ZOOKEEPER_CONFIG_POLLING, DEFAULT_ZOOKEEPER_CONFIG_POLLING));
} catch (NumberFormatException e) {
log.error("Bad " + ZOOKEEPER_CONFIG_POLLING + " value: " + commandLine.getOptionValue(ZOOKEEPER_CONFIG_POLLING, DEFAULT_ZOOKEEPER_CONFIG_POLLING));
return null;
}
String exhibitorRestPath = commandLine.getOptionValue(ZOOKEEPER_CONFIG_EXHIBITOR_URI_PATH, DEFAULT_ZOOKEEPER_CONFIG_EXHIBITOR_URI_PATH);
CuratorFramework client = makeCurator(connectString, baseSleepTimeMs, maxRetries, exhibitorPort, exhibitorRestPath, pollingMs);
if (client == null) {
return null;
}
client.start();
closeables.add(client);
return new ZookeeperConfigProvider(client, path, defaultProperties, useHostname);
}
Aggregations