From 1bdbc2369e58976f1aa3a1e6cc15eb32d74117f3 Mon Sep 17 00:00:00 2001 From: gbrodman Date: Fri, 24 Sep 2021 14:08:30 -0400 Subject: [PATCH] Fix injection with BackfillRegistryLocksCommand (#1337) It would have been nice if this had failed at compile-time rather than an NPE, but we need to make sure to specify that we need to inject this command to get e.g. the random string generator In addition, print out only the names of the failed domains (rather than the entire domain object) for readability. --- .../java/google/registry/tools/RegistryToolComponent.java | 3 +++ .../tools/javascrap/BackfillRegistryLocksCommand.java | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/google/registry/tools/RegistryToolComponent.java b/core/src/main/java/google/registry/tools/RegistryToolComponent.java index 06dcf9249..dbfd9c989 100644 --- a/core/src/main/java/google/registry/tools/RegistryToolComponent.java +++ b/core/src/main/java/google/registry/tools/RegistryToolComponent.java @@ -41,6 +41,7 @@ import google.registry.request.Modules.URLFetchServiceModule; import google.registry.request.Modules.UrlFetchTransportModule; import google.registry.request.Modules.UserServiceModule; import google.registry.tools.AuthModule.LocalCredentialModule; +import google.registry.tools.javascrap.BackfillRegistryLocksCommand; import google.registry.tools.javascrap.DeleteContactByRoidCommand; import google.registry.util.UtilsModule; import google.registry.whois.NonCachingWhoisModule; @@ -85,6 +86,8 @@ import javax.inject.Singleton; interface RegistryToolComponent { void inject(AckPollMessagesCommand command); + void inject(BackfillRegistryLocksCommand command); + void inject(CheckDomainClaimsCommand command); void inject(CheckDomainCommand command); diff --git a/core/src/main/java/google/registry/tools/javascrap/BackfillRegistryLocksCommand.java b/core/src/main/java/google/registry/tools/javascrap/BackfillRegistryLocksCommand.java index adcaa7362..ff1c61a7c 100644 --- a/core/src/main/java/google/registry/tools/javascrap/BackfillRegistryLocksCommand.java +++ b/core/src/main/java/google/registry/tools/javascrap/BackfillRegistryLocksCommand.java @@ -94,7 +94,7 @@ public class BackfillRegistryLocksCommand extends ConfirmingCommand @Override protected String execute() { - ImmutableSet.Builder failedDomainsBuilder = new ImmutableSet.Builder<>(); + ImmutableSet.Builder failedDomainsBuilder = new ImmutableSet.Builder<>(); jpaTm() .transact( () -> { @@ -114,11 +114,11 @@ public class BackfillRegistryLocksCommand extends ConfirmingCommand } catch (Throwable t) { logger.atSevere().withCause(t).log( "Error when creating lock object for domain %s.", domainBase.getDomainName()); - failedDomainsBuilder.add(domainBase); + failedDomainsBuilder.add(domainBase.getDomainName()); } } }); - ImmutableSet failedDomains = failedDomainsBuilder.build(); + ImmutableSet failedDomains = failedDomainsBuilder.build(); if (failedDomains.isEmpty()) { return String.format( "Successfully created lock objects for %d domains.", lockedDomains.size()); @@ -126,7 +126,7 @@ public class BackfillRegistryLocksCommand extends ConfirmingCommand return String.format( "Successfully created lock objects for %d domains. We failed to create locks " + "for the following domains: %s", - lockedDomains.size() - failedDomains.size(), lockedDomains); + lockedDomains.size() - failedDomains.size(), failedDomains); } }