Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public ZooKeeperServerConf getConf() {
zkDb.snapLog.getSnapDir().getAbsolutePath(),
zkDb.snapLog.getDataDir().getAbsolutePath(),
getTickTime(),
serverCnxnFactory.getMaxClientCnxnsPerHost(),
getMaxClientCnxnsPerHost(),
getMinSessionTimeout(),
getMaxSessionTimeout(),
getServerId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,22 @@ public StatCommand() {
@Override
public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs) {
CommandResponse response = super.run(zkServer, kwargs);
response.put("connections", zkServer.getServerCnxnFactory().getAllConnectionInfo(true));

final Iterable<Map<String, Object>> connections;
if (zkServer.getServerCnxnFactory() != null) {
connections = zkServer.getServerCnxnFactory().getAllConnectionInfo(true);
} else {
connections = Collections.emptyList();
}
response.put("connections", connections);

final Iterable<Map<String, Object>> secureConnections;
if (zkServer.getSecureServerCnxnFactory() != null) {
secureConnections = zkServer.getSecureServerCnxnFactory().getAllConnectionInfo(true);
} else {
secureConnections = Collections.emptyList();
}
response.put("secure_connections", secureConnections);
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.zookeeper.metrics.MetricsUtils;
import org.apache.zookeeper.server.ServerCnxnFactory;
import org.apache.zookeeper.server.ServerStats;
import org.apache.zookeeper.server.ZKDatabase;
import org.apache.zookeeper.server.ZooKeeperServer;
import org.apache.zookeeper.server.quorum.BufferStats;
import org.apache.zookeeper.test.ClientBase;
Expand Down Expand Up @@ -219,7 +220,14 @@ public void testSetTraceMask() throws IOException, InterruptedException {

@Test
public void testStat() throws IOException, InterruptedException {
testCommand("stats", new Field("version", String.class), new Field("read_only", Boolean.class), new Field("server_stats", ServerStats.class), new Field("node_count", Integer.class), new Field("connections", Iterable.class), new Field("client_response", BufferStats.class));
testCommand("stats",
new Field("version", String.class),
new Field("read_only", Boolean.class),
new Field("server_stats", ServerStats.class),
new Field("node_count", Integer.class),
new Field("connections", Iterable.class),
new Field("secure_connections", Iterable.class),
new Field("client_response", BufferStats.class));
}

@Test
Expand Down Expand Up @@ -258,4 +266,27 @@ public void testConsCommandSecureOnly() {
assertThat(response.toMap().containsKey("secure_connections"), is(true));
}

/**
* testing Stat command, when only SecureClientPort is defined by the user and there is no
* regular (non-SSL port) open. In this case zkServer.getServerCnxnFactory === null
* see: ZOOKEEPER-3633
*/
@Test
public void testStatCommandSecureOnly() {
Commands.StatCommand cmd = new Commands.StatCommand();
ZooKeeperServer zkServer = mock(ZooKeeperServer.class);
ServerCnxnFactory cnxnFactory = mock(ServerCnxnFactory.class);
ServerStats serverStats = mock(ServerStats.class);
ZKDatabase zkDatabase = mock(ZKDatabase.class);
when(zkServer.getSecureServerCnxnFactory()).thenReturn(cnxnFactory);
when(zkServer.serverStats()).thenReturn(serverStats);
when(zkServer.getZKDatabase()).thenReturn(zkDatabase);
when(zkDatabase.getNodeCount()).thenReturn(0);

CommandResponse response = cmd.run(zkServer, null);

assertThat(response.toMap().containsKey("connections"), is(true));
assertThat(response.toMap().containsKey("secure_connections"), is(true));
}

}