protected void initializeAndRun(String[] args) throws ConfigException, IOException { try { ManagedUtil.registerLog4jMBeans(); } catch (JMException e) { LOG.warn("Unable to register log4j JMX control", e); } //再次解析配置文件(我也是醉了呀,又解析一遍!!!,写这段的人你出来我保证不打你) ServerConfig config = new ServerConfig(); if (args.length == 1) { config.parse(args[0]); } else { config.parse(args); } runFromConfig(config); }
public QuorumMaj(Properties props) throws ConfigException { for (Entry<Object, Object> entry : props.entrySet()) { String key = entry.getKey().toString(); String value = entry.getValue().toString(); if (key.startsWith("server.")) { int dot = key.indexOf('.'); long sid = Long.parseLong(key.substring(dot + 1)); QuorumServer qs = new QuorumServer(sid, value); allMembers.put(Long.valueOf(sid), qs); if (qs.type == LearnerType.PARTICIPANT) votingMembers.put(Long.valueOf(sid), qs); else { observingMembers.put(Long.valueOf(sid), qs); } } else if (key.equals("version")) { version = Long.parseLong(value, 16); } } half = votingMembers.size() / 2; }
private static String[] splitWithLeadingHostname(String s) throws ConfigException { /* Does it start with an IPv6 literal? */ if (s.startsWith("[")) { int i = s.indexOf("]:"); if (i < 0) { throw new ConfigException(s + " starts with '[' but has no matching ']:'"); } String[] sa = s.substring(i + 2).split(":"); String[] nsa = new String[sa.length + 1]; nsa[0] = s.substring(1, i); System.arraycopy(sa, 0, nsa, 1, sa.length); return nsa; } else { return s.split(":"); } }
protected void initializeAndRun(String[] args) throws ConfigException, IOException, AdminServerException { QuorumPeerConfig config = new QuorumPeerConfig(); if (args.length == 1) { config.parse(args[0]); } // Start and schedule the the purge task DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config .getDataDir(), config.getDataLogDir(), config .getSnapRetainCount(), config.getPurgeInterval()); purgeMgr.start(); if (args.length == 1 && config.isDistributed()) { runFromConfig(config); } else { LOG.warn("Either no config or no quorum defined in config, running " + " in standalone mode"); // there is only server in the quorum -- run as standalone ZooKeeperServerMain.main(args); } }
protected void initializeAndRun(String[] args) throws ConfigException, IOException, AdminServerException { try { ManagedUtil.registerLog4jMBeans(); } catch (JMException e) { LOG.warn("Unable to register log4j JMX control", e); } ServerConfig config = new ServerConfig(); if (args.length == 1) { config.parse(args[0]); } else { config.parse(args); } runFromConfig(config); }
/** * Add a configuration resource. The properties form this configuration will * overwrite corresponding already loaded property and system property * * @param configFile * Configuration file. */ public void addConfiguration(File configFile) throws ConfigException { LOG.info("Reading configuration from: {}", configFile.getAbsolutePath()); try { configFile = (new VerifyingFileFactory.Builder(LOG).warnForRelativePath().failForNonExistingPath().build()) .validate(configFile); Properties cfg = new Properties(); FileInputStream in = new FileInputStream(configFile); try { cfg.load(in); } finally { in.close(); } parseProperties(cfg); } catch (IOException | IllegalArgumentException e) { LOG.error("Error while configuration from: {}", configFile.getAbsolutePath(), e); throw new ConfigException("Error while processing " + configFile.getAbsolutePath(), e); } }
/** * Test verifies that the server shouldn't allow minsessiontimeout > * maxsessiontimeout */ @Test public void testWithMinSessionTimeoutGreaterThanMaxSessionTimeout() throws Exception { ClientBase.setupTestEnv(); final int CLIENT_PORT = PortAssignment.unique(); final int tickTime = 2000; final int minSessionTimeout = 20 * tickTime + 1000; // min is higher final int maxSessionTimeout = tickTime * 2 - 100; // max is lower final String configs = "maxSessionTimeout=" + maxSessionTimeout + "\n" + "minSessionTimeout=" + minSessionTimeout + "\n"; MainThread main = new MainThread(CLIENT_PORT, true, configs); String args[] = new String[1]; args[0] = main.confFile.toString(); try { main.main.initializeAndRun(args); Assert.fail("Must throw exception as " + "minsessiontimeout > maxsessiontimeout"); } catch (ConfigException iae) { // expected } }
protected void initializeAndRun(String[] args) throws ConfigException, IOException { QuorumPeerConfig config = new QuorumPeerConfig(); if (args.length == 1) { config.parse(args[0]); } // Start and schedule the the purge task DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config .getDataDir(), config.getDataLogDir(), config .getSnapRetainCount(), config.getPurgeInterval()); purgeMgr.start(); if (args.length == 1 && config.servers.size() > 0) { runFromConfig(config); } else { LOG.warn("Either no config or no quorum defined in config, running " + " in standalone mode"); // there is only server in the quorum -- run as standalone ZooKeeperServerMain.main(args); } }
protected void initializeAndRun(String[] args) throws ConfigException, IOException { try { ManagedUtil.registerLog4jMBeans(); } catch (JMException e) { LOG.warn("Unable to register log4j JMX control", e); } ServerConfig config = new ServerConfig(); if (args.length == 1) { config.parse(args[0]); } else { config.parse(args); } runFromConfig(config); }
protected void initializeAndRun(String[] args) throws ConfigException, IOException { QuorumPeerConfig config = new QuorumPeerConfig(); if (args.length == 1) { config.parse(args[0]); } if (args.length == 1 && config.servers.size() > 0) { runFromConfig(config); } else { LOG.warn("Either no config or no quorum defined in config, running " + " in standalone mode"); // there is only server in the quorum -- run as standalone ZooKeeperServerMain.main(args); } }
/** * Test verifies that the server shouldn't allow minsessiontimeout > * maxsessiontimeout */ @Test public void testWithMinSessionTimeoutGreaterThanMaxSessionTimeout() throws Exception { ClientBase.setupTestEnv(); final int CLIENT_PORT = PortAssignment.unique(); final int tickTime = 2000; final int minSessionTimeout = 20 * tickTime + 1000; // min is higher final int maxSessionTimeout = tickTime * 2 - 100; // max is lower final String configs = "maxSessionTimeout=" + maxSessionTimeout + "\n" + "minSessionTimeout=" + minSessionTimeout + "\n"; MainThread main = new MainThread(CLIENT_PORT, false, configs); String args[] = new String[1]; args[0] = main.confFile.toString(); try { main.main.initializeAndRun(args); Assert.fail("Must throw exception as " + "minsessiontimeout > maxsessiontimeout"); } catch (ConfigException iae) { // expected } }
@Before public void setUp() throws IOException, ConfigException, InterruptedException { new File(TEST_DIR).mkdirs(); conf = NotifierTestUtil.initGenericConf(); String editsLocation = TEST_DIR + "/tmp/hadoop/name"; conf.set(AvatarNode.DFS_SHARED_EDITS_DIR0_KEY, editsLocation + "0"); conf.set(AvatarNode.DFS_SHARED_EDITS_DIR1_KEY, editsLocation + "1"); cluster = new MiniAvatarCluster.Builder(conf).numDataNodes(3).enableQJM(false) .federation(true).build(); nameService = conf.get(FSConstants.DFS_FEDERATION_NAMESERVICES); fileSys = cluster.getFileSystem(); localhostAddr = InetAddress.getLocalHost().getHostName(); DFSUtil.setGenericConf(conf, nameService, AvatarNode.DFS_SHARED_EDITS_DIR0_KEY, AvatarNode.DFS_SHARED_EDITS_DIR1_KEY); }
/** * Modify the config and start up the servers. The rpc and info ports for * servers are guaranteed to use free ports. * <p> * NameNode and DataNode directory creation and configuration will be * managed by this class. * * @param conf the base configuration to use in starting the servers. This * will be modified as necessary. * @param numDataNodes Number of DataNodes to start; may be zero * @param format if true, format the NameNode and DataNodes before starting up * @param racks array of strings indicating the rack that each DataNode is on * @param hosts array of strings indicating the hostname of each DataNode * @param numNameNodes Number of NameNodes to start; * @param federation if true, we start it with federation configure; */ public MiniAvatarCluster(Configuration conf, int numDataNodes, boolean format, String[] racks, String[] hosts, int numNameNodes, boolean federation, long[] simulatedCapacities) throws IOException, ConfigException, InterruptedException { this(new Builder(conf).numDataNodes(numDataNodes).format(format) .racks(racks) .hosts(hosts) .numNameNodes(numNameNodes) .federation(federation) .simulatedCapacities(simulatedCapacities)); }
private static ServerConfig createZooKeeperConf() throws IOException, ConfigException { // create conf file File zkConfDir = new File(TEST_DIR); zkConfDir.mkdirs(); File zkConfFile = new File(ZK_CONF_FILE); zkConfFile.delete(); zkConfFile.createNewFile(); Properties zkConfProps = new Properties(); zkConfProps.setProperty("tickTime", "2000"); zkConfProps.setProperty("dataDir", ZK_DATA_DIR); zkConfProps.setProperty("clientPort", new Integer(zkClientPort).toString()); zkConfProps.setProperty("maxClientCnxns", "500"); zkConfProps.store(new FileOutputStream(zkConfFile), ""); // create config object ServerConfig zkConf = new ServerConfig(); zkConf.parse(ZK_CONF_FILE); return zkConf; }
public static void createAndStartZooKeeper() throws IOException, ConfigException, InterruptedException { logStateChange("Creating zookeeper server"); AvatarShell.retrySleep = 1000; ServerConfig zkConf = createZooKeeperConf(); zooKeeper = new ZooKeeperServer(); FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(zkConf.getDataLogDir()), new File(zkConf.getDataDir())); zooKeeper.setTxnLogFactory(ftxn); zooKeeper.setTickTime(zkConf.getTickTime()); zooKeeper.setMinSessionTimeout(zkConf.getMinSessionTimeout()); zooKeeper.setMaxSessionTimeout(zkConf.getMaxSessionTimeout()); cnxnFactory = new NIOServerCnxnFactory(); cnxnFactory.configure(zkConf.getClientPortAddress(), zkConf.getMaxClientCnxns()); cnxnFactory.startup(zooKeeper); logStateChange("Creating zookeeper server - completed"); }
/** * 启动zookeeper服务 */ public static void startZookeeperServer() throws ConfigException, IOException { String classPath = ApplicationParseTest.class.getResource("/").getPath(); String[] args = {classPath + File.separator + "zoo.cfg"}; ServerConfig config = new ServerConfig(); if (args.length == 1) { config.parse(args[0]); } else { config.parse(args); } LOG.info("start to startup zookeeper server"); runFromConfig(config); }
protected void initializeAndRun(String[] args) throws ConfigException, IOException { try { ManagedUtil.registerLog4jMBeans(); } catch (JMException e) { log.warn("Unable to register log4j JMX control", e); } ServerConfig config = new ServerConfig(); if (args.length == 1) { config.parse(args[0]); } else { config.parse(args); } runFromConfig(config); }
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) ; } }