Search in sources :

Example 16 with ServerConfig

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

the class GitDataStoreImplTestSupport method startZooKeeper.

private NIOServerCnxnFactory startZooKeeper(int port, String directory) throws Exception {
    ServerConfig cfg = new ServerConfig();
    cfg.parse(new String[] { Integer.toString(port), directory });
    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(cfg.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(cfg.getMaxSessionTimeout());
    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) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog)

Example 17 with ServerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig 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 18 with ServerConfig

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

the class ControllerServerConfig method getZooKeeperServerConfig.

public ServerConfig getZooKeeperServerConfig() {
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(this);
    return serverConfig;
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig)

Example 19 with ServerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig in project coprhd-controller by CoprHD.

the class CoordinatorImpl method start.

@Override
public synchronized void start() throws IOException {
    if (new File(UNCOMMITTED_DATA_REVISION_FLAG).exists()) {
        _log.error("Uncommitted data revision detected. Manual relink db/zk data directory");
        throw new RuntimeException("Uncommited data revision");
    }
    _log.info(String.format("%s: %s", SpringQuorumPeerConfig.READONLY_MODE_ENABLED, System.getProperty(SpringQuorumPeerConfig.READONLY_MODE_ENABLED)));
    // snapshot clean up runs at regular interval and leaves desired snapshots
    // behind
    _exe.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            try {
                PurgeTxnLog.purge(new File(_config.getDataDir()), new File(_config.getDataDir()), _config.getSnapRetainCount());
            } catch (Exception e) {
                _log.debug("Exception is throwed when purging snapshots and logs", e);
            }
        }
    }, 0, _config.getPurgeInterval(), TimeUnit.MINUTES);
    startMutexReaper();
    // Starts JMX server for analysis and data backup
    try {
        if (_jmxServer != null) {
            _jmxServer.start();
        }
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
    if (_config.getServers().size() == 0) {
        // standalone
        ServerConfig config = new ServerConfig();
        config.readFrom(_config);
        server = new ZKMain();
        server.runFromConfig(config);
    } else {
        // cluster
        try {
            ManagedUtil.registerLog4jMBeans();
        } catch (JMException e) {
            _log.warn("Unable to register log4j JMX control", e);
        }
        try {
            runFromConfig(_config);
            // Dual coordinator - a hack for 1+0 (dev environment only) in DR. End customer uses 2+1 or 3+2 only and never goes into this case.
            // 
            // We run 2 zookeeper instances for 1+0 to address a limitation in ZOOKEEPER-1692 in 3.4.6. ZK doesn't
            // allow observers for standalone zookeeper(single zk participants). So we run 2 zookeeper servers here to
            // simulate 2 zk participants and bypass this limitation, then we are able to add zk observers for DR sites.
            // /etc/genconfig.d/coordinator generates 2 zk servers to coordinator-var.xml, and here we start
            // 
            // ZK 3.5 introduces new parameter standaloneEnabled to address this limitation. Need revisit this hack after upgraded to zk 3.5
            int serverCnt = _config.getNumberOfParitipants();
            if (serverCnt == 2 && _config.getPeerType().equals(LearnerType.PARTICIPANT)) {
                _log.info("Starting the other peer to run zk in cluster mode. Aim to address a ZK 3.4.6 limitation(cannot add observers to standalone server)");
                Properties prop = new Properties();
                prop.setProperty("dataDir", _config.getDataDir() + "/peer2");
                // a deferent port
                prop.setProperty("clientPort", DUAL_COORDINATOR_CLIENT_PORT);
                SpringQuorumPeerConfig newConfig = _config.createNewConfig(prop, 2);
                runFromConfig(newConfig);
            }
        } catch (Exception ex) {
            _log.error("Unexpected error when starting Zookeeper peer", ex);
            throw new IllegalStateException("Fail to start zookeeper", ex);
        }
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) JMException(javax.management.JMException) Properties(java.util.Properties) File(java.io.File) IOException(java.io.IOException) JMException(javax.management.JMException)

Example 20 with ServerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.ServerConfig 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)

Aggregations

ServerConfig (org.apache.zookeeper.server.ServerConfig)27 IOException (java.io.IOException)15 File (java.io.File)13 QuorumPeerConfig (org.apache.zookeeper.server.quorum.QuorumPeerConfig)11 ZooKeeperServerMain (org.apache.zookeeper.server.ZooKeeperServerMain)10 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 QuorumPeerMain (org.apache.zookeeper.server.quorum.QuorumPeerMain)3 UnknownHostException (java.net.UnknownHostException)2 DatadirCleanupManager (org.apache.zookeeper.server.DatadirCleanupManager)2 QuorumPeer (org.apache.zookeeper.server.quorum.QuorumPeer)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