Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.base.Verify.verifyNotNull;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.tld.Tlds.getTldEntities;
import static google.registry.model.tld.Tlds.getTldEntitiesOfType;
import static google.registry.persistence.PersistenceModule.TransactionIsolationLevel.TRANSACTION_REPEATABLE_READ;
import static google.registry.persistence.transaction.TransactionManagerFactory.replicaTm;
Expand All @@ -35,6 +36,7 @@
import google.registry.request.auth.Auth;
import google.registry.storage.drive.DriveConnection;
import google.registry.util.Clock;
import google.registry.util.RegistryEnvironment;
import jakarta.inject.Inject;
import java.io.IOException;
import java.io.StringWriter;
Expand All @@ -45,7 +47,10 @@
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

/** An action that exports the upcoming domain drop list across all open TLDs to Google Drive. */
/**
* An action that exports the upcoming domain drop list across TLDs with XAP enabled to Google
* Drive.
*/
@Action(
service = Action.Service.BACKEND,
path = "/_dr/task/exportDropList",
Expand Down Expand Up @@ -89,15 +94,17 @@ public void run() {

Instant now = clock.now();
ImmutableSet<String> xapTlds =
getTldEntitiesOfType(TldType.REAL).stream()
.filter(Tld::isInvoicingEnabled)
(RegistryEnvironment.get() == RegistryEnvironment.PRODUCTION
? getTldEntitiesOfType(TldType.REAL)
: getTldEntities())
.stream()
.filter(tld -> tld.getExpiryAccessPeriodModeAt(now) == ExpiryAccessPeriodMode.ENABLED)
.map(Tld::getTldStr)
.collect(toImmutableSet());
logger.atInfo().log("Exporting domain drop list for open TLDs with XAP enabled: %s", xapTlds);
logger.atInfo().log("Exporting domain drop list for TLDs with XAP enabled: %s", xapTlds);

if (xapTlds.isEmpty()) {
logger.atInfo().log("No open TLDs found with XAP enabled.");
logger.atInfo().log("No TLDs found with XAP enabled.");
exportToDrive(createCsv(ImmutableList.of()));
return;
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/google/registry/model/tld/Tlds.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public static ImmutableSet<String> getTldsOfType(TldType type) {
return ImmutableSet.copyOf(filterValues(cache.get(), equalTo(type)).keySet());
}

/** Returns all TLD entities loaded fresh from the database. */
public static ImmutableSet<Tld> getTldEntities() {
return Tld.get(cache.get().keySet());
}

/** Returns the TLD entities themselves of the given type loaded fresh from the database. */
public static ImmutableSet<Tld> getTldEntitiesOfType(TldType type) {
return Tld.get(filterValues(cache.get(), equalTo(type)).keySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.storage.drive.DriveConnection;
import google.registry.testing.FakeClock;
import google.registry.testing.SystemPropertyExtension;
import google.registry.util.RegistryEnvironment;
import java.io.IOException;
import java.time.Instant;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.ArgumentCaptor;
Expand All @@ -59,6 +62,10 @@ class ExportDropListActionTest {
final JpaIntegrationTestExtension jpa =
new JpaTestExtensions.Builder().withClock(clock).buildIntegrationTestExtension();

@RegisterExtension
@Order(Integer.MAX_VALUE)
final SystemPropertyExtension systemPropertyExtension = new SystemPropertyExtension();

@BeforeEach
void beforeEach() {
createTld("open1");
Expand All @@ -80,11 +87,23 @@ void beforeEach() {
.build());

createTld("closed");
persistResource(Tld.get("closed").asBuilder().setInvoicingEnabled(false).build());
persistResource(
Tld.get("closed")
.asBuilder()
.setInvoicingEnabled(false)
.setExpiryAccessPeriodTransitions(
ImmutableSortedMap.of(START_INSTANT, ExpiryAccessPeriodMode.ENABLED))
.build());

createTld("testtld");
persistResource(
Tld.get("testtld").asBuilder().setTldType(TldType.TEST).setInvoicingEnabled(true).build());
Tld.get("testtld")
.asBuilder()
.setTldType(TldType.TEST)
.setInvoicingEnabled(false)
.setExpiryAccessPeriodTransitions(
ImmutableSortedMap.of(START_INSTANT, ExpiryAccessPeriodMode.ENABLED))
.build());

action = new ExportDropListAction();
action.clock = clock;
Expand All @@ -104,17 +123,20 @@ private void verifyExportedToDrive(String expectedCsv) throws Exception {
}

@Test
void test_exportsDropListAcrossOpenTlds_sortedByDomainName() throws Exception {
void test_exportsDropListAcrossTlds_sortedByDomainName() throws Exception {
// Active domain with no drop date (END_INSTANT) on open TLD -> excluded
persistActiveDomain("active.open1");

// Pending delete domains on open TLDs -> included
persistDeletedDomain("zebra.open1", Instant.parse("2020-02-07T02:02:02Z"));
persistDeletedDomain("alpha.open2", Instant.parse("2020-02-04T02:02:02Z"));

// Pending delete domain on non-invoicing (closed) TLD -> excluded
// Pending delete domain on non-invoicing (closed) TLD with XAP enabled -> included
persistDeletedDomain("closed.closed", Instant.parse("2020-02-05T02:02:02Z"));

// Pending delete domain on test TLD with XAP enabled in non-PROD -> included
persistDeletedDomain("test.testtld", Instant.parse("2020-02-06T02:02:02Z"));

// Pending delete domain on open TLD with XAP disabled -> excluded
createTld("noxap");
persistResource(
Expand All @@ -126,9 +148,6 @@ void test_exportsDropListAcrossOpenTlds_sortedByDomainName() throws Exception {
.build());
persistDeletedDomain("noxap.noxap", Instant.parse("2020-02-05T02:02:02Z"));

// Pending delete domain on test TLD -> excluded
persistDeletedDomain("test.testtld", Instant.parse("2020-02-06T02:02:02Z"));

// Already deleted domain on open TLD -> excluded
persistDeletedDomain("deleted.open1", Instant.parse("2020-02-01T02:02:02Z"));

Expand All @@ -138,10 +157,33 @@ void test_exportsDropListAcrossOpenTlds_sortedByDomainName() throws Exception {
"""
domain_name,tld,deletion_time
alpha.open2,open2,2020-02-04T02:02:02Z
closed.closed,closed,2020-02-05T02:02:02Z
test.testtld,testtld,2020-02-06T02:02:02Z
zebra.open1,open1,2020-02-07T02:02:02Z
""");
}

@Test
void test_exportsDropList_excludesTestTldsInProduction() throws Exception {
RegistryEnvironment.PRODUCTION.setup(systemPropertyExtension);

// Pending delete domains on open TLD and non-invoicing TLD with XAP enabled -> included
persistDeletedDomain("alpha.open2", Instant.parse("2020-02-04T02:02:02Z"));
persistDeletedDomain("closed.closed", Instant.parse("2020-02-05T02:02:02Z"));

// Pending delete domain on test TLD with XAP enabled -> excluded in PROD
persistDeletedDomain("test.testtld", Instant.parse("2020-02-06T02:02:02Z"));

action.run();

verifyExportedToDrive(
"""
domain_name,tld,deletion_time
alpha.open2,open2,2020-02-04T02:02:02Z
closed.closed,closed,2020-02-05T02:02:02Z
""");
}

@Test
void test_skipsDriveExport_whenDriveFolderIdIsEmpty() {
action.driveFolderId = Optional.empty();
Expand All @@ -164,7 +206,7 @@ void test_emptyDropList_outputsHeaderOnly() throws Exception {
}

@Test
void test_noOpenTldsWithXap_outputsHeaderOnly() throws Exception {
void test_noTldsWithXap_outputsHeaderOnly() throws Exception {
persistResource(
Tld.get("open1")
.asBuilder()
Expand All @@ -177,6 +219,18 @@ void test_noOpenTldsWithXap_outputsHeaderOnly() throws Exception {
.setExpiryAccessPeriodTransitions(
ImmutableSortedMap.of(START_INSTANT, ExpiryAccessPeriodMode.DISABLED))
.build());
persistResource(
Tld.get("closed")
.asBuilder()
.setExpiryAccessPeriodTransitions(
ImmutableSortedMap.of(START_INSTANT, ExpiryAccessPeriodMode.DISABLED))
.build());
persistResource(
Tld.get("testtld")
.asBuilder()
.setExpiryAccessPeriodTransitions(
ImmutableSortedMap.of(START_INSTANT, ExpiryAccessPeriodMode.DISABLED))
.build());

persistDeletedDomain("zebra.open1", Instant.parse("2020-02-07T02:02:02Z"));

Expand Down
2 changes: 2 additions & 0 deletions core/src/test/java/google/registry/model/tld/TldsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ void testGetTlds() {
void test_getTldEntities() {
initTestTlds();
persistResource(newTld("testtld", "TESTTLD").asBuilder().setTldType(TldType.TEST).build());
assertThat(Tlds.getTldEntities())
.containsExactly(Tld.get("foo"), Tld.get("a.b.c"), Tld.get("testtld"));
assertThat(Tlds.getTldEntitiesOfType(TldType.REAL))
.containsExactly(Tld.get("foo"), Tld.get("a.b.c"));
assertThat(Tlds.getTldEntitiesOfType(TldType.TEST)).containsExactly(Tld.get("testtld"));
Expand Down
Loading