blob: 15d5d2f6f31689b2660e9c86ff6dcae084344259 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.zookeeper;
import com.google.inject.Inject;
import com.yahoo.cloud.config.ZookeeperServerConfig;
import com.yahoo.component.AbstractComponent;
import com.yahoo.security.tls.TransportSecurityUtils;
import java.util.logging.Level;
import static com.yahoo.vespa.defaults.Defaults.getDefaults;
import static com.yahoo.vespa.zookeeper.Configurator.zookeeperServerHostnames;
/**
* Writes zookeeper config and starts zookeeper server.
*
* @author Ulf Lilleengen
* @author Harald Musum
*/
public class VespaZooKeeperServerImpl extends AbstractComponent implements Runnable, VespaZooKeeperServer {
private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(VespaZooKeeperServerImpl.class.getName());
private final Thread zkServerThread;
private final ZookeeperServerConfig zookeeperServerConfig;
@Inject
public VespaZooKeeperServerImpl(ZookeeperServerConfig zookeeperServerConfig) {
this.zookeeperServerConfig = zookeeperServerConfig;
new Configurator(zookeeperServerConfig).writeConfigToDisk(TransportSecurityUtils.getOptions());
zkServerThread = new Thread(this, "zookeeper server");
zkServerThread.start();
}
private void shutdown() {
zkServerThread.interrupt();
try {
zkServerThread.join();
} catch (InterruptedException e) {
log.log(Level.WARNING, "Error joining server thread on shutdown", e);
}
}
@Override
public void run() {
String[] args = new String[]{getDefaults().underVespaHome(zookeeperServerConfig.zooKeeperConfigFile())};
log.log(Level.INFO, "Starting ZooKeeper server with config file " + args[0] +
". Trying to establish ZooKeeper quorum (members: " + zookeeperServerHostnames(zookeeperServerConfig) + ")");
org.apache.zookeeper.server.quorum.QuorumPeerMain.main(args);
}
@Override
public void deconstruct() {
shutdown();
super.deconstruct();
}
}
|