Search in sources :

Example 21 with ServerConfig

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

the class AiravataZKUtils method startEmbeddedZK.

public static void startEmbeddedZK(ServerCnxnFactory cnxnFactory) {
    if (ServerSettings.isEmbeddedZK()) {
        ServerConfig serverConfig = new ServerConfig();
        URL resource = ApplicationSettings.loadFile("zoo.cfg");
        try {
            if (resource == null) {
                logger.error("There is no zoo.cfg file in the classpath... Failed to start Zookeeper Server");
                System.exit(1);
            }
            serverConfig.parse(resource.getPath());
        } catch (QuorumPeerConfig.ConfigException e) {
            logger.error("Error while starting embedded Zookeeper", e);
            System.exit(2);
        }
        final ServerConfig fServerConfig = serverConfig;
        final ServerCnxnFactory fserverCnxnFactory = cnxnFactory;
        (new Thread() {

            public void run() {
                try {
                    AiravataZKUtils.runZKFromConfig(fServerConfig, fserverCnxnFactory);
                } catch (IOException e) {
                    logger.error("Error while starting embedded Zookeeper", e);
                    System.exit(3);
                }
            }
        }).start();
    } else {
        logger.info("Skipping Zookeeper embedded startup ...");
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) IOException(java.io.IOException) URL(java.net.URL)

Example 22 with ServerConfig

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

the class ZooDiscoveryContainer method startQuorumPeer.

/**
 * Start a local ZooKeeer server to write nodes to. It plays as a peer
 * within a replicated servers configuration. Implied by
 * {@link IDiscoveryConfig#ZOODISCOVERY_FLAVOR_REPLICATED} configuration.
 *
 * @param conf
 */
void startQuorumPeer(final Configuration conf) {
    if (this.quorumPeer != null && this.quorumPeer.isAlive()) {
        return;
    } else if (this.quorumPeer != null && !this.quorumPeer.isAlive()) {
        this.quorumPeer.start();
        return;
    }
    try {
        final QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parse(conf.getConfFile());
        QuorumPeer.Factory qpFactory = new QuorumPeer.Factory() {

            public QuorumPeer create(NIOServerCnxn.Factory cnxnFactory) throws IOException {
                ServerConfig serverConfig = new ServerConfig();
                serverConfig.readFrom(quorumPeerConfig);
                QuorumPeer peer = new QuorumPeer(quorumPeerConfig.getServers(), new File(serverConfig.getDataDir()), new File(serverConfig.getDataLogDir()), quorumPeerConfig.getElectionAlg(), quorumPeerConfig.getServerId(), quorumPeerConfig.getTickTime(), quorumPeerConfig.getInitLimit(), quorumPeerConfig.getSyncLimit(), cnxnFactory, quorumPeerConfig.getQuorumVerifier());
                ZooDiscoveryContainer.this.quorumPeer = peer;
                return peer;
            }

            public NIOServerCnxn.Factory createConnectionFactory() throws IOException {
                return new NIOServerCnxn.Factory(quorumPeerConfig.getClientPortAddress());
            }
        };
        quorumPeer = qpFactory.create(qpFactory.createConnectionFactory());
        quorumPeer.start();
        quorumPeer.setDaemon(true);
        isQuorumPeerReady = true;
    } catch (Exception e) {
        // $NON-NLS-1$
        Logger.log(LogService.LOG_ERROR, "Zookeeper quorum cannot be started! ", e);
        isQuorumPeerReady = false;
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) NIOServerCnxn(org.apache.zookeeper.server.NIOServerCnxn) QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer) Factory(org.apache.zookeeper.server.NIOServerCnxn.Factory) File(java.io.File) IOException(java.io.IOException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException)

Example 23 with ServerConfig

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

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

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