Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add comparator for sorting ring configs by name; add in-mem ring conf…

…ig class; sort ring groups jsp by ring group name; enhance fixtures
  • Loading branch information...
commit 662a961c74a466fc3fc21de5ba161a1c7e7c2c28 1 parent 9f89a72
bryanduxbury authored
10 src/java/com/rapleaf/hank/coordinator/RingGroupConfigComparator.java
View
@@ -0,0 +1,10 @@
+package com.rapleaf.hank.coordinator;
+
+import java.util.Comparator;
+
+public class RingGroupConfigComparator implements Comparator<RingGroupConfig> {
+ @Override
+ public int compare(RingGroupConfig arg0, RingGroupConfig arg1) {
+ return arg0.getName().compareTo(arg1.getName());
+ }
+}
11 src/java/com/rapleaf/hank/ui/ring_groups.jsp
View
@@ -2,7 +2,16 @@
pageEncoding="ISO-8859-1"%>
<%@page import="com.rapleaf.hank.coordinator.*"%>
+<%@page import="java.util.*"%>
+<%!
+
+public List<RingGroupConfig> ringGroups(Coordinator coord) {
+ List<RingGroupConfig> rgcs = new ArrayList<RingGroupConfig>(coord.getRingGroups());
+ Collections.sort(rgcs, new RingGroupConfigComparator());
+ return rgcs;
+}
+%>
<%
Coordinator coord = (Coordinator)getServletContext().getAttribute("coordinator");
%>
@@ -28,7 +37,7 @@ Coordinator coord = (Coordinator)getServletContext().getAttribute("coordinator")
<td><strong>Status</strong></td>
</tr>
<%
- for (RingGroupConfig ringGroupConfig : coord.getRingGroups()) {
+ for (RingGroupConfig ringGroupConfig : ringGroups(coord)) {
%>
<tr>
<td><%= ringGroupConfig.getName() %></td>
115 test/java/com/rapleaf/hank/coordinator/in_memory/MemRingConfig.java
View
@@ -0,0 +1,115 @@
+package com.rapleaf.hank.coordinator.in_memory;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.commons.lang.NotImplementedException;
+
+import com.rapleaf.hank.coordinator.HostCommand;
+import com.rapleaf.hank.coordinator.HostConfig;
+import com.rapleaf.hank.coordinator.HostState;
+import com.rapleaf.hank.coordinator.PartDaemonAddress;
+import com.rapleaf.hank.coordinator.RingConfig;
+import com.rapleaf.hank.coordinator.RingGroupConfig;
+import com.rapleaf.hank.coordinator.RingState;
+import com.rapleaf.hank.coordinator.RingStateChangeListener;
+
+public class MemRingConfig implements RingConfig {
+
+ private final int ringNum;
+ private RingState state;
+ private Integer updatingToVersion;
+ private Integer versionNumber;
+
+ public MemRingConfig(int ringNum) {
+ this.ringNum = ringNum;
+ state = RingState.DOWN;
+ }
+
+ @Override
+ public HostConfig addHost(PartDaemonAddress address) throws IOException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void commandAll(HostCommand command) throws IOException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public HostConfig getHostConfigByAddress(PartDaemonAddress address) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Set<HostConfig> getHosts() {
+ return Collections.EMPTY_SET;
+ }
+
+ @Override
+ public Set<HostConfig> getHostsForDomainPartition(int domainId, int partition) throws IOException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Set<HostConfig> getHostsInState(HostState state) throws IOException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Integer getOldestVersionOnHosts() throws IOException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public RingGroupConfig getRingGroupConfig() {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public int getRingNumber() {
+ return ringNum;
+ }
+
+ @Override
+ public RingState getState() throws IOException {
+ return state;
+ }
+
+ @Override
+ public Integer getUpdatingToVersionNumber() {
+ return updatingToVersion;
+ }
+
+ @Override
+ public Integer getVersionNumber() {
+ return versionNumber;
+ }
+
+ @Override
+ public boolean isUpdatePending() {
+ return getUpdatingToVersionNumber() != null;
+ }
+
+ @Override
+ public void setState(RingState newState) throws IOException {
+ state = newState;
+ }
+
+ @Override
+ public void setStateChangeListener(RingStateChangeListener listener) throws IOException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void setUpdatingToVersion(int latestVersionNumber) throws IOException {
+ updatingToVersion = latestVersionNumber;
+ }
+
+ @Override
+ public void updateComplete() throws IOException {
+ versionNumber = updatingToVersion;
+ updatingToVersion = null;
+ }
+}
12 test/java/com/rapleaf/hank/coordinator/in_memory/MemRingGroupConfig.java
View
@@ -1,7 +1,9 @@
package com.rapleaf.hank.coordinator.in_memory;
import java.io.IOException;
-import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import com.rapleaf.hank.coordinator.DomainGroupConfig;
@@ -15,6 +17,7 @@
private final String ringGroupName;
private final MemDomainGroupConfig memDomainGroupConfig;
+ private Map<Integer, MemRingConfig> ringConfigs = new HashMap<Integer, MemRingConfig>();
public MemRingGroupConfig(String ringGroupName,
MemDomainGroupConfig memDomainGroupConfig)
@@ -25,8 +28,9 @@ public MemRingGroupConfig(String ringGroupName,
@Override
public RingConfig addRing(int ringNum) throws IOException {
- // TODO Auto-generated method stub
- return null;
+ MemRingConfig rc = new MemRingConfig(ringNum);
+ ringConfigs.put(ringNum, rc);
+ return rc;
}
@Override
@@ -65,7 +69,7 @@ public RingConfig getRingConfigForHost(PartDaemonAddress hostAddress) throws Dat
@Override
public Set<RingConfig> getRingConfigs() {
- return Collections.EMPTY_SET;
+ return new HashSet<RingConfig>(ringConfigs.values());
}
@Override
86 test/java/com/rapleaf/hank/ui/StatusWebDaemonTester.java
View
@@ -8,6 +8,7 @@
import com.rapleaf.hank.coordinator.Coordinator;
import com.rapleaf.hank.coordinator.DomainConfig;
import com.rapleaf.hank.coordinator.DomainGroupConfig;
+import com.rapleaf.hank.coordinator.RingConfig;
import com.rapleaf.hank.coordinator.RingGroupConfig;
import com.rapleaf.hank.coordinator.in_memory.InMemoryCoordinator;
import com.rapleaf.hank.partitioner.Murmur64Partitioner;
@@ -15,81 +16,6 @@
public class StatusWebDaemonTester extends TestCase {
public void testIt() throws Exception {
-// final DomainConfig domainConfig1 = new MockDomainConfig("Domain 1", 1024, new Murmur64Partitioner(), new ConstantStorageEngine(null), 10);
-// final DomainConfig domainConfig2 = new MockDomainConfig("Domain 2", 1024, new Murmur64Partitioner(), new ConstantStorageEngine(null), 10);
-// final DomainConfig domainConfig3 = new MockDomainConfig("Domain 3", 1024, new Murmur64Partitioner(), new ConstantStorageEngine(null), 10);
-//
-// final DomainGroupConfig domainGroup1 = new MockDomainGroupConfig("Domain Group 1") {
-// @Override
-// public SortedSet<DomainGroupConfigVersion> getVersions() {
-// HashSet<DomainConfigVersion> domainVersions1 = new HashSet<DomainConfigVersion>(Arrays.asList(
-// new MockDomainConfigVersion(domainConfig1, 5),
-// new MockDomainConfigVersion(domainConfig3, 7))
-// );
-// HashSet<DomainConfigVersion> domainVersions2 = new HashSet<DomainConfigVersion>(Arrays.asList(
-// new MockDomainConfigVersion(domainConfig1, 6),
-// new MockDomainConfigVersion(domainConfig3, 8))
-// );
-// return new TreeSet<DomainGroupConfigVersion>(Arrays.asList(
-// new MockDomainGroupConfigVersion(domainVersions1, this, 1),
-// new MockDomainGroupConfigVersion(domainVersions2, this, 2)
-// ));
-// }
-// };
-// final DomainGroupConfig domainGroup2 = new MockDomainGroupConfig("Domain Group 2") {
-// @Override
-// public SortedSet<DomainGroupConfigVersion> getVersions() {
-// return new TreeSet<DomainGroupConfigVersion>();
-// }
-// };
-//
-// final RingConfig ring1_1 = new MockRingConfig(null, null, 1, RingState.UP) {
-// @Override
-// public Set<HostConfig> getHosts() {
-// return new HashSet<HostConfig>(Arrays.asList(
-// new MockHostConfig(new PartDaemonAddress("h1r1g1.rapleaf.com", 6200)),
-// new MockHostConfig(new PartDaemonAddress("h2r1g1.rapleaf.com", 6200))
-// ));
-// }
-// };
-// final RingConfig ring1_2 = new MockRingConfig(null, null, 2, RingState.UP) {
-// @Override
-// public Set<HostConfig> getHosts() {
-// return new HashSet<HostConfig>(Arrays.asList(
-// new MockHostConfig(new PartDaemonAddress("h1r2g1.rapleaf.com", 6200)),
-// new MockHostConfig(new PartDaemonAddress("h2r2g1.rapleaf.com", 6200))
-// ));
-// }
-// };
-// final RingGroupConfig ringGroup1 = new MockRingGroupConfig(domainGroup1, "Ring Group 1", null) {
-// @Override
-// public Set<RingConfig> getRingConfigs() {
-// return new HashSet<RingConfig>(Arrays.asList(ring1_1, ring1_2));
-// }
-// };
-// final RingGroupConfig ringGroup2 = new MockRingGroupConfig(domainGroup2, "Ring Group 2", null) {
-// @Override
-// public Set<RingConfig> getRingConfigs() {
-// return Collections.EMPTY_SET;
-// }
-// };
-//
-// final Coordinator coord = new MockCoordinator() {
-// @Override
-// public Set<DomainConfig> getDomainConfigs() {
-// return new HashSet<DomainConfig>(Arrays.asList(domainConfig1, domainConfig2, domainConfig3));
-// }
-//
-// @Override
-// public Set<DomainGroupConfig> getDomainGroupConfigs() {
-// return new HashSet<DomainGroupConfig>(Arrays.asList(domainGroup1, domainGroup2));
-// }
-//
-// @Override
-// public Set<RingGroupConfig> getRingGroups() {
-// return new HashSet<RingGroupConfig>(Arrays.asList(ringGroup1, ringGroup2));
-// }
-// };
final Coordinator coord = new InMemoryCoordinator();
final DomainConfig d0 = coord.addDomain("domain0", 1024, Curly.Factory.class.getName(), "---", Murmur64Partitioner.class.getName(), 1);
@@ -109,11 +35,19 @@ public void testIt() throws Exception {
g2.addDomain(d1, 0);
RingGroupConfig rgAlpha = coord.addRingGroup("RG_Alpha", g1.getName());
+ RingConfig r1 = rgAlpha.addRing(1);
+ RingConfig r2 = rgAlpha.addRing(2);
+ RingConfig r3 = rgAlpha.addRing(3);
RingGroupConfig rgBeta = coord.addRingGroup("RG_Beta", g1.getName());
+ r1 = rgBeta.addRing(1);
+ r2 = rgBeta.addRing(2);
+ r3 = rgBeta.addRing(3);
+ RingConfig r4 = rgBeta.addRing(4);
RingGroupConfig rgGamma = coord.addRingGroup("RG_Gamma", g2.getName());
-
+ r1 = rgGamma.addRing(1);
+
ClientConfigurator mockConf = new ClientConfigurator(){
@Override
public Coordinator getCoordinator() {
Please sign in to comment.
Something went wrong with that request. Please try again.