private void doCommandAll(HttpServletRequest req, HttpServletResponse resp) throws IOException { String rgName = req.getParameter("rgName"); int ringNum = Integer.parseInt(req.getParameter("ringNum")); HostCommand command = HostCommand.valueOf(req.getParameter("command")); Rings.commandAll(coordinator.getRingGroup(rgName).getRing(ringNum), command); resp.sendRedirect("/ring.jsp?g=" + rgName + "&n=" + ringNum); } }
public static Set<Host> getHostsInState(RingGroup ringGroup, HostState state) throws IOException { Set<Host> result = new TreeSet<Host>(); for (Ring ring : ringGroup.getRings()) { result.addAll(Rings.getHostsInState(ring, state)); } return result; }
public static Map<Ring, Map<Host, Map<String, FilesystemStatisticsAggregator>>> computeFilesystemStatistics(RingGroup ringGroup) throws IOException { Map<Ring, Map<Host, Map<String, FilesystemStatisticsAggregator>>> result = new HashMap<Ring, Map<Host, Map<String, FilesystemStatisticsAggregator>>>(); for (Ring ring : ringGroup.getRings()) { result.put(ring, Rings.computeFilesystemStatistics(ring)); } return result; }
public static boolean isUpToDate(RingGroup ringGroup, DomainGroup domainGroup, Domain domain) throws IOException { for (Ring ring : ringGroup.getRings()) { if (!Rings.isUpToDate(ring, domainGroup, domain)) { return false; } } return true; }
public static Map<Ring, Map<Host, Map<Domain, RuntimeStatisticsAggregator>>> computeRuntimeStatistics(Coordinator coordinator, RingGroup ringGroup) throws IOException { Map<Ring, Map<Host, Map<Domain, RuntimeStatisticsAggregator>>> result = new HashMap<Ring, Map<Host, Map<Domain, RuntimeStatisticsAggregator>>>(); for (Ring ring : ringGroup.getRings()) { result.put(ring, Rings.computeRuntimeStatistics(coordinator, ring)); } return result; }
public static RuntimeStatisticsAggregator computeRuntimeStatisticsForRing( Map<Ring, Map<Host, Map<Domain, RuntimeStatisticsAggregator>>> runtimeStatistics, Ring ring) { if (runtimeStatistics.containsKey(ring)) { return Rings.computeRuntimeStatisticsForRing(runtimeStatistics.get(ring)); } else { return new RuntimeStatisticsAggregator(); } }
public static FilesystemStatisticsAggregator computeFilesystemStatisticsForRing( Map<Ring, Map<Host, Map<String, FilesystemStatisticsAggregator>>> filesystemStatistics, Ring ring) { if (filesystemStatistics.containsKey(ring)) { return Rings.computeFilesystemStatisticsForRing(filesystemStatistics.get(ring)); } else { return new FilesystemStatisticsAggregator(); } }
public static ServingStatusAggregator computeServingStatusAggregator(RingGroup ringGroup, DomainGroup domainGroup) throws IOException { ServingStatusAggregator servingStatusAggregator = new ServingStatusAggregator(); for (Ring ring : ringGroup.getRings()) { servingStatusAggregator.aggregate(Rings.computeServingStatusAggregator(ring, domainGroup)); } return servingStatusAggregator; }
public static UpdateProgressAggregator computeUpdateProgress(RingGroup ringGroup, DomainGroup domainGroup) throws IOException { UpdateProgressAggregator result = new UpdateProgressAggregator(); for (Ring ring : ringGroup.getRings()) { result.aggregate(Rings.computeUpdateProgress(ring, domainGroup)); } return result; }
@Test public void testGetHostsForDomainPartition() throws Exception { final Domain d0 = new MockDomain("d0"); final Host hc = new MockHost(LOCALHOST) { HostDomain hd1 = new MockHostDomain(d0, 1, 1, 2, 2); HostDomain hd2 = new MockHostDomain(null, 1, 2, 2, 2); @Override public Set<HostDomain> getAssignedDomains() throws IOException { return new HashSet<HostDomain>(Arrays.asList(hd1, hd2)); } @Override public HostDomain getHostDomain(Domain domain) { return hd1; } }; SlightlyLessAbstractRing ring = new SlightlyLessAbstractRing(1, null) { @Override public Set<Host> getHosts() { return Collections.singleton(hc); } }; assertEquals(Collections.singleton(hc), Rings.getHostsForDomainPartition(ring, d0, 1)); assertEquals(Collections.singleton(hc), Rings.getHostsForDomainPartition(ring, d0, 2)); assertEquals(Collections.EMPTY_SET, Rings.getHostsForDomainPartition(ring, d0, 3)); }
public static boolean isUpToDate(RingGroup ringGroup, DomainGroup domainGroup) throws IOException { for (Ring ring : ringGroup.getRings()) { if (!Rings.isUpToDate(ring, domainGroup)) { return false; } } return true; }
@Test public void testGetHostsInState() throws Exception { final MockHost h1 = new MockHost(new PartitionServerAddress("localhost", 1)); final MockHost h2 = new MockHost(new PartitionServerAddress("localhost", 2)); final MockHost h3 = new MockHost(new PartitionServerAddress("localhost", 3)); SlightlyLessAbstractRing rc = new SlightlyLessAbstractRing(1, null) { @Override public Set<Host> getHosts() { return new HashSet<Host>(Arrays.asList(h1, h2, h3)); } }; h1.setState(HostState.IDLE); h2.setState(HostState.SERVING); h3.setState(HostState.OFFLINE); assertEquals(Collections.singleton(h1), Rings.getHostsInState(rc, HostState.IDLE)); assertEquals(Collections.singleton(h2), Rings.getHostsInState(rc, HostState.SERVING)); assertEquals(Collections.singleton(h3), Rings.getHostsInState(rc, HostState.OFFLINE)); } }
@Test public void testCommandAll() throws IOException { final Host hc = new MockHost(LOCALHOST); SlightlyLessAbstractRing rc = new SlightlyLessAbstractRing(1, null) { @Override public Set<Host> getHosts() { return Collections.singleton(hc); } }; assertNull(hc.getCurrentCommand()); assertTrue(hc.getCommandQueue().isEmpty()); Rings.commandAll(rc, HostCommand.SERVE_DATA); assertNull(hc.getCurrentCommand()); assertEquals(Arrays.asList(HostCommand.SERVE_DATA), hc.getCommandQueue()); }