Search in sources :

Example 11 with QuorumPeerConfig

use of org.apache.zookeeper.server.quorum.QuorumPeerConfig in project zookeeper by apache.

the class JvmPauseMonitorTest method testJvmPauseMonitorExceedWarnThreshold.

@Test
@Timeout(value = 5)
public void testJvmPauseMonitorExceedWarnThreshold() throws InterruptedException {
    QuorumPeerConfig qpConfig = mock(QuorumPeerConfig.class);
    when(qpConfig.getJvmPauseSleepTimeMs()).thenReturn(sleepTime);
    when(qpConfig.getJvmPauseWarnThresholdMs()).thenReturn(warnTH);
    pauseMonitor = new JvmPauseMonitor(qpConfig);
    pauseMonitor.serviceStart();
    assertEquals(sleepTime, Long.valueOf(pauseMonitor.sleepTimeMs));
    assertEquals(warnTH, Long.valueOf(pauseMonitor.warnThresholdMs));
    while (pauseMonitor.getNumGcWarnThresholdExceeded() == 0) {
        Thread.sleep(200);
    }
}
Also used : QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 12 with QuorumPeerConfig

use of org.apache.zookeeper.server.quorum.QuorumPeerConfig in project nifi by apache.

the class EmbeddedKafka method startZookeeper.

/**
 * Will start Zookeeper server via {@link ServerCnxnFactory}
 */
private void startZookeeper() {
    QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
    try {
        quorumConfiguration.parseProperties(this.zookeeperConfig);
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumConfiguration);
        FileTxnSnapLog txnLog = new FileTxnSnapLog(new File(configuration.getDataLogDir()), new File(configuration.getDataDir()));
        zkServer.setTxnLogFactory(txnLog);
        zkServer.setTickTime(configuration.getTickTime());
        zkServer.setMinSessionTimeout(configuration.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(configuration.getMaxSessionTimeout());
        ServerCnxnFactory zookeeperConnectionFactory = ServerCnxnFactory.createFactory();
        zookeeperConnectionFactory.configure(configuration.getClientPortAddress(), configuration.getMaxClientCnxns());
        zookeeperConnectionFactory.startup(zkServer);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start Zookeeper server", e);
    }
}
Also used : ServerConfig(org.apache.zookeeper.server.ServerConfig) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) File(java.io.File) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) IOException(java.io.IOException)

Example 13 with QuorumPeerConfig

use of 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 14 with QuorumPeerConfig

use of 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)

Example 15 with QuorumPeerConfig

use of org.apache.zookeeper.server.quorum.QuorumPeerConfig in project fabric8 by jboss-fuse.

the class ZooKeeperServerFactory method getPeerConfig.

private QuorumPeerConfig getPeerConfig(Properties props) throws IOException, ConfigException {
    QuorumPeerConfig peerConfig = new QuorumPeerConfig();
    peerConfig.parseProperties(props);
    LOGGER.info("Created zookeeper peer configuration: {}", peerConfig);
    return peerConfig;
}
Also used : QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig)

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