Search in sources :

Example 21 with QuorumPeerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.quorum.QuorumPeerConfig in project xian by happyyangyuan.

the class QuorumConfigBuilder method buildConfig.

public QuorumPeerConfig buildConfig(int instanceIndex) throws Exception {
    boolean isCluster = (instanceSpecs.size() > 1);
    InstanceSpec spec = instanceSpecs.get(instanceIndex);
    if (isCluster) {
        Files.write(Integer.toString(spec.getServerId()).getBytes(), new File(spec.getDataDirectory(), "myid"));
    }
    Properties properties = new Properties();
    properties.setProperty("initLimit", "10");
    properties.setProperty("syncLimit", "5");
    properties.setProperty("dataDir", spec.getDataDirectory().getCanonicalPath());
    properties.setProperty("clientPort", Integer.toString(spec.getPort()));
    int tickTime = spec.getTickTime();
    if (tickTime >= 0) {
        properties.setProperty("tickTime", Integer.toString(tickTime));
    }
    int maxClientCnxns = spec.getMaxClientCnxns();
    if (maxClientCnxns >= 0) {
        properties.setProperty("maxClientCnxns", Integer.toString(maxClientCnxns));
    }
    if (isCluster) {
        for (InstanceSpec thisSpec : instanceSpecs) {
            properties.setProperty("server." + thisSpec.getServerId(), String.format("%s:%d:%d", thisSpec.getHostname(), thisSpec.getQuorumPort(), thisSpec.getElectionPort()));
        }
    }
    Map<String, Object> customProperties = spec.getCustomProperties();
    if (customProperties != null) {
        for (Map.Entry<String, Object> property : customProperties.entrySet()) {
            properties.put(property.getKey(), property.getValue());
        }
    }
    QuorumPeerConfig config = new QuorumPeerConfig();
    config.parseProperties(properties);
    return config;
}
Also used : QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) Properties(java.util.Properties) File(java.io.File) Map(java.util.Map)

Example 22 with QuorumPeerConfig

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.server.quorum.QuorumPeerConfig in project xian by happyyangyuan.

the class TestingZooKeeperServer method start.

public void start() throws Exception {
    if (!state.compareAndSet(State.LATENT, State.STARTED)) {
        return;
    }
    new Thread(new Runnable() {

        public void run() {
            try {
                QuorumPeerConfig config = configBuilder.buildConfig(thisInstanceIndex);
                main.runFromConfig(config);
            } catch (Exception e) {
                logger.error(String.format("From testing server (random state: %s) for instance: %s", String.valueOf(configBuilder.isFromRandom()), getInstanceSpec()), e);
            }
        }
    }).start();
    main.blockUntilStarted();
}
Also used : QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) IOException(java.io.IOException)

Aggregations

QuorumPeerConfig (org.apache.zookeeper.server.quorum.QuorumPeerConfig)21 IOException (java.io.IOException)12 ServerConfig (org.apache.zookeeper.server.ServerConfig)10 Properties (java.util.Properties)9 File (java.io.File)8 ZooKeeperServerMain (org.apache.zookeeper.server.ZooKeeperServerMain)5 InputStream (java.io.InputStream)3 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)3 Test (org.junit.jupiter.api.Test)3 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)2 QuorumPeer (org.apache.zookeeper.server.quorum.QuorumPeer)2 Timeout (org.junit.jupiter.api.Timeout)2 RuntimeProperties (io.fabric8.api.RuntimeProperties)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 Map (java.util.Map)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