1
0
mirror of https://github.com/google/nomulus synced 2026-06-09 16:33:02 +00:00

Compare commits

...

15 Commits

Author SHA1 Message Date
Lai Jiang 4aaf31be9f Update IDN tables per ICANN's request (#812)
See b/168508962 for the request.
2020-09-21 23:08:10 -04:00
Lai Jiang e30c0f9a11 Request 101m CPU in sandbox proxy (#813)
This is suggested as a mitigation to allow us to deploy to sandbox. The default
value is 100m.

See: https://b.corp.google.com/issues/167295064#comment36.
2020-09-21 21:22:41 -04:00
gbrodman 2a5d9c8ef5 Allow explicitly for null EPP resources in History objects (#790)
* Allow explicitly for null EPP resources in History objects

* Repo IDs should always be nonnull

* Add a test to verify loading / comparison of legacy HistoryEntry objects

* Format javadoc + annotations

* More javadoc changes

* V52 -> V56

* V56 -> V57

* saveNew -> insert in new tests
2020-09-21 15:50:15 -04:00
gbrodman 597f5746a4 Rename V54 -> V56 on host table rename (#811) 2020-09-21 13:34:37 -04:00
Michael Muller 5bff53a711 Rename HostResource table to Host (#804)
* Rename HostResource table to Host

* Convert drop/creates to renames
2020-09-21 11:43:25 -04:00
Michael Muller 933394e8c3 Improve naming of TransactionManager methods (#802)
* Improve naming of TransactionManager methods

Per internal discussion, convert names of methods as follows:

    saveNew -> insert
    saveNewOrUpdate -> put
    checkExists -> exists

Likewise, convert derived names to their corresponding forms, e.g.
saveNewOrUpdateAll -> putAll.
2020-09-21 09:10:01 -04:00
gbrodman 3b841bbb5b Add domain-specific history fields to DomainHistory objects (#794)
* Add domain-specific history fields to DomainHistory objects

* Add javadoc for Hibernate-only methods

* V52 -> V54

* Use only a single DomainTransactionRecord table

* Add nullables and fix up a comment

* V54 -> V55

* Regenerate db schema

* Regen SQL file
2020-09-18 15:55:17 -04:00
gbrodman 798879d031 Fix semantic merge conflict in Registry (#810)
* Fix semantic merge conflict in Registry
2020-09-18 14:40:11 -04:00
gbrodman 1a63d50b82 Create a separate per-tld registry lock/unlock cost (#800)
* Create a separate per-tld registry lock/unlock cost

Currently we use the standard server status change cost for this, but
this might not be ideal at some point in the future if we wish to allow
manual forced updates outside of the standard registry lock system (we
would charge for these manual forced updates, even if we don't charge
for registry locks).

* Remove period
2020-09-18 13:22:29 -04:00
Lai Jiang 054571a625 Update ICANN activity reporting logging (#808)
1. It appears that when we have a 200 response, the response content is
   garbled, but we don't care since we know the request is successful.
   When we have a 400 response, the response is indeed UTF-8 encoded.
   Print the stack trace of the HTTP exception doesn't help anymore.

2. The result code is a complex type which includes the xml element with
   all its attributes, which don't care. We only want to print the
   value.
2020-09-18 11:37:23 -04:00
sarahcaseybot 7468a9915b Migrate Registry objects to a TLD table in Cloud SQL (#803)
* Add TLD table

* Change reservedLists to array

* Change ReservedLists back to a set

* Rename reservedListKeyConverter to ReservedListKeySetConverter

* Add a postload method
2020-09-17 12:47:50 -04:00
Lai Jiang 157d9f75c1 Use the save API version for the HPA controller and the deployment (#807)
This supposedly can fix our deployment problem. Tested on alpha.

Also updated the deployment script to replace the service object as
well.
2020-09-16 09:15:35 -04:00
Lai Jiang b2e4f07bb9 Update IDN tables (#806)
See b/168508962 for context.

1. Changed the contact to iana-contact@google.com
2. Changed the header from "Script" to "Language" for zh-Hans and
   zh-Hant.
3. Commented out the references in zh-Hans and Zh-Hant
2020-09-16 09:15:27 -04:00
Michael Muller 5488e1b323 Fix accessing superclass fields in checkExists() (#799)
* Fix accessing superclass fields in checkExists()

JpaTransactionManagerImpl doesn't respect @Id fields in mapped superclasses.
Replace calls to getDeclaredId() and getDeclaredField() with superclass
friendly counterparts.
2020-09-11 13:45:51 -04:00
Shicong Huang 5ab0f97351 Add and use temp_history_id_sequence to avoid release error (#795) 2020-09-11 12:25:08 -04:00
102 changed files with 1586 additions and 568 deletions
@@ -464,7 +464,7 @@ public class DeleteContactsAndHostsAction implements Runnable {
HostResource host = (HostResource) existingResource;
if (host.isSubordinate()) {
dnsQueue.addHostRefreshTask(host.getHostName());
tm().saveNewOrUpdate(
tm().put(
tm().load(host.getSuperordinateDomain())
.asBuilder()
.removeSubordinateHost(host.getHostName())
@@ -437,7 +437,7 @@ public final class Transforms {
.map(Optional::get)
.map(ofy::toPojo)
.collect(ImmutableList.toImmutableList());
retry(() -> jpaTm().transact(() -> jpaTm().saveNewOrUpdateAll(ofyEntities)));
retry(() -> jpaTm().transact(() -> jpaTm().putAll(ofyEntities)));
}
}
@@ -215,7 +215,7 @@ public class Spec11Pipeline implements Serializable {
.setRegistrarId(subdomain.registrarId())
.build();
JpaTransactionManager jpaTransactionManager = jpaSupplierFactory.get();
jpaTransactionManager.transact(() -> jpaTransactionManager.saveNew(threatMatch));
jpaTransactionManager.transact(() -> jpaTransactionManager.insert(threatMatch));
}
}
}));
@@ -173,7 +173,7 @@ public final class DomainRestoreRequestFlow implements TransactionalFlow {
existingDomain, newExpirationTime, autorenewEvent, autorenewPollMessage, now, clientId);
updateForeignKeyIndexDeletionTime(newDomain);
entitiesToSave.add(newDomain, historyEntry, autorenewEvent, autorenewPollMessage);
tm().saveNewOrUpdateAll(entitiesToSave.build());
tm().putAll(entitiesToSave.build());
tm().delete(existingDomain.getDeletePollMessage());
dnsQueue.addDomainRefreshTask(existingDomain.getDomainName());
return responseBuilder
@@ -285,7 +285,7 @@ public final class HostUpdateFlow implements TransactionalFlow {
&& newHost.isSubordinate()
&& Objects.equals(
existingHost.getSuperordinateDomain(), newHost.getSuperordinateDomain())) {
tm().saveNewOrUpdate(
tm().put(
tm().load(existingHost.getSuperordinateDomain())
.asBuilder()
.removeSubordinateHost(existingHost.getHostName())
@@ -294,14 +294,14 @@ public final class HostUpdateFlow implements TransactionalFlow {
return;
}
if (existingHost.isSubordinate()) {
tm().saveNewOrUpdate(
tm().put(
tm().load(existingHost.getSuperordinateDomain())
.asBuilder()
.removeSubordinateHost(existingHost.getHostName())
.build());
}
if (newHost.isSubordinate()) {
tm().saveNewOrUpdate(
tm().put(
tm().load(newHost.getSuperordinateDomain())
.asBuilder()
.addSubordinateHost(newHost.getHostName())
@@ -64,7 +64,7 @@ public final class PollFlowUtils {
// and re-save it for future autorenew poll messages to be delivered. Otherwise, this
// autorenew poll message has no more events to deliver and should be deleted.
if (nextEventTime.isBefore(autorenewPollMessage.getAutorenewEndTime())) {
tm().saveNewOrUpdate(autorenewPollMessage.asBuilder().setEventTime(nextEventTime).build());
tm().put(autorenewPollMessage.asBuilder().setEventTime(nextEventTime).build());
includeAckedMessageInCount = isBeforeOrAt(nextEventTime, tm().getTransactionTime());
} else {
tm().delete(autorenewPollMessage.createVKey());
@@ -2,7 +2,7 @@
# Script: Arab
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Armn
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Beng
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -1,24 +1,24 @@
# Registry: Charleston Road Registry Inc.
# Script: Chinese
# Script: zh-Hans
# Version: 1.0
# Effective Date: 04-12-2012
#
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
# Notes: This table describes codepoints allowed for the Chinese script.
Reference 0 Unicode 3.2
Reference 1 A Complete Set of Simplified Chinese Characters
Reference 2 Chinese Variants Collation Table
Reference 3 Chinese Big Dictionary
Reference 4 Chinese Relationship Table for Unihan Project
Reference 5 GB2312
Reference 6 General Table for Modern Chinese
Reference 7 International Chinese Standard Big Dictionary
Reference 8 Unihan Database
Reference 9 BIG5
# Reference 0 Unicode 3.2
# Reference 1 A Complete Set of Simplified Chinese Characters
# Reference 2 Chinese Variants Collation Table
# Reference 3 Chinese Big Dictionary
# Reference 4 Chinese Relationship Table for Unihan Project
# Reference 5 GB2312
# Reference 6 General Table for Modern Chinese
# Reference 7 International Chinese Standard Big Dictionary
# Reference 8 Unihan Database
# Reference 9 BIG5
U+002D(0);U+002D(0);
U+0030(0);U+0030(0);
@@ -2,7 +2,7 @@
# Script: Cyrl
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Deva
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Ethi
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -3,7 +3,7 @@
#
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -3,7 +3,7 @@
# Script: Grek
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -3,7 +3,7 @@
# Script: Guru
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Hebr
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Knda
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Khmr
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
#
# Telephone: +1 (650) 253-0000
@@ -2,7 +2,7 @@
# Script: Kore
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Mlym
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -3,7 +3,7 @@
# Version: 1.0
# Effective Date: 04-12-2012
#
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Orya
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Sinh
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Taml
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Telu
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Thai
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -2,7 +2,7 @@
# Script: Tibt
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
@@ -1,23 +1,23 @@
# Registry: Charleston Road Registry Inc.
# Script: Traditional Chinese
# Script: zh-Hant
# Version: 1.0
# Effective Date: 04-12-2012
# Contact: tas-contact.google.com
# Contact: iana-contact@google.com
# Address: 1600 Amphitheatre Parkway Mountain View, CA 94043, USA
# Telephone: +1 (650) 253-0000
# Website: www.google.com
# Notes: This table describes codepoints allowed for the Traditional Chinese script.
Reference 0 Unicode 3.2
Reference 1 A Complete Set of Simplified Chinese Characters
Reference 2 Chinese Variants Collation Table
Reference 3 Chinese Big Dictionary
Reference 4 Chinese Relationship Table for Unihan Project
Reference 5 GB2312
Reference 6 General Table for Modern Chinese
Reference 7 International Chinese Standard Big Dictionary
Reference 8 Unihan Database
Reference 9 BIG5
# Reference 0 Unicode 3.2
# Reference 1 A Complete Set of Simplified Chinese Characters
# Reference 2 Chinese Variants Collation Table
# Reference 3 Chinese Big Dictionary
# Reference 4 Chinese Relationship Table for Unihan Project
# Reference 5 GB2312
# Reference 6 General Table for Modern Chinese
# Reference 7 International Chinese Standard Big Dictionary
# Reference 8 Unihan Database
# Reference 9 BIG5
U+002D(0);U+002D(0);
U+0030(0);U+0030(0);
@@ -62,23 +62,32 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
/**
* Unique identifier in the registry for this resource.
*
* <p>Not persisted so that we can store these in references to other objects. Subclasses that
* wish to use this as the primary key should create a getter method annotated with @Id
*
* <p>This is in the (\w|_){1,80}-\w{1,8} format specified by RFC 5730 for roidType.
*
* @see <a href="https://tools.ietf.org/html/rfc5730">RFC 5730</a>
*/
@Id
// not persisted so that we can store these in references to other objects. Subclasses that wish
// to use this as the primary key should create a getter method annotated with @Id
@Transient
String repoId;
@Id @Transient String repoId;
/** The ID of the registrar that is currently sponsoring this resource. */
/**
* The ID of the registrar that is currently sponsoring this resource.
*
* <p>This can be null in the case of pre-Registry-3.0-migration history objects with null
* resource fields.
*/
@Index
@Column(name = "currentSponsorRegistrarId", nullable = false)
@Column(name = "currentSponsorRegistrarId")
String currentSponsorClientId;
/** The ID of the registrar that created this resource. */
@Column(name = "creationRegistrarId", nullable = false)
/**
* The ID of the registrar that created this resource.
*
* <p>This can be null in the case of pre-Registry-3.0-migration history objects with null
* resource fields.
*/
@Column(name = "creationRegistrarId")
String creationClientId;
/**
@@ -91,13 +100,17 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
@Column(name = "lastEppUpdateRegistrarId")
String lastEppUpdateClientId;
/** The time when this resource was created. */
// Map the method to XML, not the field, because if we map the field (with an adaptor class) it
// will never be omitted from the xml even if the timestamp inside creationTime is null and we
// return null from the adaptor. (Instead it gets written as an empty tag.)
@Column(nullable = false)
@Index
CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
/**
* The time when this resource was created.
*
* <p>Map the method to XML, not the field, because if we map the field (with an adaptor class) it
* will never be omitted from the xml even if the timestamp inside creationTime is null and we
* return null from the adaptor (instead it gets written as an empty tag).
*
* <p>This can be null in the case of pre-Registry-3.0-migration history objects with null
* resource fields.
*/
@Index CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
/**
* The time when this resource was or will be deleted.
@@ -112,8 +125,7 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
* out of the index at that time, as long as we query for resources whose deletion time is before
* now.
*/
@Index
DateTime deletionTime;
@Index DateTime deletionTime;
/**
* The time that this resource was last updated.
@@ -144,7 +156,7 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
return repoId;
}
// Hibernate needs this to populate the repo ID, but no one else should ever use it
/** This method exists solely to satisfy Hibernate. Use {@link Builder} instead. */
@SuppressWarnings("UnusedMethod")
private void setRepoId(String repoId) {
this.repoId = repoId;
@@ -19,6 +19,8 @@ import com.googlecode.objectify.annotation.EntitySubclass;
import google.registry.model.EppResource;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
@@ -26,6 +28,7 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PostLoad;
/**
* A persisted history entry representing an EPP modification to a contact.
@@ -47,13 +50,13 @@ import javax.persistence.Id;
public class ContactHistory extends HistoryEntry {
// Store ContactBase instead of ContactResource so we don't pick up its @Id
ContactBase contactBase;
@Nullable ContactBase contactBase;
@Column(nullable = false)
VKey<ContactResource> contactRepoId;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HistorySequenceGenerator")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TempHistorySequenceGenerator")
@Column(name = "historyRevisionId")
@Access(AccessType.PROPERTY)
@Override
@@ -61,9 +64,14 @@ public class ContactHistory extends HistoryEntry {
return super.getId();
}
/** The state of the {@link ContactBase} object at this point in time. */
public ContactBase getContactBase() {
return contactBase;
/**
* The values of all the fields on the {@link ContactBase} object after the action represented by
* this history object was executed.
*
* <p>Will be absent for objects created prior to the Registry 3.0 SQL migration.
*/
public Optional<ContactBase> getContactBase() {
return Optional.ofNullable(contactBase);
}
/** The key to the {@link ContactResource} this is based off of. */
@@ -71,6 +79,20 @@ public class ContactHistory extends HistoryEntry {
return contactRepoId;
}
@PostLoad
void postLoad() {
// Normally Hibernate would see that the contact fields are all null and would fill contactBase
// with a null object. Unfortunately, the updateTimestamp is never null in SQL.
if (contactBase != null && contactBase.getContactId() == null) {
contactBase = null;
}
// Fill in the full, symmetric, parent repo ID key
Key<ContactResource> parentKey =
Key.create(ContactResource.class, (String) contactRepoId.getSqlKey());
parent = parentKey;
contactRepoId = VKey.create(ContactResource.class, contactRepoId.getSqlKey(), parentKey);
}
@Override
public Builder asBuilder() {
return new Builder(clone(this));
@@ -23,12 +23,18 @@ import google.registry.model.EppResource;
import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainHistory.DomainHistoryId;
import google.registry.model.host.HostResource;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import java.io.Serializable;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
@@ -37,7 +43,9 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.PostLoad;
import javax.persistence.Table;
@@ -62,7 +70,7 @@ import javax.persistence.Table;
public class DomainHistory extends HistoryEntry {
// Store DomainContent instead of DomainBase so we don't pick up its @Id
DomainContent domainContent;
@Nullable DomainContent domainContent;
@Id String domainRepoId;
@@ -75,8 +83,52 @@ public class DomainHistory extends HistoryEntry {
@Column(name = "host_repo_id")
Set<VKey<HostResource>> nsHosts;
@Override
@Nullable
@Access(AccessType.PROPERTY)
@AttributeOverrides({
@AttributeOverride(
name = "unit",
column = @Column(name = "historyPeriodUnit")),
@AttributeOverride(
name = "value",
column = @Column(name = "historyPeriodValue"))
})
public Period getPeriod() {
return super.getPeriod();
}
/**
* For transfers, the id of the other registrar.
*
* <p>For requests and cancels, the other registrar is the losing party (because the registrar
* sending the EPP transfer command is the gaining party). For approves and rejects, the other
* registrar is the gaining party.
*/
@Nullable
@Access(AccessType.PROPERTY)
@Column(name = "historyOtherRegistrarId")
public String getOtherRegistrarId() {
return super.getOtherClientId();
}
/**
* Logging field for transaction reporting.
*
* <p>This will be empty for any DomainHistory/HistoryEntry generated before this field was added,
* mid-2017, as well as any action that does not generate billable events (e.g. updates).
*/
@Access(AccessType.PROPERTY)
@OneToMany(cascade = {CascadeType.ALL})
@JoinColumn(name = "historyRevisionId", referencedColumnName = "historyRevisionId")
@JoinColumn(name = "domainRepoId", referencedColumnName = "domainRepoId")
@Override
public Set<DomainTransactionRecord> getDomainTransactionRecords() {
return super.getDomainTransactionRecords();
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HistorySequenceGenerator")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TempHistorySequenceGenerator")
@Column(name = "historyRevisionId")
@Access(AccessType.PROPERTY)
@Override
@@ -89,9 +141,14 @@ public class DomainHistory extends HistoryEntry {
return nsHosts;
}
/** The state of the {@link DomainContent} object at this point in time. */
public DomainContent getDomainContent() {
return domainContent;
/**
* The values of all the fields on the {@link DomainContent} object after the action represented
* by this history object was executed.
*
* <p>Will be absent for objects created prior to the Registry 3.0 SQL migration.
*/
public Optional<DomainContent> getDomainContent() {
return Optional.ofNullable(domainContent);
}
/** The key to the {@link DomainBase} this is based off of. */
@@ -107,7 +164,13 @@ public class DomainHistory extends HistoryEntry {
void postLoad() {
if (domainContent != null) {
domainContent.nsHosts = nullToEmptyImmutableCopy(nsHosts);
// Normally Hibernate would see that the domain fields are all null and would fill
// domainContent with a null object. Unfortunately, the updateTimestamp is never null in SQL.
if (domainContent.getDomainName() == null) {
domainContent = null;
}
}
parent = Key.create(DomainBase.class, domainRepoId);
}
/** Class to represent the composite primary key of {@link DomainHistory} entity. */
@@ -31,9 +31,9 @@ public class Period extends ImmutableObject {
@XmlAttribute
Unit unit;
@XmlValue
Integer value;
@XmlValue Integer value;
@Enumerated(EnumType.STRING)
public Unit getUnit() {
return unit;
}
@@ -42,6 +42,18 @@ public class Period extends ImmutableObject {
return value;
}
/** This method exists solely to satisfy Hibernate. Use {@link #create(int, Unit)} instead. */
@SuppressWarnings("UnusedMethod")
private void setUnit(Unit unit) {
this.unit = unit;
}
/** This method exists solely to satisfy Hibernate. Use {@link #create(int, Unit)} instead. */
@SuppressWarnings("UnusedMethod")
private void setValue(Integer value) {
this.value = value;
}
/** The unit enum. */
public enum Unit {
@XmlEnumValue("y")
@@ -19,6 +19,8 @@ import com.googlecode.objectify.annotation.EntitySubclass;
import google.registry.model.EppResource;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
@@ -26,6 +28,7 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PostLoad;
/**
* A persisted history entry representing an EPP modification to a host.
@@ -48,13 +51,13 @@ import javax.persistence.Id;
public class HostHistory extends HistoryEntry {
// Store HostBase instead of HostResource so we don't pick up its @Id
HostBase hostBase;
@Nullable HostBase hostBase;
@Column(nullable = false)
VKey<HostResource> hostRepoId;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HistorySequenceGenerator")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TempHistorySequenceGenerator")
@Column(name = "historyRevisionId")
@Access(AccessType.PROPERTY)
@Override
@@ -62,9 +65,14 @@ public class HostHistory extends HistoryEntry {
return super.getId();
}
/** The state of the {@link HostBase} object at this point in time. */
public HostBase getHostBase() {
return hostBase;
/**
* The values of all the fields on the {@link HostBase} object after the action represented by
* this history object was executed.
*
* <p>Will be absent for objects created prior to the Registry 3.0 SQL migration.
*/
public Optional<HostBase> getHostBase() {
return Optional.ofNullable(hostBase);
}
/** The key to the {@link google.registry.model.host.HostResource} this is based off of. */
@@ -72,6 +80,19 @@ public class HostHistory extends HistoryEntry {
return hostRepoId;
}
@PostLoad
void postLoad() {
// Normally Hibernate would see that the host fields are all null and would fill hostBase
// with a null object. Unfortunately, the updateTimestamp is never null in SQL.
if (hostBase != null && hostBase.getHostName() == null) {
hostBase = null;
}
// Fill in the full, symmetric, parent repo ID key
Key<HostResource> parentKey = Key.create(HostResource.class, (String) hostRepoId.getSqlKey());
parent = parentKey;
hostRepoId = VKey.create(HostResource.class, hostRepoId.getSqlKey(), parentKey);
}
@Override
public Builder asBuilder() {
return new Builder(clone(this));
@@ -32,7 +32,7 @@ import javax.persistence.AccessType;
*/
@ReportedOn
@Entity
@javax.persistence.Entity
@javax.persistence.Entity(name = "Host")
@ExternalMessagingName("host")
@WithStringVKey
@Access(AccessType.FIELD) // otherwise it'll use the default if the repoId (property)
@@ -101,22 +101,22 @@ public class DatastoreTransactionManager implements TransactionManager {
}
@Override
public void saveNew(Object entity) {
public void insert(Object entity) {
saveEntity(entity);
}
@Override
public void saveAllNew(ImmutableCollection<?> entities) {
public void insertAll(ImmutableCollection<?> entities) {
getOfy().save().entities(entities);
}
@Override
public void saveNewOrUpdate(Object entity) {
public void put(Object entity) {
saveEntity(entity);
}
@Override
public void saveNewOrUpdateAll(ImmutableCollection<?> entities) {
public void putAll(ImmutableCollection<?> entities) {
getOfy().save().entities(entities);
}
@@ -131,12 +131,12 @@ public class DatastoreTransactionManager implements TransactionManager {
}
@Override
public boolean checkExists(Object entity) {
public boolean exists(Object entity) {
return getOfy().load().key(Key.create(entity)).now() != null;
}
@Override
public <T> boolean checkExists(VKey<T> key) {
public <T> boolean exists(VKey<T> key) {
return loadNullable(key) != null;
}
@@ -70,6 +70,13 @@ import java.util.concurrent.ExecutionException;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.PostLoad;
import javax.persistence.Transient;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
@@ -78,21 +85,31 @@ import org.joda.time.Duration;
/** Persisted per-TLD configuration data. */
@ReportedOn
@Entity
@javax.persistence.Entity(name = "Tld")
public class Registry extends ImmutableObject implements Buildable {
@Parent Key<EntityGroupRoot> parent = getCrossTldKey();
@Parent @Transient Key<EntityGroupRoot> parent = getCrossTldKey();
/**
* The canonical string representation of the TLD associated with this {@link Registry}, which is
* the standard ASCII for regular TLDs and punycoded ASCII for IDN TLDs.
*/
@Id String tldStrId;
@Id
@javax.persistence.Id
@Column(name = "tld_name", nullable = false)
String tldStrId;
/**
* A duplicate of {@link #tldStrId}, to simplify BigQuery reporting since the id field becomes
* {@code __key__.name} rather than being exported as a named field.
*/
String tldStr;
@Transient String tldStr;
/** Sets the Datastore specific field, tldStr, when the entity is loaded from Cloud SQL */
@PostLoad
void postLoad() {
tldStr = tldStrId;
}
/** The suffix that identifies roids as belonging to this specific tld, e.g. -HOW for .how. */
String roidSuffix;
@@ -116,6 +133,7 @@ public class Registry extends ImmutableObject implements Buildable {
public static final Money DEFAULT_RENEW_BILLING_COST = Money.of(USD, 8);
public static final Money DEFAULT_RESTORE_BILLING_COST = Money.of(USD, 100);
public static final Money DEFAULT_SERVER_STATUS_CHANGE_BILLING_COST = Money.of(USD, 20);
public static final Money DEFAULT_REGISTRY_LOCK_OR_UNLOCK_BILLING_COST = Money.of(USD, 0);
/** The type of TLD, which determines things like backups and escrow policy. */
public enum TldType {
@@ -289,6 +307,7 @@ public class Registry extends ImmutableObject implements Buildable {
* <p>All entries of this list must be valid keys for the map of {@code DnsWriter}s injected by
* <code>@Inject Map<String, DnsWriter></code>
*/
@Column(nullable = false)
Set<String> dnsWriters;
/**
@@ -312,6 +331,7 @@ public class Registry extends ImmutableObject implements Buildable {
* <p>Failure to do so can result in parallel writes to the {@link
* google.registry.dns.writer.DnsWriter}, which may be dangerous depending on your implementation.
*/
@Column(nullable = false)
int numDnsPublishLocks;
/** Updates an unset numDnsPublishLocks (0) to the standard default of 1. */
@@ -327,6 +347,7 @@ public class Registry extends ImmutableObject implements Buildable {
* <p>This will be equal to {@link #tldStr} for ASCII TLDs, but will be non-ASCII for IDN TLDs. We
* store this in a field so that it will be retained upon import into BigQuery.
*/
@Column(nullable = false)
String tldUnicode;
/**
@@ -334,9 +355,11 @@ public class Registry extends ImmutableObject implements Buildable {
*
* <p>This is optional; if not configured, then information won't be exported for this TLD.
*/
String driveFolderId;
@Nullable String driveFolderId;
/** The type of the TLD, whether it's real or for testing. */
@Column(nullable = false)
@Enumerated(EnumType.STRING)
TldType tldType = TldType.REAL;
/**
@@ -345,20 +368,24 @@ public class Registry extends ImmutableObject implements Buildable {
* <p>Note that this boolean is the sole determiner on whether invoices should be generated for a
* TLD. This applies to {@link TldType#TEST} TLDs as well.
*/
@Column(nullable = false)
boolean invoicingEnabled = false;
/**
* A property that transitions to different TldStates at different times. Stored as a list of
* TldStateTransition embedded objects using the @Mapify annotation.
*/
@Column(nullable = false)
@Mapify(TimedTransitionProperty.TimeMapper.class)
TimedTransitionProperty<TldState, TldStateTransition> tldStateTransitions =
TimedTransitionProperty.forMapify(DEFAULT_TLD_STATE, TldStateTransition.class);
/** An automatically managed creation timestamp. */
@Column(nullable = false)
CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
/** The set of reserved lists that are applicable to this registry. */
@Column(name = "reserved_list_names", nullable = false)
Set<Key<ReservedList>> reservedLists;
/** Retrieves an ImmutableSet of all ReservedLists associated with this tld. */
@@ -367,12 +394,15 @@ public class Registry extends ImmutableObject implements Buildable {
}
/** The static {@link PremiumList} for this TLD, if there is one. */
@Column(name = "premium_list_name", nullable = true)
Key<PremiumList> premiumList;
/** Should RDE upload a nightly escrow deposit for this TLD? */
@Column(nullable = false)
boolean escrowEnabled = DEFAULT_ESCROW_ENABLED;
/** Whether the pull queue that writes to authoritative DNS is paused for this TLD. */
@Column(nullable = false)
boolean dnsPaused = DEFAULT_DNS_PAUSED;
/**
@@ -381,41 +411,85 @@ public class Registry extends ImmutableObject implements Buildable {
* <p>Domain deletes are free and effective immediately so long as they take place within this
* amount of time following creation.
*/
@Column(nullable = false)
Duration addGracePeriodLength = DEFAULT_ADD_GRACE_PERIOD;
/** The length of the anchor tenant add grace period for this TLD. */
@Column(nullable = false)
Duration anchorTenantAddGracePeriodLength = DEFAULT_ANCHOR_TENANT_ADD_GRACE_PERIOD;
/** The length of the auto renew grace period for this TLD. */
@Column(nullable = false)
Duration autoRenewGracePeriodLength = DEFAULT_AUTO_RENEW_GRACE_PERIOD;
/** The length of the redemption grace period for this TLD. */
@Column(nullable = false)
Duration redemptionGracePeriodLength = DEFAULT_REDEMPTION_GRACE_PERIOD;
/** The length of the renew grace period for this TLD. */
@Column(nullable = false)
Duration renewGracePeriodLength = DEFAULT_RENEW_GRACE_PERIOD;
/** The length of the transfer grace period for this TLD. */
@Column(nullable = false)
Duration transferGracePeriodLength = DEFAULT_TRANSFER_GRACE_PERIOD;
/** The length of time before a transfer is automatically approved for this TLD. */
@Column(nullable = false)
Duration automaticTransferLength = DEFAULT_AUTOMATIC_TRANSFER_LENGTH;
/** The length of time a domain spends in the non-redeemable pending delete phase for this TLD. */
@Column(nullable = false)
Duration pendingDeleteLength = DEFAULT_PENDING_DELETE_LENGTH;
/** The currency unit for all costs associated with this TLD. */
@Column(nullable = false)
CurrencyUnit currency = DEFAULT_CURRENCY;
/** The per-year billing cost for registering a new domain name. */
@AttributeOverrides({
@AttributeOverride(
name = "money.amount",
column = @Column(name = "create_billing_cost_amount")),
@AttributeOverride(
name = "money.currency",
column = @Column(name = "create_billing_cost_currency"))
})
Money createBillingCost = DEFAULT_CREATE_BILLING_COST;
/** The one-time billing cost for restoring a domain name from the redemption grace period. */
@AttributeOverrides({
@AttributeOverride(
name = "money.amount",
column = @Column(name = "restore_billing_cost_amount")),
@AttributeOverride(
name = "money.currency",
column = @Column(name = "restore_billing_cost_currency"))
})
Money restoreBillingCost = DEFAULT_RESTORE_BILLING_COST;
/** The one-time billing cost for changing the server status (i.e. lock). */
@AttributeOverrides({
@AttributeOverride(
name = "money.amount",
column = @Column(name = "server_status_change_billing_cost_amount")),
@AttributeOverride(
name = "money.currency",
column = @Column(name = "server_status_change_billing_cost_currency"))
})
Money serverStatusChangeBillingCost = DEFAULT_SERVER_STATUS_CHANGE_BILLING_COST;
/** The one-time billing cost for a registry lock/unlock action initiated by a registrar. */
@AttributeOverrides({
@AttributeOverride(
name = "money.amount",
column = @Column(name = "registry_lock_or_unlock_cost_amount")),
@AttributeOverride(
name = "money.currency",
column = @Column(name = "registry_lock_or_unlock_cost_currency"))
})
Money registryLockOrUnlockBillingCost = DEFAULT_REGISTRY_LOCK_OR_UNLOCK_BILLING_COST;
/**
* A property that transitions to different renew billing costs at different times. Stored as a
* list of BillingCostTransition embedded objects using the @Mapify annotation.
@@ -424,11 +498,13 @@ public class Registry extends ImmutableObject implements Buildable {
* name. This cost is also used to compute costs for transfers, since each transfer includes a
* renewal to ensure transfers have a cost.
*/
@Column(nullable = false)
@Mapify(TimedTransitionProperty.TimeMapper.class)
TimedTransitionProperty<Money, BillingCostTransition> renewBillingCostTransitions =
TimedTransitionProperty.forMapify(DEFAULT_RENEW_BILLING_COST, BillingCostTransition.class);
/** A property that tracks the EAP fee schedule (if any) for the TLD. */
@Column(nullable = false)
@Mapify(TimedTransitionProperty.TimeMapper.class)
TimedTransitionProperty<Money, BillingCostTransition> eapFeeSchedule =
TimedTransitionProperty.forMapify(DEFAULT_EAP_BILLING_COST, BillingCostTransition.class);
@@ -437,13 +513,14 @@ public class Registry extends ImmutableObject implements Buildable {
String lordnUsername;
/** The end of the claims period (at or after this time, claims no longer applies). */
@Column(nullable = false)
DateTime claimsPeriodEnd = END_OF_TIME;
/** An allow list of clients allowed to be used on domains on this TLD (ignored if empty). */
Set<String> allowedRegistrantContactIds;
@Nullable Set<String> allowedRegistrantContactIds;
/** An allow list of hosts allowed to be used on domains on this TLD (ignored if empty). */
Set<String> allowedFullyQualifiedHostNames;
@Nullable Set<String> allowedFullyQualifiedHostNames;
public String getTldStr() {
return tldStr;
@@ -566,6 +643,11 @@ public class Registry extends ImmutableObject implements Buildable {
return serverStatusChangeBillingCost;
}
/** Returns the cost of a registry lock/unlock. */
public Money getRegistryLockOrUnlockBillingCost() {
return registryLockOrUnlockBillingCost;
}
public ImmutableSortedMap<DateTime, TldState> getTldStateTransitions() {
return tldStateTransitions.toValueMap();
}
@@ -867,6 +949,12 @@ public class Registry extends ImmutableObject implements Buildable {
return this;
}
public Builder setRegistryLockOrUnlockBillingCost(Money amount) {
checkArgument(amount.isPositiveOrZero(), "Registry lock/unlock cost cannot be negative");
getInstance().registryLockOrUnlockBillingCost = amount;
return this;
}
public Builder setLordnUsername(String username) {
getInstance().lordnUsername = username;
return this;
@@ -918,6 +1006,9 @@ public class Registry extends ImmutableObject implements Buildable {
checkArgument(
instance.getServerStatusChangeCost().getCurrencyUnit().equals(instance.currency),
"Server status change cost must be in the registry's currency");
checkArgument(
instance.getRegistryLockOrUnlockBillingCost().getCurrencyUnit().equals(instance.currency),
"Registry lock/unlock cost must be in the registry's currency");
Predicate<Money> currencyCheck =
(Money money) -> money.getCurrencyUnit().equals(instance.currency);
checkArgument(
@@ -43,7 +43,7 @@ public class ReservedListDualWriteDao {
/** Persist a new reserved list to Cloud SQL. */
public static void save(ReservedList reservedList) {
ofyTm().transact(() -> ofyTm().saveNewOrUpdate(reservedList));
ofyTm().transact(() -> ofyTm().put(reservedList));
try {
logger.atInfo().log("Saving reserved list %s to Cloud SQL", reservedList.getName());
ReservedListSqlDao.save(reservedList);
@@ -31,7 +31,7 @@ public class ReservedListSqlDao {
/** Persist a new reserved list to Cloud SQL. */
public static void save(ReservedList reservedList) {
checkArgumentNotNull(reservedList, "Must specify reservedList");
jpaTm().transact(() -> jpaTm().saveNew(reservedList));
jpaTm().transact(() -> jpaTm().insert(reservedList));
}
/**
@@ -19,8 +19,16 @@ import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.annotation.Embed;
import com.googlecode.objectify.annotation.Ignore;
import google.registry.model.Buildable;
import google.registry.model.ImmutableObject;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.joda.time.DateTime;
/**
@@ -34,9 +42,16 @@ import org.joda.time.DateTime;
* uses HistoryEntry.otherClientId because the losing party in a transfer is always the otherClient.
*/
@Embed
@Entity
public class DomainTransactionRecord extends ImmutableObject implements Buildable {
@Id
@Ignore
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
/** The TLD this record operates on. */
@Column(nullable = false)
String tld;
/**
@@ -50,9 +65,12 @@ public class DomainTransactionRecord extends ImmutableObject implements Buildabl
* href="https://www.icann.org/resources/unthemed-pages/registry-agmt-appc-10-2001-05-11-en">
* Grace period spec</a>
*/
@Column(nullable = false)
DateTime reportingTime;
/** The transaction report field we add reportAmount to for this registrar. */
@Column(nullable = false)
@Enumerated(value = EnumType.STRING)
TransactionReportField reportField;
/**
@@ -67,6 +85,7 @@ public class DomainTransactionRecord extends ImmutableObject implements Buildabl
* original SUCCESSFUL transfer counters. Finally, if we explicitly allow a transfer, the report
* amount is 0, as we've already counted the transfer in the original request.
*/
@Column(nullable = false)
Integer reportAmount;
/**
@@ -178,7 +178,7 @@ public class HistoryEntry extends ImmutableObject implements Buildable, Datastor
boolean bySuperuser;
/** Reason for the change. */
@Column(nullable = false, name = "historyReason")
@Column(name = "historyReason")
String reason;
/** Whether this change was requested by a registrar. */
@@ -202,7 +202,7 @@ public class HistoryEntry extends ImmutableObject implements Buildable, Datastor
return id == null ? 0L : id;
}
// This method is required by Hibernate.
/** This method exists solely to satisfy Hibernate. Use the {@link Builder} instead. */
@SuppressWarnings("UnusedMethod")
private void setId(long id) {
this.id = id;
@@ -254,10 +254,28 @@ public class HistoryEntry extends ImmutableObject implements Buildable, Datastor
return requestedByRegistrar;
}
public ImmutableSet<DomainTransactionRecord> getDomainTransactionRecords() {
public Set<DomainTransactionRecord> getDomainTransactionRecords() {
return nullToEmptyImmutableCopy(domainTransactionRecords);
}
/** This method exists solely to satisfy Hibernate. Use the {@link Builder} instead. */
@SuppressWarnings("UnusedMethod")
private void setPeriod(Period period) {
this.period = period;
}
/** This method exists solely to satisfy Hibernate. Use the {@link Builder} instead. */
@SuppressWarnings("UnusedMethod")
private void setOtherRegistrarId(String otherRegistrarId) {
this.otherClientId = otherRegistrarId;
}
/** This method exists solely to satisfy Hibernate. Use the {@link Builder} instead. */
@SuppressWarnings("UnusedMethod")
private void setDomainTransactionRecords(Set<DomainTransactionRecord> domainTransactionRecords) {
this.domainTransactionRecords = ImmutableSet.copyOf(domainTransactionRecords);
}
public static VKey<HistoryEntry> createVKey(Key<HistoryEntry> key) {
// TODO(b/159207551): This will likely need some revision. As it stands, this method was
// introduced purely to facilitate testing of VKey specialization in VKeyTranslatorFactory.
@@ -346,7 +364,10 @@ public class HistoryEntry extends ImmutableObject implements Buildable, Datastor
setBySuperuser(historyEntry.bySuperuser);
setReason(historyEntry.reason);
setRequestedByRegistrar(historyEntry.requestedByRegistrar);
setDomainTransactionRecords(nullToEmptyImmutableCopy(historyEntry.domainTransactionRecords));
setDomainTransactionRecords(
historyEntry.domainTransactionRecords == null
? null
: ImmutableSet.copyOf(historyEntry.domainTransactionRecords));
return thisCastToDerived();
}
@@ -32,7 +32,11 @@ public class CreateAutoTimestampConverter
implements AttributeConverter<CreateAutoTimestamp, Timestamp> {
@Override
public Timestamp convertToDatabaseColumn(CreateAutoTimestamp entity) {
@Nullable
public Timestamp convertToDatabaseColumn(@Nullable CreateAutoTimestamp entity) {
if (entity == null) {
return null;
}
DateTime dateTime = firstNonNull(entity.getTimestamp(), jpaTm().getTransactionTime());
return Timestamp.from(DateTimeUtils.toZonedDateTime(dateTime).toInstant());
}
@@ -18,20 +18,19 @@ import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import com.googlecode.objectify.Key;
import google.registry.model.registry.label.ReservedList;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
/** JPA converter for a {@link Key} containing a {@link ReservedList} */
/** JPA converter for a set of {@link Key} containing a {@link ReservedList} */
@Converter(autoApply = true)
public class ReservedListKeyConverter implements AttributeConverter<Key<ReservedList>, String> {
public class ReservedListKeySetConverter extends StringSetConverterBase<Key<ReservedList>> {
@Override
public String convertToDatabaseColumn(Key<ReservedList> attribute) {
return (attribute == null) ? null : attribute.getName();
String toString(Key<ReservedList> key) {
return key.getName();
}
@Override
public Key<ReservedList> convertToEntityAttribute(String dbData) {
return (dbData == null) ? null : Key.create(getCrossTldKey(), ReservedList.class, dbData);
Key<ReservedList> fromString(String value) {
return Key.create(getCrossTldKey(), ReservedList.class, value);
}
}
@@ -224,7 +224,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
@Override
public void saveNew(Object entity) {
public void insert(Object entity) {
checkArgumentNotNull(entity, "entity must be specified");
assertInTransaction();
getEntityManager().persist(entity);
@@ -232,14 +232,14 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
@Override
public void saveAllNew(ImmutableCollection<?> entities) {
public void insertAll(ImmutableCollection<?> entities) {
checkArgumentNotNull(entities, "entities must be specified");
assertInTransaction();
entities.forEach(this::saveNew);
entities.forEach(this::insert);
}
@Override
public void saveNewOrUpdate(Object entity) {
public void put(Object entity) {
checkArgumentNotNull(entity, "entity must be specified");
assertInTransaction();
getEntityManager().merge(entity);
@@ -247,17 +247,17 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
@Override
public void saveNewOrUpdateAll(ImmutableCollection<?> entities) {
public void putAll(ImmutableCollection<?> entities) {
checkArgumentNotNull(entities, "entities must be specified");
assertInTransaction();
entities.forEach(this::saveNewOrUpdate);
entities.forEach(this::put);
}
@Override
public void update(Object entity) {
checkArgumentNotNull(entity, "entity must be specified");
assertInTransaction();
checkArgument(checkExists(entity), "Given entity does not exist");
checkArgument(exists(entity), "Given entity does not exist");
getEntityManager().merge(entity);
transactionInfo.get().addUpdate(entity);
}
@@ -270,22 +270,22 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
@Override
public <T> boolean checkExists(VKey<T> key) {
public <T> boolean exists(VKey<T> key) {
checkArgumentNotNull(key, "key must be specified");
EntityType<?> entityType = getEntityType(key.getKind());
ImmutableSet<EntityId> entityIds = getEntityIdsFromSqlKey(entityType, key.getSqlKey());
return checkExists(entityType.getName(), entityIds);
return exists(entityType.getName(), entityIds);
}
@Override
public boolean checkExists(Object entity) {
public boolean exists(Object entity) {
checkArgumentNotNull(entity, "entity must be specified");
EntityType<?> entityType = getEntityType(entity.getClass());
ImmutableSet<EntityId> entityIds = getEntityIdsFromEntity(entityType, entity);
return checkExists(entityType.getName(), entityIds);
return exists(entityType.getName(), entityIds);
}
private boolean checkExists(String entityName, ImmutableSet<EntityId> entityIds) {
private boolean exists(String entityName, ImmutableSet<EntityId> entityIds) {
assertInTransaction();
TypedQuery<Integer> query =
getEntityManager()
@@ -391,7 +391,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
private static ImmutableSet<EntityId> getEntityIdsFromEntity(
EntityType<?> entityType, Object entity) {
if (entityType.hasSingleIdAttribute()) {
String idName = entityType.getDeclaredId(entityType.getIdType().getJavaType()).getName();
String idName = entityType.getId(entityType.getIdType().getJavaType()).getName();
Object idValue = getFieldValue(entity, idName);
return ImmutableSet.of(new EntityId(idName, idValue));
} else {
@@ -402,7 +402,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
private static ImmutableSet<EntityId> getEntityIdsFromSqlKey(
EntityType<?> entityType, Object sqlKey) {
if (entityType.hasSingleIdAttribute()) {
String idName = entityType.getDeclaredId(entityType.getIdType().getJavaType()).getName();
String idName = entityType.getId(entityType.getIdType().getJavaType()).getName();
return ImmutableSet.of(new EntityId(idName, sqlKey));
} else {
return getEntityIdsFromIdContainer(entityType, sqlKey);
@@ -429,7 +429,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
private static Object getFieldValue(Object object, String fieldName) {
try {
Field field = object.getClass().getDeclaredField(fieldName);
Field field = getField(object.getClass(), fieldName);
field.setAccessible(true);
return field.get(object);
} catch (NoSuchFieldException | IllegalAccessException e) {
@@ -437,6 +437,21 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
}
/** Gets the field definition from clazz or any superclass. */
private static Field getField(Class clazz, String fieldName) throws NoSuchFieldException {
try {
// Note that we have to use getDeclaredField() for this, getField() just finds public fields.
return clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
Class base = clazz.getSuperclass();
if (base != null) {
return getField(base, fieldName);
} else {
throw e;
}
}
}
private static class TransactionInfo {
EntityManager entityManager;
boolean inTransaction = false;
@@ -208,7 +208,7 @@ public class Transaction extends ImmutableObject implements Buildable {
@Override
public void writeToDatastore() {
ofyTm().saveNewOrUpdate(entity);
ofyTm().put(entity);
}
@Override
@@ -86,16 +86,16 @@ public interface TransactionManager {
DateTime getTransactionTime();
/** Persists a new entity in the database, throws exception if the entity already exists. */
void saveNew(Object entity);
void insert(Object entity);
/** Persists all new entities in the database, throws exception if any entity already exists. */
void saveAllNew(ImmutableCollection<?> entities);
void insertAll(ImmutableCollection<?> entities);
/** Persists a new entity or update the existing entity in the database. */
void saveNewOrUpdate(Object entity);
void put(Object entity);
/** Persists all new entities or update the existing entities in the database. */
void saveNewOrUpdateAll(ImmutableCollection<?> entities);
void putAll(ImmutableCollection<?> entities);
/** Updates an entity in the database, throws exception if the entity does not exist. */
void update(Object entity);
@@ -104,10 +104,10 @@ public interface TransactionManager {
void updateAll(ImmutableCollection<?> entities);
/** Returns whether the given entity with same ID exists. */
boolean checkExists(Object entity);
boolean exists(Object entity);
/** Returns whether the entity of given key exists. */
<T> boolean checkExists(VKey<T> key);
<T> boolean exists(VKey<T> key);
/** Loads the entity by its id, returns empty if the entity doesn't exist. */
<T> Optional<T> maybeLoad(VKey<T> key);
@@ -116,14 +116,10 @@ public class IcannHttpReporter {
// 1000 (i. e. success), there is no need to parse it.
if (response.getStatusCode() == HttpStatusCodes.STATUS_CODE_BAD_REQUEST) {
success = false;
// To debug if there is a problem with our parsing, we wrap the response and print the stack
// trace of it. As far as we can tell, the stack trace for such an exception contains the
// response content that is decoded correctly using the expected charset.
new HttpResponseException(response).printStackTrace();
XjcIirdeaResult result = parseResult(content);
logger.atWarning().log(
"PUT rejected, status code %s:\n%s\n%s",
result.getCode(), result.getMsg(), result.getDescription());
result.getCode().getValue(), result.getMsg(), result.getDescription());
}
} finally {
if (response != null) {
@@ -110,6 +110,12 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
description = "One-time billing cost for a server status change")
private Money serverStatusChangeCost;
@Nullable
@Parameter(
names = "--registry_lock_or_unlock_cost",
description = "One-time billing cost for a registry lock or unlock")
private Money registryLockOrUnlockCost;
@Nullable
@Parameter(
names = "--tld_type",
@@ -326,6 +332,8 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
Optional.ofNullable(roidSuffix).ifPresent(builder::setRoidSuffix);
Optional.ofNullable(serverStatusChangeCost)
.ifPresent(builder::setServerStatusChangeBillingCost);
Optional.ofNullable(registryLockOrUnlockCost)
.ifPresent(builder::setRegistryLockOrUnlockBillingCost);
Optional.ofNullable(tldType).ifPresent(builder::setTldType);
Optional.ofNullable(invoicingEnabled).ifPresent(builder::setInvoicingEnabled);
Optional.ofNullable(lordnUsername).ifPresent(u -> builder.setLordnUsername(u.orElse(null)));
@@ -72,7 +72,7 @@ final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand
@Override
void saveToCloudSql(Registrar registrar) {
jpaTm().saveNew(registrar);
jpaTm().insert(registrar);
}
@Nullable
@@ -380,7 +380,7 @@ public final class DomainLockUtils {
.setReason(Reason.SERVER_STATUS)
.setTargetId(domain.getForeignKey())
.setClientId(domain.getCurrentSponsorClientId())
.setCost(Registry.get(domain.getTld()).getServerStatusChangeCost())
.setCost(Registry.get(domain.getTld()).getRegistryLockOrUnlockBillingCost())
.setEventTime(now)
.setBillingTime(now)
.setParent(historyEntry)
+4 -1
View File
@@ -11,7 +11,10 @@
</attributes>
</embeddable>
<sequence-generator name="HistorySequenceGenerator" sequence-name="history_id_sequence" />
<sequence-generator name="HistorySequenceGenerator" sequence-name="history_id_sequence"/>
<!-- TODO(shicong): Drop this sequence and change all history tables to use the above one. -->
<sequence-generator name="TempHistorySequenceGenerator" sequence-name="temp_history_id_sequence"/>
<persistence-unit-metadata>
<persistence-unit-defaults>
@@ -45,25 +45,27 @@
<class>google.registry.model.contact.ContactResource</class>
<class>google.registry.model.domain.DomainBase</class>
<class>google.registry.model.domain.DomainHistory</class>
<class>google.registry.model.domain.GracePeriod</class>
<class>google.registry.model.domain.secdns.DelegationSignerData</class>
<class>google.registry.model.domain.token.AllocationToken</class>
<class>google.registry.model.host.HostHistory</class>
<class>google.registry.model.host.HostResource</class>
<class>google.registry.model.registrar.Registrar</class>
<class>google.registry.model.registrar.RegistrarContact</class>
<class>google.registry.model.registry.label.PremiumList</class>
<class>google.registry.model.reporting.Spec11ThreatMatch</class>
<class>google.registry.persistence.transaction.TransactionEntity</class>
<class>google.registry.model.tmch.ClaimsListShard</class>
<class>google.registry.schema.domain.RegistryLock</class>
<class>google.registry.schema.cursor.Cursor</class>
<class>google.registry.schema.server.Lock</class>
<class>google.registry.schema.tld.PremiumEntry</class>
<class>google.registry.model.domain.secdns.DelegationSignerData</class>
<class>google.registry.model.domain.GracePeriod</class>
<class>google.registry.model.poll.PollMessage</class>
<class>google.registry.model.poll.PollMessage$OneTime</class>
<class>google.registry.model.poll.PollMessage$Autorenew</class>
<class>google.registry.model.registrar.Registrar</class>
<class>google.registry.model.registrar.RegistrarContact</class>
<class>google.registry.model.registry.label.PremiumList</class>
<class>google.registry.model.registry.label.ReservedList</class>
<class>google.registry.model.registry.Registry</class>
<class>google.registry.model.reporting.DomainTransactionRecord</class>
<class>google.registry.model.reporting.Spec11ThreatMatch</class>
<class>google.registry.model.tmch.ClaimsListShard</class>
<class>google.registry.persistence.transaction.TransactionEntity</class>
<class>google.registry.schema.cursor.Cursor</class>
<class>google.registry.schema.domain.RegistryLock</class>
<class>google.registry.schema.server.Lock</class>
<class>google.registry.schema.tld.PremiumEntry</class>
<!-- Customized type converters -->
<class>google.registry.persistence.converter.AllocationTokenStatusTransitionConverter</class>
@@ -81,7 +83,7 @@
<class>google.registry.persistence.converter.PostalInfoChoiceListConverter</class>
<class>google.registry.persistence.converter.PremiumListKeyConverter</class>
<class>google.registry.persistence.converter.RegistrarPocSetConverter</class>
<class>google.registry.persistence.converter.ReservedListKeyConverter</class>
<class>google.registry.persistence.converter.ReservedListKeySetConverter</class>
<class>google.registry.persistence.converter.Spec11ThreatMatchThreatTypeSetConverter</class>
<class>google.registry.persistence.converter.StatusValueSetConverter</class>
<class>google.registry.persistence.converter.StringListConverter</class>
@@ -85,7 +85,7 @@ class WriteToSqlTest implements Serializable {
// Required for contacts created below.
Registrar ofyRegistrar = AppEngineExtension.makeRegistrar2();
store.insertOrUpdate(ofyRegistrar);
jpaTm().transact(() -> jpaTm().saveNewOrUpdate(store.loadAsOfyEntity(ofyRegistrar)));
jpaTm().transact(() -> jpaTm().put(store.loadAsOfyEntity(ofyRegistrar)));
ImmutableList.Builder<Entity> builder = new ImmutableList.Builder<>();
@@ -285,7 +285,7 @@ class Spec11PipelineTest {
.build();
verify(mockJpaTm).transact(any(Runnable.class));
verify(mockJpaTm).saveNew(expected);
verify(mockJpaTm).insert(expected);
verifyNoMoreInteractions(mockJpaTm);
}
@@ -597,6 +597,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
.setRestoreBillingCost(Money.of(EUR, 11))
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setRegistryLockOrUnlockBillingCost(Money.of(EUR, 20))
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
@@ -615,6 +616,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
.setRestoreBillingCost(Money.of(EUR, 11))
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setRegistryLockOrUnlockBillingCost(Money.of(EUR, 20))
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
@@ -633,6 +635,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
.setRestoreBillingCost(Money.of(EUR, 11))
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setRegistryLockOrUnlockBillingCost(Money.of(EUR, 20))
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
@@ -533,6 +533,7 @@ class DomainRestoreRequestFlowTest
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.setRegistryLockOrUnlockBillingCost(Money.of(EUR, 0))
.build());
EppException thrown = assertThrows(CurrencyUnitMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
@@ -32,17 +32,25 @@ import javax.annotation.Nullable;
/** Truth subject for asserting things about ImmutableObjects that are not built in. */
public final class ImmutableObjectSubject extends Subject {
private final ImmutableObject actual;
@Nullable private final ImmutableObject actual;
protected ImmutableObjectSubject(FailureMetadata failureMetadata, ImmutableObject actual) {
protected ImmutableObjectSubject(
FailureMetadata failureMetadata, @Nullable ImmutableObject actual) {
super(failureMetadata, actual);
this.actual = actual;
}
public void isEqualExceptFields(ImmutableObject expected, String... ignoredFields) {
Map<Field, Object> actualFields = filterFields(actual, ignoredFields);
Map<Field, Object> expectedFields = filterFields(expected, ignoredFields);
assertThat(actualFields).containsExactlyEntriesIn(expectedFields);
public void isEqualExceptFields(@Nullable ImmutableObject expected, String... ignoredFields) {
if (actual == null) {
assertThat(expected).isNull();
} else {
assertThat(expected).isNotNull();
}
if (actual != null) {
Map<Field, Object> actualFields = filterFields(actual, ignoredFields);
Map<Field, Object> expectedFields = filterFields(expected, ignoredFields);
assertThat(actualFields).containsExactlyEntriesIn(expectedFields);
}
}
public static Correspondence<ImmutableObject, ImmutableObject> immutableObjectCorrespondence(
@@ -180,7 +180,7 @@ public class BillingEventTest extends EntityTestCase {
private void saveNewBillingEvent(BillingEvent billingEvent) {
billingEvent.id = null;
jpaTm().transact(() -> jpaTm().saveNew(billingEvent));
jpaTm().transact(() -> jpaTm().insert(billingEvent));
}
@Test
@@ -124,7 +124,7 @@ public class ContactResourceTest extends EntityTestCase {
@Test
void testCloudSqlPersistence_failWhenViolateForeignKeyConstraint() {
assertThrowForeignKeyViolation(() -> jpaTm().transact(() -> jpaTm().saveNew(originalContact)));
assertThrowForeignKeyViolation(() -> jpaTm().transact(() -> jpaTm().insert(originalContact)));
}
@Test
@@ -134,7 +134,7 @@ public class ContactResourceTest extends EntityTestCase {
saveRegistrar("registrar3");
saveRegistrar("gaining");
saveRegistrar("losing");
jpaTm().transact(() -> jpaTm().saveNew(originalContact));
jpaTm().transact(() -> jpaTm().insert(originalContact));
ContactResource persisted =
jpaTm()
.transact(
@@ -139,9 +139,9 @@ public class DomainBaseSqlTest {
.transact(
() -> {
// Persist the domain without the associated host object.
jpaTm().saveNew(contact);
jpaTm().saveNew(contact2);
jpaTm().saveNew(domain);
jpaTm().insert(contact);
jpaTm().insert(contact2);
jpaTm().insert(domain);
}));
}
@@ -153,8 +153,8 @@ public class DomainBaseSqlTest {
.transact(
() -> {
// Persist the domain without the associated contact objects.
jpaTm().saveNew(domain);
jpaTm().saveNew(host);
jpaTm().insert(domain);
jpaTm().insert(host);
}));
}
@@ -165,7 +165,7 @@ public class DomainBaseSqlTest {
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
jpaTm().saveNewOrUpdate(persisted.asBuilder().build());
jpaTm().put(persisted.asBuilder().build());
});
jpaTm()
.transact(
@@ -185,7 +185,7 @@ public class DomainBaseSqlTest {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase modified =
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
jpaTm().saveNewOrUpdate(modified);
jpaTm().put(modified);
});
jpaTm()
@@ -204,7 +204,7 @@ public class DomainBaseSqlTest {
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase modified = persisted.asBuilder().setGracePeriods(null).build();
jpaTm().saveNewOrUpdate(modified);
jpaTm().put(modified);
});
jpaTm()
@@ -229,7 +229,7 @@ public class DomainBaseSqlTest {
GracePeriod.create(
GracePeriodStatus.RENEW, "4-COM", END_OF_TIME, "registrar1", null))
.build();
jpaTm().saveNewOrUpdate(modified);
jpaTm().put(modified);
});
jpaTm()
@@ -281,7 +281,7 @@ public class DomainBaseSqlTest {
builder.removeGracePeriod(gracePeriod);
}
}
jpaTm().saveNewOrUpdate(builder.build());
jpaTm().put(builder.build());
});
jpaTm()
@@ -301,7 +301,7 @@ public class DomainBaseSqlTest {
DomainBase persisted = jpaTm().load(domain.createVKey());
DomainBase modified =
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
jpaTm().saveNewOrUpdate(modified);
jpaTm().put(modified);
});
jpaTm()
@@ -316,7 +316,7 @@ public class DomainBaseSqlTest {
GracePeriod.create(
GracePeriodStatus.ADD, "4-COM", END_OF_TIME, "registrar1", null))
.build();
jpaTm().saveNewOrUpdate(modified);
jpaTm().put(modified);
});
jpaTm()
@@ -339,13 +339,13 @@ public class DomainBaseSqlTest {
jpaTm()
.transact(
() -> {
jpaTm().saveNew(contact);
jpaTm().saveNew(contact2);
jpaTm().saveNew(domain);
jpaTm().saveNew(host);
jpaTm().insert(contact);
jpaTm().insert(contact2);
jpaTm().insert(domain);
jpaTm().insert(host);
});
domain = domain.asBuilder().setNameservers(ImmutableSet.of()).build();
jpaTm().transact(() -> jpaTm().saveNewOrUpdate(domain));
jpaTm().transact(() -> jpaTm().put(domain));
jpaTm()
.transact(
() -> {
@@ -382,16 +382,16 @@ public class DomainBaseSqlTest {
// Persist the contacts. Note that these need to be persisted before the domain
// otherwise we get a foreign key constraint error. If we ever decide to defer the
// relevant foreign key checks to commit time, then the order would not matter.
jpaTm().saveNew(contact);
jpaTm().saveNew(contact2);
jpaTm().insert(contact);
jpaTm().insert(contact2);
// Persist the domain.
jpaTm().saveNew(domain);
jpaTm().insert(domain);
// Persist the host. This does _not_ need to be persisted before the domain,
// because only the row in the join table (DomainHost) is subject to foreign key
// constraints, and Hibernate knows to insert it after domain and host.
jpaTm().saveNew(host);
jpaTm().insert(host);
});
}
@@ -95,8 +95,8 @@ public class AllocationTokenTest extends EntityTestCase {
jpaTm()
.transact(
() -> {
jpaTm().saveNew(unlimitedUseToken);
jpaTm().saveNew(singleUseToken);
jpaTm().insert(unlimitedUseToken);
jpaTm().insert(singleUseToken);
});
jpaTm()
.transact(
@@ -44,16 +44,41 @@ public class ContactHistoryTest extends EntityTestCase {
saveRegistrar("TheRegistrar");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
jpaTm().transact(() -> jpaTm().saveNew(contact));
jpaTm().transact(() -> jpaTm().insert(contact));
VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().load(contactVKey));
ContactHistory contactHistory = createContactHistory(contactFromDb, contactVKey);
contactHistory.id = null;
jpaTm().transact(() -> jpaTm().saveNew(contactHistory));
jpaTm().transact(() -> jpaTm().insert(contactHistory));
jpaTm()
.transact(
() -> {
ContactHistory fromDatabase = jpaTm().load(VKey.createSql(ContactHistory.class, 1L));
ContactHistory fromDatabase =
jpaTm().load(VKey.createSql(ContactHistory.class, contactHistory.getId()));
assertContactHistoriesEqual(fromDatabase, contactHistory);
assertThat(fromDatabase.getContactRepoId().getSqlKey())
.isEqualTo(contactHistory.getContactRepoId().getSqlKey());
});
}
@Test
void testLegacyPersistence_nullContactBase() {
saveRegistrar("TheRegistrar");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
jpaTm().transact(() -> jpaTm().insert(contact));
VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().load(contactVKey));
ContactHistory contactHistory =
createContactHistory(contactFromDb, contactVKey).asBuilder().setContactBase(null).build();
contactHistory.id = null;
jpaTm().transact(() -> jpaTm().insert(contactHistory));
jpaTm()
.transact(
() -> {
ContactHistory fromDatabase =
jpaTm().load(VKey.createSql(ContactHistory.class, contactHistory.getId()));
assertContactHistoriesEqual(fromDatabase, contactHistory);
assertThat(fromDatabase.getContactRepoId().getSqlKey())
.isEqualTo(contactHistory.getContactRepoId().getSqlKey());
@@ -65,12 +90,12 @@ public class ContactHistoryTest extends EntityTestCase {
saveRegistrar("TheRegistrar");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
tm().transact(() -> tm().saveNew(contact));
tm().transact(() -> tm().insert(contact));
VKey<ContactResource> contactVKey = contact.createVKey();
ContactResource contactFromDb = tm().transact(() -> tm().load(contactVKey));
fakeClock.advanceOneMilli();
ContactHistory contactHistory = createContactHistory(contactFromDb, contactVKey);
tm().transact(() -> tm().saveNew(contactHistory));
tm().transact(() -> tm().insert(contactHistory));
// retrieving a HistoryEntry or a ContactHistory with the same key should return the same object
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
@@ -106,7 +131,7 @@ public class ContactHistoryTest extends EntityTestCase {
.that(one)
.isEqualExceptFields(two, "contactBase", "contactRepoId", "parent");
assertAboutImmutableObjects()
.that(one.getContactBase())
.isEqualExceptFields(two.getContactBase(), "repoId");
.that(one.getContactBase().orElse(null))
.isEqualExceptFields(two.getContactBase().orElse(null), "repoId");
}
}
@@ -17,6 +17,7 @@ package google.registry.model.history;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatastoreHelper.newContactResourceWithRoid;
@@ -25,16 +26,21 @@ import static google.registry.testing.DatastoreHelper.newHostResourceWithRoid;
import static google.registry.testing.SqlHelper.saveRegistrar;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainContent;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.Period;
import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostResource;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Tests for {@link DomainHistory}. */
@@ -44,30 +50,35 @@ public class DomainHistoryTest extends EntityTestCase {
super(JpaEntityCoverageCheck.ENABLED);
}
@BeforeEach
void beforeEach() {
saveRegistrar("TheRegistrar");
}
@Test
void testPersistence() {
saveRegistrar("TheRegistrar");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
DomainBase domain = createDomainWithContactsAndHosts();
DomainHistory domainHistory = createDomainHistory(domain);
domainHistory.id = null;
jpaTm().transact(() -> jpaTm().insert(domainHistory));
jpaTm()
.transact(
() -> {
jpaTm().saveNew(host);
jpaTm().saveNew(contact);
DomainHistory fromDatabase = jpaTm().load(domainHistory.createVKey());
assertDomainHistoriesEqual(fromDatabase, domainHistory);
assertThat(fromDatabase.getDomainRepoId().getSqlKey())
.isEqualTo(domainHistory.getDomainRepoId().getSqlKey());
});
}
DomainBase domain =
newDomainBase("example.tld", "domainRepoId", contact)
.asBuilder()
.setNameservers(host.createVKey())
.build();
jpaTm().transact(() -> jpaTm().saveNew(domain));
DomainHistory domainHistory = createDomainHistory(domain);
@Test
void testLegacyPersistence_nullResource() {
DomainBase domain = createDomainWithContactsAndHosts();
DomainHistory domainHistory =
createDomainHistory(domain).asBuilder().setDomainContent(null).build();
domainHistory.id = null;
jpaTm().transact(() -> jpaTm().saveNew(domainHistory));
jpaTm().transact(() -> jpaTm().insert(domainHistory));
jpaTm()
.transact(
@@ -86,15 +97,13 @@ public class DomainHistoryTest extends EntityTestCase {
@Test
void testOfyPersistence() {
saveRegistrar("TheRegistrar");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
tm().transact(
() -> {
tm().saveNew(host);
tm().saveNew(contact);
tm().insert(host);
tm().insert(contact);
});
fakeClock.advanceOneMilli();
@@ -103,14 +112,14 @@ public class DomainHistoryTest extends EntityTestCase {
.asBuilder()
.setNameservers(host.createVKey())
.build();
tm().transact(() -> tm().saveNew(domain));
tm().transact(() -> tm().insert(domain));
fakeClock.advanceOneMilli();
DomainHistory domainHistory = createDomainHistory(domain);
tm().transact(() -> tm().saveNew(domainHistory));
tm().transact(() -> tm().insert(domainHistory));
// retrieving a HistoryEntry or a DomainHistory with the same key should return the same object
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
// note: due to the @EntitySubclass annotation. all Keys for DomainHistory objects will have
// type HistoryEntry
VKey<DomainHistory> domainHistoryVKey =
VKey.createOfy(DomainHistory.class, Key.create(domainHistory));
@@ -122,13 +131,49 @@ public class DomainHistoryTest extends EntityTestCase {
assertThat(domainHistoryFromDb).isEqualTo(historyEntryFromDb);
}
static DomainBase createDomainWithContactsAndHosts() {
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
jpaTm()
.transact(
() -> {
jpaTm().insert(host);
jpaTm().insert(contact);
});
DomainBase domain =
newDomainBase("example.tld", "domainRepoId", contact)
.asBuilder()
.setNameservers(host.createVKey())
.build();
jpaTm().transact(() -> jpaTm().insert(domain));
return domain;
}
static void assertDomainHistoriesEqual(DomainHistory one, DomainHistory two) {
assertAboutImmutableObjects()
.that(one)
.isEqualExceptFields(two, "domainContent", "domainRepoId", "parent", "nsHosts");
.isEqualExceptFields(
two, "domainContent", "domainRepoId", "parent", "nsHosts", "domainTransactionRecords");
assertThat(one.getDomainContent().map(DomainContent::getDomainName))
.isEqualTo(two.getDomainContent().map(DomainContent::getDomainName));
// NB: the record's ID gets reset by Hibernate, causing the hash code to differ so we have to
// compare it separately
assertThat(one.getDomainTransactionRecords())
.comparingElementsUsing(immutableObjectCorrespondence())
.containsExactlyElementsIn(two.getDomainTransactionRecords());
}
private DomainHistory createDomainHistory(DomainContent domain) {
DomainTransactionRecord transactionRecord =
new DomainTransactionRecord.Builder()
.setTld("tld")
.setReportingTime(fakeClock.nowUtc())
.setReportField(TransactionReportField.NET_ADDS_1_YR)
.setReportAmount(1)
.build();
return new DomainHistory.Builder()
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
@@ -140,6 +185,9 @@ public class DomainHistoryTest extends EntityTestCase {
.setRequestedByRegistrar(true)
.setDomainContent(domain)
.setDomainRepoId(domain.getRepoId())
.setDomainTransactionRecords(ImmutableSet.of(transactionRecord))
.setOtherClientId("otherClient")
.setPeriod(Period.create(1, Period.Unit.YEARS))
.build();
}
}
@@ -1,4 +1,4 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -44,12 +44,13 @@ public class HostHistoryTest extends EntityTestCase {
saveRegistrar("TheRegistrar");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
jpaTm().transact(() -> jpaTm().saveNew(host));
VKey<HostResource> hostVKey = VKey.createSql(HostResource.class, "host1");
jpaTm().transact(() -> jpaTm().insert(host));
VKey<HostResource> hostVKey =
VKey.create(HostResource.class, "host1", Key.create(HostResource.class, "host1"));
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().load(hostVKey));
HostHistory hostHistory = createHostHistory(hostFromDb, hostVKey);
hostHistory.id = null;
jpaTm().transact(() -> jpaTm().saveNew(hostHistory));
jpaTm().transact(() -> jpaTm().insert(hostHistory));
jpaTm()
.transact(
() -> {
@@ -62,19 +63,46 @@ public class HostHistoryTest extends EntityTestCase {
}
@Test
public void testOfySave() {
void testLegacyPersistence_nullHostBase() {
saveRegistrar("TheRegistrar");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
jpaTm().transact(() -> jpaTm().insert(host));
VKey<HostResource> hostVKey =
VKey.create(HostResource.class, "host1", Key.create(HostResource.class, "host1"));
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().load(hostVKey));
HostHistory hostHistory =
createHostHistory(hostFromDb, hostVKey).asBuilder().setHostBase(null).build();
hostHistory.id = null;
jpaTm().transact(() -> jpaTm().insert(hostHistory));
jpaTm()
.transact(
() -> {
HostHistory fromDatabase =
jpaTm().load(VKey.createSql(HostHistory.class, hostHistory.getId()));
assertHostHistoriesEqual(fromDatabase, hostHistory);
assertThat(fromDatabase.getHostRepoId().getSqlKey())
.isEqualTo(hostHistory.getHostRepoId().getSqlKey());
});
}
@Test
void testOfySave() {
saveRegistrar("registrar1");
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
tm().transact(() -> tm().saveNew(host));
VKey<HostResource> hostVKey = VKey.create(HostResource.class, "host1", Key.create(host));
tm().transact(() -> tm().insert(host));
VKey<HostResource> hostVKey =
VKey.create(HostResource.class, "host1", Key.create(HostResource.class, "host1"));
HostResource hostFromDb = tm().transact(() -> tm().load(hostVKey));
HostHistory hostHistory = createHostHistory(hostFromDb, hostVKey);
fakeClock.advanceOneMilli();
tm().transact(() -> tm().saveNew(hostHistory));
tm().transact(() -> tm().insert(hostHistory));
// retrieving a HistoryEntry or a HostHistory with the same key should return the same object
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
// note: due to the @EntitySubclass annotation. all Keys for HostHistory objects will have
// type HistoryEntry
VKey<HostHistory> hostHistoryVKey = VKey.createOfy(HostHistory.class, Key.create(hostHistory));
VKey<HistoryEntry> historyEntryVKey =
@@ -88,8 +116,8 @@ public class HostHistoryTest extends EntityTestCase {
private void assertHostHistoriesEqual(HostHistory one, HostHistory two) {
assertAboutImmutableObjects().that(one).isEqualExceptFields(two, "hostBase");
assertAboutImmutableObjects()
.that(one.getHostBase())
.isEqualExceptFields(two.getHostBase(), "repoId");
.that(one.getHostBase().orElse(null))
.isEqualExceptFields(two.getHostBase().orElse(null), "repoId");
}
private HostHistory createHostHistory(HostBase hostBase, VKey<HostResource> hostVKey) {
@@ -0,0 +1,211 @@
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.model.history;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatastoreHelper.newContactResourceWithRoid;
import static google.registry.testing.DatastoreHelper.newHostResourceWithRoid;
import static google.registry.testing.SqlHelper.saveRegistrar;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase;
import google.registry.model.EppResource;
import google.registry.model.contact.ContactHistory;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.Period;
import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostHistory;
import google.registry.model.host.HostResource;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Tests to check {@link HistoryEntry} + its subclasses' transitions to/from Datastore/SQL. */
public class LegacyHistoryObjectTest extends EntityTestCase {
public LegacyHistoryObjectTest() {
super(JpaEntityCoverageCheck.ENABLED);
}
@BeforeEach
void beforeEach() {
saveRegistrar("TheRegistrar");
}
@Test
void testFullConversion_contact() {
// Create+save an old contact HistoryEntry, reload it, and verify it's a proper ContactHistory
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
HistoryEntry legacyHistoryEntry = historyEntryBuilderFor(contact).build();
tm().transact(() -> tm().insert(legacyHistoryEntry));
// In Datastore, we will save it as HistoryEntry but retrieve it as ContactHistory
long historyEntryId = legacyHistoryEntry.getId();
HistoryEntry fromObjectify =
tm().transact(
() ->
tm().load(
VKey.create(
HistoryEntry.class,
historyEntryId,
Key.create(legacyHistoryEntry))));
// The objects will be mostly the same, but the ContactHistory object has a couple extra fields
assertAboutImmutableObjects()
.that(legacyHistoryEntry)
.isEqualExceptFields(fromObjectify, "contactBase", "contactRepoId");
assertThat(fromObjectify instanceof ContactHistory).isTrue();
ContactHistory legacyContactHistory = (ContactHistory) fromObjectify;
// Next, save that from-Datastore object in SQL and verify we can load it back in
legacyContactHistory.id = null;
jpaTm()
.transact(
() -> {
jpaTm().insert(contact);
jpaTm().insert(legacyContactHistory);
});
ContactHistory legacyHistoryFromSql =
jpaTm()
.transact(
() ->
jpaTm()
.load(VKey.createSql(ContactHistory.class, legacyContactHistory.getId())));
assertAboutImmutableObjects()
.that(legacyContactHistory)
.isEqualExceptFields(legacyHistoryFromSql);
// can't compare contactRepoId directly since it doesn't save the ofy key
assertThat(legacyContactHistory.getContactRepoId().getSqlKey())
.isEqualTo(legacyHistoryFromSql.getContactRepoId().getSqlKey());
}
@Test
void testFullConversion_domain() {
// Create+save an old domain HistoryEntry, reload it, and verify it's a proper DomainHistory
DomainBase domain = DomainHistoryTest.createDomainWithContactsAndHosts();
HistoryEntry legacyHistoryEntry = historyEntryForDomain(domain);
tm().transact(() -> tm().insert(legacyHistoryEntry));
// In Datastore, we will save it as HistoryEntry but retrieve it as DomainHistory
long historyEntryId = legacyHistoryEntry.getId();
HistoryEntry fromObjectify =
tm().transact(
() ->
tm().load(
VKey.create(
HistoryEntry.class,
historyEntryId,
Key.create(legacyHistoryEntry))));
// The objects will be mostly the same, but the DomainHistory object has a couple extra fields
assertAboutImmutableObjects()
.that(legacyHistoryEntry)
.isEqualExceptFields(fromObjectify, "domainContent", "domainRepoId", "nsHosts");
assertThat(fromObjectify instanceof DomainHistory).isTrue();
DomainHistory legacyDomainHistory = (DomainHistory) fromObjectify;
// Next, save that from-Datastore object in SQL and verify we can load it back in
jpaTm().transact(() -> jpaTm().insert(legacyDomainHistory));
DomainHistory legacyHistoryFromSql =
jpaTm().transact(() -> jpaTm().load(legacyDomainHistory.createVKey()));
// Don't compare nsHosts directly because one is null and the other is empty
assertAboutImmutableObjects()
.that(legacyDomainHistory)
.isEqualExceptFields(
// NB: period, transaction records, and other client ID are added in #794
legacyHistoryFromSql, "period", "domainTransactionRecords", "otherClientId", "nsHosts");
assertThat(nullToEmpty(legacyDomainHistory.getNsHosts()))
.isEqualTo(nullToEmpty(legacyHistoryFromSql.getNsHosts()));
}
@Test
void testFullConversion_host() {
// Create+save an old host HistoryEntry, reload it, and verify it's a proper HostHistory
HostResource host = newHostResourceWithRoid("hs1.example.com", "host1");
HistoryEntry legacyHistoryEntry = historyEntryBuilderFor(host).build();
tm().transact(() -> tm().insert(legacyHistoryEntry));
// In Datastore, we will save it as HistoryEntry but retrieve it as HostHistory
long historyEntryId = legacyHistoryEntry.getId();
HistoryEntry fromObjectify =
tm().transact(
() ->
tm().load(
VKey.create(
HistoryEntry.class,
historyEntryId,
Key.create(legacyHistoryEntry))));
// The objects will be mostly the same, but the HostHistory object has a couple extra fields
assertAboutImmutableObjects()
.that(legacyHistoryEntry)
.isEqualExceptFields(fromObjectify, "hostBase", "hostRepoId");
assertThat(fromObjectify instanceof HostHistory).isTrue();
HostHistory legacyHostHistory = (HostHistory) fromObjectify;
// Next, save that from-Datastore object in SQL and verify we can load it back in
legacyHostHistory.id = null;
jpaTm()
.transact(
() -> {
jpaTm().insert(host);
jpaTm().insert(legacyHostHistory);
});
HostHistory legacyHistoryFromSql =
jpaTm()
.transact(
() -> jpaTm().load(VKey.createSql(HostHistory.class, legacyHostHistory.getId())));
assertAboutImmutableObjects().that(legacyHostHistory).isEqualExceptFields(legacyHistoryFromSql);
// can't compare hostRepoId directly since it doesn't save the ofy key in SQL
assertThat(legacyHostHistory.getHostRepoId().getSqlKey())
.isEqualTo(legacyHistoryFromSql.getHostRepoId().getSqlKey());
}
private HistoryEntry historyEntryForDomain(DomainBase domain) {
DomainTransactionRecord transactionRecord =
new DomainTransactionRecord.Builder()
.setTld("foobar")
.setReportingTime(fakeClock.nowUtc())
.setReportField(TransactionReportField.NET_ADDS_1_YR)
.setReportAmount(1)
.build();
return historyEntryBuilderFor(domain)
.setPeriod(Period.create(1, Period.Unit.YEARS))
.setDomainTransactionRecords(ImmutableSet.of(transactionRecord))
.setOtherClientId("TheRegistrar")
.build();
}
private HistoryEntry.Builder historyEntryBuilderFor(EppResource parent) {
return new HistoryEntry.Builder()
.setParent(parent)
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
.setModificationTime(fakeClock.nowUtc())
.setClientId("TheRegistrar")
.setTrid(Trid.create("ABC-123", "server-trid"))
.setBySuperuser(false)
.setReason("reason")
.setRequestedByRegistrar(false);
}
}
@@ -84,7 +84,7 @@ public class PollMessageTest extends EntityTestCase {
@Test
void testCloudSqlPersistenceOneTime() {
saveRegistrar("TheRegistrar");
jpaTm().transact(() -> jpaTm().saveNew(oneTime));
jpaTm().transact(() -> jpaTm().insert(oneTime));
PollMessage.OneTime persisted =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.OneTime.class, oneTime.id)));
persisted.parent = oneTime.parent;
@@ -94,7 +94,7 @@ public class PollMessageTest extends EntityTestCase {
@Test
void testCloudSqlPersistenceAutorenew() {
saveRegistrar("TheRegistrar");
jpaTm().transact(() -> jpaTm().saveNew(autoRenew));
jpaTm().transact(() -> jpaTm().insert(autoRenew));
PollMessage.Autorenew persisted =
jpaTm()
.transact(
@@ -107,14 +107,14 @@ public class PollMessageTest extends EntityTestCase {
void testCloudSqlSupportForPolymorphicVKey() {
saveRegistrar("TheRegistrar");
jpaTm().transact(() -> jpaTm().saveNew(oneTime));
jpaTm().transact(() -> jpaTm().insert(oneTime));
PollMessage persistedOneTime =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, oneTime.getId())));
assertThat(persistedOneTime).isInstanceOf(PollMessage.OneTime.class);
persistedOneTime.parent = oneTime.parent;
assertThat(persistedOneTime).isEqualTo(oneTime);
jpaTm().transact(() -> jpaTm().saveNew(autoRenew));
jpaTm().transact(() -> jpaTm().insert(autoRenew));
PollMessage persistedAutoRenew =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, autoRenew.getId())));
assertThat(persistedAutoRenew).isInstanceOf(PollMessage.Autorenew.class);
@@ -23,6 +23,7 @@ import static google.registry.model.registry.Registry.TldState.GENERAL_AVAILABIL
import static google.registry.model.registry.Registry.TldState.PREDELEGATION;
import static google.registry.model.registry.Registry.TldState.QUIET_PERIOD;
import static google.registry.model.registry.Registry.TldState.START_DATE_SUNRISE;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newRegistry;
import static google.registry.testing.DatastoreHelper.persistPremiumList;
@@ -43,20 +44,40 @@ import google.registry.model.registry.Registry.RegistryNotFoundException;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.label.PremiumList;
import google.registry.model.registry.label.ReservedList;
import google.registry.persistence.VKey;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension;
import java.math.BigDecimal;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link Registry}. */
class RegistryTest extends EntityTestCase {
public class RegistryTest extends EntityTestCase {
@BeforeEach
void beforeEach() {
createTld("tld");
}
@RegisterExtension
JpaIntegrationWithCoverageExtension jpa =
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
@Test
public void testCloudSqlPersistence() {
ReservedList rl15 = persistReservedList("tld-reserved15", "potato,FULLY_BLOCKED");
PremiumList pl = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700");
Registry registry =
Registry.get("tld").asBuilder().setReservedLists(rl15).setPremiumList(pl).build();
jpaTm().transact(() -> jpaTm().insert(registry));
Registry persisted =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(Registry.class, registry.tldStrId)));
assertThat(persisted).isEqualTo(registry);
}
@Test
void testPersistence() {
assertWithMessage("Registry not found").that(Registry.get("tld")).isNotNull();
@@ -37,8 +37,8 @@ public class Spec11ThreatMatchDaoTest extends EntityTestCase {
jpaTm()
.transact(
() -> {
jpaTm().saveAllNew(getThreatMatchesToday());
jpaTm().saveAllNew(getThreatMatchesYesterday());
jpaTm().insertAll(getThreatMatchesToday());
jpaTm().insertAll(getThreatMatchesYesterday());
});
}
@@ -107,10 +107,10 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
jpaTm()
.transact(
() -> {
jpaTm().saveNew(registrantContact);
jpaTm().saveNew(domain);
jpaTm().saveNew(host);
jpaTm().saveNew(threat);
jpaTm().insert(registrantContact);
jpaTm().insert(domain);
jpaTm().insert(host);
jpaTm().insert(threat);
});
VKey<Spec11ThreatMatch> threatVKey = VKey.createSql(Spec11ThreatMatch.class, threat.getId());
@@ -130,10 +130,10 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
.transact(
() -> {
// Persist the threat without the associated registrar.
jpaTm().saveNew(host);
jpaTm().saveNew(registrantContact);
jpaTm().saveNew(domain);
jpaTm().saveNew(threat);
jpaTm().insert(host);
jpaTm().insert(registrantContact);
jpaTm().insert(domain);
jpaTm().insert(threat);
});
});
@@ -145,9 +145,9 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
.transact(
() -> {
// Persist the threat without the associated domain.
jpaTm().saveNew(registrantContact);
jpaTm().saveNew(host);
jpaTm().saveNew(threat);
jpaTm().insert(registrantContact);
jpaTm().insert(host);
jpaTm().insert(threat);
});
});
}
@@ -49,7 +49,7 @@ class EntityCallbacksListenerTest {
@Test
void verifyAllCallbacks_executedExpectedTimes() {
TestEntity testPersist = new TestEntity();
jpaTm().transact(() -> jpaTm().saveNew(testPersist));
jpaTm().transact(() -> jpaTm().insert(testPersist));
checkAll(testPersist, 1, 0, 0, 0);
TestEntity testUpdate = new TestEntity();
@@ -78,7 +78,7 @@ public class DurationConverterTest {
private void assertPersistedEntityHasSameDuration(Duration duration) {
DurationTestEntity entity = new DurationTestEntity(duration);
jpaTm().transact(() -> jpaTm().saveNew(entity));
jpaTm().transact(() -> jpaTm().insert(entity));
DurationTestEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(DurationTestEntity.class, "id"));
assertThat(persisted.duration.getMillis()).isEqualTo(duration.getMillis());
@@ -63,7 +63,7 @@ public class InetAddressSetConverterTest {
private void verifySaveAndLoad(@Nullable Set<InetAddress> inetAddresses) {
InetAddressSetTestEntity testEntity = new InetAddressSetTestEntity(inetAddresses);
jpaTm().transact(() -> jpaTm().saveNew(testEntity));
jpaTm().transact(() -> jpaTm().insert(testEntity));
InetAddressSetTestEntity persisted =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(InetAddressSetTestEntity.class, "id")));
assertThat(persisted.addresses).isEqualTo(inetAddresses);
@@ -54,7 +54,7 @@ public class LocalDateConverterTest {
private LocalDateConverterTestEntity persistAndLoadTestEntity(LocalDate date) {
LocalDateConverterTestEntity entity = new LocalDateConverterTestEntity(date);
jpaTm().transact(() -> jpaTm().saveNew(entity));
jpaTm().transact(() -> jpaTm().insert(entity));
LocalDateConverterTestEntity retrievedEntity =
jpaTm()
.transact(() -> jpaTm().load(VKey.createSql(LocalDateConverterTestEntity.class, "id")));
@@ -1,90 +0,0 @@
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import com.googlecode.objectify.Key;
import google.registry.model.ImmutableObject;
import google.registry.model.registry.label.ReservedList;
import google.registry.testing.AppEngineExtension;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link ReservedListKeyConverter}. */
class ReservedListKeyConverterTest {
@RegisterExtension
final AppEngineExtension appEngine =
AppEngineExtension.builder()
.withDatastoreAndCloudSql()
.withJpaUnitTestEntities(ReservedListEntity.class)
.build();
private final ReservedListKeyConverter converter = new ReservedListKeyConverter();
@Test
void convertToDatabaseColumn_returnsNullIfInputIsNull() {
assertThat(converter.convertToDatabaseColumn(null)).isNull();
}
@Test
void convertToDatabaseColumn_convertsCorrectly() {
assertThat(
converter.convertToDatabaseColumn(
Key.create(getCrossTldKey(), ReservedList.class, "testList")))
.isEqualTo("testList");
}
@Test
void convertToEntityAttribute_returnsNullIfInputIsNull() {
assertThat(converter.convertToEntityAttribute(null)).isNull();
}
@Test
void convertToEntityAttribute_convertsCorrectly() {
assertThat(converter.convertToEntityAttribute("testList"))
.isEqualTo(Key.create(getCrossTldKey(), ReservedList.class, "testList"));
}
@Test
void testRoundTrip() {
Key<ReservedList> key = Key.create(getCrossTldKey(), ReservedList.class, "test");
ReservedListEntity testEntity = new ReservedListEntity(key);
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
ReservedListEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListEntity.class, "test"));
assertThat(persisted.reservedList).isEqualTo(key);
}
@Entity(name = "ReservedListEntity")
private static class ReservedListEntity extends ImmutableObject {
@Id String name;
Key<ReservedList> reservedList;
public ReservedListEntity() {}
ReservedListEntity(Key<ReservedList> reservedList) {
this.name = reservedList.getName();
this.reservedList = reservedList;
}
}
}
@@ -0,0 +1,87 @@
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import com.googlecode.objectify.Key;
import google.registry.model.ImmutableObject;
import google.registry.model.registry.label.ReservedList;
import google.registry.testing.AppEngineExtension;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
/** Unit tests for {@link ReservedListKeySetConverter}. */
class ReservedListKeySetConverterTest {
@RegisterExtension
final AppEngineExtension appEngine =
AppEngineExtension.builder()
.withDatastoreAndCloudSql()
.withJpaUnitTestEntities(ReservedListSetEntity.class)
.build();
@Test
void roundTripConversion_returnsSameSet() {
Key<ReservedList> key1 = Key.create(getCrossTldKey(), ReservedList.class, "test1");
Key<ReservedList> key2 = Key.create(getCrossTldKey(), ReservedList.class, "test2");
Key<ReservedList> key3 = Key.create(getCrossTldKey(), ReservedList.class, "test3");
Set<Key<ReservedList>> reservedLists = ImmutableSet.of(key1, key2, key3);
ReservedListSetEntity testEntity = new ReservedListSetEntity(reservedLists);
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
ReservedListSetEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListSetEntity.class, "id"));
assertThat(persisted.reservedList).containsExactly(key1, key2, key3);
}
@Test
void testNullValue_writesAndReadsNullSuccessfully() {
ReservedListSetEntity testEntity = new ReservedListSetEntity(null);
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
ReservedListSetEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListSetEntity.class, "id"));
assertThat(persisted.reservedList).isNull();
}
@Test
void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() {
ReservedListSetEntity testEntity = new ReservedListSetEntity(ImmutableSet.of());
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
ReservedListSetEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListSetEntity.class, "id"));
assertThat(persisted.reservedList).isEmpty();
}
@Entity(name = "ReservedListSetEntity")
private static class ReservedListSetEntity extends ImmutableObject {
@Id String name = "id";
Set<Key<ReservedList>> reservedList;
public ReservedListSetEntity() {}
ReservedListSetEntity(Set<Key<ReservedList>> reservedList) {
this.reservedList = reservedList;
}
}
}
@@ -132,10 +132,10 @@ class JpaTransactionManagerImplTest {
}
@Test
void saveNew_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue();
void insert_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
}
@@ -143,7 +143,7 @@ class JpaTransactionManagerImplTest {
void transact_retriesOptimisticLockExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
OptimisticLockException.class,
() -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
@@ -162,7 +162,7 @@ class JpaTransactionManagerImplTest {
void transactNoRetry_doesNotRetryOptimisticLockException() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
spyJpaTm.transactNoRetry(() -> spyJpaTm.saveNew(theEntity));
spyJpaTm.transactNoRetry(() -> spyJpaTm.insert(theEntity));
assertThrows(
OptimisticLockException.class,
() -> spyJpaTm.transactNoRetry(() -> spyJpaTm.delete(theEntityKey)));
@@ -183,7 +183,7 @@ class JpaTransactionManagerImplTest {
doThrow(new RuntimeException().initCause(new OptimisticLockException()))
.when(spyJpaTm)
.delete(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
RuntimeException.class, () -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
verify(spyJpaTm, times(3)).delete(theEntityKey);
@@ -201,7 +201,7 @@ class JpaTransactionManagerImplTest {
void transactNewReadOnly_retriesJdbcConnectionExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
JDBCConnectionException.class,
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
@@ -224,7 +224,7 @@ class JpaTransactionManagerImplTest {
.initCause(new JDBCConnectionException("connection exception", new SQLException())))
.when(spyJpaTm)
.load(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
RuntimeException.class,
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
@@ -243,7 +243,7 @@ class JpaTransactionManagerImplTest {
void doTransactionless_retriesJdbcConnectionExceptions() {
JpaTransactionManager spyJpaTm = spy(jpaTm());
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
assertThrows(
RuntimeException.class,
() -> spyJpaTm.doTransactionless(() -> spyJpaTm.load(theEntityKey)));
@@ -251,19 +251,19 @@ class JpaTransactionManagerImplTest {
}
@Test
void saveNew_throwsExceptionIfEntityExists() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue();
void insert_throwsExceptionIfEntityExists() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
assertThrows(RollbackException.class, () -> jpaTm().transact(() -> jpaTm().saveNew(theEntity)));
assertThrows(RollbackException.class, () -> jpaTm().transact(() -> jpaTm().insert(theEntity)));
}
@Test
void createCompoundIdEntity_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey)))
.isEqualTo(compoundIdEntity);
}
@@ -271,10 +271,10 @@ class JpaTransactionManagerImplTest {
@Test
void saveAllNew_succeeds() {
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isFalse());
jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities));
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isTrue());
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue());
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
.containsExactlyElementsIn(moreEntities);
}
@@ -282,48 +282,48 @@ class JpaTransactionManagerImplTest {
@Test
void saveAllNew_rollsBackWhenFailure() {
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isFalse());
jpaTm().transact(() -> jpaTm().saveNew(moreEntities.get(0)));
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
jpaTm().transact(() -> jpaTm().insert(moreEntities.get(0)));
assertThrows(
RollbackException.class, () -> jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities)));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(moreEntities.get(0)))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().checkExists(moreEntities.get(1)))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().checkExists(moreEntities.get(2)))).isFalse();
RollbackException.class, () -> jpaTm().transact(() -> jpaTm().insertAll(moreEntities)));
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(0)))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(1)))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(2)))).isFalse();
}
@Test
void saveNewOrUpdate_persistsNewEntity() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().saveNewOrUpdate(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue();
void put_persistsNewEntity() {
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().put(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
}
@Test
void saveNewOrUpdate_updatesExistingEntity() {
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
void put_updatesExistingEntity() {
jpaTm().transact(() -> jpaTm().insert(theEntity));
TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
assertThat(persisted.data).isEqualTo("foo");
theEntity.data = "bar";
jpaTm().transact(() -> jpaTm().saveNewOrUpdate(theEntity));
jpaTm().transact(() -> jpaTm().put(theEntity));
persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
assertThat(persisted.data).isEqualTo("bar");
}
@Test
void saveNewOrUpdateAll_succeeds() {
void putAll_succeeds() {
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isFalse());
jpaTm().transact(() -> jpaTm().saveNewOrUpdateAll(moreEntities));
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
jpaTm().transact(() -> jpaTm().putAll(moreEntities));
moreEntities.forEach(
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isTrue());
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue());
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
.containsExactlyElementsIn(moreEntities);
}
@Test
void update_succeeds() {
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
jpaTm().transact(() -> jpaTm().insert(theEntity));
TestEntity persisted =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TestEntity.class, "theEntity")));
assertThat(persisted.data).isEqualTo("foo");
@@ -335,7 +335,7 @@ class JpaTransactionManagerImplTest {
@Test
void updateCompoundIdEntity_succeeds() {
jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity));
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
assertThat(persisted.data).isEqualTo("foo");
compoundIdEntity.data = "bar";
@@ -346,15 +346,15 @@ class JpaTransactionManagerImplTest {
@Test
void update_throwsExceptionWhenEntityDoesNotExist() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThrows(
IllegalArgumentException.class, () -> jpaTm().transact(() -> jpaTm().update(theEntity)));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
}
@Test
void updateAll_succeeds() {
jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities));
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
ImmutableList<TestEntity> updated =
ImmutableList.of(
new TestEntity("entity1", "foo_updated"),
@@ -367,7 +367,7 @@ class JpaTransactionManagerImplTest {
@Test
void updateAll_rollsBackWhenFailure() {
jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities));
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
ImmutableList<TestEntity> updated =
ImmutableList.of(
new TestEntity("entity1", "foo_updated"),
@@ -382,8 +382,8 @@ class JpaTransactionManagerImplTest {
@Test
void load_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
@@ -391,15 +391,15 @@ class JpaTransactionManagerImplTest {
@Test
void load_throwsOnMissingElement() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThrows(
NoSuchElementException.class, () -> jpaTm().transact(() -> jpaTm().load(theEntityKey)));
}
@Test
void maybeLoad_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(theEntity));
TestEntity persisted = jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey).get());
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
@@ -407,14 +407,14 @@ class JpaTransactionManagerImplTest {
@Test
void maybeLoad_nonExistentObject() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey)).isPresent()).isFalse();
}
@Test
void loadCompoundIdEntity_succeeds() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
assertThat(persisted.name).isEqualTo("compoundIdEntity");
assertThat(persisted.age).isEqualTo(10);
@@ -423,37 +423,37 @@ class JpaTransactionManagerImplTest {
@Test
void loadAll_succeeds() {
jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities));
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
ImmutableList<TestEntity> persisted = jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class));
assertThat(persisted).containsExactlyElementsIn(moreEntities);
}
@Test
void delete_succeeds() {
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue();
jpaTm().transact(() -> jpaTm().insert(theEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
jpaTm().transact(() -> jpaTm().delete(theEntityKey));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
}
@Test
void delete_returnsZeroWhenNoEntity() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
jpaTm().transact(() -> jpaTm().delete(theEntityKey));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
}
@Test
void deleteCompoundIdEntity_succeeds() {
jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isTrue();
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
jpaTm().transact(() -> jpaTm().delete(compoundIdEntityKey));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
}
@Test
void assertDelete_throwsExceptionWhenEntityNotDeleted() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
assertThrows(
IllegalArgumentException.class,
() -> jpaTm().transact(() -> jpaTm().assertDelete(theEntityKey)));
@@ -37,6 +37,8 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.stream.Stream;
import javax.persistence.Embeddable;
import javax.persistence.MappedSuperclass;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -65,7 +67,7 @@ public class TransactionManagerTest {
.withClock(fakeClock)
.withDatastoreAndCloudSql()
.withOfyTestEntities(TestEntity.class)
.withJpaUnitTestEntities(TestEntity.class)
.withJpaUnitTestEntities(TestEntity.class, TestEntityBase.class)
.build();
TransactionManagerTest() {}
@@ -105,7 +107,7 @@ public class TransactionManagerTest {
() ->
tm().transact(
() -> {
tm().saveNew(theEntity);
tm().insert(theEntity);
throw new RuntimeException();
}));
assertEntityNotExist(theEntity);
@@ -114,21 +116,21 @@ public class TransactionManagerTest {
@TestTemplate
void transact_reusesExistingTransaction() {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().transact(() -> tm().saveNew(theEntity)));
tm().transact(() -> tm().transact(() -> tm().insert(theEntity)));
assertEntityExists(theEntity);
}
@TestTemplate
void transactNew_succeeds() {
assertEntityNotExist(theEntity);
tm().transactNew(() -> tm().saveNew(theEntity));
tm().transactNew(() -> tm().insert(theEntity));
assertEntityExists(theEntity);
}
@TestTemplate
void transactNewReadOnly_succeeds() {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().saveNew(theEntity));
tm().transact(() -> tm().insert(theEntity));
assertEntityExists(theEntity);
TestEntity persisted = tm().transactNewReadOnly(() -> tm().load(theEntity.key()));
assertThat(persisted).isEqualTo(theEntity);
@@ -138,14 +140,14 @@ public class TransactionManagerTest {
void transactNewReadOnly_throwsWhenWritingEntity() {
assertEntityNotExist(theEntity);
assertThrows(
RuntimeException.class, () -> tm().transactNewReadOnly(() -> tm().saveNew(theEntity)));
RuntimeException.class, () -> tm().transactNewReadOnly(() -> tm().insert(theEntity)));
assertEntityNotExist(theEntity);
}
@TestTemplate
void saveNew_succeeds() {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().saveNew(theEntity));
tm().transact(() -> tm().insert(theEntity));
assertEntityExists(theEntity);
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
}
@@ -153,26 +155,26 @@ public class TransactionManagerTest {
@TestTemplate
void saveAllNew_succeeds() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().saveAllNew(moreEntities));
tm().transact(() -> tm().insertAll(moreEntities));
assertAllEntitiesExist(moreEntities);
}
@TestTemplate
void saveNewOrUpdate_persistsNewEntity() {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().saveNewOrUpdate(theEntity));
tm().transact(() -> tm().put(theEntity));
assertEntityExists(theEntity);
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
}
@TestTemplate
void saveNewOrUpdate_updatesExistingEntity() {
tm().transact(() -> tm().saveNew(theEntity));
tm().transact(() -> tm().insert(theEntity));
TestEntity persisted = tm().transact(() -> tm().load(theEntity.key()));
assertThat(persisted.data).isEqualTo("foo");
theEntity.data = "bar";
fakeClock.advanceOneMilli();
tm().transact(() -> tm().saveNewOrUpdate(theEntity));
tm().transact(() -> tm().put(theEntity));
persisted = tm().transact(() -> tm().load(theEntity.key()));
assertThat(persisted.data).isEqualTo("bar");
}
@@ -180,13 +182,13 @@ public class TransactionManagerTest {
@TestTemplate
void saveNewOrUpdateAll_succeeds() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().saveNewOrUpdateAll(moreEntities));
tm().transact(() -> tm().putAll(moreEntities));
assertAllEntitiesExist(moreEntities);
}
@TestTemplate
void update_succeeds() {
tm().transact(() -> tm().saveNew(theEntity));
tm().transact(() -> tm().insert(theEntity));
TestEntity persisted =
tm().transact(
() ->
@@ -203,7 +205,7 @@ public class TransactionManagerTest {
@TestTemplate
void load_succeeds() {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().saveNew(theEntity));
tm().transact(() -> tm().insert(theEntity));
TestEntity persisted = tm().transact(() -> tm().load(theEntity.key()));
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
@@ -219,7 +221,7 @@ public class TransactionManagerTest {
@TestTemplate
void maybeLoad_succeeds() {
assertEntityNotExist(theEntity);
tm().transact(() -> tm().saveNew(theEntity));
tm().transact(() -> tm().insert(theEntity));
TestEntity persisted = tm().transact(() -> tm().maybeLoad(theEntity.key()).get());
assertThat(persisted.name).isEqualTo("theEntity");
assertThat(persisted.data).isEqualTo("foo");
@@ -233,7 +235,7 @@ public class TransactionManagerTest {
@TestTemplate
void delete_succeeds() {
tm().transact(() -> tm().saveNew(theEntity));
tm().transact(() -> tm().insert(theEntity));
assertEntityExists(theEntity);
fakeClock.advanceOneMilli();
tm().transact(() -> tm().delete(theEntity.key()));
@@ -250,7 +252,7 @@ public class TransactionManagerTest {
@TestTemplate
void delete_succeedsForEntitySet() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().saveAllNew(moreEntities));
tm().transact(() -> tm().insertAll(moreEntities));
Set<VKey<TestEntity>> keys =
moreEntities.stream().map(TestEntity::key).collect(toImmutableSet());
assertAllEntitiesExist(moreEntities);
@@ -262,7 +264,7 @@ public class TransactionManagerTest {
@TestTemplate
void delete_ignoreNonExistentEntity() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().saveAllNew(moreEntities));
tm().transact(() -> tm().insertAll(moreEntities));
List<VKey<TestEntity>> keys =
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
assertAllEntitiesExist(moreEntities);
@@ -277,7 +279,7 @@ public class TransactionManagerTest {
@TestTemplate
void load_multi() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().saveAllNew(moreEntities));
tm().transact(() -> tm().insertAll(moreEntities));
List<VKey<TestEntity>> keys =
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
assertThat(tm().transact(() -> tm().load(keys)))
@@ -287,7 +289,7 @@ public class TransactionManagerTest {
@TestTemplate
void load_multiWithDuplicateKeys() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().saveAllNew(moreEntities));
tm().transact(() -> tm().insertAll(moreEntities));
ImmutableList<VKey<TestEntity>> keys =
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
ImmutableList<VKey<TestEntity>> doubleKeys =
@@ -299,7 +301,7 @@ public class TransactionManagerTest {
@TestTemplate
void load_multiMissingKeys() {
assertAllEntitiesNotExist(moreEntities);
tm().transact(() -> tm().saveAllNew(moreEntities));
tm().transact(() -> tm().insertAll(moreEntities));
List<VKey<TestEntity>> keys =
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
.map(TestEntity::key)
@@ -309,11 +311,11 @@ public class TransactionManagerTest {
}
private static void assertEntityExists(TestEntity entity) {
assertThat(tm().transact(() -> tm().checkExists(entity))).isTrue();
assertThat(tm().transact(() -> tm().exists(entity))).isTrue();
}
private static void assertEntityNotExist(TestEntity entity) {
assertThat(tm().transact(() -> tm().checkExists(entity))).isFalse();
assertThat(tm().transact(() -> tm().exists(entity))).isFalse();
}
private static void assertAllEntitiesExist(ImmutableList<TestEntity> entities) {
@@ -324,17 +326,31 @@ public class TransactionManagerTest {
entities.forEach(TransactionManagerTest::assertEntityNotExist);
}
/**
* We put the id field into a base class to test that id fields can be discovered in a base class.
*/
@MappedSuperclass
@Embeddable
private static class TestEntityBase extends ImmutableObject {
@Id @javax.persistence.Id protected String name;
TestEntityBase(String name) {
this.name = name;
}
TestEntityBase() {}
}
@Entity(name = "TxnMgrTestEntity")
@javax.persistence.Entity(name = "TestEntity")
private static class TestEntity extends ImmutableObject {
@Id @javax.persistence.Id private String name;
private static class TestEntity extends TestEntityBase {
private String data;
private TestEntity() {}
private TestEntity(String name, String data) {
this.name = name;
super(name);
this.data = data;
}
@@ -66,7 +66,7 @@ class TransactionTest {
txn = new Transaction.Builder().addDelete(barEntity.key()).build();
txn.writeToDatastore();
assertThat(ofyTm().checkExists(barEntity.key())).isEqualTo(false);
assertThat(ofyTm().exists(barEntity.key())).isEqualTo(false);
}
@Test
@@ -83,7 +83,7 @@ class TransactionTest {
.transact(
() -> {
assertThat(ofyTm().load(fooEntity.key())).isEqualTo(fooEntity);
assertThat(ofyTm().checkExists(barEntity.key())).isEqualTo(false);
assertThat(ofyTm().exists(barEntity.key())).isEqualTo(false);
});
}
@@ -107,8 +107,8 @@ class TransactionTest {
jpaTm()
.transact(
() -> {
jpaTm().saveNew(fooEntity);
jpaTm().saveNew(barEntity);
jpaTm().insert(fooEntity);
jpaTm().insert(barEntity);
});
TransactionEntity txnEnt =
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TransactionEntity.class, 1L)));
@@ -123,8 +123,7 @@ class TransactionTest {
// Verify that no transaction was persisted for the load transaction.
assertThat(
jpaTm()
.transact(() -> jpaTm().checkExists(VKey.createSql(TransactionEntity.class, 2L))))
jpaTm().transact(() -> jpaTm().exists(VKey.createSql(TransactionEntity.class, 2L))))
.isFalse();
} finally {
RegistryConfig.overrideCloudSqlReplicateTransactions(false);
@@ -136,12 +135,10 @@ class TransactionTest {
jpaTm()
.transact(
() -> {
jpaTm().saveNew(fooEntity);
jpaTm().saveNew(barEntity);
jpaTm().insert(fooEntity);
jpaTm().insert(barEntity);
});
assertThat(
jpaTm()
.transact(() -> jpaTm().checkExists(VKey.createSql(TransactionEntity.class, 1L))))
assertThat(jpaTm().transact(() -> jpaTm().exists(VKey.createSql(TransactionEntity.class, 1L))))
.isFalse();
}
@@ -73,7 +73,7 @@ class RdeStagingMapperTest {
// Set Registrar states which are required for reporting.
tm().transact(
() ->
tm().saveNewOrUpdateAll(
tm().putAll(
ImmutableList.of(
externalMonitoringRegistrar.asBuilder().setState(State.ACTIVE).build(),
testRegistrar.asBuilder().setState(State.ACTIVE).build(),
@@ -25,6 +25,7 @@ import google.registry.model.history.DomainHistoryTest;
import google.registry.model.history.HostHistoryTest;
import google.registry.model.poll.PollMessageTest;
import google.registry.model.registry.RegistryLockDaoTest;
import google.registry.model.registry.RegistryTest;
import google.registry.model.registry.label.ReservedListSqlDaoTest;
import google.registry.model.reporting.Spec11ThreatMatchTest;
import google.registry.model.tmch.ClaimsListDaoTest;
@@ -86,6 +87,7 @@ import org.junit.runner.RunWith;
PollMessageTest.class,
PremiumListDaoTest.class,
RegistrarDaoTest.class,
RegistryTest.class,
ReservedListSqlDaoTest.class,
RegistryLockDaoTest.class,
Spec11ThreatMatchTest.class,
@@ -65,7 +65,7 @@ class RegistrarContactTest {
@Test
void testPersistence_succeeds() {
jpaTm().transact(() -> jpaTm().saveNew(testRegistrarPoc));
jpaTm().transact(() -> jpaTm().insert(testRegistrarPoc));
RegistrarContact persisted =
jpaTm().transact(() -> jpaTm().load(testRegistrarPoc.createVKey()));
assertThat(persisted).isEqualTo(testRegistrarPoc);
@@ -70,14 +70,14 @@ public class RegistrarDaoTest {
@Test
void saveNew_worksSuccessfully() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(testRegistrar))).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(testRegistrar));
assertThat(jpaTm().transact(() -> jpaTm().checkExists(testRegistrar))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse();
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isTrue();
}
@Test
void update_worksSuccessfully() {
jpaTm().transact(() -> jpaTm().saveNew(testRegistrar));
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
Registrar persisted = jpaTm().transact(() -> jpaTm().load(registrarKey));
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");
jpaTm()
@@ -92,7 +92,7 @@ public class RegistrarDaoTest {
@Test
void update_throwsExceptionWhenEntityDoesNotExist() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(testRegistrar))).isFalse();
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse();
assertThrows(
IllegalArgumentException.class,
() -> jpaTm().transact(() -> jpaTm().update(testRegistrar)));
@@ -100,8 +100,8 @@ public class RegistrarDaoTest {
@Test
void load_worksSuccessfully() {
assertThat(jpaTm().transact(() -> jpaTm().checkExists(testRegistrar))).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(testRegistrar));
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse();
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
Registrar persisted = jpaTm().transact(() -> jpaTm().load(registrarKey));
assertThat(persisted.getClientId()).isEqualTo("registrarId");
@@ -62,7 +62,7 @@ public class SqlHelper {
public static Registrar saveRegistrar(String clientId) {
Registrar registrar = makeRegistrar1().asBuilder().setClientId(clientId).build();
jpaTm().transact(() -> jpaTm().saveNew(registrar));
jpaTm().transact(() -> jpaTm().insert(registrar));
return jpaTm().transact(() -> jpaTm().load(registrar.createVKey()));
}
@@ -120,7 +120,7 @@ class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarCommand>
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().verifyPassword("some_password")).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().checkExists(registrar.get()))).isTrue();
assertThat(jpaTm().transact(() -> jpaTm().exists(registrar.get()))).isTrue();
}
@Test
@@ -69,6 +69,8 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
assertThat(registry.getRedemptionGracePeriodLength())
.isEqualTo(Registry.DEFAULT_REDEMPTION_GRACE_PERIOD);
assertThat(registry.getPendingDeleteLength()).isEqualTo(Registry.DEFAULT_PENDING_DELETE_LENGTH);
assertThat(registry.getRegistryLockOrUnlockBillingCost())
.isEqualTo(Registry.DEFAULT_REGISTRY_LOCK_OR_UNLOCK_BILLING_COST);
}
@Test
@@ -230,6 +232,17 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
.isEqualTo(Money.of(USD, 42.42));
}
@Test
void testSuccess_registryLockOrUnlockCostFlag() throws Exception {
runCommandForced(
"--registry_lock_or_unlock_cost=\"USD 42.42\"",
"--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getRegistryLockOrUnlockBillingCost())
.isEqualTo(Money.of(USD, 42.42));
}
@Test
void testSuccess_nonUsdBillingCostFlag() throws Exception {
runCommandForced(
@@ -237,6 +250,7 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"--restore_billing_cost=\"JPY 67890\"",
"--initial_renew_billing_cost=\"JPY 101112\"",
"--server_status_change_cost=\"JPY 97865\"",
"--registry_lock_or_unlock_cost=\"JPY 9001\"",
"--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c");
@@ -528,7 +528,7 @@ public final class DomainLockUtilsTest {
.setReason(Reason.SERVER_STATUS)
.setTargetId(domain.getForeignKey())
.setClientId(domain.getCurrentSponsorClientId())
.setCost(Registry.get(domain.getTld()).getServerStatusChangeCost())
.setCost(Registry.get(domain.getTld()).getRegistryLockOrUnlockBillingCost())
.setEventTime(clock.nowUtc())
.setBillingTime(clock.nowUtc())
.setParent(entry)
@@ -47,7 +47,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void testSuccess_alsoUpdateInCloudSql() throws Exception {
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isFalse();
jpaTm().transact(() -> jpaTm().saveNew(loadRegistrar("NewRegistrar")));
jpaTm().transact(() -> jpaTm().insert(loadRegistrar("NewRegistrar")));
runCommand("--password=some_password", "--force", "NewRegistrar");
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isTrue();
assertThat(
@@ -212,19 +212,21 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 1)))
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(JPY)))
.setServerStatusChangeBillingCost(Money.ofMajor(JPY, 1))
.setRegistryLockOrUnlockBillingCost(Money.ofMajor(JPY, 1))
.build());
runCommandForced(
"--create_billing_cost=\"JPY 12345\"",
"--restore_billing_cost=\"JPY 67890\"",
"--renew_billing_cost_transitions=\"0=JPY 101112\"",
"--server_status_change_cost=\"JPY 97865\"",
"--registry_lock_or_unlock_cost=\"JPY 9001\"",
"xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getStandardCreateCost())
.isEqualTo(Money.ofMajor(JPY, 12345));
assertThat(Registry.get("xn--q9jyb4c").getStandardRestoreCost())
.isEqualTo(Money.ofMajor(JPY, 67890));
assertThat(Registry.get("xn--q9jyb4c").getStandardRenewCost(START_OF_TIME))
.isEqualTo(Money.ofMajor(JPY, 101112));
Registry registry = Registry.get("xn--q9jyb4c");
assertThat(registry.getStandardCreateCost()).isEqualTo(Money.ofMajor(JPY, 12345));
assertThat(registry.getStandardRestoreCost()).isEqualTo(Money.ofMajor(JPY, 67890));
assertThat(registry.getStandardRenewCost(START_OF_TIME)).isEqualTo(Money.ofMajor(JPY, 101112));
assertThat(registry.getServerStatusChangeCost()).isEqualTo(Money.ofMajor(JPY, 97865));
assertThat(registry.getRegistryLockOrUnlockBillingCost()).isEqualTo(Money.ofMajor(JPY, 9001));
}
@Test
@@ -317,7 +317,7 @@ final class RegistryLockVerifyActionTest {
.setReason(Reason.SERVER_STATUS)
.setTargetId(domain.getForeignKey())
.setClientId(domain.getCurrentSponsorClientId())
.setCost(Registry.get(domain.getTld()).getServerStatusChangeCost())
.setCost(Registry.get(domain.getTld()).getRegistryLockOrUnlockBillingCost())
.setEventTime(fakeClock.nowUtc())
.setBillingTime(fakeClock.nowUtc())
.setParent(historyEntry)
@@ -640,6 +640,7 @@ class google.registry.model.registry.Registry {
java.util.Set<java.lang.String> dnsWriters;
org.joda.money.CurrencyUnit currency;
org.joda.money.Money createBillingCost;
org.joda.money.Money registryLockOrUnlockBillingCost;
org.joda.money.Money restoreBillingCost;
org.joda.money.Money serverStatusChangeBillingCost;
org.joda.time.DateTime claimsPeriodEnd;
@@ -0,0 +1,20 @@
-- Copyright 2020 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
create sequence "temp_history_id_sequence"
start with 1
increment by 50
no minvalue
no maxvalue
cache 1;
@@ -0,0 +1,55 @@
-- Copyright 2020 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
create table "Tld" (
tld_name text not null,
add_grace_period_length interval not null,
allowed_fully_qualified_host_names text[],
allowed_registrant_contact_ids text[],
anchor_tenant_add_grace_period_length interval not null,
auto_renew_grace_period_length interval not null,
automatic_transfer_length interval not null,
claims_period_end timestamptz not null,
create_billing_cost_amount numeric(19, 2),
create_billing_cost_currency text,
creation_time timestamptz not null,
currency text not null,
dns_paused boolean not null,
dns_writers text[] not null,
drive_folder_id text,
eap_fee_schedule hstore not null,
escrow_enabled boolean not null,
invoicing_enabled boolean not null,
lordn_username text,
num_dns_publish_locks int4 not null,
pending_delete_length interval not null,
premium_list_name text,
pricing_engine_class_name text,
redemption_grace_period_length interval not null,
registry_lock_or_unlock_cost_amount numeric(19, 2),
registry_lock_or_unlock_cost_currency text,
renew_billing_cost_transitions hstore not null,
renew_grace_period_length interval not null,
reserved_list_names text[] not null,
restore_billing_cost_amount numeric(19, 2),
restore_billing_cost_currency text,
roid_suffix text,
server_status_change_billing_cost_amount numeric(19, 2),
server_status_change_billing_cost_currency text,
tld_state_transitions hstore not null,
tld_type text not null,
tld_unicode text not null,
transfer_grace_period_length interval not null,
primary key (tld_name)
);
@@ -0,0 +1,34 @@
-- Copyright 2020 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
ALTER TABLE "DomainHistory" ADD COLUMN history_other_registrar_id text;
ALTER TABLE "DomainHistory" ADD COLUMN history_period_unit text;
ALTER TABLE "DomainHistory" ADD COLUMN history_period_value int4;
CREATE TABLE "DomainTransactionRecord" (
id bigserial NOT NULL,
report_amount int4 NOT NULL,
report_field text NOT NULL,
reporting_time timestamptz NOT NULL,
tld text NOT NULL,
domain_repo_id text,
history_revision_id int8,
PRIMARY KEY (id)
);
ALTER TABLE IF EXISTS "DomainTransactionRecord"
ADD CONSTRAINT FKcjqe54u72kha71vkibvxhjye7
FOREIGN KEY (domain_repo_id, history_revision_id)
REFERENCES "DomainHistory";
@@ -0,0 +1,21 @@
-- Copyright 2020 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
ALTER TABLE "HostResource" RENAME TO "Host";
ALTER TABLE "HostHistory" RENAME CONSTRAINT fk_hosthistory_hostresource TO fk_hosthistory_host;
ALTER TABLE "Host"
RENAME CONSTRAINT fk_host_resource_superordinate_domain TO fk_host_superordinate_domain;
ALTER TABLE "Host" RENAME CONSTRAINT "HostResource_pkey" TO "Host_pkey";
@@ -0,0 +1,31 @@
-- Copyright 2020 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- Note: we drop the not-null constraints from the history tables but we keep them in the
-- EPP resource tables since nothing inserted there should be null
ALTER TABLE "ContactHistory" ALTER COLUMN creation_registrar_id DROP NOT NULL;
ALTER TABLE "ContactHistory" ALTER COLUMN creation_time DROP NOT NULL;
ALTER TABLE "ContactHistory" ALTER COLUMN current_sponsor_registrar_id DROP NOT NULL;
ALTER TABLE "ContactHistory" ALTER COLUMN history_reason DROP NOT NULL;
ALTER TABLE "DomainHistory" ALTER COLUMN creation_registrar_id DROP NOT NULL;
ALTER TABLE "DomainHistory" ALTER COLUMN creation_time DROP NOT NULL;
ALTER TABLE "DomainHistory" ALTER COLUMN current_sponsor_registrar_id DROP NOT NULL;
ALTER TABLE "DomainHistory" ALTER COLUMN history_reason DROP NOT NULL;
ALTER TABLE "HostHistory" ALTER COLUMN creation_registrar_id DROP NOT NULL;
ALTER TABLE "HostHistory" ALTER COLUMN creation_time DROP NOT NULL;
ALTER TABLE "HostHistory" ALTER COLUMN current_sponsor_registrar_id DROP NOT NULL;
ALTER TABLE "HostHistory" ALTER COLUMN history_reason DROP NOT NULL;
@@ -11,7 +11,7 @@
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
create sequence history_id_sequence start 1 increment 50;
create sequence temp_history_id_sequence start 1 increment 50;
create table "AllocationToken" (
token text not null,
@@ -94,9 +94,9 @@ create sequence history_id_sequence start 1 increment 50;
create table "Contact" (
repo_id text not null,
update_timestamp timestamptz,
creation_registrar_id text not null,
creation_time timestamptz not null,
current_sponsor_registrar_id text not null,
creation_registrar_id text,
creation_time timestamptz,
current_sponsor_registrar_id text,
deletion_time timestamptz,
last_epp_update_registrar_id text,
last_epp_update_time timestamptz,
@@ -155,7 +155,7 @@ create sequence history_id_sequence start 1 increment 50;
history_by_superuser boolean not null,
history_registrar_id text,
history_modification_time timestamptz not null,
history_reason text not null,
history_reason text,
history_requested_by_registrar boolean not null,
history_client_transaction_id text,
history_server_transaction_id text,
@@ -207,9 +207,9 @@ create sequence history_id_sequence start 1 increment 50;
transfer_status text,
voice_phone_extension text,
voice_phone_number text,
creation_registrar_id text not null,
creation_time timestamptz not null,
current_sponsor_registrar_id text not null,
creation_registrar_id text,
creation_time timestamptz,
current_sponsor_registrar_id text,
deletion_time timestamptz,
last_epp_update_registrar_id text,
last_epp_update_time timestamptz,
@@ -238,9 +238,9 @@ create sequence history_id_sequence start 1 increment 50;
create table "Domain" (
repo_id text not null,
update_timestamp timestamptz,
creation_registrar_id text not null,
creation_time timestamptz not null,
current_sponsor_registrar_id text not null,
creation_registrar_id text,
creation_time timestamptz,
current_sponsor_registrar_id text,
deletion_time timestamptz,
last_epp_update_registrar_id text,
last_epp_update_time timestamptz,
@@ -291,7 +291,7 @@ create sequence history_id_sequence start 1 increment 50;
history_by_superuser boolean not null,
history_registrar_id text,
history_modification_time timestamptz not null,
history_reason text not null,
history_reason text,
history_requested_by_registrar boolean not null,
history_client_transaction_id text,
history_server_transaction_id text,
@@ -334,14 +334,17 @@ create sequence history_id_sequence start 1 increment 50;
transfer_pending_expiration_time timestamptz,
transfer_request_time timestamptz,
transfer_status text,
creation_registrar_id text not null,
creation_time timestamptz not null,
current_sponsor_registrar_id text not null,
creation_registrar_id text,
creation_time timestamptz,
current_sponsor_registrar_id text,
deletion_time timestamptz,
last_epp_update_registrar_id text,
last_epp_update_time timestamptz,
statuses text[],
update_timestamp timestamptz,
history_other_registrar_id text,
history_period_unit text,
history_period_value int4,
primary key (domain_repo_id, history_revision_id)
);
@@ -356,6 +359,17 @@ create sequence history_id_sequence start 1 increment 50;
host_repo_id text
);
create table "DomainTransactionRecord" (
id bigserial not null,
report_amount int4 not null,
report_field text not null,
reporting_time timestamptz not null,
tld text not null,
domain_repo_id text,
history_revision_id int8,
primary key (id)
);
create table "GracePeriod" (
id bigserial not null,
billing_event_id int8,
@@ -367,40 +381,12 @@ create sequence history_id_sequence start 1 increment 50;
primary key (id)
);
create table "HostHistory" (
history_revision_id int8 not null,
history_by_superuser boolean not null,
history_registrar_id text,
history_modification_time timestamptz not null,
history_reason text not null,
history_requested_by_registrar boolean not null,
history_client_transaction_id text,
history_server_transaction_id text,
history_type text not null,
history_xml_bytes bytea not null,
host_name text,
inet_addresses text[],
last_superordinate_change timestamptz,
last_transfer_time timestamptz,
superordinate_domain text,
creation_registrar_id text not null,
creation_time timestamptz not null,
current_sponsor_registrar_id text not null,
deletion_time timestamptz,
last_epp_update_registrar_id text,
last_epp_update_time timestamptz,
statuses text[],
update_timestamp timestamptz,
host_repo_id text not null,
primary key (history_revision_id)
);
create table "HostResource" (
create table "Host" (
repo_id text not null,
update_timestamp timestamptz,
creation_registrar_id text not null,
creation_time timestamptz not null,
current_sponsor_registrar_id text not null,
creation_registrar_id text,
creation_time timestamptz,
current_sponsor_registrar_id text,
deletion_time timestamptz,
last_epp_update_registrar_id text,
last_epp_update_time timestamptz,
@@ -413,6 +399,34 @@ create sequence history_id_sequence start 1 increment 50;
primary key (repo_id)
);
create table "HostHistory" (
history_revision_id int8 not null,
history_by_superuser boolean not null,
history_registrar_id text,
history_modification_time timestamptz not null,
history_reason text,
history_requested_by_registrar boolean not null,
history_client_transaction_id text,
history_server_transaction_id text,
history_type text not null,
history_xml_bytes bytea not null,
host_name text,
inet_addresses text[],
last_superordinate_change timestamptz,
last_transfer_time timestamptz,
superordinate_domain text,
creation_registrar_id text,
creation_time timestamptz,
current_sponsor_registrar_id text,
deletion_time timestamptz,
last_epp_update_registrar_id text,
last_epp_update_time timestamptz,
statuses text[],
update_timestamp timestamptz,
host_repo_id text not null,
primary key (history_revision_id)
);
create table "Lock" (
resource_name text not null,
tld text not null,
@@ -580,6 +594,48 @@ create sequence history_id_sequence start 1 increment 50;
primary key (id)
);
create table "Tld" (
tld_name text not null,
add_grace_period_length interval not null,
allowed_fully_qualified_host_names text[],
allowed_registrant_contact_ids text[],
anchor_tenant_add_grace_period_length interval not null,
auto_renew_grace_period_length interval not null,
automatic_transfer_length interval not null,
claims_period_end timestamptz not null,
create_billing_cost_amount numeric(19, 2),
create_billing_cost_currency text,
creation_time timestamptz not null,
currency text not null,
dns_paused boolean not null,
dns_writers text[] not null,
drive_folder_id text,
eap_fee_schedule hstore not null,
escrow_enabled boolean not null,
invoicing_enabled boolean not null,
lordn_username text,
num_dns_publish_locks int4 not null,
pending_delete_length interval not null,
premium_list_name text,
pricing_engine_class_name text,
redemption_grace_period_length interval not null,
registry_lock_or_unlock_cost_amount numeric(19, 2),
registry_lock_or_unlock_cost_currency text,
renew_billing_cost_transitions hstore not null,
renew_grace_period_length interval not null,
reserved_list_names text[] not null,
restore_billing_cost_amount numeric(19, 2),
restore_billing_cost_currency text,
roid_suffix text,
server_status_change_billing_cost_amount numeric(19, 2),
server_status_change_billing_cost_currency text,
tld_state_transitions hstore not null,
tld_type text not null,
tld_unicode text not null,
transfer_grace_period_length interval not null,
primary key (tld_name)
);
create table "Transaction" (
id bigserial not null,
contents bytea,
@@ -654,6 +710,11 @@ create index spec11threatmatch_check_date_idx on "Spec11ThreatMatch" (check_date
foreign key (domain_repo_id)
references "Domain";
alter table if exists "DomainTransactionRecord"
add constraint FKcjqe54u72kha71vkibvxhjye7
foreign key (domain_repo_id, history_revision_id)
references "DomainHistory";
alter table if exists "GracePeriod"
add constraint FK2mys4hojm6ev2g9tmy5aq6m7g
foreign key (domain_repo_id)
@@ -284,7 +284,7 @@ CREATE TABLE public."ContactHistory" (
history_by_superuser boolean NOT NULL,
history_registrar_id text,
history_modification_time timestamp with time zone NOT NULL,
history_reason text NOT NULL,
history_reason text,
history_requested_by_registrar boolean NOT NULL,
history_client_transaction_id text,
history_server_transaction_id text,
@@ -336,9 +336,9 @@ CREATE TABLE public."ContactHistory" (
transfer_status text,
voice_phone_extension text,
voice_phone_number text,
creation_registrar_id text NOT NULL,
creation_time timestamp with time zone NOT NULL,
current_sponsor_registrar_id text NOT NULL,
creation_registrar_id text,
creation_time timestamp with time zone,
current_sponsor_registrar_id text,
deletion_time timestamp with time zone,
last_epp_update_registrar_id text,
last_epp_update_time timestamp with time zone,
@@ -423,7 +423,7 @@ CREATE TABLE public."DomainHistory" (
history_by_superuser boolean NOT NULL,
history_registrar_id text,
history_modification_time timestamp with time zone NOT NULL,
history_reason text NOT NULL,
history_reason text,
history_requested_by_registrar boolean NOT NULL,
history_client_transaction_id text,
history_server_transaction_id text,
@@ -465,16 +465,19 @@ CREATE TABLE public."DomainHistory" (
transfer_pending_expiration_time timestamp with time zone,
transfer_request_time timestamp with time zone,
transfer_status text,
creation_registrar_id text NOT NULL,
creation_time timestamp with time zone NOT NULL,
current_sponsor_registrar_id text NOT NULL,
creation_registrar_id text,
creation_time timestamp with time zone,
current_sponsor_registrar_id text,
deletion_time timestamp with time zone,
last_epp_update_registrar_id text,
last_epp_update_time timestamp with time zone,
statuses text[],
update_timestamp timestamp with time zone,
domain_repo_id text NOT NULL,
autorenew_end_time timestamp with time zone
autorenew_end_time timestamp with time zone,
history_other_registrar_id text,
history_period_unit text,
history_period_value integer
);
@@ -499,6 +502,40 @@ CREATE TABLE public."DomainHost" (
);
--
-- Name: DomainTransactionRecord; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."DomainTransactionRecord" (
id bigint NOT NULL,
report_amount integer NOT NULL,
report_field text NOT NULL,
reporting_time timestamp with time zone NOT NULL,
tld text NOT NULL,
domain_repo_id text,
history_revision_id bigint
);
--
-- Name: DomainTransactionRecord_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public."DomainTransactionRecord_id_seq"
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: DomainTransactionRecord_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public."DomainTransactionRecord_id_seq" OWNED BY public."DomainTransactionRecord".id;
--
-- Name: GracePeriod; Type: TABLE; Schema: public; Owner: -
--
@@ -534,42 +571,10 @@ ALTER SEQUENCE public."GracePeriod_id_seq" OWNED BY public."GracePeriod".id;
--
-- Name: HostHistory; Type: TABLE; Schema: public; Owner: -
-- Name: Host; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."HostHistory" (
history_revision_id bigint NOT NULL,
history_by_superuser boolean NOT NULL,
history_registrar_id text NOT NULL,
history_modification_time timestamp with time zone NOT NULL,
history_reason text NOT NULL,
history_requested_by_registrar boolean NOT NULL,
history_client_transaction_id text,
history_server_transaction_id text,
history_type text NOT NULL,
history_xml_bytes bytea NOT NULL,
host_name text,
inet_addresses text[],
last_superordinate_change timestamp with time zone,
last_transfer_time timestamp with time zone,
superordinate_domain text,
creation_registrar_id text NOT NULL,
creation_time timestamp with time zone NOT NULL,
current_sponsor_registrar_id text NOT NULL,
deletion_time timestamp with time zone,
last_epp_update_registrar_id text,
last_epp_update_time timestamp with time zone,
statuses text[],
host_repo_id text NOT NULL,
update_timestamp timestamp with time zone
);
--
-- Name: HostResource; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."HostResource" (
CREATE TABLE public."Host" (
repo_id text NOT NULL,
creation_registrar_id text,
creation_time timestamp with time zone,
@@ -587,6 +592,38 @@ CREATE TABLE public."HostResource" (
);
--
-- Name: HostHistory; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."HostHistory" (
history_revision_id bigint NOT NULL,
history_by_superuser boolean NOT NULL,
history_registrar_id text NOT NULL,
history_modification_time timestamp with time zone NOT NULL,
history_reason text,
history_requested_by_registrar boolean NOT NULL,
history_client_transaction_id text,
history_server_transaction_id text,
history_type text NOT NULL,
history_xml_bytes bytea NOT NULL,
host_name text,
inet_addresses text[],
last_superordinate_change timestamp with time zone,
last_transfer_time timestamp with time zone,
superordinate_domain text,
creation_registrar_id text,
creation_time timestamp with time zone,
current_sponsor_registrar_id text,
deletion_time timestamp with time zone,
last_epp_update_registrar_id text,
last_epp_update_time timestamp with time zone,
statuses text[],
host_repo_id text NOT NULL,
update_timestamp timestamp with time zone
);
--
-- Name: Lock; Type: TABLE; Schema: public; Owner: -
--
@@ -889,6 +926,52 @@ CREATE SEQUENCE public."SafeBrowsingThreat_id_seq"
ALTER SEQUENCE public."SafeBrowsingThreat_id_seq" OWNED BY public."Spec11ThreatMatch".id;
--
-- Name: Tld; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."Tld" (
tld_name text NOT NULL,
add_grace_period_length interval NOT NULL,
allowed_fully_qualified_host_names text[],
allowed_registrant_contact_ids text[],
anchor_tenant_add_grace_period_length interval NOT NULL,
auto_renew_grace_period_length interval NOT NULL,
automatic_transfer_length interval NOT NULL,
claims_period_end timestamp with time zone NOT NULL,
create_billing_cost_amount numeric(19,2),
create_billing_cost_currency text,
creation_time timestamp with time zone NOT NULL,
currency text NOT NULL,
dns_paused boolean NOT NULL,
dns_writers text[] NOT NULL,
drive_folder_id text,
eap_fee_schedule public.hstore NOT NULL,
escrow_enabled boolean NOT NULL,
invoicing_enabled boolean NOT NULL,
lordn_username text,
num_dns_publish_locks integer NOT NULL,
pending_delete_length interval NOT NULL,
premium_list_name text,
pricing_engine_class_name text,
redemption_grace_period_length interval NOT NULL,
registry_lock_or_unlock_cost_amount numeric(19,2),
registry_lock_or_unlock_cost_currency text,
renew_billing_cost_transitions public.hstore NOT NULL,
renew_grace_period_length interval NOT NULL,
reserved_list_names text[] NOT NULL,
restore_billing_cost_amount numeric(19,2),
restore_billing_cost_currency text,
roid_suffix text,
server_status_change_billing_cost_amount numeric(19,2),
server_status_change_billing_cost_currency text,
tld_state_transitions public.hstore NOT NULL,
tld_type text NOT NULL,
tld_unicode text NOT NULL,
transfer_grace_period_length interval NOT NULL
);
--
-- Name: Transaction; Type: TABLE; Schema: public; Owner: -
--
@@ -930,6 +1013,18 @@ CREATE SEQUENCE public.history_id_sequence
CACHE 1;
--
-- Name: temp_history_id_sequence; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.temp_history_id_sequence
START WITH 1
INCREMENT BY 50
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: BillingCancellation billing_cancellation_id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -958,6 +1053,13 @@ ALTER TABLE ONLY public."BillingRecurrence" ALTER COLUMN billing_recurrence_id S
ALTER TABLE ONLY public."ClaimsList" ALTER COLUMN revision_id SET DEFAULT nextval('public."ClaimsList_revision_id_seq"'::regclass);
--
-- Name: DomainTransactionRecord id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."DomainTransactionRecord" ALTER COLUMN id SET DEFAULT nextval('public."DomainTransactionRecord_id_seq"'::regclass);
--
-- Name: GracePeriod id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -1087,6 +1189,14 @@ ALTER TABLE ONLY public."DomainHistory"
ADD CONSTRAINT "DomainHistory_pkey" PRIMARY KEY (domain_repo_id, history_revision_id);
--
-- Name: DomainTransactionRecord DomainTransactionRecord_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."DomainTransactionRecord"
ADD CONSTRAINT "DomainTransactionRecord_pkey" PRIMARY KEY (id);
--
-- Name: Domain Domain_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -1112,11 +1222,11 @@ ALTER TABLE ONLY public."HostHistory"
--
-- Name: HostResource HostResource_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: Host Host_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."HostResource"
ADD CONSTRAINT "HostResource_pkey" PRIMARY KEY (repo_id);
ALTER TABLE ONLY public."Host"
ADD CONSTRAINT "Host_pkey" PRIMARY KEY (repo_id);
--
@@ -1199,6 +1309,14 @@ ALTER TABLE ONLY public."Spec11ThreatMatch"
ADD CONSTRAINT "SafeBrowsingThreat_pkey" PRIMARY KEY (id);
--
-- Name: Tld Tld_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."Tld"
ADD CONSTRAINT "Tld_pkey" PRIMARY KEY (tld_name);
--
-- Name: Transaction Transaction_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -1826,7 +1944,7 @@ ALTER TABLE ONLY public."Domain"
--
ALTER TABLE ONLY public."DomainHost"
ADD CONSTRAINT fk_domainhost_host_valid FOREIGN KEY (host_repo_id) REFERENCES public."HostResource"(repo_id);
ADD CONSTRAINT fk_domainhost_host_valid FOREIGN KEY (host_repo_id) REFERENCES public."Host"(repo_id);
--
@@ -1846,19 +1964,19 @@ ALTER TABLE ONLY public."GracePeriod"
--
-- Name: HostResource fk_host_resource_superordinate_domain; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: Host fk_host_superordinate_domain; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."HostResource"
ADD CONSTRAINT fk_host_resource_superordinate_domain FOREIGN KEY (superordinate_domain) REFERENCES public."Domain"(repo_id);
ALTER TABLE ONLY public."Host"
ADD CONSTRAINT fk_host_superordinate_domain FOREIGN KEY (superordinate_domain) REFERENCES public."Domain"(repo_id);
--
-- Name: HostHistory fk_hosthistory_hostresource; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: HostHistory fk_hosthistory_host; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."HostHistory"
ADD CONSTRAINT fk_hosthistory_hostresource FOREIGN KEY (host_repo_id) REFERENCES public."HostResource"(repo_id);
ADD CONSTRAINT fk_hosthistory_host FOREIGN KEY (host_repo_id) REFERENCES public."Host"(repo_id);
--
@@ -1882,7 +2000,7 @@ ALTER TABLE ONLY public."PollMessage"
--
ALTER TABLE ONLY public."PollMessage"
ADD CONSTRAINT fk_poll_message_host_repo_id FOREIGN KEY (host_repo_id) REFERENCES public."HostResource"(repo_id);
ADD CONSTRAINT fk_poll_message_host_repo_id FOREIGN KEY (host_repo_id) REFERENCES public."Host"(repo_id);
--
@@ -1917,6 +2035,14 @@ ALTER TABLE ONLY public."DomainHistoryHost"
ADD CONSTRAINT fka9woh3hu8gx5x0vly6bai327n FOREIGN KEY (domain_history_domain_repo_id, domain_history_history_revision_id) REFERENCES public."DomainHistory"(domain_repo_id, history_revision_id);
--
-- Name: DomainTransactionRecord fkcjqe54u72kha71vkibvxhjye7; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."DomainTransactionRecord"
ADD CONSTRAINT fkcjqe54u72kha71vkibvxhjye7 FOREIGN KEY (domain_repo_id, history_revision_id) REFERENCES public."DomainHistory"(domain_repo_id, history_revision_id);
--
-- Name: DomainHost fkfmi7bdink53swivs390m2btxg; Type: FK CONSTRAINT; Schema: public; Owner: -
--
+3 -1
View File
@@ -31,14 +31,16 @@ do
echo "Updating cluster ${parts[0]} in zone ${parts[1]}..."
gcloud container clusters get-credentials "${parts[0]}" \
--project "${project}" --zone "${parts[1]}"
# Kills all running pods, new pods created will be pulling the new image.
sed s/GCP_PROJECT/${project}/g "./kubernetes/proxy-deployment-${environment}.yaml" | \
kubectl replace -f -
kubectl replace -f "./kubernetes/proxy-service.yaml" --force
# Alpha does not have canary
if [[ ${environment} != "alpha" ]]; then
sed s/GCP_PROJECT/${project}/g "./kubernetes/proxy-deployment-${environment}-canary.yaml" | \
kubectl replace -f -
kubectl replace -f "./kubernetes/proxy-service-canary.yaml" --force
fi
# Kills all running pods, new pods created will be pulling the new image.
kubectl delete pods --all
done < <(gcloud container clusters list --project ${project} | grep proxy-cluster)
kubectl config use-context "$current_context"
@@ -18,6 +18,9 @@ spec:
containers:
- name: proxy-canary
image: gcr.io/GCP_PROJECT/proxy
resources:
requests:
cpu: "101m"
ports:
- containerPort: 30000
name: health-check
@@ -18,6 +18,9 @@ spec:
containers:
- name: proxy
image: gcr.io/GCP_PROJECT/proxy
resources:
requests:
cpu: "101m"
ports:
- containerPort: 30000
name: health-check

Some files were not shown because too many files have changed in this diff Show More