You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2012/11/11 06:04:33 UTC
svn commit: r1407918 - in /accumulo/trunk/server/src:
main/java/org/apache/accumulo/server/monitor/ZooKeeperStatus.java
test/java/org/apache/accumulo/server/monitor/
test/java/org/apache/accumulo/server/monitor/ZooKeeperStatusTest.java
Author: elserj
Date: Sun Nov 11 05:04:32 2012
New Revision: 1407918
URL: http://svn.apache.org/viewvc?rev=1407918&view=rev
Log:
ACCUMULO-849 Sort the table of ZooKeeper hosts on the monitor page.
- Make ZooKeeperStatus Comparable, based on hostname
- Instead of using the order specified in accumulo-site.xml, use an ordered structure to easily sort on hostname
Added:
accumulo/trunk/server/src/test/java/org/apache/accumulo/server/monitor/
accumulo/trunk/server/src/test/java/org/apache/accumulo/server/monitor/ZooKeeperStatusTest.java
Modified:
accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/ZooKeeperStatus.java
Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/ZooKeeperStatus.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/ZooKeeperStatus.java?rev=1407918&r1=1407917&r2=1407918&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/ZooKeeperStatus.java (original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/ZooKeeperStatus.java Sun Nov 11 05:04:32 2012
@@ -19,8 +19,9 @@ package org.apache.accumulo.server.monit
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.util.TTimeoutTransport;
@@ -36,7 +37,7 @@ public class ZooKeeperStatus implements
private volatile boolean stop = false;
- public static class ZooKeeperState {
+ public static class ZooKeeperState implements Comparable<ZooKeeperState> {
public final String keeper;
public final String mode;
public final int clients;
@@ -46,9 +47,28 @@ public class ZooKeeperStatus implements
this.mode = mode;
this.clients = clients;
}
+
+ @Override
+ public int compareTo(ZooKeeperState other) {
+ if (this == other) {
+ return 0;
+ } else if (other == null) {
+ return 1;
+ } else {
+ if (this.keeper == other.keeper) {
+ return 0;
+ } else if (null == this.keeper) {
+ return -1;
+ } else if (null == other.keeper) {
+ return 1;
+ } else {
+ return this.keeper.compareTo(other.keeper);
+ }
+ }
+ }
}
- private static Collection<ZooKeeperState> status = Collections.emptyList();
+ private static SortedSet<ZooKeeperState> status = new TreeSet<ZooKeeperState>();
public static Collection<ZooKeeperState> getZooKeeperStatus() {
return status;
@@ -63,7 +83,7 @@ public class ZooKeeperStatus implements
while (!stop) {
- List<ZooKeeperState> update = new ArrayList<ZooKeeperState>();
+ TreeSet<ZooKeeperState> update = new TreeSet<ZooKeeperState>();
String zookeepers[] = ServerConfiguration.getSiteConfiguration().get(Property.INSTANCE_ZK_HOST).split(",");
for (String keeper : zookeepers) {
Added: accumulo/trunk/server/src/test/java/org/apache/accumulo/server/monitor/ZooKeeperStatusTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/test/java/org/apache/accumulo/server/monitor/ZooKeeperStatusTest.java?rev=1407918&view=auto
==============================================================================
--- accumulo/trunk/server/src/test/java/org/apache/accumulo/server/monitor/ZooKeeperStatusTest.java (added)
+++ accumulo/trunk/server/src/test/java/org/apache/accumulo/server/monitor/ZooKeeperStatusTest.java Sun Nov 11 05:04:32 2012
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.server.monitor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.TreeSet;
+
+import org.apache.accumulo.server.monitor.ZooKeeperStatus.ZooKeeperState;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ZooKeeperStatusTest {
+
+ @Test
+ public void zkHostSortingTest() {
+ List<String> expectedHosts = Arrays.asList("rack1node1", "rack2node1", "rack4node1", "rack4node4");
+
+ // Add the states in a not correctly sorted order
+ TreeSet<ZooKeeperState> states = new TreeSet<ZooKeeperState>();
+ states.add(new ZooKeeperState("rack4node4", "leader", 10));
+ states.add(new ZooKeeperState("rack4node1", "follower", 10));
+ states.add(new ZooKeeperState("rack1node1", "follower", 10));
+ states.add(new ZooKeeperState("rack2node1", "follower", 10));
+
+ List<String> actualHosts = new ArrayList<String>(4);
+ for (ZooKeeperState state : states) {
+ actualHosts.add(state.keeper);
+ }
+
+ // Assert we have 4 of each
+ Assert.assertEquals(expectedHosts.size(), actualHosts.size());
+
+ // Assert the ordering is correct
+ for (int i = 0; i < expectedHosts.size(); i++) {
+ Assert.assertEquals(expectedHosts.get(i), actualHosts.get(i));
+ }
+
+ }
+
+}