mirror of
https://github.com/google/nomulus.git
synced 2025-07-06 11:13:35 +02:00
Allow command to enqueue poll messages for multiple registrars (#1446)
* Allow command to enqueue poll messages for multiple registrars
This commit is contained in:
parent
0a31e6e71c
commit
a96db1f236
4 changed files with 137 additions and 23 deletions
|
@ -18,14 +18,21 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.reporting.HistoryEntry.Type.SYNTHETIC;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.util.CollectionUtils.isNullOrEmpty;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Streams;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.model.domain.DomainBase;
|
||||
import google.registry.model.domain.DomainHistory;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Tool to enqueue a poll message for a registrar.
|
||||
|
@ -54,14 +61,26 @@ class EnqueuePollMessageCommand extends MutatingCommand {
|
|||
String domainName;
|
||||
|
||||
@Parameter(
|
||||
names = {"-c", "--client"},
|
||||
names = {"-c", "--clients"},
|
||||
description =
|
||||
"Client identifier of the registrar to send the poll message to, if not the owning"
|
||||
+ " registrar of the domain")
|
||||
String clientId;
|
||||
"Comma-delimited list of the client identifier(s) of the registrar(s) to send the poll"
|
||||
+ " message to, if not the owning registrar of the domain")
|
||||
List<String> clientIds;
|
||||
|
||||
@Parameter(
|
||||
names = {"-a", "--all"},
|
||||
description = "Whether to send the message to all real registrars",
|
||||
arity = 1)
|
||||
boolean sendToAll;
|
||||
|
||||
@Inject
|
||||
@Config("registryAdminClientId")
|
||||
String registryAdminClientId;
|
||||
|
||||
@Override
|
||||
protected final void init() {
|
||||
checkArgument(
|
||||
!sendToAll || isNullOrEmpty(clientIds), "Cannot specify both --all and --clients");
|
||||
tm().transact(
|
||||
() -> {
|
||||
Optional<DomainBase> domainOpt =
|
||||
|
@ -69,27 +88,39 @@ class EnqueuePollMessageCommand extends MutatingCommand {
|
|||
checkArgument(
|
||||
domainOpt.isPresent(), "Domain %s doesn't exist or isn't active", domainName);
|
||||
DomainBase domain = domainOpt.get();
|
||||
String registrarId =
|
||||
Optional.ofNullable(clientId).orElse(domain.getCurrentSponsorRegistrarId());
|
||||
ImmutableList<String> registrarIds;
|
||||
if (sendToAll) {
|
||||
registrarIds =
|
||||
Streams.stream(Registrar.loadAllCached())
|
||||
.filter(r -> r.isLive() && r.getType() == Registrar.Type.REAL)
|
||||
.map(Registrar::getRegistrarId)
|
||||
.collect(ImmutableList.toImmutableList());
|
||||
} else if (!isNullOrEmpty(clientIds)) {
|
||||
registrarIds = ImmutableList.copyOf(clientIds);
|
||||
} else {
|
||||
registrarIds = ImmutableList.of(domain.getCurrentSponsorRegistrarId());
|
||||
}
|
||||
HistoryEntry historyEntry =
|
||||
new DomainHistory.Builder()
|
||||
.setDomain(domain)
|
||||
.setType(SYNTHETIC)
|
||||
.setBySuperuser(true)
|
||||
.setReason("Manual enqueueing of poll message")
|
||||
.setReason("Manual enqueueing of poll message: " + message)
|
||||
.setModificationTime(tm().getTransactionTime())
|
||||
.setRequestedByRegistrar(false)
|
||||
.setRegistrarId(registrarId)
|
||||
.build();
|
||||
PollMessage.OneTime pollMessage =
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setRegistrarId(registrarId)
|
||||
.setParent(historyEntry)
|
||||
.setEventTime(tm().getTransactionTime())
|
||||
.setMsg(message)
|
||||
.setRegistrarId(registryAdminClientId)
|
||||
.build();
|
||||
stageEntityChange(null, historyEntry);
|
||||
stageEntityChange(null, pollMessage);
|
||||
for (String registrarId : registrarIds) {
|
||||
stageEntityChange(
|
||||
null,
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setRegistrarId(registrarId)
|
||||
.setParent(historyEntry)
|
||||
.setEventTime(tm().getTransactionTime())
|
||||
.setMsg(message)
|
||||
.build());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ public class SyncRegistrarsSheetTest {
|
|||
ImmutableMap<String, String> row = getOnlyElement(getOnlyElement(rowsCaptor.getAllValues()));
|
||||
assertThat(row).containsEntry("clientIdentifier", "SomeRegistrar");
|
||||
assertThat(row).containsEntry("registrarName", "Some Registrar");
|
||||
assertThat(row).containsEntry("state", "");
|
||||
assertThat(row).containsEntry("state", "ACTIVE");
|
||||
assertThat(row).containsEntry("ianaIdentifier", "8");
|
||||
assertThat(row).containsEntry("billingIdentifier", "");
|
||||
assertThat(row).containsEntry("primaryContacts", "");
|
||||
|
|
|
@ -96,6 +96,7 @@ import google.registry.model.index.ForeignKeyIndex;
|
|||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.pricing.StaticPremiumListPricingEngine;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.Registrar.State;
|
||||
import google.registry.model.registrar.RegistrarAddress;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.reporting.HistoryEntryDao;
|
||||
|
@ -758,6 +759,7 @@ public class DatabaseHelper {
|
|||
.setRegistrarId(registrarId)
|
||||
.setRegistrarName(registrarName)
|
||||
.setType(type)
|
||||
.setState(State.ACTIVE)
|
||||
.setIanaIdentifier(ianaIdentifier)
|
||||
.setLocalizedAddress(
|
||||
new RegistrarAddress.Builder()
|
||||
|
|
|
@ -20,6 +20,7 @@ import static google.registry.testing.DatabaseHelper.assertPollMessages;
|
|||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.getOnlyHistoryEntryOfType;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatabaseHelper.persistNewRegistrar;
|
||||
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
|
@ -47,6 +48,8 @@ class EnqueuePollMessageCommandTest extends CommandTestCase<EnqueuePollMessageCo
|
|||
createTld("tld");
|
||||
inject.setStaticField(Ofy.class, "clock", fakeClock);
|
||||
domain = persistActiveDomain("example.tld");
|
||||
persistNewRegistrar("AdminRegistrar");
|
||||
command.registryAdminClientId = "AdminRegistrar";
|
||||
fakeClock.advanceOneMilli();
|
||||
}
|
||||
|
||||
|
@ -59,11 +62,11 @@ class EnqueuePollMessageCommandTest extends CommandTestCase<EnqueuePollMessageCo
|
|||
.that(synthetic)
|
||||
.bySuperuser(true)
|
||||
.and()
|
||||
.hasMetadataReason("Manual enqueueing of poll message")
|
||||
.hasMetadataReason("Manual enqueueing of poll message: This domain is bad")
|
||||
.and()
|
||||
.hasNoXml()
|
||||
.and()
|
||||
.hasRegistrarId("TheRegistrar")
|
||||
.hasRegistrarId("AdminRegistrar")
|
||||
.and()
|
||||
.hasModificationTime(fakeClock.nowUtc())
|
||||
.and()
|
||||
|
@ -79,24 +82,35 @@ class EnqueuePollMessageCommandTest extends CommandTestCase<EnqueuePollMessageCo
|
|||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSuccess_specifyClientId() throws Exception {
|
||||
void testSuccess_specifyClientIds() throws Exception {
|
||||
persistNewRegistrar("foobaz");
|
||||
runCommandForced(
|
||||
"--domain=example.tld", "--message=This domain needs work", "--client=NewRegistrar");
|
||||
"--domain=example.tld",
|
||||
"--message=This domain needs work",
|
||||
"--clients=TheRegistrar,NewRegistrar,foobaz");
|
||||
|
||||
HistoryEntry synthetic = getOnlyHistoryEntryOfType(domain, SYNTHETIC);
|
||||
assertAboutHistoryEntries()
|
||||
.that(synthetic)
|
||||
.bySuperuser(true)
|
||||
.and()
|
||||
.hasMetadataReason("Manual enqueueing of poll message")
|
||||
.hasMetadataReason("Manual enqueueing of poll message: This domain needs work")
|
||||
.and()
|
||||
.hasNoXml()
|
||||
.and()
|
||||
.hasRegistrarId("NewRegistrar")
|
||||
.hasRegistrarId("AdminRegistrar")
|
||||
.and()
|
||||
.hasModificationTime(fakeClock.nowUtc())
|
||||
.and()
|
||||
.hasMetadataRequestedByRegistrar(false);
|
||||
assertPollMessages(
|
||||
"TheRegistrar",
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setParent(synthetic)
|
||||
.setMsg("This domain needs work")
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setEventTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
assertPollMessages(
|
||||
"NewRegistrar",
|
||||
new PollMessage.OneTime.Builder()
|
||||
|
@ -105,6 +119,59 @@ class EnqueuePollMessageCommandTest extends CommandTestCase<EnqueuePollMessageCo
|
|||
.setRegistrarId("NewRegistrar")
|
||||
.setEventTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
assertPollMessages(
|
||||
"foobaz",
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setParent(synthetic)
|
||||
.setMsg("This domain needs work")
|
||||
.setRegistrarId("foobaz")
|
||||
.setEventTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSuccess_sendToAllRegistrars() throws Exception {
|
||||
persistNewRegistrar("foobaz");
|
||||
runCommandForced("--domain=example.tld", "--message=This domain needs work", "--all=true");
|
||||
|
||||
HistoryEntry synthetic = getOnlyHistoryEntryOfType(domain, SYNTHETIC);
|
||||
assertAboutHistoryEntries()
|
||||
.that(synthetic)
|
||||
.bySuperuser(true)
|
||||
.and()
|
||||
.hasMetadataReason("Manual enqueueing of poll message: This domain needs work")
|
||||
.and()
|
||||
.hasNoXml()
|
||||
.and()
|
||||
.hasRegistrarId("AdminRegistrar")
|
||||
.and()
|
||||
.hasModificationTime(fakeClock.nowUtc())
|
||||
.and()
|
||||
.hasMetadataRequestedByRegistrar(false);
|
||||
assertPollMessages(
|
||||
"TheRegistrar",
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setParent(synthetic)
|
||||
.setMsg("This domain needs work")
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setEventTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
assertPollMessages(
|
||||
"NewRegistrar",
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setParent(synthetic)
|
||||
.setMsg("This domain needs work")
|
||||
.setRegistrarId("NewRegistrar")
|
||||
.setEventTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
assertPollMessages(
|
||||
"foobaz",
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setParent(synthetic)
|
||||
.setMsg("This domain needs work")
|
||||
.setRegistrarId("foobaz")
|
||||
.setEventTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
|
@ -131,4 +198,18 @@ class EnqueuePollMessageCommandTest extends CommandTestCase<EnqueuePollMessageCo
|
|||
assertThrows(ParameterException.class, () -> runCommandForced("--domain=example.tld"));
|
||||
assertThat(thrown).hasMessageThat().contains("The following option is required: -m, --message");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testCantSpecifyClientIdsAndAll() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
runCommandForced(
|
||||
"--domain=example.tld",
|
||||
"--message=Domain is ended",
|
||||
"--all=true",
|
||||
"--clients=TheRegistrar"));
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Cannot specify both --all and --clients");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue