Skip to content

Commit

Permalink
Use Jackson to create and read Tld YAML files (google#2082)
Browse files Browse the repository at this point in the history
* Use Jackson to create and read Tld YAML files

* Add getObjectMapper to TldYamlUtils

* revert lockfiles

* Fix optionals

* Add more tests and javadocs

* small fixes
  • Loading branch information
sarahcaseybot authored Jul 26, 2023
1 parent 43d325d commit f583977
Show file tree
Hide file tree
Showing 11 changed files with 553 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ FeesAndCredits getRestorePrice(Tld tld, String domainName, DateTime dateTime, bo
new FeesAndCredits.Builder()
.setCurrency(tld.getCurrency())
.addFeeOrCredit(
Fee.create(tld.getStandardRestoreCost().getAmount(), FeeType.RESTORE, false));
Fee.create(tld.getRestoreBillingCost().getAmount(), FeeType.RESTORE, false));
if (isExpired) {
feesAndCredits.addFeeOrCredit(
Fee.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private Optional<BillingEvent> createBillingEventForStatusUpdates(
.setReason(Reason.SERVER_STATUS)
.setTargetId(targetId)
.setRegistrarId(registrarId)
.setCost(Tld.get(existingDomain.getTld()).getServerStatusChangeCost())
.setCost(Tld.get(existingDomain.getTld()).getServerStatusChangeBillingCost())
.setEventTime(now)
.setBillingTime(now)
.setDomainHistory(historyEntry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DomainPrices getDomainPrices(String domainName, DateTime priceTime) {
tld.getPremiumListName().flatMap(pl -> PremiumListDao.getPremiumPrice(pl, label));
return DomainPrices.create(
premiumPrice.isPresent(),
premiumPrice.orElse(tld.getStandardCreateCost()),
premiumPrice.orElse(tld.getCreateBillingCost()),
premiumPrice.orElse(tld.getStandardRenewCost(priceTime)));
}
}
56 changes: 49 additions & 7 deletions core/src/main/java/google/registry/model/tld/Tld.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static org.joda.money.CurrencyUnit.USD;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.common.annotations.VisibleForTesting;
Expand All @@ -48,6 +52,15 @@
import google.registry.model.domain.fee.Fee;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.tld.TldYamlUtils.CreateAutoTimestampDeserializer;
import google.registry.model.tld.TldYamlUtils.CurrencyDeserializer;
import google.registry.model.tld.TldYamlUtils.CurrencySerializer;
import google.registry.model.tld.TldYamlUtils.OptionalDurationSerializer;
import google.registry.model.tld.TldYamlUtils.OptionalStringSerializer;
import google.registry.model.tld.TldYamlUtils.TimedTransitionPropertyMoneyDeserializer;
import google.registry.model.tld.TldYamlUtils.TimedTransitionPropertyTldStateDeserializer;
import google.registry.model.tld.TldYamlUtils.TokenVKeyListDeserializer;
import google.registry.model.tld.TldYamlUtils.TokenVKeyListSerializer;
import google.registry.model.tld.label.PremiumList;
import google.registry.model.tld.label.ReservedList;
import google.registry.persistence.VKey;
Expand Down Expand Up @@ -281,20 +294,23 @@ void setDefaultNumDnsPublishLocks() {
*
* <p>When this field is null, the "dnsDefaultATtl" value from the config file will be used.
*/
@JsonSerialize(using = OptionalDurationSerializer.class)
Duration dnsAPlusAaaaTtl;

/**
* The time to live for DNS NS records.
*
* <p>When this field is null, the "dnsDefaultNsTtl" value from the config file will be used.
*/
@JsonSerialize(using = OptionalDurationSerializer.class)
Duration dnsNsTtl;

/**
* The time to live for DNS DS records.
*
* <p>When this field is null, the "dnsDefaultDsTtl" value from the config file will be used.
*/
@JsonSerialize(using = OptionalDurationSerializer.class)
Duration dnsDsTtl;
/**
* The unicode-aware representation of the TLD associated with this {@link Tld}.
Expand Down Expand Up @@ -328,11 +344,13 @@ void setDefaultNumDnsPublishLocks() {

/** A property that transitions to different {@link TldState}s at different times. */
@Column(nullable = false)
@JsonDeserialize(using = TimedTransitionPropertyTldStateDeserializer.class)
TimedTransitionProperty<TldState> tldStateTransitions =
TimedTransitionProperty.withInitialValue(DEFAULT_TLD_STATE);

/** An automatically managed creation timestamp. */
@Column(nullable = false)
@JsonDeserialize(using = CreateAutoTimestampDeserializer.class)
CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);

/** The set of reserved list names that are applicable to this tld. */
Expand All @@ -359,6 +377,7 @@ public ImmutableSet<String> getReservedListNames() {
* the database should be queried for the entity with this name that has the largest revision ID.
*/
@Column(name = "premium_list_name")
@JsonSerialize(using = OptionalStringSerializer.class)
String premiumListName;

/** Should RDE upload a nightly escrow deposit for this TLD? */
Expand Down Expand Up @@ -408,6 +427,8 @@ public ImmutableSet<String> getReservedListNames() {

/** The currency unit for all costs associated with this TLD. */
@Column(nullable = false)
@JsonSerialize(using = CurrencySerializer.class)
@JsonDeserialize(using = CurrencyDeserializer.class)
CurrencyUnit currency = DEFAULT_CURRENCY;

/** The per-year billing cost for registering a new domain name. */
Expand Down Expand Up @@ -454,11 +475,13 @@ public ImmutableSet<String> getReservedListNames() {
* renewal to ensure transfers have a cost.
*/
@Column(nullable = false)
@JsonDeserialize(using = TimedTransitionPropertyMoneyDeserializer.class)
TimedTransitionProperty<Money> renewBillingCostTransitions =
TimedTransitionProperty.withInitialValue(DEFAULT_RENEW_BILLING_COST);

/** A property that tracks the EAP fee schedule (if any) for the TLD. */
@Column(nullable = false)
@JsonDeserialize(using = TimedTransitionPropertyMoneyDeserializer.class)
TimedTransitionProperty<Money> eapFeeSchedule =
TimedTransitionProperty.withInitialValue(DEFAULT_EAP_BILLING_COST);

Expand All @@ -475,6 +498,11 @@ public ImmutableSet<String> getReservedListNames() {
/** An allowlist of hosts allowed to be used on domains on this TLD (ignored if empty). */
@Nullable Set<String> allowedFullyQualifiedHostNames;

/**
* Indicates when the TLD is being modified using locally modified files to override the source
* control procedures. This field is ignored in Tld YAML files.
*/
@JsonIgnore
@Column(nullable = false)
boolean breakglassMode = false;

Expand All @@ -488,6 +516,8 @@ public ImmutableSet<String> getReservedListNames() {
* (ex: add a token to the list or remove a token from the list) should not be allowed without
* resetting the entire list contents.
*/
@JsonSerialize(using = TokenVKeyListSerializer.class)
@JsonDeserialize(using = TokenVKeyListDeserializer.class)
List<VKey<AllocationToken>> defaultPromoTokens;

/** A set of allowed {@link IdnTableEnum}s for this TLD, or empty if we should use the default. */
Expand All @@ -502,6 +532,7 @@ public String getRoidSuffix() {
}

/** Retrieve the actual domain name representing the TLD for which this registry operates. */
@JsonIgnore
public InternetDomainName getTld() {
return InternetDomainName.from(tldStr);
}
Expand All @@ -511,6 +542,11 @@ public TldType getTldType() {
return tldType;
}

/** Retrieve whether invoicing is enabled. */
public boolean isInvoicingEnabled() {
return invoicingEnabled;
}

/**
* Retrieve the TLD state at the given time. Defaults to {@link TldState#PREDELEGATION}.
*
Expand Down Expand Up @@ -588,15 +624,15 @@ public CurrencyUnit getCurrency() {
* domain create.
*/
@VisibleForTesting
public Money getStandardCreateCost() {
public Money getCreateBillingCost() {
return createBillingCost;
}

/**
* Returns the add-on cost of a domain restore (the flat tld-wide fee charged in addition to one
* year of renewal for that name).
*/
public Money getStandardRestoreCost() {
public Money getRestoreBillingCost() {
return restoreBillingCost;
}

Expand All @@ -610,7 +646,7 @@ public Money getStandardRenewCost(DateTime now) {
}

/** Returns the cost of a server status change (i.e. lock). */
public Money getServerStatusChangeCost() {
public Money getServerStatusChangeBillingCost() {
return serverStatusChangeBillingCost;
}

Expand Down Expand Up @@ -648,6 +684,7 @@ public Fee getEapFeeFor(DateTime now) {
}

@VisibleForTesting
@JsonProperty("eapFeeSchedule")
public ImmutableSortedMap<DateTime, Money> getEapFeeScheduleAsMap() {
return eapFeeSchedule.toValueMap();
}
Expand All @@ -660,7 +697,7 @@ public DateTime getClaimsPeriodEnd() {
return claimsPeriodEnd;
}

public String getPremiumPricingEngineClassName() {
public String getPricingEngineClassName() {
return pricingEngineClassName;
}

Expand Down Expand Up @@ -688,6 +725,11 @@ public Optional<Duration> getDnsDsTtl() {
return Optional.ofNullable(dnsDsTtl);
}

/** Retrieve the TLD unicode representation. */
public String getTldUnicode() {
return tldUnicode;
}

public ImmutableSet<String> getAllowedRegistrantContactIds() {
return nullToEmptyImmutableCopy(allowedRegistrantContactIds);
}
Expand Down Expand Up @@ -1037,13 +1079,13 @@ public Tld build() {
// All costs must be in the expected currency.
checkArgumentNotNull(instance.getCurrency(), "Currency must be set");
checkArgument(
instance.getStandardCreateCost().getCurrencyUnit().equals(instance.currency),
instance.getCreateBillingCost().getCurrencyUnit().equals(instance.currency),
"Create cost must be in the tld's currency");
checkArgument(
instance.getStandardRestoreCost().getCurrencyUnit().equals(instance.currency),
instance.getRestoreBillingCost().getCurrencyUnit().equals(instance.currency),
"Restore cost must be in the TLD's currency");
checkArgument(
instance.getServerStatusChangeCost().getCurrencyUnit().equals(instance.currency),
instance.getServerStatusChangeBillingCost().getCurrencyUnit().equals(instance.currency),
"Server status change cost must be in the TLD's currency");
checkArgument(
instance.getRegistryLockOrUnlockBillingCost().getCurrencyUnit().equals(instance.currency),
Expand Down
Loading

0 comments on commit f583977

Please sign in to comment.