epugh commented on code in PR #4124:
URL: https://github.com/apache/solr/pull/4124#discussion_r2818246694
##########
solr/core/src/java/org/apache/solr/handler/admin/ZookeeperInfoHandler.java:
##########
@@ -723,89 +686,116 @@ boolean printZnode(JSONWriter json, String path) throws
IOException {
try {
dataStr = (new BytesRef(data)).utf8ToString();
} catch (Exception e) {
- dataStrErr = "data is not parsable as a utf8 String: " +
e.toString();
+ dataStrErr = "data is not parsable as a utf8 String: " + e;
}
}
- json.writeString("znode");
- json.writeNameSeparator();
- json.startObject();
-
- writeKeyValue(json, PATH, path, true);
-
- json.writeValueSeparator();
- json.writeString("prop");
- json.writeNameSeparator();
- json.startObject();
- writeKeyValue(json, "version", stat.getVersion(), true);
- writeKeyValue(json, "aversion", stat.getAversion(), false);
- writeKeyValue(json, "children_count", stat.getNumChildren(), false);
- writeKeyValue(json, "ctime", time(stat.getCtime()), false);
- writeKeyValue(json, "cversion", stat.getCversion(), false);
- writeKeyValue(json, "czxid", stat.getCzxid(), false);
- writeKeyValue(json, "ephemeralOwner", stat.getEphemeralOwner(), false);
- writeKeyValue(json, "mtime", time(stat.getMtime()), false);
- writeKeyValue(json, "mzxid", stat.getMzxid(), false);
- writeKeyValue(json, "pzxid", stat.getPzxid(), false);
- writeKeyValue(json, "dataLength", stat.getDataLength(), false);
+ Map<String, Object> znodeMap = new LinkedHashMap<>();
+ Map<String, Object> znodeContent = new LinkedHashMap<>();
+
+ znodeContent.put(PATH, path);
+
+ Map<String, Object> prop = new LinkedHashMap<>();
+ prop.put("version", stat.getVersion());
+ prop.put("aversion", stat.getAversion());
+ prop.put("children_count", stat.getNumChildren());
+ prop.put("ctime", time(stat.getCtime()));
+ prop.put("cversion", stat.getCversion());
+ prop.put("czxid", stat.getCzxid());
+ prop.put("ephemeralOwner", stat.getEphemeralOwner());
+ prop.put("mtime", time(stat.getMtime()));
+ prop.put("mzxid", stat.getMzxid());
+ prop.put("pzxid", stat.getPzxid());
+ prop.put("dataLength", stat.getDataLength());
if (null != dataStrErr) {
- writeKeyValue(json, "dataNote", dataStrErr, false);
+ prop.put("dataNote", dataStrErr);
}
- json.endObject();
+ znodeContent.put("prop", prop);
if (null != dataStr) {
- writeKeyValue(json, "data", dataStr, false);
- }
-
- if (page != null) {
- writeKeyValue(json, "paging", page.getPagingHeader(), false);
+ znodeContent.put("data", dataStr);
}
- json.endObject();
- } catch (KeeperException e) {
- writeError(500, e.toString());
- return false;
- } catch (InterruptedException e) {
+ znodeMap.put("znode", znodeContent);
+ return znodeMap;
+ } catch (KeeperException | InterruptedException e) {
writeError(500, e.toString());
- return false;
+ return null;
}
- return true;
}
+ }
- /* @Override
- public void write(OutputStream os) throws IOException {
- ByteBuffer bytes = baos.getByteBuffer();
- os.write(bytes.array(),0,bytes.limit());
- }
- */
- @Override
- public String getName() {
- return null;
- }
+ /**
+ * Response builder implementation for a paginated, filtered view of
collections. Supports
+ * pagination, and collection state retrieval.
+ */
+ static class ZkGraphResponseBuilder extends ZkBaseResponseBuilder {
+ private final PageOfCollections page;
+ private final PagedCollectionSupport pagingSupport;
- @Override
- public String getSourceInfo() {
- return null;
+ public ZkGraphResponseBuilder(
+ ZkController controller,
+ PageOfCollections page,
+ PagedCollectionSupport pagingSupport,
+ boolean detail,
+ boolean dump) {
+ super(controller, detail, dump);
+ this.page = page;
+ this.pagingSupport = pagingSupport;
}
@Override
- public String getContentType() {
- return JSONResponseWriter.CONTENT_TYPE_JSON_UTF8;
- }
+ public void build() throws IOException {
+ SortedMap<String, Object> collectionStates;
+ try {
+ // support paging of the collections graph view (in case there are
many collections)
+ // fetch the requested page of collections and then retrieve the state
for each
+ pagingSupport.fetchPage(page, zkClient);
+ // keep track of how many collections match the filter
+ boolean applyStatusFilter = (page.filterType == FilterType.status &&
page.filter != null);
+ List<String> matchesStatusFilter = applyStatusFilter ? new
ArrayList<>() : null;
+ ClusterState cs = zkController.getZkStateReader().getClusterState();
+ Set<String> liveNodes = applyStatusFilter ? cs.getLiveNodes() : null;
- @Override
- public Long getSize() {
- return null;
- }
+ collectionStates = new TreeMap<>(pagingSupport);
+ for (String collection : page.selected) {
+ DocCollection dc = cs.getCollectionOrNull(collection);
+ if (dc != null) {
+ Map<String, Object> collectionState = dc.toMap(new
LinkedHashMap<>());
+ if (applyStatusFilter) {
+ // verify this collection matches the filtered state
+ if (page.matchesStatusFilter(collectionState, liveNodes)) {
+ matchesStatusFilter.add(collection);
+ collectionStates.put(
+ collection,
ClusterStatus.postProcessCollectionJSON(collectionState));
+ }
+ } else {
+ collectionStates.put(
+ collection,
ClusterStatus.postProcessCollectionJSON(collectionState));
+ }
+ }
+ }
- @Override
- public InputStream getStream() throws IOException {
- return new ByteBufferInputStream(baos.getByteBuffer());
- }
+ if (applyStatusFilter) {
+ // update the paged navigation info after applying the status filter
+ page.selectPage(matchesStatusFilter);
- @Override
- public Reader getReader() throws IOException {
- return null;
+ // rebuild the Map of state data
+ SortedMap<String, Object> map = new TreeMap<>(pagingSupport);
+ for (String next : page.selected) map.put(next,
collectionStates.get(next));
+ collectionStates = map;
+ }
+ } catch (KeeperException | InterruptedException e) {
+ writeError(500, e.toString());
+ return;
+ }
+
+ Map<String, Object> znodeContent = new LinkedHashMap<>();
Review Comment:
done!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]