You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2019/07/05 22:28:43 UTC

[GitHub] [zookeeper] eolivelli commented on a change in pull request #940: ZOOKEEPER-3386: Add admin command to display voting view

eolivelli commented on a change in pull request #940: ZOOKEEPER-3386: Add admin command to display voting view
URL: https://github.com/apache/zookeeper/pull/940#discussion_r300806012
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/Commands.java
 ##########
 @@ -607,12 +609,40 @@ public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs)
             CommandResponse response = initializeResponse();
             if (zkServer instanceof QuorumZooKeeperServer) {
                 QuorumPeer peer = ((QuorumZooKeeperServer) zkServer).self;
-                response.put("current_config", peer.getVotingView());
+                VotingView votingView = new VotingView(peer.getVotingView());
+                response.put("current_config", votingView);
             } else {
                 response.put("current_config", "");
             }
             return response;
         }
+
+
+        private static class VotingView {
+            final String stringRepresentation;
+
+            VotingView(Map<Long,QuorumPeer.QuorumServer> view) {
+                this.stringRepresentation = view.entrySet().stream()
+                        .sorted(Comparator.comparingLong(Map.Entry::getKey))
+                        .filter(e -> e.getValue().addr != null)
+                        .map(e -> String.format("%s=%s:%d%s:%s%s",
+                                e.getKey().toString(),
+                                QuorumPeer.QuorumServer.delimitedHostString(e.getValue().addr),
+                                e.getValue().addr.getPort(),
+                                e.getValue().electionAddr == null ? "" : ":" + e.getValue().electionAddr.getPort(),
+                                e.getValue().type.equals(QuorumPeer.LearnerType.PARTICIPANT) ? "participant" : "observer",
+                                e.getValue().clientAddr ==null || e.getValue().isClientAddrFromStatic ? "" :
+                                        String.format(";%s:%d",
+                                                QuorumPeer.QuorumServer.delimitedHostString(e.getValue().clientAddr),
+                                                e.getValue().clientAddr.getPort())))
+                        .collect(Collectors.joining(", "));
+            }
+
+            @Override
+            public String toString() {
+                return "{" + stringRepresentation + "}";
+            }
+        }
     }
 
 
 Review comment:
   It is not a parse error but a serialization error, Jackson is not able to serialize a VotingView, I guess because it does not have any getter.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services