|
@@ -126,6 +126,7 @@ public class Commands {
|
|
registerCommand(new GetTraceMaskCommand());
|
|
registerCommand(new GetTraceMaskCommand());
|
|
registerCommand(new IsroCommand());
|
|
registerCommand(new IsroCommand());
|
|
registerCommand(new LastSnapshotCommand());
|
|
registerCommand(new LastSnapshotCommand());
|
|
|
|
+ registerCommand(new LeaderCommand());
|
|
registerCommand(new MonitorCommand());
|
|
registerCommand(new MonitorCommand());
|
|
registerCommand(new RuokCommand());
|
|
registerCommand(new RuokCommand());
|
|
registerCommand(new SetTraceMaskCommand());
|
|
registerCommand(new SetTraceMaskCommand());
|
|
@@ -318,6 +319,30 @@ public class Commands {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns the leader status of this instance and the leader host string.
|
|
|
|
+ */
|
|
|
|
+ public static class LeaderCommand extends CommandBase {
|
|
|
|
+ public LeaderCommand() {
|
|
|
|
+ super(Arrays.asList("leader", "lead"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs) {
|
|
|
|
+ CommandResponse response = initializeResponse();
|
|
|
|
+ if (zkServer instanceof QuorumZooKeeperServer) {
|
|
|
|
+ response.put("is_leader", zkServer instanceof LeaderZooKeeperServer);
|
|
|
|
+ QuorumPeer peer = ((QuorumZooKeeperServer) zkServer).self;
|
|
|
|
+ response.put("leader_id", peer.getLeaderId());
|
|
|
|
+ String leaderAddress = peer.getLeaderAddress();
|
|
|
|
+ response.put("leader_ip", leaderAddress != null ? leaderAddress : "");
|
|
|
|
+ } else {
|
|
|
|
+ response.put("error", "server is not initialized");
|
|
|
|
+ }
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Some useful info for monitoring. Returned map contains:
|
|
* Some useful info for monitoring. Returned map contains:
|
|
* - "version": String
|
|
* - "version": String
|