Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 098B1D676 for ; Sun, 11 Nov 2012 05:05:03 +0000 (UTC) Received: (qmail 62026 invoked by uid 500); 11 Nov 2012 05:05:01 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 61915 invoked by uid 500); 11 Nov 2012 05:04:58 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 61837 invoked by uid 99); 11 Nov 2012 05:04:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Nov 2012 05:04:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Nov 2012 05:04:53 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A4C6223888EA for ; Sun, 11 Nov 2012 05:04:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Sun, 11 Nov 2012 05:04:33 -0000 To: commits@accumulo.apache.org From: elserj@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121111050433.A4C6223888EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 { 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 status = Collections.emptyList(); + private static SortedSet status = new TreeSet(); public static Collection getZooKeeperStatus() { return status; @@ -63,7 +83,7 @@ public class ZooKeeperStatus implements while (!stop) { - List update = new ArrayList(); + TreeSet update = new TreeSet(); 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 expectedHosts = Arrays.asList("rack1node1", "rack2node1", "rack4node1", "rack4node4"); + + // Add the states in a not correctly sorted order + TreeSet states = new TreeSet(); + 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 actualHosts = new ArrayList(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)); + } + + } + +}