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()); } }
@Override public Ring getRingForHost(PartitionServerAddress hostAddress) { for (Ring ring : rings.values()) { if (ring.getHostByAddress(hostAddress) != null) { return ring; } } return null; }
private boolean hasEnoughHosts(Ring ring) { return ring.getHosts().size() >= targetHostsPerRing; }
public static String formatHostListTooltip(Ring ring, Set<Host> hosts) throws IOException { return formatHostListTooltip(ring.getRingGroup().getName() + " ring " + ring.getRingNumber(), hosts); }
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()); }
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 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 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); } }
Host host = rg.getRing(1).addHost(address, Collections.emptyList()); WaitUntil.orDie(() -> dataLocationChangeListener.isCalled); assertTrue(dataLocationChangeListener.isCalled()); dataLocationChangeListener.clear(); rg.getRing(1).getHostByAddress(address).setState(HostState.SERVING); WaitUntil.orDie(() -> dataLocationChangeListener.isCalled); assertTrue(dataLocationChangeListener.isCalled());
private void doAddHost(HttpServletRequest req, HttpServletResponse resp) throws IOException { String rgName = req.getParameter("rgName"); int ringNum = Integer.parseInt(req.getParameter("ringNum")); String hostname = req.getParameter("hostname").trim(); int portNum = Integer.parseInt(req.getParameter("port")); String flagsStr = req.getParameter("hostFlags"); coordinator.getRingGroup(rgName).getRing(ringNum).addHost( new PartitionServerAddress(hostname, portNum), Hosts.splitHostFlags(flagsStr)); resp.sendRedirect("/ring.jsp?g=" + rgName + "&n=" + ringNum); }
DomainGroup domainGroup = ring.getRingGroup().getDomainGroup(); if (domainGroup == null) { throw new IOException(String.format("Could not get DomainGroup of Ring %s", ring)); host = ring.getHostByAddress(address); if (host == null) { throw new IOException(String.format("Could not get Host at address %s of Ring %s", address, ring));
for (Host host : ring.getHostsSorted()) {
@Override public int compareTo(Ring other) { return Integer.valueOf(ringNumber).compareTo(other.getRingNumber()); }
LOG.info("Found ring for host: "+ring); host = ring.getHostByAddress(hostAddress); + " in ring group " + ringGroup.getName() + " ring " + ring.getRingNumber());
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())); }
r1.addHost(addy("alpha-1-1"), Collections.<String>emptyList()); r1.addHost(addy("alpha-1-2"), Collections.<String>emptyList()); r1.addHost(addy("alpha-1-3"), Collections.<String>emptyList()); Ring r2 = rg0.addRing(2); r2.addHost(addy("alpha-2-1"), Collections.<String>emptyList()); r2.addHost(addy("alpha-2-2"), Collections.<String>emptyList()); r2.addHost(addy("alpha-2-3"), Collections.<String>emptyList()); Ring r3 = rg0.addRing(3); r3.addHost(addy("alpha-3-1"), Collections.<String>emptyList()); r3.addHost(addy("alpha-3-2"), Collections.<String>emptyList()); r3.addHost(addy("alpha-3-3"), Collections.<String>emptyList()); for (int i = 0; i < 16; ++i) { rg0.registerClient(new ClientMetadata( r1.addHost(addy("beta-1-1"), Collections.<String>emptyList()); r1.addHost(addy("beta-1-2"), Collections.<String>emptyList()); r1.addHost(addy("beta-1-3"), Collections.<String>emptyList()); r1.addHost(addy("beta-1-4"), Collections.<String>emptyList()); r2 = rg1.addRing(2); r2.addHost(addy("beta-2-1"), Collections.<String>emptyList()); r2.addHost(addy("beta-2-2"), Collections.<String>emptyList()); r2.addHost(addy("beta-2-3"), Collections.<String>emptyList()); r2.addHost(addy("beta-2-4"), Collections.<String>emptyList()); r3 = rg1.addRing(3); r3.addHost(addy("beta-3-1"), Collections.<String>emptyList()); r3.addHost(addy("beta-3-2"), Collections.<String>emptyList()); r3.addHost(addy("beta-3-3"), Collections.<String>emptyList()); r3.addHost(addy("beta-3-4"), Collections.<String>emptyList()); Ring r4 = rg1.addRing(4);
@Override public void manageTransitions(Coordinator coordinator, RingGroup ringGroup) throws IOException { DomainGroup domainGroup = ringGroup.getDomainGroup(); if (domainGroup == null) { // Nothing to do LOG.info("Domain group not found. Nothing to do."); return; } Map<Domain, Map<Integer, Set<Host>>> domainToPartitionToHostsFullyServing = PartitionUtils.domainToPartitionToHostsServing(ringGroup, status); ThreeNestedMap<Domain, Integer, String, Long> domainPartitionBucketHostCounts = PartitionUtils.domainToPartitionToHostsServingInBucket(domainToPartitionToHostsFullyServing, status); SortedSet<Ring> rings = ringGroup.getRingsSorted(); int ringCount = rings.size(); for (Ring ring : rings) { partitionAssigner.prepare(ring, domainGroup.getDomainVersions(), ringGroup.getRingGroupConductorMode()); for (Host host : ring.getHostsSorted()) { manageTransitions(ringCount, host, domainGroup, domainToPartitionToHostsFullyServing, domainPartitionBucketHostCounts); } } }
public static long computeUpdateETA(Ring ring) { long maxUpdateETA = -1; for (Host host : ring.getHosts()) { long hostUpdateETA = Hosts.computeUpdateETA(host); if (hostUpdateETA > maxUpdateETA) { maxUpdateETA = hostUpdateETA; } } return maxUpdateETA; } }
private int getNextRingNum(RingGroup group) { return group.getRings() .stream() .map(ring -> ring.getRingNumber()) .max(Comparator.naturalOrder()) .orElse(-1) + 1; }
protected void doClearCommandQueue(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.clearCommandQueue(); redirectBack(resp, rg, r, h); }