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/03 06:06:54 UTC

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

maoling 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_r299788112
 
 

 ##########
 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:
   Is there an JSON parse Exception???
   ```
   2019-07-03 13:58:49,968 [myid:3] - WARN  [qtp2134991632-28:JsonOutputter@59] - Exception writing command response to JSON:
   com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.apache.zookeeper.server.admin.Commands$VotingViewCommand$VotingView and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.LinkedHashMap["current_config"])
   	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
   	at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1191)
   	at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:313)
   	at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:71)
   	at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:33)
   	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:722)
   	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:643)
   	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33)
   	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
   	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
   	at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3905)
   	at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3201)
   	at org.apache.zookeeper.server.admin.JsonOutputter.output(JsonOutputter.java:54)
   	at org.apache.zookeeper.server.admin.JettyAdminServer$CommandServlet.doGet(JettyAdminServer.java:181)
   	at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
   	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
   	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:867)
   ```

----------------------------------------------------------------
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