Search in sources :

Example 6 with ServerConfig

use of org.apache.zookeeper.server.ServerConfig in project camel by apache.

the class GroupTest method startZooKeeper.

private NIOServerCnxnFactory startZooKeeper(int port) throws Exception {
    ServerConfig cfg = new ServerConfig();
    cfg.parse(new String[] { Integer.toString(port), "target/zk/data" });
    ZooKeeperServer zkServer = new ZooKeeperServer();
    FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(cfg.getDataLogDir()), new File(cfg.getDataDir()));
    zkServer.setTxnLogFactory(ftxn);
    zkServer.setTickTime(cfg.getTickTime());
    zkServer.setMinSessionTimeout(6000);
    zkServer.setMaxSessionTimeout(9000);
    NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
    cnxnFactory.configure(cfg.getClientPortAddress(), cfg.getMaxClientCnxns());
    cnxnFactory.startup(zkServer);
    return cnxnFactory;
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog)

Example 7 with ServerConfig

use of org.apache.zookeeper.server.ServerConfig 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);
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerMain(org.apache.zookeeper.server.quorum.QuorumPeerMain) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) ZooKeeperServerMain(org.apache.zookeeper.server.ZooKeeperServerMain)

Example 8 with ServerConfig

use of org.apache.zookeeper.server.ServerConfig 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();
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) ZooKeeperServerMain(org.apache.zookeeper.server.ZooKeeperServerMain)

Example 9 with ServerConfig

use of org.apache.zookeeper.server.ServerConfig 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();
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) ZooKeeperServerMain(org.apache.zookeeper.server.ZooKeeperServerMain)

Aggregations

ServerConfig (org.apache.zookeeper.server.ServerConfig)9 ZooKeeperServerMain (org.apache.zookeeper.server.ZooKeeperServerMain)6 IOException (java.io.IOException)5 QuorumPeerConfig (org.apache.zookeeper.server.quorum.QuorumPeerConfig)5 Properties (java.util.Properties)4 File (java.io.File)3 InputStream (java.io.InputStream)3 QuorumPeerMain (org.apache.zookeeper.server.quorum.QuorumPeerMain)3 UnknownHostException (java.net.UnknownHostException)2 FileInputStream (java.io.FileInputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 CarbonProperties (org.apache.carbondata.core.util.CarbonProperties)1 SolrException (org.apache.solr.common.SolrException)1 KeeperException (org.apache.zookeeper.KeeperException)1 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)1 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)1 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)1 Before (org.junit.Before)1