@Override public int compareTo(Ring other) { return Integer.valueOf(ringNumber).compareTo(other.getRingNumber()); }
public MockRingGroup(DomainGroup dcg, String name, Set<Ring> ringConfigs) { super(name); this.dcg = dcg; this.ringConfigs = Maps.newHashMap(); for (Ring ringConfig : ringConfigs) { this.ringConfigs.put(ringConfig.getRingNumber(), ringConfig); } }
private int getNextRingNum(RingGroup group) { return group.getRings() .stream() .map(ring -> ring.getRingNumber()) .max(Comparator.naturalOrder()) .orElse(-1) + 1; }
protected void doDeleteHost(HttpServletRequest req, HttpServletResponse resp) throws IOException { RingGroup ringGroup = coordinator.getRingGroup(req.getParameter("g")); Ring ring = ringGroup.getRing(Integer.parseInt(req.getParameter("n"))); ring.removeHost(PartitionServerAddress.parse(URLEnc.decode(req.getParameter("h")))); resp.sendRedirect(String.format("/ring.jsp?g=%s&n=%d", ringGroup.getName(), ring.getRingNumber())); }
private void doAddRing(HttpServletRequest req, HttpServletResponse resp) throws IOException { RingGroup ringGroup; String encodedRingGroupName = req.getParameter("g"); ringGroup = coordinator.getRingGroup(URLEnc.decode(encodedRingGroupName)); if (ringGroup == null) { throw new IOException("couldn't find any ring group called " + URLEnc.decode(encodedRingGroupName)); } // Find new ring ID (largest ID + 1) int newRingID = 0; for (Ring ring : ringGroup.getRings()) { if (ring.getRingNumber() >= newRingID) { newRingID = ring.getRingNumber() + 1; } } ringGroup.addRing(newRingID); resp.sendRedirect("/ring_group.jsp?name=" + encodedRingGroupName); }
private void removeHost(Ring ring, Host host) throws IOException { // put to idle host.clearCommandQueue(); Hosts.enqueueCommandIfNotPresent(host, HostCommand.GO_TO_IDLE); // sleep for a few seconds try { Thread.sleep(5000); } catch (InterruptedException e) { LOG.error("Interrupted waiting for host to idle", e); } PartitionServerAddress address = host.getAddress(); ring.removeHost(address); LOG.info("Removed host " + address + " from ring " + ring.getRingNumber()); }
private void redirectBack(HttpServletResponse resp, RingGroup rgc, Ring rc, Host hc) throws IOException { resp.sendRedirect(String.format("/host.jsp?g=%s&r=%s&h=%s", rgc.getName(), rc.getRingNumber(), URLEnc.encode(hc.getAddress().toString()))); }
protected RingData getRingData(Ring ring) throws IOException { RingData data = new RingData(); data.ringNumber = ring.getRingNumber(); Map<String, HostData> hostMap = new HashMap<String, HostData>(); for (Host host : ring.getHosts()) { hostMap.put(host.getAddress().toString(), getHostData(host)); } data.hostsMap = hostMap; return data; }
public static String formatHostListTooltip(Ring ring, Set<Host> hosts) throws IOException { return formatHostListTooltip(ring.getRingGroup().getName() + " ring " + ring.getRingNumber(), hosts); }
private void addHost(Ring ring, ConnectedServerMetadata server) throws IOException { Host host = ring.addHost( new PartitionServerAddress(server.get_host(), server.get_port_number()), Lists.newArrayList() // TODO should these be associated with host config? ); host.setEnvironmentFlags(server.get_environment_flags()); LOG.info("\tadded host " + host + " to ring " + ring.getRingNumber()); } }
private void doUpdate(HttpServletRequest req, HttpServletResponse resp) throws IOException { RingGroup rg = coordinator.getRingGroup(req.getParameter("g")); Ring r = rg.getRing(Integer.parseInt(req.getParameter("n"))); Host h = r.getHostByAddress(PartitionServerAddress.parse(URLEnc.decode(req.getParameter("h")))); h.setFlags(Hosts.splitHostFlags(req.getParameter("hostFlags"))); PartitionServerAddress address = PartitionServerAddress.parse(req.getParameter("hostAddress")); if (!h.getAddress().equals(address)) { h.setAddress(address); // Redirect to Ring (host address has changed) resp.sendRedirect("/ring.jsp?g=" + rg.getName() + "&n=" + r.getRingNumber()); } else { redirectBack(resp, rg, r, h); } }
public static String getHostUrl(RingGroup ringGroup, Ring ring, Host host) { return "host.jsp?g=" + URLEnc.encode(ringGroup.getName()) + "&r=" + ring.getRingNumber() + "&h=" + URLEnc.encode(host.getAddress().toString()); } }
+ " in ring group " + ringGroup.getName() + " ring " + ring.getRingNumber());
protected RingGroupData getRingGroupData(RingGroup ringGroup) throws IOException { RingGroupData data = new RingGroupData(); data.name = ringGroup.getName(); data.isRingGroupConductorOnline = ringGroup.isRingGroupConductorOnline(); data.ringGroupConductorMode = ringGroup.getRingGroupConductorMode(); data.domainGroupName = ringGroup.getDomainGroup().getName(); ServingStatus servingStatus = RingGroups.computeServingStatusAggregator(ringGroup, ringGroup.getDomainGroup()).computeServingStatus(); data.numPartitions = servingStatus.getNumPartitions(); data.numPartitionsServedAndUpToDate = servingStatus.getNumPartitionsServedAndUpToDate(); Map<Integer, RingData> ringsMap = new HashMap<Integer, RingData>(); for (Ring ring : ringGroup.getRings()) { ringsMap.put(ring.getRingNumber(), getRingData(ring)); } data.ringsMap = ringsMap; data.clients = Maps.newHashMap(); for (ClientMetadata clientData : ringGroup.getClients()) { data.clients.put(clientData.get_host(), new ConnectedHostData( clientData.get_host(), Long.toString(clientData.get_connected_at()), clientData.get_type(), clientData.get_version() )); } return data; }
@Test public void testLoad() throws Exception { create(ring_group, ZkPath.append(dg_root, "myDomainGroup")); createRing(1); createRing(2); createRing(3); MockDomainGroup dg = new MockDomainGroup("myDomainGroup"); ZkRingGroup rg = new ZkRingGroup(getZk(), ring_group, dg, coordinator); assertEquals("ring group name", "myRingGroup", rg.getName()); assertEquals("num rings", 3, rg.getRings().size()); assertEquals("domain group config", dg, rg.getDomainGroup()); assertEquals("ring group for localhost:2", 2, rg.getRingForHost(new PartitionServerAddress("localhost", 2)).getRingNumber()); assertEquals("ring group by number", 3, rg.getRing(3).getRingNumber()); }