Add ROID flag in FixDomainNameserverKeysCommand

There's a deleted domain with bad host resource keys. Since FKIs won't help us here, load a domain directly by key (i.e. by ROID) if we so choose.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148685240
This commit is contained in:
ctingue 2017-02-27 13:15:13 -08:00 committed by Ben McIlwain
parent 5a00317dcc
commit 023a76349e

View file

@ -31,6 +31,7 @@ import com.googlecode.objectify.Key;
import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.VoidWork;
import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.index.ForeignKeyIndex;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.Command.RemoteApiCommand;
import google.registry.tools.ConfirmingCommand; import google.registry.tools.ConfirmingCommand;
@ -51,17 +52,25 @@ import org.joda.time.DateTime;
@Parameters(separators = " =", commandDescription = "Fix bad host keys on domains.") @Parameters(separators = " =", commandDescription = "Fix bad host keys on domains.")
public class FixDomainNameserverKeysCommand extends ConfirmingCommand implements RemoteApiCommand { public class FixDomainNameserverKeysCommand extends ConfirmingCommand implements RemoteApiCommand {
@Parameter(description = "Fully-qualified domain names", required = true) @Parameter(description = "Fully-qualified domain names (or ROIDs, with -r)", required = true)
private List<String> mainParameters; private List<String> mainParameters;
@Parameter(
names = {"-r", "--roid"},
description = "Use domain ROID instead of fully qualified name (useful for deleted domains)")
boolean useRoid;
private final LinkedHashMap<DomainResource, DomainResource> domainUpdates = new LinkedHashMap<>(); private final LinkedHashMap<DomainResource, DomainResource> domainUpdates = new LinkedHashMap<>();
private final LinkedHashMap<DomainResource, HistoryEntry> historyEntries = new LinkedHashMap<>(); private final LinkedHashMap<DomainResource, HistoryEntry> historyEntries = new LinkedHashMap<>();
@Override @Override
protected void init() throws Exception { protected void init() throws Exception {
DateTime now = DateTime.now(UTC); DateTime now = DateTime.now(UTC);
for (String domainName : mainParameters) { for (String domainNameOrRoid : mainParameters) {
DomainResource domain = checkNotNull(loadByForeignKey(DomainResource.class, domainName, now)); Key<DomainResource> domainKey = useRoid
? Key.create(DomainResource.class, domainNameOrRoid)
: ForeignKeyIndex.load(DomainResource.class, domainNameOrRoid, now).getResourceKey();
DomainResource domain = checkNotNull(ofy().load().key(domainKey).now());
ImmutableSet.Builder<Key<HostResource>> nameservers = new ImmutableSet.Builder<>(); ImmutableSet.Builder<Key<HostResource>> nameservers = new ImmutableSet.Builder<>();
for (Key<HostResource> hostKey : domain.getNameservers()) { for (Key<HostResource> hostKey : domain.getNameservers()) {
HostResource existingHost = ofy().load().key(hostKey).now(); HostResource existingHost = ofy().load().key(hostKey).now();
@ -117,8 +126,7 @@ public class FixDomainNameserverKeysCommand extends ConfirmingCommand implements
checkState( checkState(
Objects.equals( Objects.equals(
existingDomain, existingDomain,
ofy().load().entity(existingDomain).now() ofy().load().entity(existingDomain).now()),
.cloneProjectedAtTime(ofy().getTransactionTime())),
"Domain %s changed since init() was called.", "Domain %s changed since init() was called.",
existingDomain.getFullyQualifiedDomainName()); existingDomain.getFullyQualifiedDomainName());
HistoryEntry historyEntryWithModificationTime = HistoryEntry historyEntryWithModificationTime =