diff --git a/core/src/main/java/google/registry/batch/DeleteContactsAndHostsAction.java b/core/src/main/java/google/registry/batch/DeleteContactsAndHostsAction.java index ed947c3b6..1e75cde79 100644 --- a/core/src/main/java/google/registry/batch/DeleteContactsAndHostsAction.java +++ b/core/src/main/java/google/registry/batch/DeleteContactsAndHostsAction.java @@ -347,7 +347,7 @@ public class DeleteContactsAndHostsAction implements Runnable { String resourceClientId = resource.getPersistedCurrentSponsorClientId(); if (resource instanceof HostResource && ((HostResource) resource).isSubordinate()) { resourceClientId = - ofy().load().key(((HostResource) resource).getSuperordinateDomain()).now() + tm().load(((HostResource) resource).getSuperordinateDomain()) .cloneProjectedAtTime(now) .getCurrentSponsorClientId(); } @@ -466,10 +466,11 @@ public class DeleteContactsAndHostsAction implements Runnable { HostResource host = (HostResource) existingResource; if (host.isSubordinate()) { dnsQueue.addHostRefreshTask(host.getFullyQualifiedHostName()); - ofy().save().entity( - ofy().load().key(host.getSuperordinateDomain()).now().asBuilder() - .removeSubordinateHost(host.getFullyQualifiedHostName()) - .build()); + tm().saveNewOrUpdate( + tm().load(host.getSuperordinateDomain()) + .asBuilder() + .removeSubordinateHost(host.getFullyQualifiedHostName()) + .build()); } } else { throw new IllegalStateException( diff --git a/core/src/main/java/google/registry/flows/host/HostCreateFlow.java b/core/src/main/java/google/registry/flows/host/HostCreateFlow.java index aa76553be..5e5b919dd 100644 --- a/core/src/main/java/google/registry/flows/host/HostCreateFlow.java +++ b/core/src/main/java/google/registry/flows/host/HostCreateFlow.java @@ -128,7 +128,7 @@ public final class HostCreateFlow implements TransactionalFlow { .setFullyQualifiedHostName(targetId) .setInetAddresses(command.getInetAddresses()) .setRepoId(createRepoId(ObjectifyService.allocateId(), roidSuffix)) - .setSuperordinateDomain(superordinateDomain.map(Key::create).orElse(null)) + .setSuperordinateDomain(superordinateDomain.map(DomainBase::createVKey).orElse(null)) .build(); historyBuilder .setType(HistoryEntry.Type.HOST_CREATE) diff --git a/core/src/main/java/google/registry/flows/host/HostDeleteFlow.java b/core/src/main/java/google/registry/flows/host/HostDeleteFlow.java index 94d89c00b..822c4192d 100644 --- a/core/src/main/java/google/registry/flows/host/HostDeleteFlow.java +++ b/core/src/main/java/google/registry/flows/host/HostDeleteFlow.java @@ -96,8 +96,7 @@ public final class HostDeleteFlow implements TransactionalFlow { // the client id, needs to be read off of it. EppResource owningResource = existingHost.isSubordinate() - ? ofy().load().key(existingHost.getSuperordinateDomain()).now() - .cloneProjectedAtTime(now) + ? tm().load(existingHost.getSuperordinateDomain()).cloneProjectedAtTime(now) : existingHost; verifyResourceOwnership(clientId, owningResource); } diff --git a/core/src/main/java/google/registry/flows/host/HostInfoFlow.java b/core/src/main/java/google/registry/flows/host/HostInfoFlow.java index 3d602eab5..cd9525118 100644 --- a/core/src/main/java/google/registry/flows/host/HostInfoFlow.java +++ b/core/src/main/java/google/registry/flows/host/HostInfoFlow.java @@ -18,7 +18,7 @@ import static google.registry.flows.FlowUtils.validateClientIsLoggedIn; import static google.registry.flows.ResourceFlowUtils.loadAndVerifyExistence; import static google.registry.flows.host.HostFlowUtils.validateHostName; import static google.registry.model.EppResourceUtils.isLinked; -import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; @@ -77,7 +77,7 @@ public final class HostInfoFlow implements Flow { // there is no superordinate domain, the host's own values for these fields will be correct. if (host.isSubordinate()) { DomainBase superordinateDomain = - ofy().load().key(host.getSuperordinateDomain()).now().cloneProjectedAtTime(now); + tm().load(host.getSuperordinateDomain()).cloneProjectedAtTime(now); hostInfoDataBuilder .setCurrentSponsorClientId(superordinateDomain.getCurrentSponsorClientId()) .setLastTransferTime(host.computeLastTransferTime(superordinateDomain)); diff --git a/core/src/main/java/google/registry/flows/host/HostUpdateFlow.java b/core/src/main/java/google/registry/flows/host/HostUpdateFlow.java index 96f54a3f6..fa0d110b6 100644 --- a/core/src/main/java/google/registry/flows/host/HostUpdateFlow.java +++ b/core/src/main/java/google/registry/flows/host/HostUpdateFlow.java @@ -60,6 +60,7 @@ import google.registry.model.host.HostResource; import google.registry.model.index.ForeignKeyIndex; import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.IcannReportingTypes.ActivityReportField; +import google.registry.persistence.VKey; import java.util.Objects; import java.util.Optional; import javax.inject.Inject; @@ -136,9 +137,10 @@ public final class HostUpdateFlow implements TransactionalFlow { boolean isHostRename = suppliedNewHostName != null; String oldHostName = targetId; String newHostName = firstNonNull(suppliedNewHostName, oldHostName); - DomainBase oldSuperordinateDomain = existingHost.isSubordinate() - ? ofy().load().key(existingHost.getSuperordinateDomain()).now().cloneProjectedAtTime(now) - : null; + DomainBase oldSuperordinateDomain = + existingHost.isSubordinate() + ? tm().load(existingHost.getSuperordinateDomain()).cloneProjectedAtTime(now) + : null; // Note that lookupSuperordinateDomain calls cloneProjectedAtTime on the domain for us. Optional newSuperordinateDomain = lookupSuperordinateDomain(validateHostName(newHostName), now); @@ -153,8 +155,8 @@ public final class HostUpdateFlow implements TransactionalFlow { AddRemove remove = command.getInnerRemove(); checkSameValuesNotAddedAndRemoved(add.getStatusValues(), remove.getStatusValues()); checkSameValuesNotAddedAndRemoved(add.getInetAddresses(), remove.getInetAddresses()); - Key newSuperordinateDomainKey = - newSuperordinateDomain.map(Key::create).orElse(null); + VKey newSuperordinateDomainKey = + newSuperordinateDomain.map(DomainBase::createVKey).orElse(null); // If the superordinateDomain field is changing, set the lastSuperordinateChange to now. DateTime lastSuperordinateChange = Objects.equals(newSuperordinateDomainKey, existingHost.getSuperordinateDomain()) @@ -280,28 +282,28 @@ public final class HostUpdateFlow implements TransactionalFlow { if (existingHost.isSubordinate() && newHost.isSubordinate() && Objects.equals( - existingHost.getSuperordinateDomain(), - newHost.getSuperordinateDomain())) { - ofy().save().entity( - ofy().load().key(existingHost.getSuperordinateDomain()).now().asBuilder() - .removeSubordinateHost(existingHost.getFullyQualifiedHostName()) - .addSubordinateHost(newHost.getFullyQualifiedHostName()) - .build()); + existingHost.getSuperordinateDomain(), newHost.getSuperordinateDomain())) { + tm().saveNewOrUpdate( + tm().load(existingHost.getSuperordinateDomain()) + .asBuilder() + .removeSubordinateHost(existingHost.getFullyQualifiedHostName()) + .addSubordinateHost(newHost.getFullyQualifiedHostName()) + .build()); return; } if (existingHost.isSubordinate()) { - ofy().save().entity( - ofy().load().key(existingHost.getSuperordinateDomain()).now() - .asBuilder() - .removeSubordinateHost(existingHost.getFullyQualifiedHostName()) - .build()); + tm().saveNewOrUpdate( + tm().load(existingHost.getSuperordinateDomain()) + .asBuilder() + .removeSubordinateHost(existingHost.getFullyQualifiedHostName()) + .build()); } if (newHost.isSubordinate()) { - ofy().save().entity( - ofy().load().key(newHost.getSuperordinateDomain()).now() - .asBuilder() - .addSubordinateHost(newHost.getFullyQualifiedHostName()) - .build()); + tm().saveNewOrUpdate( + tm().load(newHost.getSuperordinateDomain()) + .asBuilder() + .addSubordinateHost(newHost.getFullyQualifiedHostName()) + .build()); } } diff --git a/core/src/main/java/google/registry/model/domain/DomainBase.java b/core/src/main/java/google/registry/model/domain/DomainBase.java index 999af6913..bc37c4d93 100644 --- a/core/src/main/java/google/registry/model/domain/DomainBase.java +++ b/core/src/main/java/google/registry/model/domain/DomainBase.java @@ -66,6 +66,7 @@ import google.registry.model.registry.Registry; import google.registry.model.transfer.TransferData; import google.registry.model.transfer.TransferStatus; import google.registry.persistence.VKey; +import google.registry.persistence.WithStringVKey; import google.registry.schema.replay.DatastoreAndSqlEntity; import google.registry.util.CollectionUtils; import java.util.HashSet; @@ -106,6 +107,7 @@ import org.joda.time.Interval; @javax.persistence.Index(columnList = "fullyQualifiedDomainName"), @javax.persistence.Index(columnList = "tld") }) +@WithStringVKey @ExternalMessagingName("domain") public class DomainBase extends EppResource implements DatastoreAndSqlEntity, ForeignKeyedEppResource, ResourceWithTransferData { diff --git a/core/src/main/java/google/registry/model/host/HostResource.java b/core/src/main/java/google/registry/model/host/HostResource.java index eb1923541..32d386a25 100644 --- a/core/src/main/java/google/registry/model/host/HostResource.java +++ b/core/src/main/java/google/registry/model/host/HostResource.java @@ -76,7 +76,7 @@ public class HostResource extends EppResource @Index @IgnoreSave(IfNull.class) @DoNotHydrate - Key superordinateDomain; + VKey superordinateDomain; /** * The time that this resource was last transferred. @@ -98,7 +98,7 @@ public class HostResource extends EppResource return fullyQualifiedHostName; } - public Key getSuperordinateDomain() { + public VKey getSuperordinateDomain() { return superordinateDomain; } @@ -145,18 +145,18 @@ public class HostResource extends EppResource * *

If the host is not subordinate the domain can be null and we just return last transfer time. * - * @param superordinateDomain the loaded superordinate domain, which must match the key in - * the {@link #superordinateDomain} field. Passing it as a parameter allows the caller to - * control the degree of consistency used to load it. + * @param superordinateDomain the loaded superordinate domain, which must match the key in the + * {@link #superordinateDomain} field. Passing it as a parameter allows the caller to control + * the degree of consistency used to load it. */ - public DateTime computeLastTransferTime(@Nullable DomainBase superordinateDomain) { + public DateTime computeLastTransferTime(@Nullable DomainBase superordinateDomain) { if (!isSubordinate()) { checkArgument(superordinateDomain == null); return getLastTransferTime(); } checkArgument( superordinateDomain != null - && Key.create(superordinateDomain).equals(getSuperordinateDomain())); + && superordinateDomain.createVKey().equals(getSuperordinateDomain())); DateTime lastSuperordinateChange = Optional.ofNullable(getLastSuperordinateChange()).orElse(getCreationTime()); DateTime lastTransferOfCurrentSuperordinate = @@ -207,7 +207,7 @@ public class HostResource extends EppResource difference(getInstance().getInetAddresses(), inetAddresses))); } - public Builder setSuperordinateDomain(Key superordinateDomain) { + public Builder setSuperordinateDomain(VKey superordinateDomain) { getInstance().superordinateDomain = superordinateDomain; return this; } diff --git a/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java b/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java index 4932fb3c1..7d7b5db47 100644 --- a/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java +++ b/core/src/main/java/google/registry/rdap/RdapJsonFormatter.java @@ -433,10 +433,7 @@ public class RdapJsonFormatter { statuses.add(StatusValue.LINKED); } if (hostResource.isSubordinate() - && ofy() - .load() - .key(hostResource.getSuperordinateDomain()) - .now() + && tm().load(hostResource.getSuperordinateDomain()) .cloneProjectedAtTime(getRequestTime()) .getStatusValues() .contains(StatusValue.PENDING_TRANSFER)) { diff --git a/core/src/main/java/google/registry/rde/HostResourceToXjcConverter.java b/core/src/main/java/google/registry/rde/HostResourceToXjcConverter.java index ce929f8c4..2bd6b17e5 100644 --- a/core/src/main/java/google/registry/rde/HostResourceToXjcConverter.java +++ b/core/src/main/java/google/registry/rde/HostResourceToXjcConverter.java @@ -17,7 +17,6 @@ package google.registry.rde; import static com.google.common.base.Preconditions.checkArgument; import com.google.common.net.InetAddresses; -import com.googlecode.objectify.Key; import google.registry.model.domain.DomainBase; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; @@ -35,9 +34,8 @@ import org.joda.time.DateTime; final class HostResourceToXjcConverter { /** Converts a subordinate {@link HostResource} to {@link XjcRdeHostElement}. */ - static XjcRdeHostElement convertSubordinate( - HostResource host, DomainBase superordinateDomain) { - checkArgument(Key.create(superordinateDomain).equals(host.getSuperordinateDomain())); + static XjcRdeHostElement convertSubordinate(HostResource host, DomainBase superordinateDomain) { + checkArgument(superordinateDomain.createVKey().equals(host.getSuperordinateDomain())); return new XjcRdeHostElement(convertSubordinateHost(host, superordinateDomain)); } diff --git a/core/src/main/java/google/registry/rde/RdeStagingMapper.java b/core/src/main/java/google/registry/rde/RdeStagingMapper.java index 5c3f8da67..78e46bb54 100644 --- a/core/src/main/java/google/registry/rde/RdeStagingMapper.java +++ b/core/src/main/java/google/registry/rde/RdeStagingMapper.java @@ -18,6 +18,7 @@ import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static google.registry.model.EppResourceUtils.loadAtPointInTime; import static google.registry.model.ofy.ObjectifyService.ofy; +import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import com.google.appengine.tools.mapreduce.Mapper; import com.google.auto.value.AutoValue; @@ -186,13 +187,16 @@ public final class RdeStagingMapper extends Mapper google.registry.model.billing.VKeyConverter_BillingEvent + google.registry.model.domain.VKeyConverter_DomainBase google.registry.model.domain.token.VKeyConverter_AllocationToken google.registry.model.host.VKeyConverter_HostResource google.registry.model.contact.VKeyConverter_ContactResource diff --git a/core/src/test/java/google/registry/batch/DeleteContactsAndHostsActionTest.java b/core/src/test/java/google/registry/batch/DeleteContactsAndHostsActionTest.java index 19634c362..1ec8e6b37 100644 --- a/core/src/test/java/google/registry/batch/DeleteContactsAndHostsActionTest.java +++ b/core/src/test/java/google/registry/batch/DeleteContactsAndHostsActionTest.java @@ -725,7 +725,7 @@ public class DeleteContactsAndHostsActionTest persistResource( persistHostPendingDelete("ns2.example.tld") .asBuilder() - .setSuperordinateDomain(Key.create(domain)) + .setSuperordinateDomain(domain.createVKey()) .build()); enqueuer.enqueueAsyncDelete( host, diff --git a/core/src/test/java/google/registry/flows/EppLifecycleHostTest.java b/core/src/test/java/google/registry/flows/EppLifecycleHostTest.java index 8e0e7a199..a75f1b80d 100644 --- a/core/src/test/java/google/registry/flows/EppLifecycleHostTest.java +++ b/core/src/test/java/google/registry/flows/EppLifecycleHostTest.java @@ -24,7 +24,6 @@ import static google.registry.testing.EppMetricSubject.assertThat; import static google.registry.testing.HostResourceSubject.assertAboutHosts; import com.google.common.collect.ImmutableMap; -import com.googlecode.objectify.Key; import google.registry.model.domain.DomainBase; import google.registry.model.host.HostResource; import google.registry.testing.AppEngineRule; @@ -221,7 +220,7 @@ public class EppLifecycleHostTest extends EppTestCase { loadByForeignKey(DomainBase.class, "example.bar.foo.tld", timeAfterCreates).get(); assertAboutHosts() .that(exampleBarFooTldHost) - .hasSuperordinateDomain(Key.create(exampleBarFooTldDomain)); + .hasSuperordinateDomain(exampleBarFooTldDomain.createVKey()); assertThat(exampleBarFooTldDomain.getSubordinateHosts()) .containsExactly("ns1.example.bar.foo.tld"); @@ -231,14 +230,14 @@ public class EppLifecycleHostTest extends EppTestCase { loadByForeignKey(DomainBase.class, "example.foo.tld", timeAfterCreates).get(); assertAboutHosts() .that(exampleFooTldHost) - .hasSuperordinateDomain(Key.create(exampleFooTldDomain)); + .hasSuperordinateDomain(exampleFooTldDomain.createVKey()); assertThat(exampleFooTldDomain.getSubordinateHosts()).containsExactly("ns1.example.foo.tld"); HostResource exampleTldHost = loadByForeignKey(HostResource.class, "ns1.example.tld", timeAfterCreates).get(); DomainBase exampleTldDomain = loadByForeignKey(DomainBase.class, "example.tld", timeAfterCreates).get(); - assertAboutHosts().that(exampleTldHost).hasSuperordinateDomain(Key.create(exampleTldDomain)); + assertAboutHosts().that(exampleTldHost).hasSuperordinateDomain(exampleTldDomain.createVKey()); assertThat(exampleTldDomain.getSubordinateHosts()).containsExactly("ns1.example.tld"); assertThatLogoutSucceeds(); diff --git a/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java index 836bf2082..a1643daf9 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java @@ -719,7 +719,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase .setPersistedCurrentSponsorClientId("TheRegistrar") .setCreationClientId("TheRegistrar") .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) - .setSuperordinateDomain(Key.create(domain)) + .setSuperordinateDomain(domain.createVKey()) .build()); domain = persistResource( diff --git a/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java index 411d3a617..5f3fcb3c1 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java @@ -389,8 +389,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase hostNameToHostMap = new HashMap<>(); - enum RequestType { NONE, NAME, NS_LDH_NAME, NS_IP } + enum RequestType { + NONE, + NAME, + NS_LDH_NAME, + NS_IP + } private JsonObject generateActualJson(RequestType requestType, String paramValue) { return generateActualJson(requestType, paramValue, null); } - private JsonObject generateActualJson( - RequestType requestType, String paramValue, String cursor) { + private JsonObject generateActualJson(RequestType requestType, String paramValue, String cursor) { action.requestPath = actionPath; action.requestMethod = POST; String requestTypeParam = null; @@ -179,9 +182,9 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase= 1; i--) { String hostName = String.format("ns%d.%s", i, mainDomainName); subordinateHostnamesBuilder.add(hostName); - HostResource host = makeAndPersistHostResource( - hostName, String.format("5.5.%d.%d", 5 + i / 250, i % 250), clock.nowUtc().minusYears(1)); + HostResource host = + makeAndPersistHostResource( + hostName, + String.format("5.5.%d.%d", 5 + i / 250, i % 250), + clock.nowUtc().minusYears(1)); hostKeysBuilder.add(host.createVKey()); } ImmutableSet> hostKeys = hostKeysBuilder.build(); @@ -533,8 +536,7 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase", Registrar.State.ACTIVE)); persistSimpleResources(makeRegistrarContacts(registrar)); - hostNs1CatLol = makeAndPersistHostResource( - "ns1.cat.lol", "1.2.3.4", clock.nowUtc().minusYears(1)); - hostNs2CatLol = makeAndPersistHostResource( - "ns2.cat.lol", "bad:f00d:cafe::15:beef", clock.nowUtc().minusYears(1)); + hostNs1CatLol = + makeAndPersistHostResource("ns1.cat.lol", "1.2.3.4", clock.nowUtc().minusYears(1)); + hostNs2CatLol = + makeAndPersistHostResource( + "ns2.cat.lol", "bad:f00d:cafe::15:beef", clock.nowUtc().minusYears(1)); makeAndPersistHostResource( "ns1.cat2.lol", "1.2.3.3", "bad:f00d:cafe::15:beef", clock.nowUtc().minusYears(1)); makeAndPersistHostResource("ns1.cat.external", null, null, clock.nowUtc().minusYears(1)); @@ -132,25 +132,28 @@ public class RdapNameserverSearchActionTest makeAndPersistHostResource("ns1.cat.1.test", "1.2.3.6", clock.nowUtc().minusYears(1)); // create a domain so that we can use it as a test nameserver search string suffix - domainCatLol = persistResource( - makeDomainBase( - "cat.lol", - persistResource( - makeContactResource("5372808-ERL", "Goblin Market", "lol@cat.lol", registrar)), - persistResource( - makeContactResource("5372808-IRL", "Santa Claus", "BOFH@cat.lol", registrar)), - persistResource( - makeContactResource("5372808-TRL", "The Raven", "bog@cat.lol", registrar)), - hostNs1CatLol, - hostNs2CatLol, - registrar) - .asBuilder() - .setSubordinateHosts(ImmutableSet.of("ns1.cat.lol", "ns2.cat.lol")) - .build()); + domainCatLol = + persistResource( + makeDomainBase( + "cat.lol", + persistResource( + makeContactResource( + "5372808-ERL", "Goblin Market", "lol@cat.lol", registrar)), + persistResource( + makeContactResource( + "5372808-IRL", "Santa Claus", "BOFH@cat.lol", registrar)), + persistResource( + makeContactResource("5372808-TRL", "The Raven", "bog@cat.lol", registrar)), + hostNs1CatLol, + hostNs2CatLol, + registrar) + .asBuilder() + .setSubordinateHosts(ImmutableSet.of("ns1.cat.lol", "ns2.cat.lol")) + .build()); persistResource( - hostNs1CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build()); + hostNs1CatLol.asBuilder().setSuperordinateDomain(domainCatLol.createVKey()).build()); persistResource( - hostNs2CatLol.asBuilder().setSuperordinateDomain(Key.create(domainCatLol)).build()); + hostNs2CatLol.asBuilder().setSuperordinateDomain(domainCatLol.createVKey()).build()); action.ipParam = Optional.empty(); action.nameParam = Optional.empty(); @@ -187,10 +190,9 @@ public class RdapNameserverSearchActionTest hostsBuilder.add(makeHostResource(hostName, "5.5.5.1", "5.5.5.2")); } persistResources(hostsBuilder.build()); - domainCatLol = persistResource( - domainCatLol.asBuilder() - .setSubordinateHosts(subordinateHostsBuilder.build()) - .build()); + domainCatLol = + persistResource( + domainCatLol.asBuilder().setSubordinateHosts(subordinateHostsBuilder.build()).build()); } private void createDeletedHost() { @@ -245,10 +247,7 @@ public class RdapNameserverSearchActionTest public void testInvalidRequest_rejected() { action.run(); assertThat(parseJsonObject(response.getPayload())) - .isEqualTo( - generateExpectedJsonError( - "You must specify either name=XXXX or ip=YYYY", - 400)); + .isEqualTo(generateExpectedJsonError("You must specify either name=XXXX or ip=YYYY", 400)); assertThat(response.getStatus()).isEqualTo(400); verifyErrorMetrics(Optional.empty(), 400); } @@ -294,8 +293,7 @@ public class RdapNameserverSearchActionTest public void testNoCharactersToMatch_rejected() { assertThat(generateActualJsonWithName("*")) .isEqualTo( - generateExpectedJsonError( - "Initial search string must be at least 2 characters", 422)); + generateExpectedJsonError("Initial search string must be at least 2 characters", 422)); assertThat(response.getStatus()).isEqualTo(422); verifyErrorMetrics(Optional.empty(), 422); } @@ -304,8 +302,7 @@ public class RdapNameserverSearchActionTest public void testFewerThanTwoCharactersToMatch_rejected() { assertThat(generateActualJsonWithName("a*")) .isEqualTo( - generateExpectedJsonError( - "Initial search string must be at least 2 characters", 422)); + generateExpectedJsonError("Initial search string must be at least 2 characters", 422)); assertThat(response.getStatus()).isEqualTo(422); verifyErrorMetrics(Optional.empty(), 422); } @@ -349,7 +346,8 @@ public class RdapNameserverSearchActionTest @Test public void testNameMatch_ns2_cat_lol_found() { assertThat(generateActualJsonWithName("ns2.cat.lol")) - .isEqualTo(generateExpectedJsonForNameserver( + .isEqualTo( + generateExpectedJsonForNameserver( "ns2.cat.lol", null, "4-ROID", @@ -505,7 +503,7 @@ public class RdapNameserverSearchActionTest public void testNameMatch_nontruncatedResultSet() { createManyHosts(4); assertThat(generateActualJsonWithName("nsx*.cat.lol")) - .isEqualTo(loadJsonFile("rdap_nontruncated_hosts.json")); + .isEqualTo(loadJsonFile("rdap_nontruncated_hosts.json")); assertThat(response.getStatus()).isEqualTo(200); verifyMetrics(4); } @@ -535,8 +533,7 @@ public class RdapNameserverSearchActionTest @Test public void testNameMatchDeletedHost_foundTheOtherHost() { - persistResource( - hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); + persistResource(hostNs1CatLol.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); assertThat(generateActualJsonWithName("ns*.cat.lol")) .isEqualTo( generateExpectedJsonForNameserver( @@ -648,8 +645,7 @@ public class RdapNameserverSearchActionTest * @param expectedNames an immutable list of the host names we expect to retrieve */ private void checkCursorNavigation( - boolean byName, String paramValue, ImmutableList expectedNames) - throws Exception { + boolean byName, String paramValue, ImmutableList expectedNames) throws Exception { String cursor = null; int expectedNameOffset = 0; int expectedPageCount = @@ -792,9 +788,9 @@ public class RdapNameserverSearchActionTest public void testAddressMatch_truncatedResultSet() { createManyHosts(5); assertThat(generateActualJsonWithIp("5.5.5.1")) - .isEqualTo( - loadJsonFile( - "rdap_truncated_hosts.json", "QUERY", "ip=5.5.5.1&cursor=MTctUk9JRA%3D%3D")); + .isEqualTo( + loadJsonFile( + "rdap_truncated_hosts.json", "QUERY", "ip=5.5.5.1&cursor=MTctUk9JRA%3D%3D")); assertThat(response.getStatus()).isEqualTo(200); verifyMetrics(5, IncompletenessWarningType.TRUNCATED); } diff --git a/core/src/test/java/google/registry/rde/HostResourceToXjcConverterTest.java b/core/src/test/java/google/registry/rde/HostResourceToXjcConverterTest.java index 5fee41692..23098e2d1 100644 --- a/core/src/test/java/google/registry/rde/HostResourceToXjcConverterTest.java +++ b/core/src/test/java/google/registry/rde/HostResourceToXjcConverterTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; -import com.googlecode.objectify.Key; import google.registry.model.domain.DomainBase; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; @@ -43,8 +42,8 @@ import org.junit.runners.JUnit4; /** * Unit tests for {@link HostResourceToXjcConverter}. * - *

This tests the mapping between {@link HostResource} and {@link XjcRdeHost} as well as - * some exceptional conditions. + *

This tests the mapping between {@link HostResource} and {@link XjcRdeHost} as well as some + * exceptional conditions. */ @RunWith(JUnit4.class) public class HostResourceToXjcConverterTest { @@ -59,26 +58,29 @@ public class HostResourceToXjcConverterTest { @Test public void testConvertSubordinateHost() { - DomainBase domain = newDomainBase("love.foobar").asBuilder() - .setPersistedCurrentSponsorClientId("LeisureDog") - .setLastTransferTime(DateTime.parse("2010-01-01T00:00:00Z")) - .addStatusValue(StatusValue.PENDING_TRANSFER) - .build(); - XjcRdeHost bean = HostResourceToXjcConverter.convertSubordinateHost( - new HostResource.Builder() - .setCreationClientId("LawyerCat") - .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) - .setPersistedCurrentSponsorClientId("BusinessCat") - .setFullyQualifiedHostName("ns1.love.foobar") - .setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1"))) - .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) - .setLastEppUpdateClientId("CeilingCat") - .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) - .setRepoId("2-roid") - .setStatusValues(ImmutableSet.of(StatusValue.OK)) - .setSuperordinateDomain(Key.create(domain)) - .build(), - domain); + DomainBase domain = + newDomainBase("love.foobar") + .asBuilder() + .setPersistedCurrentSponsorClientId("LeisureDog") + .setLastTransferTime(DateTime.parse("2010-01-01T00:00:00Z")) + .addStatusValue(StatusValue.PENDING_TRANSFER) + .build(); + XjcRdeHost bean = + HostResourceToXjcConverter.convertSubordinateHost( + new HostResource.Builder() + .setCreationClientId("LawyerCat") + .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) + .setPersistedCurrentSponsorClientId("BusinessCat") + .setFullyQualifiedHostName("ns1.love.foobar") + .setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1"))) + .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) + .setLastEppUpdateClientId("CeilingCat") + .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) + .setRepoId("2-roid") + .setStatusValues(ImmutableSet.of(StatusValue.OK)) + .setSuperordinateDomain(domain.createVKey()) + .build(), + domain); assertThat(bean.getAddrs()).hasSize(1); assertThat(bean.getAddrs().get(0).getIp().value()).isEqualTo("v4"); @@ -119,19 +121,20 @@ public class HostResourceToXjcConverterTest { @Test public void testConvertExternalHost() { - XjcRdeHost bean = HostResourceToXjcConverter.convertExternalHost( - new HostResource.Builder() - .setCreationClientId("LawyerCat") - .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) - .setPersistedCurrentSponsorClientId("BusinessCat") - .setFullyQualifiedHostName("ns1.love.lol") - .setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1"))) - .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) - .setLastEppUpdateClientId("CeilingCat") - .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) - .setRepoId("2-roid") - .setStatusValues(ImmutableSet.of(StatusValue.OK)) - .build()); + XjcRdeHost bean = + HostResourceToXjcConverter.convertExternalHost( + new HostResource.Builder() + .setCreationClientId("LawyerCat") + .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) + .setPersistedCurrentSponsorClientId("BusinessCat") + .setFullyQualifiedHostName("ns1.love.lol") + .setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1"))) + .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) + .setLastEppUpdateClientId("CeilingCat") + .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) + .setRepoId("2-roid") + .setStatusValues(ImmutableSet.of(StatusValue.OK)) + .build()); assertThat(bean.getAddrs()).hasSize(1); assertThat(bean.getAddrs().get(0).getIp().value()).isEqualTo("v4"); @@ -167,19 +170,20 @@ public class HostResourceToXjcConverterTest { @Test public void testConvertExternalHost_ipv6() { - XjcRdeHost bean = HostResourceToXjcConverter.convertExternalHost( - new HostResource.Builder() - .setCreationClientId("LawyerCat") - .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) - .setPersistedCurrentSponsorClientId("BusinessCat") - .setFullyQualifiedHostName("ns1.love.lol") - .setInetAddresses(ImmutableSet.of(InetAddresses.forString("cafe::abba"))) - .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) - .setLastEppUpdateClientId("CeilingCat") - .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) - .setRepoId("2-LOL") - .setStatusValues(ImmutableSet.of(StatusValue.OK)) - .build()); + XjcRdeHost bean = + HostResourceToXjcConverter.convertExternalHost( + new HostResource.Builder() + .setCreationClientId("LawyerCat") + .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) + .setPersistedCurrentSponsorClientId("BusinessCat") + .setFullyQualifiedHostName("ns1.love.lol") + .setInetAddresses(ImmutableSet.of(InetAddresses.forString("cafe::abba"))) + .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) + .setLastEppUpdateClientId("CeilingCat") + .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) + .setRepoId("2-LOL") + .setStatusValues(ImmutableSet.of(StatusValue.OK)) + .build()); assertThat(bean.getAddrs()).hasSize(1); assertThat(bean.getAddrs().get(0).getIp().value()).isEqualTo("v6"); assertThat(bean.getAddrs().get(0).getValue()).isEqualTo("cafe::abba"); @@ -208,19 +212,20 @@ public class HostResourceToXjcConverterTest { @Test public void testMarshal() throws Exception { // Bean! Bean! Bean! - XjcRdeHostElement bean = HostResourceToXjcConverter.convertExternal( - new HostResource.Builder() - .setCreationClientId("LawyerCat") - .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) - .setPersistedCurrentSponsorClientId("BusinessCat") - .setFullyQualifiedHostName("ns1.love.lol") - .setInetAddresses(ImmutableSet.of(InetAddresses.forString("cafe::abba"))) - .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) - .setLastEppUpdateClientId("CeilingCat") - .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) - .setRepoId("2-LOL") - .setStatusValues(ImmutableSet.of(StatusValue.OK)) - .build()); + XjcRdeHostElement bean = + HostResourceToXjcConverter.convertExternal( + new HostResource.Builder() + .setCreationClientId("LawyerCat") + .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) + .setPersistedCurrentSponsorClientId("BusinessCat") + .setFullyQualifiedHostName("ns1.love.lol") + .setInetAddresses(ImmutableSet.of(InetAddresses.forString("cafe::abba"))) + .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) + .setLastEppUpdateClientId("CeilingCat") + .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) + .setRepoId("2-LOL") + .setStatusValues(ImmutableSet.of(StatusValue.OK)) + .build()); marshalStrict(bean, new ByteArrayOutputStream(), UTF_8); } } diff --git a/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java b/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java index 318f3eaec..397c28022 100644 --- a/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java +++ b/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java @@ -185,7 +185,7 @@ abstract class AbstractEppResourceSubject< return andChainer(); } - protected And hasValue(E expected, E actual, String name) { + protected And hasValue(@Nullable E expected, @Nullable E actual, String name) { check(name).that(actual).isEqualTo(expected); return andChainer(); } diff --git a/core/src/test/java/google/registry/testing/DatastoreHelper.java b/core/src/test/java/google/registry/testing/DatastoreHelper.java index 7215525d9..0353f4efa 100644 --- a/core/src/test/java/google/registry/testing/DatastoreHelper.java +++ b/core/src/test/java/google/registry/testing/DatastoreHelper.java @@ -239,7 +239,7 @@ public class DatastoreHelper { return persistResource( newHostResource(hostName) .asBuilder() - .setSuperordinateDomain(Key.create(superordinateDomain)) + .setSuperordinateDomain(superordinateDomain.createVKey()) .setInetAddresses( ImmutableSet.of(InetAddresses.forString("1080:0:0:0:8:800:200C:417A"))) .build()); diff --git a/core/src/test/java/google/registry/testing/HostResourceSubject.java b/core/src/test/java/google/registry/testing/HostResourceSubject.java index 5fae683e7..f11407cdd 100644 --- a/core/src/test/java/google/registry/testing/HostResourceSubject.java +++ b/core/src/test/java/google/registry/testing/HostResourceSubject.java @@ -19,10 +19,11 @@ import static com.google.common.truth.Truth.assertAbout; import com.google.common.truth.FailureMetadata; import com.google.common.truth.SimpleSubjectBuilder; -import com.googlecode.objectify.Key; import google.registry.model.domain.DomainBase; import google.registry.model.host.HostResource; +import google.registry.persistence.VKey; import google.registry.testing.TruthChainer.And; +import javax.annotation.Nullable; import org.joda.time.DateTime; /** Truth subject for asserting things about {@link HostResource} instances. */ @@ -55,7 +56,8 @@ public final class HostResourceSubject "has lastSuperordinateChange"); } - public And hasSuperordinateDomain(Key superordinateDomain) { + public And hasSuperordinateDomain( + @Nullable VKey superordinateDomain) { return hasValue( superordinateDomain, actual.getSuperordinateDomain(), "has superordinateDomain"); } diff --git a/core/src/test/resources/google/registry/model/schema.txt b/core/src/test/resources/google/registry/model/schema.txt index ae5d03b80..63d95eef4 100644 --- a/core/src/test/resources/google/registry/model/schema.txt +++ b/core/src/test/resources/google/registry/model/schema.txt @@ -288,9 +288,9 @@ class google.registry.model.eppcommon.Trid { class google.registry.model.host.HostResource { @Id java.lang.String repoId; com.google.common.collect.ImmutableSortedMap> revisions; - com.googlecode.objectify.Key superordinateDomain; google.registry.model.CreateAutoTimestamp creationTime; google.registry.model.UpdateAutoTimestamp updateTimestamp; + google.registry.persistence.VKey superordinateDomain; java.lang.String creationClientId; java.lang.String currentSponsorClientId; java.lang.String fullyQualifiedHostName; diff --git a/db/src/main/resources/sql/flyway/V28__superordinate_domain_vkey.sql b/db/src/main/resources/sql/flyway/V28__superordinate_domain_vkey.sql new file mode 100644 index 000000000..23c834716 --- /dev/null +++ b/db/src/main/resources/sql/flyway/V28__superordinate_domain_vkey.sql @@ -0,0 +1,19 @@ +-- 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" ALTER COLUMN superordinate_domain TYPE text; + +ALTER TABLE IF EXISTS "HostResource" + ADD CONSTRAINT fk_host_resource_superordinate_domain + FOREIGN KEY (superordinate_domain) REFERENCES "Domain"(repo_id); diff --git a/db/src/main/resources/sql/schema/db-schema.sql.generated b/db/src/main/resources/sql/schema/db-schema.sql.generated index efd5db2c6..496c1123a 100644 --- a/db/src/main/resources/sql/schema/db-schema.sql.generated +++ b/db/src/main/resources/sql/schema/db-schema.sql.generated @@ -195,7 +195,7 @@ fully_qualified_host_name text, last_superordinate_change timestamptz, last_transfer_time timestamptz, - superordinate_domain bytea, + superordinate_domain text, primary key (repo_id) ); diff --git a/db/src/main/resources/sql/schema/nomulus.golden.sql b/db/src/main/resources/sql/schema/nomulus.golden.sql index a120fc9d3..598e84165 100644 --- a/db/src/main/resources/sql/schema/nomulus.golden.sql +++ b/db/src/main/resources/sql/schema/nomulus.golden.sql @@ -316,7 +316,7 @@ CREATE TABLE public."HostResource" ( fully_qualified_host_name text, last_superordinate_change timestamp with time zone, last_transfer_time timestamp with time zone, - superordinate_domain bytea + superordinate_domain text ); @@ -1167,6 +1167,14 @@ ALTER TABLE ONLY public."DomainHost" ADD CONSTRAINT fk_domainhost_host_valid FOREIGN KEY (ns_hosts) REFERENCES public."HostResource"(repo_id); +-- +-- Name: HostResource fk_host_resource_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); + + -- -- Name: PollMessage fk_poll_message_contact_repo_id; Type: FK CONSTRAINT; Schema: public; Owner: - --