use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ZooKeeperServerMain in project zookeeper by apache.
the class ZooKeeperServerEmbeddedImpl method start.
@Override
public void start(long startupTimeout) throws Exception {
switch(exitHandler) {
case EXIT:
ServiceUtils.setSystemExitProcedure(ServiceUtils.SYSTEM_EXIT);
break;
case LOG_ONLY:
ServiceUtils.setSystemExitProcedure(ServiceUtils.LOG_ONLY);
break;
default:
ServiceUtils.setSystemExitProcedure(ServiceUtils.SYSTEM_EXIT);
break;
}
final CompletableFuture<String> started = new CompletableFuture<>();
if (config.getServers().size() > 1 || config.isDistributed()) {
LOG.info("Running ZK Server in single Quorum MODE");
maincluster = new QuorumPeerMain() {
protected QuorumPeer getQuorumPeer() throws SaslException {
return new QuorumPeer() {
@Override
public void start() {
super.start();
LOG.info("ZK Server {} started", this);
started.complete(null);
}
};
}
};
// Start and schedule the the purge task
purgeMgr = new DatadirCleanupManager(config.getDataDir(), config.getDataLogDir(), config.getSnapRetainCount(), config.getPurgeInterval());
purgeMgr.start();
thread = new Thread("zkservermainrunner") {
@Override
public void run() {
try {
maincluster.runFromConfig(config);
maincluster.close();
LOG.info("ZK server died. Requsting stop on JVM");
if (!stopping) {
ServiceUtils.requestSystemExit(ExitCode.EXECUTION_FINISHED.getValue());
}
} catch (Throwable t) {
LOG.error("error during server lifecycle", t);
maincluster.close();
if (!stopping) {
ServiceUtils.requestSystemExit(ExitCode.INVALID_INVOCATION.getValue());
}
}
}
};
thread.start();
} else {
LOG.info("Running ZK Server in single STANDALONE MODE");
mainsingle = new ZooKeeperServerMain() {
@Override
public void serverStarted() {
LOG.info("ZK Server started");
started.complete(null);
}
};
purgeMgr = new DatadirCleanupManager(config.getDataDir(), config.getDataLogDir(), config.getSnapRetainCount(), config.getPurgeInterval());
purgeMgr.start();
thread = new Thread("zkservermainrunner") {
@Override
public void run() {
try {
ServerConfig cc = new ServerConfig();
cc.readFrom(config);
LOG.info("ZK server starting");
mainsingle.runFromConfig(cc);
LOG.info("ZK server died. Requesting stop on JVM");
if (!stopping) {
ServiceUtils.requestSystemExit(ExitCode.EXECUTION_FINISHED.getValue());
}
} catch (Throwable t) {
LOG.error("error during server lifecycle", t);
mainsingle.close();
if (!stopping) {
ServiceUtils.requestSystemExit(ExitCode.INVALID_INVOCATION.getValue());
}
}
}
};
thread.start();
}
try {
started.get(startupTimeout, TimeUnit.MILLISECONDS);
} catch (TimeoutException err) {
LOG.info("Startup timed out, trying to close");
close();
throw err;
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ZooKeeperServerMain in project coprhd-controller by CoprHD.
the class ZkSimulator method start.
/**
* Starts standalone Zookeeper service
*/
public void start() throws Exception {
final ServerConfig serverConfig = new ServerConfig();
serverConfig.readFrom(config);
final ZooKeeperServerMain server = new ZooKeeperServerMain();
Thread zkService = new Thread(new Runnable() {
@Override
public void run() {
try {
server.runFromConfig(serverConfig);
} catch (IOException e) {
log.error("coordinator start failure", e);
}
}
});
zkService.setDaemon(true);
zkService.start();
coordinatorClient = connectClient();
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ZooKeeperServerMain in project motan by weibocom.
the class EmbeddedZookeeper method start.
public void start() throws IOException, QuorumPeerConfig.ConfigException {
Properties properties = new Properties();
InputStream in = EmbeddedZookeeper.class.getResourceAsStream("/zoo.cfg");
properties.load(in);
QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
quorumConfiguration.parseProperties(properties);
in.close();
zookeeperServer = new ZooKeeperServerMain();
final ServerConfig configuration = new ServerConfig();
configuration.readFrom(quorumConfiguration);
t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
zookeeperServer.runFromConfig(configuration);
} catch (IOException e) {
}
}
});
t1.start();
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ZooKeeperServerMain in project motan by weibocom.
the class EmbeddedZookeeper method start.
public void start() throws IOException, QuorumPeerConfig.ConfigException {
Properties properties = new Properties();
InputStream in = EmbeddedZookeeper.class.getResourceAsStream("/zoo.cfg");
properties.load(in);
QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
quorumConfiguration.parseProperties(properties);
in.close();
zookeeperServer = new ZooKeeperServerMain();
final ServerConfig configuration = new ServerConfig();
configuration.readFrom(quorumConfiguration);
t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
zookeeperServer.runFromConfig(configuration);
} catch (IOException e) {
}
}
});
t1.start();
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ZooKeeperServerMain in project flink by apache.
the class FlinkZooKeeperQuorumPeer method runFlinkZkQuorumPeer.
// ------------------------------------------------------------------------
/**
* Runs a ZooKeeper {@link QuorumPeer} if further peers are configured or a single {@link
* ZooKeeperServer} if no further peers are configured.
*
* @param zkConfigFile ZooKeeper config file 'zoo.cfg'
* @param peerId ID for the 'myid' file
*/
public static void runFlinkZkQuorumPeer(String zkConfigFile, int peerId) throws Exception {
Properties zkProps = new Properties();
try (InputStream inStream = new FileInputStream(new File(zkConfigFile))) {
zkProps.load(inStream);
}
LOG.info("Configuration: " + zkProps);
// Set defaults for required properties
setRequiredProperties(zkProps);
// Write peer id to myid file
writeMyIdToDataDir(zkProps, peerId);
// The myid file needs to be written before creating the instance. Otherwise, this
// will fail.
QuorumPeerConfig conf = new QuorumPeerConfig();
conf.parseProperties(zkProps);
if (conf.isDistributed()) {
// Run quorum peer
LOG.info("Running distributed ZooKeeper quorum peer (total peers: {}).", conf.getServers().size());
QuorumPeerMain qp = new QuorumPeerMain();
qp.runFromConfig(conf);
} else {
// Run standalone
LOG.info("Running standalone ZooKeeper quorum peer.");
ZooKeeperServerMain zk = new ZooKeeperServerMain();
ServerConfig sc = new ServerConfig();
sc.readFrom(conf);
zk.runFromConfig(sc);
}
}
Aggregations