mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 08:27:14 +02:00
Add history entry to FixDomainNameserverKeysCommand
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=147468517
This commit is contained in:
parent
53262d82bb
commit
07625ce81b
1 changed files with 57 additions and 3 deletions
|
@ -15,19 +15,29 @@
|
||||||
package google.registry.tools.javascrap;
|
package google.registry.tools.javascrap;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static google.registry.model.EppResourceUtils.isDeleted;
|
import static google.registry.model.EppResourceUtils.isDeleted;
|
||||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
|
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
|
||||||
import static org.joda.time.DateTimeZone.UTC;
|
import static org.joda.time.DateTimeZone.UTC;
|
||||||
|
|
||||||
import com.beust.jcommander.Parameter;
|
import com.beust.jcommander.Parameter;
|
||||||
import com.beust.jcommander.Parameters;
|
import com.beust.jcommander.Parameters;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
|
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.tools.MutatingCommand;
|
import google.registry.model.reporting.HistoryEntry;
|
||||||
|
import google.registry.tools.Command.RemoteApiCommand;
|
||||||
|
import google.registry.tools.ConfirmingCommand;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Objects;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,11 +49,14 @@ import org.joda.time.DateTime;
|
||||||
* the non-deleted versions (as determined by loading the host's foreign key). See b/35258209.
|
* the non-deleted versions (as determined by loading the host's foreign key). See b/35258209.
|
||||||
*/
|
*/
|
||||||
@Parameters(separators = " =", commandDescription = "Fix bad host keys on domains.")
|
@Parameters(separators = " =", commandDescription = "Fix bad host keys on domains.")
|
||||||
public class FixDomainNameserverKeysCommand extends MutatingCommand {
|
public class FixDomainNameserverKeysCommand extends ConfirmingCommand implements RemoteApiCommand {
|
||||||
|
|
||||||
@Parameter(description = "Fully-qualified domain names", required = true)
|
@Parameter(description = "Fully-qualified domain names", required = true)
|
||||||
private List<String> mainParameters;
|
private List<String> mainParameters;
|
||||||
|
|
||||||
|
private final LinkedHashMap<DomainResource, DomainResource> domainUpdates = 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);
|
||||||
|
@ -70,7 +83,48 @@ public class FixDomainNameserverKeysCommand extends MutatingCommand {
|
||||||
nameservers.add(hostKey);
|
nameservers.add(hostKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stageEntityChange(domain, domain.asBuilder().setNameservers(nameservers.build()).build());
|
DomainResource updatedDomain = domain.asBuilder().setNameservers(nameservers.build()).build();
|
||||||
|
domainUpdates.put(domain, updatedDomain);
|
||||||
|
historyEntries.put(updatedDomain, new HistoryEntry.Builder()
|
||||||
|
.setClientId("CharlestonRoad")
|
||||||
|
.setParent(updatedDomain)
|
||||||
|
.setType(HistoryEntry.Type.DOMAIN_UPDATE)
|
||||||
|
.setReason("Fixing keys to deleted host resources, see b/35258209")
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the changes that have been staged thus far. */
|
||||||
|
@Override
|
||||||
|
protected String prompt() {
|
||||||
|
ImmutableList.Builder<String> updates = new ImmutableList.Builder<>();
|
||||||
|
for (Entry<DomainResource, DomainResource> entry : domainUpdates.entrySet()) {
|
||||||
|
updates.add(prettyPrintEntityDeepDiff(
|
||||||
|
entry.getKey().toDiffableFieldMap(), entry.getValue().toDiffableFieldMap()));
|
||||||
|
updates.add(historyEntries.get(entry.getValue()).toString());
|
||||||
|
}
|
||||||
|
return Joiner.on("\n").join(updates.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String execute() throws Exception {
|
||||||
|
ofy().transact(new VoidWork() {
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void vrun() {
|
||||||
|
for (Entry<DomainResource, DomainResource> entry : domainUpdates.entrySet()) {
|
||||||
|
DomainResource existingDomain = entry.getKey();
|
||||||
|
checkState(
|
||||||
|
Objects.equals(existingDomain, ofy().load().entity(existingDomain).now()),
|
||||||
|
"Domain %s changed since init() was called.",
|
||||||
|
existingDomain.getFullyQualifiedDomainName());
|
||||||
|
HistoryEntry historyEntryWithModificationTime =
|
||||||
|
historyEntries.get(entry.getValue()).asBuilder()
|
||||||
|
.setModificationTime(ofy().getTransactionTime())
|
||||||
|
.build();
|
||||||
|
ofy().save().entities(entry.getValue(), historyEntryWithModificationTime).now();
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
return String.format("Updated %d domains.", domainUpdates.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue