This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def configureServer(serverNames: ServerNames): () => Unit = { | |
// Recreate data directory | |
if (dataDir == null || dataDir == "") { | |
dataDir = "./zookeeper-" + nodeId | |
} | |
val dir = new File(dataDir) | |
log.info("(Re)creating data directory: " + dataDir) | |
rmdir(dir) | |
dir.mkdirs() | |
val startupProperties = new Properties() | |
if (serverNames.useReplicated) { | |
for ((server, idx) <- serverNames.hosts.zipWithIndex) { | |
startupProperties.put(serverNames.serversKey(idx), serverNames.serversVal(idx)) | |
// Create myid file | |
if (server == nodeId) { | |
val myidFile = new File(dir, "myid") | |
val fw = new FileWriter(myidFile) | |
fw.write((idx+1).toString + "\n") | |
fw.close() | |
} | |
} | |
} | |
startupProperties.put("tickTime", "1000") | |
startupProperties.put("initLimit", "10") | |
startupProperties.put("syncLimit", "5") | |
startupProperties.put("dataDir", dataDir) | |
startupProperties.put("clientPort", clientPort.toString) | |
startupProperties.put("skipACL", "true") | |
startupProperties.put("autopurge.purgeInterval", "24") | |
val (serverStartFunc, server) = | |
if (serverNames.useReplicated) { // Replicated Zookeeper | |
val quorumConfiguration = new QuorumPeerConfig | |
quorumConfiguration.parseProperties(startupProperties) | |
val quorumPeerMain = new QuorumPeerMain | |
val startFunc = { () => | |
quorumPeerMain.runFromConfig(quorumConfiguration) | |
} | |
(startFunc, quorumPeerMain) | |
} else { // Standalone Zookeeper | |
val quorumConfiguration = new QuorumPeerConfig | |
quorumConfiguration.parseProperties(startupProperties) | |
val configuration = new ServerConfig | |
configuration.readFrom(quorumConfiguration) | |
val zkServerMain = new ZooKeeperServerMain | |
val startFunc = { () => | |
zkServerMain.runFromConfig(configuration) | |
} | |
(startFunc, zkServerMain) | |
} | |
zkServer = Some(server) | |
serverStartFunc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment