本文整理汇总了Java中org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties方法的典型用法代码示例。如果您正苦于以下问题:Java QuorumPeerConfig.parseProperties方法的具体用法?Java QuorumPeerConfig.parseProperties怎么用?Java QuorumPeerConfig.parseProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.server.quorum.QuorumPeerConfig
的用法示例。
在下文中一共展示了QuorumPeerConfig.parseProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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);
}
示例5: 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);
}
示例6: 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) ;
}
}
示例7: 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);
}
}
示例8: start
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入方法依赖的package包/类
public void start() throws Exception {
try {
// zkDir = genZookeeperDataDir();
zkConfig = genZookeeperConfig(zkDir);
port = Integer.valueOf(zkConfig.getProperty("clientPort"));
QuorumPeerConfig qpConfig = new QuorumPeerConfig();
qpConfig.parseProperties(zkConfig);
final ServerConfig sConfig = new ServerConfig();
sConfig.readFrom(qpConfig);
thread = new Thread() {
@Override
public void run() {
try {
LOGGER.info("Starting ZK server");
runFromConfig(sConfig);
} catch (Throwable t) {
LOGGER.error("Failure in embedded ZooKeeper", t);
}
}
};
thread.start();
Thread.sleep(500);
} catch (Throwable t) {
throw new Exception("Cannot start embedded zookeeper", t);
}
}
示例9: start
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入方法依赖的package包/类
public void start() throws IOException, ConfigException, InterruptedException {
log.info("Starting Zookeeper on port {}", port);
Properties properties = new Properties();
properties.setProperty("dataDir", getDataDir().getAbsolutePath());
properties.setProperty("clientPort", Integer.toString(getPort()));
QuorumPeerConfig quorumConfig = new QuorumPeerConfig();
quorumConfig.parseProperties(properties);
cleanupManager = new DatadirCleanupManager(quorumConfig.getDataDir(), quorumConfig.getDataLogDir(),
quorumConfig.getSnapRetainCount(), quorumConfig.getPurgeInterval());
cleanupManager.start();
ServerConfig serverConfig = new ServerConfig();
serverConfig.readFrom(quorumConfig);
zkServer = new ZooKeeperServer();
zkServer.setTickTime(serverConfig.getTickTime());
zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());
transactionLog = new FileTxnSnapLog(new File(serverConfig.getDataLogDir().toString()),
new File(serverConfig.getDataDir().toString()));
zkServer.setTxnLogFactory(transactionLog);
connectionFactory = ServerCnxnFactory.createFactory();
connectionFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns());
connectionFactory.startup(zkServer);
}
示例10: run
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入方法依赖的package包/类
public void run() throws Exception {
pidFileLocker.lock();
server = new ZooKeeperServerMain();
QuorumPeerConfig qp = new QuorumPeerConfig();
qp.parseProperties(configuration);
ServerConfig sc = new ServerConfig();
sc.readFrom(qp);
server.runFromConfig(sc);
}
示例11: ZookeeperInstance
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入方法依赖的package包/类
public ZookeeperInstance(File commonWorkDir, boolean useCrusher, int instance) throws Exception {
File workDir = new File(commonWorkDir, "instance-" + instance);
FileUtils.forceMkdir(workDir);
File logDir = new File(commonWorkDir, "log-" + instance);
FileUtils.forceMkdir(logDir);
File markerFile = new File(workDir, "myid");
FileUtils.write(markerFile, Integer.toString(instance), "UTF-8");
this.instance = instance;
this.clientPort = PORT_BASE_CLIENT + instance;
Properties properties = new Properties();
properties.put("tickTime", "100");
properties.put("dataDir", workDir.getAbsolutePath());
properties.put("dataLogDir", logDir.getAbsolutePath());
properties.put("clientPort", Integer.toString(clientPort));
properties.put("clientPortAddress", "127.0.0.1");
properties.put("initLimit", "5");
properties.put("syncLimit", "5");
for (int i = 1; i <= CLUSTER_SIZE; i++) {
int leaderPort = (i != instance && useCrusher) ?
PORT_BASE_LEADER + PORT_CRUSHER_BASE + i : PORT_BASE_LEADER + i;
int electionPort = (i != instance && useCrusher) ?
PORT_BASE_ELECTION + PORT_CRUSHER_BASE + i : PORT_BASE_ELECTION + i;
properties.put("server." + i, "127.0.0.1:" + leaderPort + ":" + electionPort);
}
QuorumPeerConfig config = new QuorumPeerConfig();
config.parseProperties(properties);
this.factory = ServerCnxnFactory.createFactory();
this.peer = createPeer(factory, config);
LOGGER.info("Zookeeper #{} is started", instance);
}
示例12: runFlinkZkQuorumPeer
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入方法依赖的package包/类
/**
* 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);
}
}
示例13: TestZkServer
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入方法依赖的package包/类
public TestZkServer() throws IOException, ConfigException {
final Properties props = new Properties();
props.setProperty("clientPort", String.valueOf(PORT));
props.setProperty("dataDir", Files.createTempDirectory("zk").toString());
final QuorumPeerConfig quorumConfig = new QuorumPeerConfig();
quorumConfig.parseProperties(props);
config = new ServerConfig();
config.readFrom(quorumConfig);
}
示例14: 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);
runZKServer(zkConfig);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
示例15: startup
import org.apache.zookeeper.server.quorum.QuorumPeerConfig; //导入方法依赖的package包/类
public int startup(File baseDir, int numZooKeeperServers) throws IOException, InterruptedException {
if (numZooKeeperServers <= 0)
return -1;
shutdown();
service = Executors.newFixedThreadPool(numZooKeeperServers);
// running all the ZK servers
for (int i = 0; i < numZooKeeperServers; i++) {
int l = i + 1;
File dir = new File(baseDir, "zookeeper_" + l).getAbsoluteFile();
prepareDir(dir, i + 1);
Properties startupProperties = new Properties();
startupProperties.setProperty("tickTime", "2000");
startupProperties.setProperty("dataDir", dir.getAbsolutePath());
startupProperties.setProperty("initLimit", "10");
startupProperties.setProperty("syncLimit", "5");
startupProperties.setProperty("maxClientCnxns", "100");
for (int j = 0; j < numZooKeeperServers; j++) {
int m = j + 1;
startupProperties.setProperty("server." + m, "localhost:" + (2888 + j) + ":" + (3888 + j));
}
startupProperties.setProperty("clientPort", String.valueOf(2181 + i));
LOG.trace("startup Properties: " + startupProperties);
QuorumPeerConfig config = new QuorumPeerConfig();
try {
config.parseProperties(startupProperties);
} catch (Exception e) {
throw new RuntimeException(e);
}
service.execute(new SpliceZoo(config, l));
}
started = true;
return 0;
}