Skip to content

Instantly share code, notes, and snippets.

@ericacm
Last active December 13, 2015 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericacm/4981497 to your computer and use it in GitHub Desktop.
Save ericacm/4981497 to your computer and use it in GitHub Desktop.
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