/** * Return true if all partitions assigned to that host for domains of the given domain group * version are at the correct version. And there are no deletable partitions. * * @param host * @param domainGroupVersion * @return * @throws IOException */ public static boolean isUpToDate(Host host, DomainGroupVersion domainGroupVersion) throws IOException { if (domainGroupVersion == null || domainGroupVersion.getDomainVersions() == null) { return false; } // Check that each domain of the given domain group version is up to date on this host for (DomainGroupVersionDomainVersion dgvdv : domainGroupVersion.getDomainVersions()) { Domain domain = dgvdv.getDomain(); HostDomain hostDomain = host.getHostDomain(domain); if (hostDomain != null) { for (HostDomainPartition partition : hostDomain.getPartitions()) { // Ignore deletable partitions if (!partition.isDeletable()) { // If the partition is not currently at the given domain group version, the host is not // up-to-date if (partition.getCurrentDomainGroupVersion() == null || partition.getCurrentDomainGroupVersion() != domainGroupVersion.getVersionNumber()) { return false; } } } } } // Check if there is any deletable partition for (HostDomain hostDomain : host.getAssignedDomains()) { for (HostDomainPartition partition : hostDomain.getPartitions()) { if (partition.isDeletable()) { return false; } } } return true; }
public static ServingStatusAggregator computeServingStatusAggregator( Host host, DomainGroupVersion domainGroupVersion) throws IOException { ServingStatusAggregator result = new ServingStatusAggregator(); for (HostDomain hostDomain : host.getAssignedDomains()) { for (HostDomainPartition partition : hostDomain.getPartitions()) { // Ignore deletable partitions if (!partition.isDeletable()) { // Check if partition is served and up to date boolean servedAndUpToDate = host.getState() == HostState.SERVING && partition.getCurrentDomainGroupVersion() != null && partition .getCurrentDomainGroupVersion() .equals(domainGroupVersion.getVersionNumber()); // Aggregate counts result.add(hostDomain.getDomain(), partition.getPartitionNumber(), servedAndUpToDate); } } } return result; }
public static UpdateProgress computeUpdateProgress( Host host, DomainGroupVersion domainGroupVersion) throws IOException { int numPartitions = 0; int numPartitionsUpToDate = 0; for (DomainGroupVersionDomainVersion dgvdv : domainGroupVersion.getDomainVersions()) { Domain domain = dgvdv.getDomain(); HostDomain hostDomain = host.getHostDomain(domain); if (hostDomain != null) { for (HostDomainPartition partition : hostDomain.getPartitions()) { // Ignore deletable partitions if (!partition.isDeletable()) { ++numPartitions; if (partition.getCurrentDomainGroupVersion() != null && partition .getCurrentDomainGroupVersion() .equals(domainGroupVersion.getVersionNumber())) { ++numPartitionsUpToDate; } } } } } return new UpdateProgress(numPartitions, numPartitionsUpToDate); }
/** * Returns true when the host is online. Note that this is distinct from "serving data" - a host * is online when it's NOT offline. * * @param host * @return * @throws IOException */ public static boolean isOnline(Host host) throws IOException { return host.getState() != HostState.OFFLINE; }
public static void enqueueCommandIfNotPresent(Host host, HostCommand command) throws IOException { if (host.getCurrentCommand() != command && !host.getCommandQueue().contains(command)) { host.enqueueCommand(command); } }