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