@InterfaceAudience.Public public class MiniZooKeeperCluster extends Object
Modifier and Type | Field and Description |
---|---|
private int |
activeZKServerIndex |
private List<Integer> |
clientPortList |
private org.apache.hadoop.conf.Configuration |
configuration |
private int |
connectionTimeout |
private static int |
DEFAULT_CONNECTION_TIMEOUT |
private int |
defaultClientPort
The default port.
|
static String |
HOST |
private static org.slf4j.Logger |
LOG |
static String |
LOOPBACK_HOST |
private List<org.apache.zookeeper.server.NIOServerCnxnFactory> |
standaloneServerFactoryList |
private boolean |
started |
private static int |
TICK_TIME |
private int |
tickTime |
private static int |
TIMEOUT |
private List<org.apache.zookeeper.server.ZooKeeperServer> |
zooKeeperServers |
Constructor and Description |
---|
MiniZooKeeperCluster() |
MiniZooKeeperCluster(org.apache.hadoop.conf.Configuration configuration) |
Modifier and Type | Method and Description |
---|---|
void |
addClientPort(int clientPort)
Add a client port to the list.
|
private void |
createDir(File dir) |
Address |
getAddress()
Returns Address for this cluster instance.
|
int |
getBackupZooKeeperServerNum() |
int |
getClientPort() |
List<Integer> |
getClientPortList()
Get the list of client ports.
|
private String |
getServerConfigurationOnOneLine(org.apache.zookeeper.server.ZooKeeperServer server) |
int |
getZooKeeperServerNum() |
(package private) List<org.apache.zookeeper.server.ZooKeeperServer> |
getZooKeeperServers() |
private boolean |
hasValidClientPortInList(int index)
Check whether the client port in a specific position of the client port list is valid.
|
int |
killCurrentActiveZooKeeperServer() |
void |
killOneBackupZooKeeperServer()
Kill one back up ZK servers.
|
private int |
selectClientPort(int seedPort)
Selects a ZK client port.
|
void |
setDefaultClientPort(int clientPort) |
void |
setTickTime(int tickTime) |
private static void |
setupTestEnv() |
void |
shutdown() |
int |
startup(File baseDir) |
int |
startup(File baseDir,
int numZooKeeperServers) |
private static boolean |
waitForServerDown(int port,
long timeout) |
private static boolean |
waitForServerUp(int port,
long timeout) |
private static final org.slf4j.Logger LOG
private static final int TICK_TIME
private static final int TIMEOUT
private static final int DEFAULT_CONNECTION_TIMEOUT
private int connectionTimeout
public static final String LOOPBACK_HOST
private boolean started
private int defaultClientPort
private final List<org.apache.zookeeper.server.NIOServerCnxnFactory> standaloneServerFactoryList
private final List<org.apache.zookeeper.server.ZooKeeperServer> zooKeeperServers
private final List<Integer> clientPortList
private int activeZKServerIndex
private int tickTime
private final org.apache.hadoop.conf.Configuration configuration
public MiniZooKeeperCluster()
public MiniZooKeeperCluster(org.apache.hadoop.conf.Configuration configuration)
public void addClientPort(int clientPort)
clientPort
- the specified port@InterfaceAudience.Private public List<Integer> getClientPortList()
private boolean hasValidClientPortInList(int index)
index
- the specified positionpublic void setDefaultClientPort(int clientPort)
private int selectClientPort(int seedPort)
seedPort
- the seed port to start with; -1 means first time.public void setTickTime(int tickTime)
public int getBackupZooKeeperServerNum()
public int getZooKeeperServerNum()
private static void setupTestEnv()
public int startup(File baseDir) throws IOException, InterruptedException
IOException
InterruptedException
public int startup(File baseDir, int numZooKeeperServers) throws IOException, InterruptedException
baseDir
- the base directory to usenumZooKeeperServers
- the number of ZooKeeper serversIOException
- if an operation fails during the startupInterruptedException
- if the startup failsprivate String getServerConfigurationOnOneLine(org.apache.zookeeper.server.ZooKeeperServer server)
private void createDir(File dir) throws IOException
IOException
public void shutdown() throws IOException
IOException
- if waiting for the shutdown of a server failspublic int killCurrentActiveZooKeeperServer() throws IOException, InterruptedException
IOException
- if waiting for the shutdown of a server failsInterruptedException
public void killOneBackupZooKeeperServer() throws IOException, InterruptedException
IOException
- if waiting for the shutdown of a server failsInterruptedException
private static boolean waitForServerDown(int port, long timeout) throws IOException
IOException
private static boolean waitForServerUp(int port, long timeout) throws IOException
IOException
public int getClientPort()
public Address getAddress()
List<org.apache.zookeeper.server.ZooKeeperServer> getZooKeeperServers()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.