private ZooKeeperStateServer(final Properties zkProperties) throws IOException, ConfigException { quorumPeerConfig = new QuorumPeerConfig(); quorumPeerConfig.parseProperties(zkProperties); }
/** * Parse a ZooKeeper configuration file * @param path the patch of the configuration file * @throws ConfigException error processing configuration */ public void parse(String path) throws ConfigException { File configFile = new File(path); LOG.info("Reading configuration from: " + configFile); try { if (!configFile.exists()) { throw new IllegalArgumentException(configFile.toString() + " file is missing"); } Properties cfg = new Properties(); FileInputStream in = new FileInputStream(configFile); try { cfg.load(in); } finally { in.close(); } parseProperties(cfg); } catch (IOException e) { throw new ConfigException("Error processing " + path, e); } catch (IllegalArgumentException e) { throw new ConfigException("Error processing " + path, e); } }
Properties startupProperties = ... QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig(); try { quorumConfiguration.parseProperties(startupProperties); } catch(Exception e) { throw new RuntimeException(e); } zooKeeperServer = new ZooKeeperServerMain(); final ServerConfig configuration = new ServerConfig(); configuration.readFrom(quorumConfiguration); new Thread() { public void run() { try { zooKeeperServer.runFromConfig(configuration); } catch (IOException e) { log.error("ZooKeeper Failed", e); } } }.start();
@Override public void run() { try { Properties properties = new Properties(); File file = new File(System.getProperty("java.io.tmpdir") + File.separator + UUID.randomUUID()); file.deleteOnExit(); properties.setProperty("dataDir", file.getAbsolutePath()); properties.setProperty("clientPort", String.valueOf(clientPort)); QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); quorumPeerConfig.parseProperties(properties); zkServer = new ZooKeeperServerMain(); ServerConfig configuration = new ServerConfig(); configuration.readFrom(quorumPeerConfig); zkServer.runFromConfig(configuration); } catch (Exception e) { if (errorHandler != null) { errorHandler.handleError(e); } else { logger.error("Exception running embedded ZooKeeper", e); } } } }
parseProperties(cfg); } catch (IOException e) { throw new ConfigException("Error processing " + path, e);
/** * 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) { LOG.error("Failed to start ZKServer", e); System.exit(-1); } }
/** * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2873 */ @Test(expected = ConfigException.class) public void testSamePortConfiguredForClientAndElection() throws IOException, ConfigException { QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); Properties zkProp = getDefaultZKProperties(); zkProp.setProperty("server.1", "localhost:2888:2888"); quorumPeerConfig.parseProperties(zkProp); }
/** * https://issues.apache.org/jira/browse/ZOOKEEPER-2297 */ @Test public void testConfigureSSLAuthGetsConfiguredIfSecurePortConfigured() throws IOException, ConfigException { String sslAuthProp = "zookeeper.authProvider.x509"; QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); Properties zkProp = getDefaultZKProperties(); zkProp.setProperty("secureClientPort", "12345"); quorumPeerConfig.parseProperties(zkProp); String expected = "org.apache.zookeeper.server.auth.X509AuthenticationProvider"; String result = System.getProperty(sslAuthProp); assertEquals(expected, result); }
/** * test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2264 */ @Test public void testErrorMessageWhensecureClientPortNotSetButsecureClientPortAddressSet() throws IOException, ConfigException { QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); try { Properties zkProp = getDefaultZKProperties(); zkProp.setProperty("secureClientPortAddress", "localhost"); quorumPeerConfig.parseProperties(zkProp); fail("IllegalArgumentException is expected"); } catch (IllegalArgumentException e) { String expectedMessage = "secureClientPortAddress is set but secureClientPort is not set"; assertEquals(expectedMessage, e.getMessage()); } }
/** * * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2264 */ @Test public void testErrorMessageWhenclientPortNotSetButclientPortAddressSet() throws IOException, ConfigException { QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); try { Properties zkProp = getDefaultZKProperties(); zkProp.setProperty("clientPortAddress", "localhost"); quorumPeerConfig.parseProperties(zkProp); fail("IllegalArgumentException is expected"); } catch (IllegalArgumentException e) { String expectedMessage = "clientPortAddress is set but clientPort is not set"; assertEquals(expectedMessage, e.getMessage()); } }
/** * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2847 */ @Test public void testClientAddrFromClientPort() throws IOException, ConfigException { long serverId = 1; QuorumPeerConfig quorumPeerConfig = new MockQuorumPeerConfig(serverId); Properties zkProp = getDefaultZKProperties(); int clientPort = 12345; zkProp.setProperty("clientPort", Integer.toString(clientPort)); zkProp.setProperty("server.1", "127.0.0.1:2889:3889:participant"); quorumPeerConfig.parseProperties(zkProp); QuorumServer qs = quorumPeerConfig.getQuorumVerifier().getAllMembers().get(serverId); InetSocketAddress expectedAddress = new InetSocketAddress("0.0.0.0", clientPort); assertEquals(expectedAddress, quorumPeerConfig.getClientPortAddress()); assertEquals(quorumPeerConfig.getClientPortAddress(), qs.clientAddr); }
quorumConfiguration.parseProperties(startupProperties); } catch(Exception e) { throw new RuntimeException(e);
quorumConfiguration.parseProperties(startupProperties); } catch(Exception e) { throw new RuntimeException(e);
/** * https://issues.apache.org/jira/browse/ZOOKEEPER-2297 */ @Test public void testCustomSSLAuth() throws IOException { try (ClientX509Util x509Util = new ClientX509Util()) { System.setProperty(x509Util.getSslAuthProviderProperty(), "y509"); QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); try { Properties zkProp = getDefaultZKProperties(); zkProp.setProperty("secureClientPort", "12345"); quorumPeerConfig.parseProperties(zkProp); fail("ConfigException is expected"); } catch (ConfigException e) { assertNotNull(e.getMessage()); } } }
public ZooKeeperLocal(Properties zkProperties) throws IOException { QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig(); try { quorumConfiguration.parseProperties(zkProperties); } catch (Exception e) { throw new RuntimeException(e); } zooKeeperServer = new ZooKeeperServerMain(); final ServerConfig configuration = new ServerConfig(); configuration.readFrom(quorumConfiguration); new Thread() { public void run() { try { zooKeeperServer.runFromConfig(configuration); } catch (IOException e) { logger.error("Zookeeper startup failed.", e); } } }.start(); } }
quorumConfig.parseProperties(ConfigUtils.keyValueToProperties( "dataDir", dataDir.toAbsolutePath(), "clientPort", port
public static void main(String[] args) throws Exception { QuorumPeerConfig config = new QuorumPeerConfig(); InputStream is = ZKStartup.class.getResourceAsStream("/zookeeper.properties"); Properties p = new Properties(); p.load(is); config.parseProperties(p); ServerConfig serverconfig = new ServerConfig(); serverconfig.readFrom(config); new ZooKeeperServerMain().runFromConfig(serverconfig); } }
/** * Parse ZooKeeper configuration from Hama XML config and run a QuorumPeer. * * @param conf Hadoop Configuration. */ public static void runZooKeeper(Configuration conf) throws Exception { Properties zkProperties = makeZKProps(conf); writeMyID(zkProperties); QuorumPeerConfig zkConfig = new QuorumPeerConfig(); zkConfig.parseProperties(zkProperties); runZKServer(zkConfig); }
/** * Parse ZooKeeper configuration from Hama XML config and run a QuorumPeer. * * @param conf Hadoop Configuration. */ public static void runZooKeeper(Configuration conf) throws Exception { Properties zkProperties = makeZKProps(conf); writeMyID(zkProperties); QuorumPeerConfig zkConfig = new QuorumPeerConfig(); zkConfig.parseProperties(zkProperties); runZKServer(zkConfig); }
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); } }