本文整理汇总了Java中org.apache.zookeeper.server.quorum.QuorumPeerConfig类的典型用法代码示例。如果您正苦于以下问题:Java QuorumPeerConfig类的具体用法?Java QuorumPeerConfig怎么用?Java QuorumPeerConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QuorumPeerConfig类属于org.apache.zookeeper.server.quorum包,在下文中一共展示了QuorumPeerConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startFakeCluster
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
/**
* 启动伪集群模式
* @param config
* @throws IOException
* @throws InterruptedException
* @throws ConfigException
*/
public void startFakeCluster(QuorumPeerConfig config) throws IOException{
ServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
QuorumPeer quorumPeer = new QuorumPeer(config.getServers(), config.getDataDir(), config.getDataLogDir(), config.getElectionAlg(), config.getServerId(), config.getTickTime(), config.getInitLimit(), config.getSyncLimit(), config.getQuorumListenOnAllIPs(), cnxnFactory, config.getQuorumVerifier());
quorumPeer.setClientAddress(config.getClientPortAddress());
quorumPeer.setTxnFactory(new FileTxnSnapLog(config.getDataLogDir(), config.getDataDir()));
quorumPeer.setElectionType(config.getElectionAlg());
quorumPeer.setMyid(config.getServerId());
quorumPeer.setTickTime(config.getTickTime());
quorumPeer.setMinSessionTimeout(config.getMinSessionTimeout());
quorumPeer.setMaxSessionTimeout(config.getMaxSessionTimeout());
quorumPeer.setInitLimit(config.getInitLimit());
quorumPeer.setSyncLimit(config.getSyncLimit());
quorumPeer.setQuorumVerifier(config.getQuorumVerifier(), true);
quorumPeer.setCnxnFactory(cnxnFactory);
quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
quorumPeer.setLearnerType(config.getPeerType());
quorumPeer.setSyncEnabled(config.getSyncEnabled());
quorumPeer.setQuorumListenOnAllIPs(config.getQuorumListenOnAllIPs());
quorumPeer.start();
LOGGER.info("ZkServerCluster Started! ClientPortAddress={}", config.getClientPortAddress());
}
示例2: setup
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
@Before
public void setup() throws InterruptedException {
System.setProperty(authProvider, superDigest);
QuorumPeerConfig.setReconfigEnabled(true);
// Get a three server quorum.
qu = new QuorumUtil(1);
qu.disableJMXTest = true;
try {
qu.startAll();
} catch (IOException e) {
Assert.fail("Fail to start quorum servers.");
}
resetZKAdmin();
}
示例3: startZkLocal
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
private static void startZkLocal() throws Exception {
final File zkTmpDir = File.createTempFile("zookeeper", "test");
if (zkTmpDir.delete() && zkTmpDir.mkdir()) {
Properties zkProperties = new Properties();
zkProperties.setProperty("dataDir", zkTmpDir.getAbsolutePath());
zkProperties.setProperty("clientPort", String.valueOf(ZK_PORT));
ServerConfig configuration = new ServerConfig();
QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
quorumConfiguration.parseProperties(zkProperties);
configuration.readFrom(quorumConfiguration);
new Thread() {
public void run() {
try {
new ZooKeeperServerMain().runFromConfig(configuration);
} catch (IOException e) {
System.out.println("Start of Local ZooKeeper Failed");
e.printStackTrace(System.err);
}
}
}.start();
} else {
System.out.println("Failed to delete or create data dir for Zookeeper");
}
}
示例4: main
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
/**
* Parse ZooKeeper configuration from HBase XML config and run a QuorumPeer.
* @param args String[] of command line arguments. Not used.
*/
public static void main(String[] args) {
Configuration conf = HBaseConfiguration.create();
try {
Properties zkProperties = ZKConfig.makeZKProps(conf);
writeMyID(zkProperties);
QuorumPeerConfig zkConfig = new QuorumPeerConfig();
zkConfig.parseProperties(zkProperties);
// login the zookeeper server principal (if using security)
ZKUtil.loginServer(conf, HConstants.ZK_SERVER_KEYTAB_FILE,
HConstants.ZK_SERVER_KERBEROS_PRINCIPAL,
zkConfig.getClientPortAddress().getHostName());
runZKServer(zkConfig);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
示例5: testUpdateConfig
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
public void testUpdateConfig() throws Exception {
final File tempDir = new File("target");
IMocksControl control = EasyMock.createControl();
BundleContext bc = control.createMock(BundleContext.class);
expect(bc.getDataFile("")).andReturn(tempDir);
final MyZooKeeperServerMain mockServer = control.createMock(MyZooKeeperServerMain.class);
control.replay();
ZookeeperStarter starter = new ZookeeperStarter(bc) {
@Override
protected void startFromConfig(QuorumPeerConfig config) {
assertEquals(1234, config.getClientPortAddress().getPort());
assertTrue(config.getDataDir().contains(tempDir + File.separator + "zkdata"));
assertEquals(2000, config.getTickTime());
assertEquals(10, config.getInitLimit());
assertEquals(5, config.getSyncLimit());
this.main = mockServer;
}
};
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("clientPort", "1234");
starter.updated(props);
assertNotNull(starter.main);
control.verify();
}
示例6: main
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
/**
* Parse ZooKeeper configuration from HBase XML config and run a QuorumPeer.
* @param args String[] of command line arguments. Not used.
*/
public static void main(String[] args) {
Configuration conf = HBaseConfiguration.create();
try {
Properties zkProperties = ZKConfig.makeZKProps(conf);
writeMyID(zkProperties);
QuorumPeerConfig zkConfig = new QuorumPeerConfig();
zkConfig.parseProperties(zkProperties);
// login the zookeeper server principal (if using security)
ZKUtil.loginServer(conf, "hbase.zookeeper.server.keytab.file",
"hbase.zookeeper.server.kerberos.principal",
zkConfig.getClientPortAddress().getHostName());
runZKServer(zkConfig);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
示例7: TestingZookeeperServerEmbedded
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
public TestingZookeeperServerEmbedded(int clientPort, File baseDir) throws Exception {
Properties p = new Properties();
String host = "localhost";
String dataDir = "data";
File dir = new File(baseDir, dataDir);
p.setProperty("syncEnabled", "false");
p.setProperty("dataDir", dir.getAbsolutePath());
p.setProperty("clientPort", clientPort + "");
p.setProperty("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
p.setProperty("kerberos.removeHostFromPrincipal", "true");
p.setProperty("kerberos.removeRealmFromPrincipal", "true");
config = new QuorumPeerConfig();
config.parseProperties(p);
}
示例8: TestingZookeeperServerEmbedded
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
public TestingZookeeperServerEmbedded(int clientPort, File baseDir) throws Exception {
this.clientPort = clientPort;
Properties p = new Properties();
String host = "localhost";
String dataDir = "data";
File dir = new File(baseDir, dataDir);
p.setProperty("syncEnabled", "false");
p.setProperty("dataDir", dir.getAbsolutePath());
p.setProperty("clientPort", clientPort + "");
p.setProperty("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
p.setProperty("kerberos.removeHostFromPrincipal", "true");
p.setProperty("kerberos.removeRealmFromPrincipal", "true");
config = new QuorumPeerConfig();
config.parseProperties(p);
}
示例9: start
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
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();
}
示例10: create
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
ZookeeperLaucher create(Properties zkProperties) throws ConfigException, IOException {
QuorumPeerConfig zkConfig = new QuorumPeerConfig();
zkConfig.parseProperties(zkProperties);
DatadirCleanupManager purgeMgr = new DatadirCleanupManager(
zkConfig.getDataDir(),
zkConfig.getDataLogDir(),
zkConfig.getSnapRetainCount(),
zkConfig.getPurgeInterval());
purgeMgr.start();
if (zkConfig.getServers().size() > 0) {
return new QuorumPeerMainExt(zkConfig);
} else {
logger.warn(
"Either no config or no quorum defined in config, running in standalone mode"
);
// there is only server in the quorum -- run as standalone
return new ZooKeeperServerMainExt(zkConfig) ;
}
}
示例11: create
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
ZookeeperLaucher create(Properties zkProperties) throws ConfigException, IOException {
QuorumPeerConfig zkConfig = new QuorumPeerConfig();
zkConfig.parseProperties(zkProperties);
DatadirCleanupManager purgeMgr =
new DatadirCleanupManager(zkConfig.getDataDir(), zkConfig.getDataLogDir(),
zkConfig.getSnapRetainCount(), zkConfig.getPurgeInterval());
purgeMgr.start();
if (zkConfig.getServers().size() > 0) {
return new QuorumPeerMainExt(zkConfig);
} else {
System.out
.println("Either no config or no quorum defined in config, running in standalone mode");
// there is only server in the quorum -- run as standalone
return new ZooKeeperServerMainExt(zkConfig);
}
}
示例12: SpliceZoo
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
public SpliceZoo(QuorumPeerConfig config, int number) throws IOException {
this.config = config;
ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
cnxnFactory.configure(config.getClientPortAddress(),config.getMaxClientCnxns());
peer = new QuorumPeer(config.getServers(), null, null, config.getElectionAlg(),
number, config.getTickTime(), config.getInitLimit(), config.getSyncLimit(), cnxnFactory);
peer.setClientPortAddress(config.getClientPortAddress());
peer.setTxnFactory(new FileTxnSnapLog(new File(config.getDataLogDir()),
new File(config.getDataDir())));
peer.setQuorumPeers(config.getServers());
peer.setElectionType(config.getElectionAlg());
peer.setMyid(config.getServerId());
peer.setTickTime(config.getTickTime());
peer.setMinSessionTimeout(config.getMinSessionTimeout());
peer.setMaxSessionTimeout(config.getMaxSessionTimeout());
peer.setInitLimit(config.getInitLimit());
peer.setSyncLimit(config.getSyncLimit());
peer.setQuorumVerifier(config.getQuorumVerifier());
peer.setCnxnFactory(cnxnFactory);
peer.setZKDatabase(new ZKDatabase(peer.getTxnFactory()));
peer.setLearnerType(config.getPeerType());
peer.setMyid(number);
}
示例13: SpliceZoo
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
public SpliceZoo(QuorumPeerConfig config, int number) throws IOException {
this.config = config;
this.peer = new QuorumPeer();
ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
cnxnFactory.configure(config.getClientPortAddress(),config.getMaxClientCnxns());
peer.setClientPortAddress(config.getClientPortAddress());
peer.setTxnFactory(new FileTxnSnapLog(new File(config.getDataLogDir()),
new File(config.getDataDir())));
peer.setQuorumPeers(config.getServers());
peer.setElectionType(config.getElectionAlg());
peer.setMyid(config.getServerId());
peer.setTickTime(config.getTickTime());
peer.setMinSessionTimeout(config.getMinSessionTimeout());
peer.setMaxSessionTimeout(config.getMaxSessionTimeout());
peer.setInitLimit(config.getInitLimit());
peer.setSyncLimit(config.getSyncLimit());
peer.setQuorumVerifier(config.getQuorumVerifier());
peer.setCnxnFactory(cnxnFactory);
peer.setZKDatabase(new ZKDatabase(peer.getTxnFactory()));
peer.setLearnerType(config.getPeerType());
peer.setMyid(number);
}
示例14: SpliceZoo
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
public SpliceZoo(QuorumPeerConfig config, int number) throws IOException {
this.config = config;
ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
cnxnFactory.configure(config.getClientPortAddress(),config.getMaxClientCnxns());
peer.setClientPortAddress(config.getClientPortAddress());
peer.setTxnFactory(new FileTxnSnapLog(new File(config.getDataLogDir()),
new File(config.getDataDir())));
peer.setQuorumPeers(config.getServers());
peer.setElectionType(config.getElectionAlg());
peer.setMyid(config.getServerId());
peer.setTickTime(config.getTickTime());
peer.setMinSessionTimeout(config.getMinSessionTimeout());
peer.setMaxSessionTimeout(config.getMaxSessionTimeout());
peer.setInitLimit(config.getInitLimit());
peer.setSyncLimit(config.getSyncLimit());
peer.setQuorumVerifier(config.getQuorumVerifier());
peer.setCnxnFactory(cnxnFactory);
peer.setZKDatabase(new ZKDatabase(peer.getTxnFactory()));
peer.setLearnerType(config.getPeerType());
peer.setMyid(number);
}
示例15: parse
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入依赖的package包/类
/**
* Parse a ZooKeeper configuration file
* @param path the patch of the configuration file
* @return ServerConfig configured wrt arguments
* @throws ConfigException error processing configuration
*/
public void parse(String path) throws ConfigException {
QuorumPeerConfig config = new QuorumPeerConfig();
config.parse(path);
// let qpconfig parse the file and then pull the stuff we are
// interested in
readFrom(config);
}