Search in sources :

Example 1 with ZooKeeperServerMain

use of org.apache.zookeeper.server.ZooKeeperServerMain 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 2 with ZooKeeperServerMain

use of org.apache.zookeeper.server.ZooKeeperServerMain 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 ZooKeeperServerMain

use of org.apache.zookeeper.server.ZooKeeperServerMain 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)

Example 4 with ZooKeeperServerMain

use of 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);
    }
}
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 5 with ZooKeeperServerMain

use of 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();
}
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)6 ZooKeeperServerMain (org.apache.zookeeper.server.ZooKeeperServerMain)6 IOException (java.io.IOException)4 Properties (java.util.Properties)4 QuorumPeerConfig (org.apache.zookeeper.server.quorum.QuorumPeerConfig)4 InputStream (java.io.InputStream)3 QuorumPeerMain (org.apache.zookeeper.server.quorum.QuorumPeerMain)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)1 UnknownHostException (java.net.UnknownHostException)1 CarbonProperties (org.apache.carbondata.core.util.CarbonProperties)1 SolrException (org.apache.solr.common.SolrException)1 Before (org.junit.Before)1