smiklosovic commented on code in PR #3733:
URL: https://github.com/apache/cassandra/pull/3733#discussion_r1883618190
##########
src/java/org/apache/cassandra/tools/nodetool/Status.java:
##########
@@ -179,15 +244,112 @@ private void addNode(String endpoint, Float owns,
HostStatWithPort hostStat, int
throw new RuntimeException(e);
}
- epDns = hostStat.ipOrDns(printPort);
if (isTokenPerNode)
+ return List.of(addressAndPort, statusAndState, epDns, load,
strOwns, hostID, hostStat.token, rack);
+ else
+ return List.of(addressAndPort, statusAndState, epDns, load,
String.valueOf(size), strOwns, hostID, rack);
+ }
+
+ private Boolean desc()
+ {
+ if(sortOrder==sortOrder.desc)
+ {
+ return true;
+ }
+ else if(sortOrder==sortOrder.asc)
{
- tableBuilder.add(statusAndState, epDns, load, strOwns, hostID,
hostStat.token, rack);
+ return false;
}
else
{
- tableBuilder.add(statusAndState, epDns, load,
String.valueOf(size), strOwns, hostID, rack);
+ return null;
+ }
+ }
+
+ private Map<String, List<Object>> sort(Map<String, List<Object>> map)
+ {
+ switch (sortBy)
+ {
+ case none:
+ return map;
+ case ip:
+ return sortInternal(map, SortBy.ip, 0, desc() != null ? desc()
: false); // default order is ascending
+ case load:
+ return sortInternal(map, SortBy.load, 3, desc() != null ?
desc() : true); // default order is descending
+ case id:
+ return sortInternal(map, SortBy.id, isTokenPerNode ? 5 : 6,
desc() != null ? desc() : false); // default order is ascending
+ case rack:
+ return sortInternal(map, SortBy.rack, 7, desc() != null ?
desc() : false); // default order is ascending
+ case owns:
+ return sortInternal(map, SortBy.owns, isTokenPerNode ? 4 : 5,
desc() != null ? desc() : true); // default order is descending
+ case status:
+ return sortInternal(map, SortBy.status, 1, desc() != null ?
desc() : true); // default order is descending
+ default:
+ throw new IllegalArgumentException("Sorting by " + sortBy + "
is not supported.");
}
}
+ private LinkedHashMap<String, List<Object>> sortInternal(Map<String,
List<Object>> data, SortBy sortBy, int index, boolean descending)
Review Comment:
@manish-m-pillai @bbotella One big if is totally fine here. I get that it is
in one comparator but ... so what? We have limited / clearly specified number
of things to compare on which are very likely not going to change. There is no
value in splitting that into individual methods.
--
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]