mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Remove UNRESERVED as a reservation type
This is a follow-up to Lai's refactoring of the get reservation types code to return a set rather than a single type. Since we're always returning a set now, the more natural way to represent a label that is not reserved is to return an empty set rather than a set containing UNRESERVED. Also fixes some minor style issues I ran across regarding static importing and test method naming that I ran across (no logic implications). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=151132116
This commit is contained in:
parent
4260fb573f
commit
b03bd3b525
12 changed files with 83 additions and 90 deletions
|
@ -17,6 +17,7 @@ package google.registry.model.eppoutput;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.eppoutput.EppResponse.ResponseData;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElements;
|
||||
|
@ -124,7 +125,7 @@ public abstract class CheckData extends ImmutableObject implements ResponseData
|
|||
/** A version with domain namespacing. */
|
||||
@XmlType(namespace = "urn:ietf:params:xml:ns:domain-1.0")
|
||||
public static class DomainCheck extends Check {
|
||||
public static DomainCheck create(boolean avail, String name, String reason) {
|
||||
public static DomainCheck create(boolean avail, String name, @Nullable String reason) {
|
||||
return init(new DomainCheck(), CheckName.create(avail, name), reason);
|
||||
}
|
||||
|
||||
|
|
|
@ -166,8 +166,7 @@ class DomainLabelMetrics {
|
|||
String mostSevereReservedList =
|
||||
matches.isEmpty() ? "(none)" : mostSevereMatch.reservedListName();
|
||||
String mostSevereReservationType =
|
||||
(matches.isEmpty() ? ReservationType.UNRESERVED : mostSevereMatch.reservationType())
|
||||
.toString();
|
||||
(matches.isEmpty() ? "(none)" : mostSevereMatch.reservationType()).toString();
|
||||
reservedListChecks.increment(
|
||||
tld, matchCount, mostSevereReservedList, mostSevereReservationType);
|
||||
reservedListProcessingTime.record(
|
||||
|
|
|
@ -14,8 +14,11 @@
|
|||
|
||||
package google.registry.model.registry.label;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -27,13 +30,12 @@ public enum ReservationType {
|
|||
// label has multiple reservation types, its message is the that of the one with the highest
|
||||
// severity.
|
||||
|
||||
UNRESERVED(null, 0),
|
||||
NAMESERVER_RESTRICTED("Nameserver restricted", 1),
|
||||
ALLOWED_IN_SUNRISE("Reserved for non-sunrise", 2),
|
||||
MISTAKEN_PREMIUM("Reserved", 3),
|
||||
RESERVED_FOR_ANCHOR_TENANT("Reserved", 4),
|
||||
NAME_COLLISION("Cannot be delegated", 5),
|
||||
FULLY_BLOCKED("Reserved", 6);
|
||||
NAMESERVER_RESTRICTED("Nameserver restricted", 0),
|
||||
ALLOWED_IN_SUNRISE("Reserved for non-sunrise", 1),
|
||||
MISTAKEN_PREMIUM("Reserved", 2),
|
||||
RESERVED_FOR_ANCHOR_TENANT("Reserved", 3),
|
||||
NAME_COLLISION("Cannot be delegated", 4),
|
||||
FULLY_BLOCKED("Reserved", 5);
|
||||
|
||||
@Nullable
|
||||
private final String messageForCheck;
|
||||
|
@ -48,20 +50,23 @@ public enum ReservationType {
|
|||
return messageForCheck;
|
||||
}
|
||||
|
||||
private static final Ordering<ReservationType> ORDERING = new Ordering<ReservationType>() {
|
||||
@Override
|
||||
public int compare(ReservationType left, ReservationType right) {
|
||||
return Integer.compare(left.ordinal(), right.ordinal());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the {@code ReservationType} with the highest severity, used when a label has multiple
|
||||
* reservation types and a reservation message is needed.
|
||||
*
|
||||
* @param types the set of reservation types that a label is associated with.
|
||||
* @return the reservation type with the highest severity.
|
||||
*/
|
||||
public static ReservationType getTypeOfHighestSeverity(Set<ReservationType> types) {
|
||||
ReservationType mostSevereType = UNRESERVED;
|
||||
|
||||
for (ReservationType type : types) {
|
||||
if (type.compareTo(mostSevereType) > 0) {
|
||||
mostSevereType = type;
|
||||
}
|
||||
}
|
||||
return mostSevereType;
|
||||
checkArgumentNotNull(types, "types must not be null");
|
||||
checkArgument(!types.isEmpty(), "types must not be empty");
|
||||
return ORDERING.max(types);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
|
|||
import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED;
|
||||
import static google.registry.model.registry.label.ReservationType.NAMESERVER_RESTRICTED;
|
||||
import static google.registry.model.registry.label.ReservationType.RESERVED_FOR_ANCHOR_TENANT;
|
||||
import static google.registry.model.registry.label.ReservationType.UNRESERVED;
|
||||
import static google.registry.util.CollectionUtils.nullToEmpty;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
@ -37,9 +36,9 @@ import com.google.common.base.Splitter;
|
|||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import com.googlecode.objectify.Key;
|
||||
|
@ -211,27 +210,25 @@ public final class ReservedList
|
|||
}
|
||||
|
||||
/**
|
||||
* Queries the set of all reserved lists associated with the specified tld and returns the
|
||||
* reservation types of the label. If the label is in none of the lists, it returns a set that
|
||||
* contains UNRESERVED.
|
||||
* Queries the set of all reserved lists associated with the specified TLD and returns the
|
||||
* reservation types of the label.
|
||||
*
|
||||
* <p>If the label is in none of the lists, it returns an empty set.
|
||||
*/
|
||||
public static ImmutableSet<ReservationType> getReservationTypes(String label, String tld) {
|
||||
checkNotNull(label, "label");
|
||||
if (label.length() == 0) {
|
||||
return ImmutableSet.of(FULLY_BLOCKED);
|
||||
}
|
||||
ImmutableSet<ReservedListEntry> entries = getReservedListEntries(label, tld);
|
||||
return entries.isEmpty()
|
||||
? ImmutableSet.of(UNRESERVED)
|
||||
: ImmutableSet.copyOf(
|
||||
Iterables.transform(
|
||||
entries,
|
||||
new Function<ReservedListEntry, ReservationType>() {
|
||||
@Override
|
||||
public ReservationType apply(ReservedListEntry reservedListEntry) {
|
||||
return reservedListEntry.reservationType;
|
||||
}
|
||||
}));
|
||||
return FluentIterable.from(getReservedListEntries(label, tld))
|
||||
.transform(
|
||||
new Function<ReservedListEntry, ReservationType>() {
|
||||
@Override
|
||||
public ReservationType apply(ReservedListEntry reservedListEntry) {
|
||||
return reservedListEntry.reservationType;
|
||||
}
|
||||
})
|
||||
.toSet();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue