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.
This commit is contained in:
gbrodman 2021-09-24 14:08:30 -04:00 committed by GitHub
parent 243e8a6585
commit 1bdbc2369e
2 changed files with 7 additions and 4 deletions

View file

@ -41,6 +41,7 @@ import google.registry.request.Modules.URLFetchServiceModule;
import google.registry.request.Modules.UrlFetchTransportModule; import google.registry.request.Modules.UrlFetchTransportModule;
import google.registry.request.Modules.UserServiceModule; import google.registry.request.Modules.UserServiceModule;
import google.registry.tools.AuthModule.LocalCredentialModule; import google.registry.tools.AuthModule.LocalCredentialModule;
import google.registry.tools.javascrap.BackfillRegistryLocksCommand;
import google.registry.tools.javascrap.DeleteContactByRoidCommand; import google.registry.tools.javascrap.DeleteContactByRoidCommand;
import google.registry.util.UtilsModule; import google.registry.util.UtilsModule;
import google.registry.whois.NonCachingWhoisModule; import google.registry.whois.NonCachingWhoisModule;
@ -85,6 +86,8 @@ import javax.inject.Singleton;
interface RegistryToolComponent { interface RegistryToolComponent {
void inject(AckPollMessagesCommand command); void inject(AckPollMessagesCommand command);
void inject(BackfillRegistryLocksCommand command);
void inject(CheckDomainClaimsCommand command); void inject(CheckDomainClaimsCommand command);
void inject(CheckDomainCommand command); void inject(CheckDomainCommand command);

View file

@ -94,7 +94,7 @@ public class BackfillRegistryLocksCommand extends ConfirmingCommand
@Override @Override
protected String execute() { protected String execute() {
ImmutableSet.Builder<DomainBase> failedDomainsBuilder = new ImmutableSet.Builder<>(); ImmutableSet.Builder<String> failedDomainsBuilder = new ImmutableSet.Builder<>();
jpaTm() jpaTm()
.transact( .transact(
() -> { () -> {
@ -114,11 +114,11 @@ public class BackfillRegistryLocksCommand extends ConfirmingCommand
} catch (Throwable t) { } catch (Throwable t) {
logger.atSevere().withCause(t).log( logger.atSevere().withCause(t).log(
"Error when creating lock object for domain %s.", domainBase.getDomainName()); "Error when creating lock object for domain %s.", domainBase.getDomainName());
failedDomainsBuilder.add(domainBase); failedDomainsBuilder.add(domainBase.getDomainName());
} }
} }
}); });
ImmutableSet<DomainBase> failedDomains = failedDomainsBuilder.build(); ImmutableSet<String> failedDomains = failedDomainsBuilder.build();
if (failedDomains.isEmpty()) { if (failedDomains.isEmpty()) {
return String.format( return String.format(
"Successfully created lock objects for %d domains.", lockedDomains.size()); "Successfully created lock objects for %d domains.", lockedDomains.size());
@ -126,7 +126,7 @@ public class BackfillRegistryLocksCommand extends ConfirmingCommand
return String.format( return String.format(
"Successfully created lock objects for %d domains. We failed to create locks " "Successfully created lock objects for %d domains. We failed to create locks "
+ "for the following domains: %s", + "for the following domains: %s",
lockedDomains.size() - failedDomains.size(), lockedDomains); lockedDomains.size() - failedDomains.size(), failedDomains);
} }
} }