use of org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException in project zookeeper by apache.
the class ConfigUtils method getClientConfigStr.
public static String getClientConfigStr(String configData) {
Properties props = new Properties();
try {
props.load(new StringReader(configData));
} catch (IOException e) {
e.printStackTrace();
return "";
}
StringBuffer sb = new StringBuffer();
boolean first = true;
String version = "";
for (Entry<Object, Object> entry : props.entrySet()) {
String key = entry.getKey().toString().trim();
String value = entry.getValue().toString().trim();
if (key.equals("version")) {
version = value;
}
if (!key.startsWith("server.")) {
continue;
}
QuorumPeer.QuorumServer qs;
try {
qs = new QuorumPeer.QuorumServer(-1, value);
} catch (ConfigException e) {
e.printStackTrace();
continue;
}
if (!first) {
sb.append(",");
} else {
first = false;
}
if (null != qs.clientAddr) {
sb.append(qs.clientAddr.getHostString() + ":" + qs.clientAddr.getPort());
}
}
return version + " " + sb.toString();
}
use of org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException in project zookeeper by apache.
the class QuorumHierarchical method readConfigFile.
/**
* Reads a configuration file. Called from the constructor
* that takes a file as an input.
*/
private void readConfigFile(String filename) throws ConfigException {
File configFile = new File(filename);
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();
}
parse(cfg);
} catch (IOException e) {
throw new ConfigException("Error processing " + filename, e);
} catch (IllegalArgumentException e) {
throw new ConfigException("Error processing " + filename, e);
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException in project zookeeper by apache.
the class QuorumDigestAuthTest method testEnableQuorumAuthenticationConfigurations.
/**
* If quorumpeer learner is not auth enabled then self won't be able to join
* quorum. So this test is ensuring that the quorumpeer learner is also auth
* enabled while enabling quorum server require sasl.
*/
@Test
@Timeout(value = 10)
public void testEnableQuorumAuthenticationConfigurations() throws Exception {
Map<String, String> authConfigs = new HashMap<String, String>();
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_LOGIN_CONTEXT, "QuorumLearner");
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "false");
// case-1) 'quorum.auth.enableSasl' is off. Tries to enable server sasl.
authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "true");
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "false");
MainThread mthread = new MainThread(1, PortAssignment.unique(), "", authConfigs);
String[] args = new String[1];
args[0] = mthread.getConfFile().toString();
try {
new QuorumPeerMain() {
@Override
protected void initializeAndRun(String[] args) throws ConfigException, IOException, AdminServer.AdminServerException {
super.initializeAndRun(args);
}
}.initializeAndRun(args);
fail("Must throw exception as quorum sasl is not enabled!");
} catch (ConfigException e) {
// expected
}
// case-1) 'quorum.auth.enableSasl' is off. Tries to enable learner sasl.
authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "false");
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "true");
try {
new QuorumPeerMain() {
@Override
protected void initializeAndRun(String[] args) throws ConfigException, IOException, AdminServer.AdminServerException {
super.initializeAndRun(args);
}
}.initializeAndRun(args);
fail("Must throw exception as quorum sasl is not enabled!");
} catch (ConfigException e) {
// expected
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException in project zookeeper by apache.
the class ZKConfig method addConfiguration.
/**
* 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);
}
}
Aggregations