@Override public String toString() { return getDomain().getName() + "@v" + getVersionNumber(); }
@Override public void removeDomain(Domain domain) throws IOException { domainVersions.remove(new DomainAndVersion(domain, -1)); }
@Override public Set<Domain> getDomains() throws IOException { Set<Domain> result = new TreeSet<Domain>(); for (DomainAndVersion dgdv : getDomainVersions()) { result.add(dgdv.getDomain()); } return result; }
public static boolean isCurrentlyServed(Domain domain, DomainVersion domainVersion, Coordinator coord) throws IOException { for (DomainGroup domainGroup : coord.getDomainGroups()) { DomainAndVersion version = domainGroup.getDomainVersion(domain); if (version != null) { if (version.getVersionNumber() == domainVersion.getVersionNumber()) { return true; } } } return false; }
@Override public void prepare(Ring ring, Set<DomainAndVersion> domainVersions, RingGroupConductorMode ringGroupConductorMode) throws IOException { this.domainVersions = domainVersions; this.ringGroupConductorMode = ringGroupConductorMode; this.hostToDomainToPartitionsMappings = getHostToDomainToPartitionsMapping(ring, domainVersions); domains = new HashSet<Domain>(); for (DomainAndVersion domainVersion : domainVersions) { domains.add(domainVersion.getDomain()); } }
private DomainDeployStatusForRingGroup getDomainDeployStatusForRingGroup(DomainGroup domainGroup, Domain domain, RingGroup ringGroup) throws IOException { DomainDeployStatusForRingGroup status = new DomainDeployStatusForRingGroup(); status.ringGroupName = ringGroup.getName(); if (domainGroup != null) { status.targetDomainVersion = domainGroup.getDomainVersion(domain) == null ? null : domainGroup.getDomainVersion(domain).getVersionNumber(); } ServingStatus servingStatus = RingGroups.computeServingStatusAggregator(ringGroup, domainGroup).computeServingStatus(); status.numPartitions = servingStatus.getNumPartitions(); status.numPartitionsServedAndUpToDate = servingStatus.getNumPartitionsServedAndUpToDate(); return status; }
protected DomainGroupData getDomainGroupData(DomainGroup domainGroup) throws IOException { DomainGroupData data = new DomainGroupData(); data.name = domainGroup.getName(); Map<String, Integer> versionsMap = new HashMap<String, Integer>(); for (DomainAndVersion v : domainGroup.getDomainVersions()) { versionsMap.put(v.getDomain().getName(), v.getVersionNumber()); } data.domainVersions = versionsMap; return data; }
domain.getVersion(targetDomainAndVersion.getVersionNumber());
@Override public void setDomainVersions(Map<Domain, Integer> domainVersions) throws IOException { this.domainVersions.clear(); for (Map.Entry<Domain, Integer> entry : domainVersions.entrySet()) { this.domainVersions.add(new DomainAndVersion(entry.getKey(), entry.getValue())); } notifyListeners(); }
@Override public String toString() { StringBuilder domainVersionsString = new StringBuilder(); domainVersionsString.append('['); try { if (getDomainVersions() != null) { for (DomainAndVersion dgvdv : getDomainVersionsSorted()) { domainVersionsString.append(dgvdv.getDomain() != null ? dgvdv.getDomain().getName() : "null"); domainVersionsString.append('@'); domainVersionsString.append(dgvdv.getVersionNumber()); domainVersionsString.append(", "); } } } catch (IOException e) { throw new RuntimeException(e); } domainVersionsString.append(']'); return "AbstractDomainGroup [name=" + getName() + ", domainVersions=" + domainVersionsString.toString() + "]"; } }
@Override public DomainAndVersion getDomainVersion(Domain domain) throws IOException { if (domain == null || domain.getName() == null) { return null; } for (DomainAndVersion domainVersion : getDomainVersions()) { if (domainVersion.getDomain() != null && domain.getId() == domainVersion.getDomain().getId()) { return domainVersion; } } return null; }
assertEquals(0, dg.getDomainVersion(d0).getVersionNumber()); assertEquals(0, dg.getDomainVersion(d1).getVersionNumber()); return dg.getDomainVersion(d0).getVersionNumber() != 0; } catch (IOException e) { throw new RuntimeException(e); assertEquals(1, dg.getDomainVersion(d0).getVersionNumber()); assertEquals(1, dg.getDomainVersion(d1).getVersionNumber());
@Override public void setDomainVersion(Domain domain, int versionNumber) { domainVersions.add(new DomainAndVersion(domain, versionNumber)); notifyListeners(); }
public static String formatDomainGroupDomainVersionsTable(DomainGroup domainGroup, String cssClass, boolean linkToDomains) throws IOException { StringBuilder content = new StringBuilder(); content.append("<table class='" + cssClass + "'><tr><th>Domain</th><th>Version</th><th>Closed On</th></tr>"); for (DomainAndVersion version : domainGroup.getDomainVersionsSorted()) { content.append("<tr><td class='centered'>"); if (linkToDomains) { content.append("<a href='/domain.jsp?n=" + URLEnc.encode(version.getDomain().getName()) + "'>"); content.append(version.getDomain().getName()); content.append("</a>"); } else { content.append(version.getDomain().getName()); } content.append("</td><td class='centered'>"); content.append(version.getVersionNumber()); content.append("</td><td class='centered'>"); content.append(formatDomainVersionClosedAt(version.getDomain().getVersion(version.getVersionNumber()))); content.append("</td></tr>"); } content.append("</table>"); return content.toString(); }
Map<Host, Map<Domain, Set<Integer>>> result = new TreeMap<Host, Map<Domain, Set<Integer>>>(); for (DomainAndVersion dgvdv : domainVersions) { Domain domain = dgvdv.getDomain();
public static ServingStatusAggregator computeServingStatusAggregator(Host host, DomainGroup domainGroup) throws IOException { ServingStatusAggregator result = new ServingStatusAggregator(); for (HostDomain hostDomain : host.getAssignedDomains()) { DomainAndVersion domainVersion = domainGroup.getDomainVersion(hostDomain.getDomain()); // Ignore domains that are not relevant if (domainVersion != null) { 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.getCurrentDomainVersion() != null && partition.getCurrentDomainVersion().equals(domainVersion.getVersionNumber()); // Aggregate counts result.add(hostDomain.getDomain(), partition.getPartitionNumber(), servedAndUpToDate); } } } } return result; }
@Override public void mergeDomainVersions(Map<Domain, Integer> domainVersions) throws IOException { for (Map.Entry<Domain, Integer> entry : domainVersions.entrySet()) { this.domainVersions.add(new DomainAndVersion(entry.getKey(), entry.getValue())); } notifyListeners(); }
private static boolean allPartitionsUpToDate(Host host, Collection<DomainAndVersion> domainVersions, boolean allowMoreRecentDomainVersions) throws IOException { // Check that each domain of the given domain group version is up to date on this host for (DomainAndVersion domainAndVersion : domainVersions) { Domain domain = domainAndVersion.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.getCurrentDomainVersion() == null || (!allowMoreRecentDomainVersions && partition.getCurrentDomainVersion() != domainAndVersion.getVersionNumber()) || (allowMoreRecentDomainVersions && (partition.getCurrentDomainVersion() < domainAndVersion.getVersionNumber()))) { LOG.info("Host " + host.getAddress().getHostName() + " is not up to date for domain " + domain.getName() + " and version " + domainAndVersion.getVersionNumber()); LOG.info("Host " + host.getAddress().getHostName() + " has a partition on domain " + domain.getName() + " at version " + partition.getCurrentDomainVersion()); return false; } } } } } return true; }
public ServingStatus computeUniquePartitionsServingStatus(DomainGroup domainGroup) throws IOException { ServingStatus result = new ServingStatus(); for (DomainAndVersion dgvdv : domainGroup.getDomainVersions()) { Domain domain = dgvdv.getDomain(); Map<Integer, ServingStatus> partitionToServingStatus = domainToPartitionToPartitionServingStatus.get(domain); int partitionsServedAndUpToDate = 0; if (partitionToServingStatus != null) { for (ServingStatus servingStatus : partitionToServingStatus.values()) { // A unique partition is served and up to date if all host corresponding domain partitions are // served and up to date if (servingStatus.getNumPartitionsServedAndUpToDate() == servingStatus.getNumPartitions()) { partitionsServedAndUpToDate += 1; } } } result.aggregate(domain.getNumParts(), partitionToServingStatus == null ? 0 : partitionsServedAndUpToDate); } return result; } }