Search in sources :

Example 1 with ServerConfig

use of 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.zookeeper.server.ServerConfig in project carbondata by apache.

the class ZooKeeperLockingTest method setUp.

/**
   * @throws java.lang.Exception
   */
@Before
public void setUp() throws Exception {
    Properties startupProperties = new Properties();
    startupProperties.setProperty("dataDir", (new File("./target").getAbsolutePath()));
    startupProperties.setProperty("dataLogDir", (new File("./target").getAbsolutePath()));
    freePort = findFreePort();
    startupProperties.setProperty("clientPort", "" + freePort);
    QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
    try {
        quorumConfiguration.parseProperties(startupProperties);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    final ZooKeeperServerMain zooKeeperServer = new ZooKeeperServerMain();
    final ServerConfig configuration = new ServerConfig();
    configuration.readFrom(quorumConfiguration);
    new Thread() {

        public void run() {
            try {
                zooKeeperServer.runFromConfig(configuration);
            } catch (IOException e) {
                System.out.println("ZooKeeper failure");
            }
        }
    }.start();
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) IOException(java.io.IOException) Properties(java.util.Properties) CarbonProperties(org.apache.carbondata.core.util.CarbonProperties) File(java.io.File) IOException(java.io.IOException) ZooKeeperServerMain(org.apache.zookeeper.server.ZooKeeperServerMain) Before(org.junit.Before)

Example 3 with ServerConfig

use of 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.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 5 with ServerConfig

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

the class HQuorumPeer method runZKServer.

private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
    if (zkConfig.isDistributed()) {
        QuorumPeerMain qp = new QuorumPeerMain();
        qp.runFromConfig(zkConfig);
    } else {
        ZooKeeperServerMain zk = new ZooKeeperServerMain();
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.readFrom(zkConfig);
        zk.runFromConfig(serverConfig);
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerMain(org.apache.zookeeper.server.quorum.QuorumPeerMain) 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