mirror of
https://github.com/google/nomulus.git
synced 2025-05-21 03:39:36 +02:00
Add mapper to import domains from RDE deposits
With some additional cleanup by Ben McIlwain. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=146695665
This commit is contained in:
parent
d6e6e8a49c
commit
a904f2c6ee
37 changed files with 2916 additions and 268 deletions
|
@ -24,6 +24,7 @@ import com.google.appengine.tools.cloudstorage.RetryParams;
|
|||
import com.google.appengine.tools.mapreduce.Mapper;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.config.RegistryConfig.ConfigModule;
|
||||
import google.registry.gcs.GcsUtils;
|
||||
|
@ -32,7 +33,11 @@ import google.registry.model.contact.ContactResource;
|
|||
import google.registry.request.Action;
|
||||
import google.registry.request.Parameter;
|
||||
import google.registry.request.Response;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import google.registry.util.SystemClock;
|
||||
import google.registry.xjc.JaxbFragment;
|
||||
import google.registry.xjc.rdecontact.XjcRdeContact;
|
||||
import google.registry.xjc.rdecontact.XjcRdeContactElement;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -43,6 +48,7 @@ import javax.inject.Inject;
|
|||
@Action(path = "/_dr/task/importRdeContacts")
|
||||
public class RdeContactImportAction implements Runnable {
|
||||
|
||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||
private static final GcsService GCS_SERVICE =
|
||||
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
|
||||
|
||||
|
@ -91,9 +97,11 @@ public class RdeContactImportAction implements Runnable {
|
|||
}
|
||||
|
||||
/** Mapper to import contacts from an escrow file. */
|
||||
public static class RdeContactImportMapper extends Mapper<ContactResource, Void, Void> {
|
||||
public static class RdeContactImportMapper
|
||||
extends Mapper<JaxbFragment<XjcRdeContactElement>, Void, Void> {
|
||||
|
||||
private static final long serialVersionUID = -7645091075256589374L;
|
||||
|
||||
private final String importBucketName;
|
||||
private transient RdeImportUtils importUtils;
|
||||
|
||||
|
@ -120,8 +128,39 @@ public class RdeContactImportAction implements Runnable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void map(ContactResource contact) {
|
||||
getImportUtils().importContact(contact);
|
||||
public void map(JaxbFragment<XjcRdeContactElement> fragment) {
|
||||
final XjcRdeContact xjcContact = fragment.getInstance().getValue();
|
||||
try {
|
||||
logger.infofmt("Converting xml for contact %s", xjcContact.getId());
|
||||
// Record number of attempted map operations
|
||||
getContext().incrementCounter("contact imports attempted");
|
||||
logger.infofmt("Saving contact %s", xjcContact.getId());
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ContactResource contact =
|
||||
XjcToContactResourceConverter.convertContact(xjcContact);
|
||||
getImportUtils().importContact(contact);
|
||||
}
|
||||
});
|
||||
// Record number of contacts imported
|
||||
getContext().incrementCounter("contacts saved");
|
||||
logger.infofmt("Contact %s was imported successfully", xjcContact.getId());
|
||||
} catch (ResourceExistsException e) {
|
||||
// Record the number of contacts already in the registry
|
||||
getContext().incrementCounter("contacts skipped");
|
||||
logger.infofmt("Contact %s already exists", xjcContact.getId());
|
||||
} catch (Exception e) {
|
||||
// Record the number of contacts with unexpected errors
|
||||
getContext().incrementCounter("contact import errors");
|
||||
throw new ContactImportException(xjcContact.getId(), xjcContact.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ContactImportException extends RuntimeException {
|
||||
ContactImportException(String contactId, String xml, Throwable cause) {
|
||||
super(String.format("Error importing contact %s; xml=%s", contactId, xml), cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue