Search in sources :

Example 6 with ZooKeeperServerMain

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;
    }
}
Also used : QuorumPeerMain(org.apache.zookeeper.server.quorum.QuorumPeerMain) SaslException(javax.security.sasl.SaslException) DatadirCleanupManager(org.apache.zookeeper.server.DatadirCleanupManager) ServerConfig(org.apache.zookeeper.server.ServerConfig) CompletableFuture(java.util.concurrent.CompletableFuture) QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer) ZooKeeperServerMain(org.apache.zookeeper.server.ZooKeeperServerMain) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with ZooKeeperServerMain

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();
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) IOException(java.io.IOException) ZooKeeperServerMain(org.apache.zookeeper.server.ZooKeeperServerMain)

Example 8 with ZooKeeperServerMain

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();
}
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 ZooKeeperServerMain

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();
}
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 10 with ZooKeeperServerMain

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);
    }
}
Also used : ServerConfig(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig) QuorumPeerMain(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.quorum.QuorumPeerMain) QuorumPeerConfig(org.apache.flink.shaded.zookeeper3.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.flink.shaded.zookeeper3.org.apache.zookeeper.server.ZooKeeperServerMain)

Aggregations

ServerConfig (org.apache.zookeeper.server.ServerConfig)10 ZooKeeperServerMain (org.apache.zookeeper.server.ZooKeeperServerMain)10 IOException (java.io.IOException)6 Properties (java.util.Properties)5 QuorumPeerConfig (org.apache.zookeeper.server.quorum.QuorumPeerConfig)5 File (java.io.File)4 InputStream (java.io.InputStream)3 QuorumPeerMain (org.apache.zookeeper.server.quorum.QuorumPeerMain)3 DatadirCleanupManager (org.apache.zookeeper.server.DatadirCleanupManager)2 FileInputStream (java.io.FileInputStream)1 UnknownHostException (java.net.UnknownHostException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeoutException (java.util.concurrent.TimeoutException)1 SaslException (javax.security.sasl.SaslException)1 CarbonProperties (org.apache.carbondata.core.util.CarbonProperties)1 ServerConfig (org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig)1 ZooKeeperServerMain (org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ZooKeeperServerMain)1 QuorumPeerConfig (org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.quorum.QuorumPeerConfig)1 QuorumPeerMain (org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.quorum.QuorumPeerMain)1 SolrException (org.apache.solr.common.SolrException)1