Search in sources :

Example 1 with ServerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig in project Dempsy by Dempsy.

the class ZookeeperTestServer method startZookeeper.

private static TestZookeeperServerIntern startZookeeper(Properties zkConfig) {
    logger.debug("Starting the test zookeeper server on port " + zkConfig.get("clientPort"));
    final TestZookeeperServerIntern server = new TestZookeeperServerIntern();
    try {
        QuorumPeerConfig qpConfig = new QuorumPeerConfig();
        qpConfig.parseProperties(zkConfig);
        final ServerConfig sConfig = new ServerConfig();
        sConfig.readFrom(qpConfig);
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    server.runFromConfig(sConfig);
                } catch (IOException ioe) {
                    logger.error(MarkerFactory.getMarker("FATAL"), "", ioe);
                    fail("can't start zookeeper");
                }
            }
        });
        t.start();
        // give the server time to start
        Thread.sleep(2000);
    } catch (Exception e) {
        logger.error("Can't start zookeeper", e);
        fail("Can't start zookeeper");
    }
    return server;
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 2 with ServerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig in project lucene-solr by apache.

the class SolrZkServerProps method start.

public void start() {
    if (zkRun == null)
        return;
    zkThread = new Thread() {

        @Override
        public void run() {
            try {
                if (zkProps.getServers().size() > 1) {
                    QuorumPeerMain zkServer = new QuorumPeerMain();
                    zkServer.runFromConfig(zkProps);
                } else {
                    ServerConfig sc = new ServerConfig();
                    sc.readFrom(zkProps);
                    ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
                    zkServer.runFromConfig(sc);
                }
                log.info("ZooKeeper Server exited.");
            } catch (Exception e) {
                log.error("ZooKeeper Server ERROR", e);
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
            }
        }
    };
    if (zkProps.getServers().size() > 1) {
        log.info("STARTING EMBEDDED ENSEMBLE ZOOKEEPER SERVER at port " + zkProps.getClientPortAddress().getPort());
    } else {
        log.info("STARTING EMBEDDED STANDALONE ZOOKEEPER SERVER at port " + zkProps.getClientPortAddress().getPort());
    }
    zkThread.setDaemon(true);
    zkThread.start();
    try {
        // pause for ZooKeeper to start
        Thread.sleep(500);
    } catch (Exception e) {
        log.error("STARTING ZOOKEEPER", e);
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerMain(org.apache.zookeeper.server.quorum.QuorumPeerMain) ZooKeeperServerMain(org.apache.zookeeper.server.ZooKeeperServerMain) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 3 with ServerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig in project lucene-solr by apache.

the class ZkTestServer method run.

public void run() throws InterruptedException {
    log.info("STARTING ZK TEST SERVER");
    // we don't call super.distribSetUp
    zooThread = new Thread() {

        @Override
        public void run() {
            ServerConfig config = new ServerConfig() {

                {
                    setClientPort(ZkTestServer.this.clientPort);
                    this.dataDir = zkDir;
                    this.dataLogDir = zkDir;
                    this.tickTime = theTickTime;
                }

                public void setClientPort(int clientPort) {
                    if (clientPortAddress != null) {
                        try {
                            this.clientPortAddress = new InetSocketAddress(InetAddress.getByName(clientPortAddress.getHostName()), clientPort);
                        } catch (UnknownHostException e) {
                            throw new RuntimeException(e);
                        }
                    } else {
                        this.clientPortAddress = new InetSocketAddress(clientPort);
                    }
                    log.info("client port:" + this.clientPortAddress);
                }
            };
            try {
                zkServer.runFromConfig(config);
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
        }
    };
    zooThread.setDaemon(true);
    zooThread.start();
    int cnt = 0;
    int port = -1;
    try {
        port = getPort();
    } catch (IllegalStateException e) {
    }
    while (port < 1) {
        Thread.sleep(100);
        try {
            port = getPort();
        } catch (IllegalStateException e) {
        }
        if (cnt == 500) {
            throw new RuntimeException("Could not get the port for ZooKeeper server");
        }
        cnt++;
    }
    log.info("start zk server on port:" + port);
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress)

Example 4 with ServerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig in project nifi by apache.

the class EmbeddedKafka method startZookeeper.

/**
 * Will start Zookeeper server via {@link ServerCnxnFactory}
 */
private void startZookeeper() {
    QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
    try {
        quorumConfiguration.parseProperties(this.zookeeperConfig);
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumConfiguration);
        FileTxnSnapLog txnLog = new FileTxnSnapLog(new File(configuration.getDataLogDir()), new File(configuration.getDataDir()));
        zkServer.setTxnLogFactory(txnLog);
        zkServer.setTickTime(configuration.getTickTime());
        zkServer.setMinSessionTimeout(configuration.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(configuration.getMaxSessionTimeout());
        ServerCnxnFactory zookeeperConnectionFactory = ServerCnxnFactory.createFactory();
        zookeeperConnectionFactory.configure(configuration.getClientPortAddress(), configuration.getMaxClientCnxns());
        zookeeperConnectionFactory.startup(zkServer);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start Zookeeper server", e);
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) File(java.io.File) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) IOException(java.io.IOException)

Example 5 with ServerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig in project fabric8 by jboss-fuse.

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)

Aggregations

ServerConfig (org.apache.zookeeper.server.ServerConfig)24 IOException (java.io.IOException)15 File (java.io.File)12 QuorumPeerConfig (org.apache.zookeeper.server.quorum.QuorumPeerConfig)11 ZooKeeperServerMain (org.apache.zookeeper.server.ZooKeeperServerMain)8 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)8 Properties (java.util.Properties)7 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)6 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)5 InputStream (java.io.InputStream)3 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)3 UnknownHostException (java.net.UnknownHostException)2 QuorumPeerMain (org.apache.zookeeper.server.quorum.QuorumPeerMain)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 Date (java.util.Date)1 JMException (javax.management.JMException)1 CarbonProperties (org.apache.carbondata.core.util.CarbonProperties)1