SOLR-13672: Cloud -> Zk Status page now parses response from Zookeeper 3.5.5 correctly

This commit is contained in:
Jan Høydahl 2019-08-02 13:01:20 +02:00
parent 52b5ec8068
commit 1123afae94
2 changed files with 25 additions and 17 deletions

View File

@ -126,6 +126,8 @@ Bug Fixes
* SOLR-13664: Fixed SolrTestCaseJ4.deleteCore() to properly reset the dataDir used by initCore() * SOLR-13664: Fixed SolrTestCaseJ4.deleteCore() to properly reset the dataDir used by initCore()
(hossman) (hossman)
* SOLR-13672: Cloud -> Zk Status page now parses response from Zookeeper 3.5.5 correctly (Jörn Franke, janhoy)
Other Changes Other Changes
---------------------- ----------------------

View File

@ -99,6 +99,9 @@ public final class ZookeeperStatusHandler extends RequestHandlerBase {
for (String zk : zookeepers) { for (String zk : zookeepers) {
try { try {
Map<String, Object> stat = monitorZookeeper(zk); Map<String, Object> stat = monitorZookeeper(zk);
if (stat.containsKey("errors")) {
errors.addAll((List<String>)stat.get("errors"));
}
details.add(stat); details.add(stat);
if ("true".equals(String.valueOf(stat.get("ok")))) { if ("true".equals(String.valueOf(stat.get("ok")))) {
numOk++; numOk++;
@ -115,12 +118,11 @@ public final class ZookeeperStatusHandler extends RequestHandlerBase {
} catch (SolrException se) { } catch (SolrException se) {
log.warn("Failed talking to zookeeper" + zk, se); log.warn("Failed talking to zookeeper" + zk, se);
errors.add(se.getMessage()); errors.add(se.getMessage());
zkStatus.put("errors", errors);
Map<String, Object> stat = new HashMap<>(); Map<String, Object> stat = new HashMap<>();
stat.put("host", zk); stat.put("host", zk);
stat.put("ok", false); stat.put("ok", false);
zkStatus.put("status", STATUS_YELLOW); status = STATUS_YELLOW;
return zkStatus; details.add(stat);
} }
} }
zkStatus.put("details", details); zkStatus.put("details", details);
@ -180,36 +182,34 @@ public final class ZookeeperStatusHandler extends RequestHandlerBase {
private Map<String, Object> monitorZookeeper(String zkHostPort) throws SolrException { private Map<String, Object> monitorZookeeper(String zkHostPort) throws SolrException {
Map<String, Object> obj = new HashMap<>(); Map<String, Object> obj = new HashMap<>();
List<String> errors = new ArrayList<>();
obj.put("host", zkHostPort); obj.put("host", zkHostPort);
List<String> lines = getZkRawResponse(zkHostPort, "ruok"); List<String> lines = getZkRawResponse(zkHostPort, "ruok");
boolean ok = "imok".equals(lines.get(0)); boolean ok = "imok".equals(lines.get(0));
if (ok == false) {
log.warn("Check 4lw.commands.whitelist setting in zookeeper configuration file, ZK response {}", lines.get(0));
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, lines.get(0) + " Check 4lw.commands.whitelist setting in zookeeper configuration file.");
}
obj.put("ok", ok); obj.put("ok", ok);
lines = getZkRawResponse(zkHostPort, "mntr"); lines = getZkRawResponse(zkHostPort, "mntr");
String[] parts;
for (String line : lines) { for (String line : lines) {
parts = line.split("\t"); String[] parts = line.split("\t");
if (parts.length >= 2) { if (parts.length >= 2) {
obj.put(parts[0], parts[1]); obj.put(parts[0], parts[1]);
} else { } else {
log.warn("Check 4lw.commands.whitelist setting in zookeeper configuration file, ZK response {}", line); String err = String.format("Unexpected line in 'mntr' response from Zookeeper %s: %s", zkHostPort, line);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, line + " Check 4lw.commands.whitelist setting in zookeeper configuration file."); log.warn(err);
errors.add(err);
} }
} }
lines = getZkRawResponse(zkHostPort, "conf"); lines = getZkRawResponse(zkHostPort, "conf");
for (String line : lines) { for (String line : lines) {
parts = line.split("="); String[] parts = line.split("=");
if (parts.length >= 2) { if (parts.length >= 2) {
obj.put(parts[0], parts[1]); obj.put(parts[0], parts[1]);
} else { } else if (!line.startsWith("membership:")) {
log.warn("Check 4lw.commands.whitelist setting in zookeeper configuration file, ZK response {}", line); String err = String.format("Unexpected line in 'conf' response from Zookeeper %s: %s", zkHostPort, line);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, line + " Check 4lw.commands.whitelist setting in zookeeper configuration file."); log.warn(err);
errors.add(err);
} }
} }
obj.put("errors", errors);
return obj; return obj;
} }
@ -238,6 +238,12 @@ public final class ZookeeperStatusHandler extends RequestHandlerBase {
if (response == null || response.isEmpty()) { if (response == null || response.isEmpty()) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Empty response from Zookeeper " + zkHostPort); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Empty response from Zookeeper " + zkHostPort);
} }
if (response.size() == 1 && response.get(0).contains("not in the whitelist")) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not execute " + fourLetterWordCommand +
" towards ZK host " + zkHostPort + ". Add this line to the 'zoo.cfg' " +
"configuration file on each zookeeper node: '4lw.commands.whitelist=mntr,conf,ruok'. See also chapter " +
"'Setting Up an External ZooKeeper Ensemble' in the Solr Reference Guide.");
}
return response; return response;
} catch (IOException e) { } catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Failed talking to Zookeeper " + zkHostPort, e); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Failed talking to Zookeeper " + zkHostPort, e);