use of com.netflix.exhibitor.core.state.UsState in project exhibitor by soabase.
the class StandardProcessOperations method prepConfigFile.
private void prepConfigFile(Details details) throws IOException {
UsState usState = new UsState(exhibitor);
File idFile = new File(details.dataDirectory, "myid");
if (usState.getUs() != null) {
Files.createParentDirs(idFile);
String id = String.format("%d\n", usState.getUs().getServerId());
Files.write(id.getBytes(), idFile);
} else {
exhibitor.getLog().add(ActivityLog.Type.INFO, "Starting in standalone mode");
if (idFile.exists() && !idFile.delete()) {
exhibitor.getLog().add(ActivityLog.Type.ERROR, "Could not delete ID file: " + idFile);
}
}
Properties localProperties = new Properties();
localProperties.putAll(details.properties);
localProperties.setProperty("clientPort", Integer.toString(usState.getConfig().getInt(IntConfigs.CLIENT_PORT)));
String portSpec = String.format(":%d:%d", usState.getConfig().getInt(IntConfigs.CONNECT_PORT), usState.getConfig().getInt(IntConfigs.ELECTION_PORT));
for (ServerSpec spec : usState.getServerList().getSpecs()) {
localProperties.setProperty("server." + spec.getServerId(), spec.getHostname() + portSpec + spec.getServerType().getZookeeperConfigValue());
}
if ((usState.getUs() != null) && (usState.getUs().getServerType() == ServerType.OBSERVER)) {
localProperties.setProperty("peerType", "observer");
}
File configFile = new File(details.configDirectory, "zoo.cfg");
OutputStream out = new BufferedOutputStream(new FileOutputStream(configFile));
try {
localProperties.store(out, "Auto-generated by Exhibitor - " + new Date());
} finally {
CloseableUtils.closeQuietly(out);
}
}
Aggregations