Migrate to Flogger (green)

This is a 'green' Flogger migration CL. Green CLs are intended to be as
safe as possible and should be easy to review and submit.

No changes should be necessary to the code itself prior to submission,
but small changes to BUILD files may be required.

Changes within files are completely independent of each other, so this CL
can be safely split up for review using tools such as Rosie.

For more information, see []
Base CL: 197826149

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=198560170
This commit is contained in:
jianglai 2018-05-30 07:58:51 -07:00
parent 0d2fb3a8f0
commit 70b13596e4
178 changed files with 984 additions and 988 deletions

View file

@ -8,7 +8,6 @@ java_library(
name = "imports",
srcs = glob(["*.java"]),
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/config",
"//java/google/registry/dns",
"//java/google/registry/flows",
@ -30,6 +29,8 @@ java_library(
"@com_google_auto_value",
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@javax_servlet_api",
"@joda_time",

View file

@ -23,7 +23,7 @@ import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.appengine.tools.cloudstorage.RetryParams;
import com.google.appengine.tools.mapreduce.Mapper;
import com.google.common.collect.ImmutableList;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.googlecode.objectify.VoidWork;
import google.registry.config.RegistryConfig.Config;
import google.registry.config.RegistryConfig.ConfigModule;
@ -52,7 +52,7 @@ import javax.inject.Inject;
)
public class RdeContactImportAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final GcsService GCS_SERVICE =
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
@ -135,10 +135,10 @@ public class RdeContactImportAction implements Runnable {
public void map(JaxbFragment<XjcRdeContactElement> fragment) {
final XjcRdeContact xjcContact = fragment.getInstance().getValue();
try {
logger.infofmt("Converting xml for contact %s", xjcContact.getId());
logger.atInfo().log("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());
logger.atInfo().log("Saving contact %s", xjcContact.getId());
ofy().transact(new VoidWork() {
@Override
public void vrun() {
@ -149,15 +149,16 @@ public class RdeContactImportAction implements Runnable {
});
// Record number of contacts imported
getContext().incrementCounter("contacts saved");
logger.infofmt("Contact %s was imported successfully", xjcContact.getId());
logger.atInfo().log("Contact %s was imported successfully", xjcContact.getId());
} catch (ResourceExistsException e) {
// Record the number of contacts already in the registry
getContext().incrementCounter("existing contacts skipped");
logger.infofmt("Contact %s already exists", xjcContact.getId());
logger.atInfo().log("Contact %s already exists", xjcContact.getId());
} catch (Exception e) {
// Record the number of contacts with unexpected errors
getContext().incrementCounter("contact import errors");
logger.severefmt(e, "Error importing contact %s; xml=%s", xjcContact.getId(), xjcContact);
logger.atSevere().withCause(e).log(
"Error importing contact %s; xml=%s", xjcContact.getId(), xjcContact);
}
}
}

View file

@ -19,7 +19,7 @@ import com.google.appengine.tools.cloudstorage.GcsService;
import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.appengine.tools.cloudstorage.RetryParams;
import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.config.RegistryConfig.ConfigModule;
import google.registry.gcs.GcsUtils;
import google.registry.xjc.JaxbFragment;
@ -37,7 +37,7 @@ public class RdeContactReader extends InputReader<JaxbFragment<XjcRdeContactElem
private static final long serialVersionUID = -3688793834175577691L;
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final GcsService GCS_SERVICE =
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
@ -65,8 +65,8 @@ public class RdeContactReader extends InputReader<JaxbFragment<XjcRdeContactElem
parser.skipContacts(offset + count);
return parser;
} catch (Exception e) {
logger.severefmt(e, "Error opening rde file %s/%s", importBucketName, importFileName);
throw new RuntimeException(e);
throw new RuntimeException(
String.format("Error opening rde file %s/%s", importBucketName, importFileName), e);
}
}

View file

@ -34,7 +34,7 @@ import com.google.appengine.tools.cloudstorage.RetryParams;
import com.google.appengine.tools.mapreduce.Mapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.googlecode.objectify.VoidWork;
import google.registry.config.RegistryConfig.Config;
import google.registry.config.RegistryConfig.ConfigModule;
@ -75,7 +75,7 @@ import org.joda.time.DateTime;
)
public class RdeDomainImportAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final GcsService GCS_SERVICE =
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
@ -101,10 +101,9 @@ public class RdeDomainImportAction implements Runnable {
@Override
public void run() {
logger.infofmt(
logger.atInfo().log(
"Launching domains import mapreduce: bucket=%s, filename=%s",
this.importBucketName,
this.importFileName);
this.importBucketName, this.importFileName);
response.sendJavaScriptRedirect(createJobPath(mrRunner
.setJobName("Import domains from escrow file")
.setModuleName("backend")
@ -173,7 +172,7 @@ public class RdeDomainImportAction implements Runnable {
// Record number of attempted map operations
getContext().incrementCounter("domain imports attempted");
logger.infofmt("Saving domain %s", xjcDomain.getName());
logger.atInfo().log("Saving domain %s", xjcDomain.getName());
ofy()
.transact(
new VoidWork() {
@ -288,14 +287,15 @@ public class RdeDomainImportAction implements Runnable {
});
// Record the number of domains imported
getContext().incrementCounter("domains saved");
logger.infofmt("Domain %s was imported successfully", xjcDomain.getName());
logger.atInfo().log("Domain %s was imported successfully", xjcDomain.getName());
} catch (ResourceExistsException e) {
// Record the number of domains already in the registry
getContext().incrementCounter("existing domains skipped");
logger.infofmt("Domain %s already exists", xjcDomain.getName());
logger.atInfo().log("Domain %s already exists", xjcDomain.getName());
} catch (Exception e) {
getContext().incrementCounter("domain import errors");
logger.severefmt(e, "Error processing domain %s; xml=%s", xjcDomain.getName(), xjcDomain);
logger.atSevere().withCause(e).log(
"Error processing domain %s; xml=%s", xjcDomain.getName(), xjcDomain);
}
}
}

View file

@ -19,7 +19,7 @@ import com.google.appengine.tools.cloudstorage.GcsService;
import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.appengine.tools.cloudstorage.RetryParams;
import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.config.RegistryConfig.ConfigModule;
import google.registry.gcs.GcsUtils;
import google.registry.xjc.JaxbFragment;
@ -34,7 +34,7 @@ public class RdeDomainReader extends InputReader<JaxbFragment<XjcRdeDomainElemen
implements Serializable {
private static final long serialVersionUID = -2175777052970160122L;
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final GcsService GCS_SERVICE =
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
@ -62,8 +62,8 @@ public class RdeDomainReader extends InputReader<JaxbFragment<XjcRdeDomainElemen
parser.skipDomains(offset + count);
return parser;
} catch (Exception e) {
logger.severefmt(e, "Error opening rde file %s/%s", importBucketName, importFileName);
throw new RuntimeException(e);
throw new RuntimeException(
String.format("Error opening rde file %s/%s", importBucketName, importFileName), e);
}
}

View file

@ -23,7 +23,7 @@ import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.appengine.tools.cloudstorage.RetryParams;
import com.google.appengine.tools.mapreduce.Mapper;
import com.google.common.collect.ImmutableList;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.googlecode.objectify.VoidWork;
import google.registry.config.RegistryConfig.Config;
import google.registry.config.RegistryConfig.ConfigModule;
@ -52,7 +52,7 @@ import javax.inject.Inject;
)
public class RdeHostImportAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final GcsService GCS_SERVICE =
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
@ -123,7 +123,7 @@ public class RdeHostImportAction implements Runnable {
try {
// Record number of attempted map operations
getContext().incrementCounter("host imports attempted");
logger.infofmt("Saving host %s", xjcHost.getName());
logger.atInfo().log("Saving host %s", xjcHost.getName());
ofy().transact(new VoidWork() {
@Override
@ -134,15 +134,16 @@ public class RdeHostImportAction implements Runnable {
});
// Record number of hosts imported
getContext().incrementCounter("hosts saved");
logger.infofmt("Host %s was imported successfully", xjcHost.getName());
logger.atInfo().log("Host %s was imported successfully", xjcHost.getName());
} catch (ResourceExistsException e) {
// Record the number of hosts already in the registry
getContext().incrementCounter("existing hosts skipped");
logger.infofmt("Host %s already exists", xjcHost.getName());
logger.atInfo().log("Host %s already exists", xjcHost.getName());
} catch (Exception e) {
// Record the number of hosts with unexpected errors
getContext().incrementCounter("host import errors");
logger.severefmt(e, "Error processing host %s; xml=%s", xjcHost.getName(), xjcHost);
logger.atSevere().withCause(e).log(
"Error processing host %s; xml=%s", xjcHost.getName(), xjcHost);
}
}
}

View file

@ -24,7 +24,7 @@ import static java.util.stream.Collectors.joining;
import com.google.appengine.tools.mapreduce.Mapper;
import com.google.common.collect.ImmutableList;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Key;
import google.registry.config.RegistryConfig.Config;
@ -62,7 +62,7 @@ import org.joda.time.DateTime;
)
public class RdeHostLinkAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final MapreduceRunner mrRunner;
private final Response response;
@ -105,7 +105,7 @@ public class RdeHostLinkAction implements Runnable {
// Record number of attempted map operations
getContext().incrementCounter("post-import hosts read");
final XjcRdeHost xjcHost = fragment.getInstance().getValue();
logger.infofmt("Attempting to link superordinate domain for host %s", xjcHost.getName());
logger.atInfo().log("Attempting to link superordinate domain for host %s", xjcHost.getName());
try {
final InternetDomainName hostName = InternetDomainName.from(xjcHost.getName());
@ -142,31 +142,32 @@ public class RdeHostLinkAction implements Runnable {
switch (hostLinkResult) {
case HOST_LINKED:
getContext().incrementCounter("post-import hosts linked");
logger.infofmt(
logger.atInfo().log(
"Successfully linked host %s to superordinate domain", xjcHost.getName());
// Record number of hosts successfully linked
break;
case HOST_NOT_FOUND:
getContext().incrementCounter("hosts not found");
logger.severefmt(
logger.atSevere().log(
"Host with name %s and repoid %s not found", xjcHost.getName(), xjcHost.getRoid());
break;
case SUPERORDINATE_DOMAIN_IN_PENDING_DELETE:
getContext()
.incrementCounter(
"post-import hosts with superordinate domains in pending delete");
logger.infofmt(
logger.atInfo().log(
"Host %s has a superordinate domain in pending delete", xjcHost.getName());
break;
case HOST_OUT_OF_ZONE:
getContext().incrementCounter("post-import hosts out of zone");
logger.infofmt("Host %s is out of zone", xjcHost.getName());
logger.atInfo().log("Host %s is out of zone", xjcHost.getName());
break;
}
} catch (RuntimeException e) {
// Record the number of hosts with unexpected errors
getContext().incrementCounter("post-import host errors");
logger.severefmt(e, "Error linking host %s; xml=%s", xjcHost.getName(), xjcHost);
logger.atSevere().withCause(e).log(
"Error linking host %s; xml=%s", xjcHost.getName(), xjcHost);
}
}

View file

@ -19,7 +19,7 @@ import com.google.appengine.tools.cloudstorage.GcsService;
import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.appengine.tools.cloudstorage.RetryParams;
import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.config.RegistryConfig.ConfigModule;
import google.registry.gcs.GcsUtils;
import google.registry.xjc.JaxbFragment;
@ -37,7 +37,7 @@ public class RdeHostReader extends InputReader<JaxbFragment<XjcRdeHostElement>>
private static final long serialVersionUID = 3037264959150412846L;
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final GcsService GCS_SERVICE =
GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
@ -65,8 +65,8 @@ public class RdeHostReader extends InputReader<JaxbFragment<XjcRdeHostElement>>
parser.skipHosts(offset + count);
return parser;
} catch (Exception e) {
logger.severefmt(e, "Error opening RDE file %s/%s", importBucketName, importFileName);
throw new RuntimeException(e);
throw new RuntimeException(
String.format("Error opening RDE file %s/%s", importBucketName, importFileName), e);
}
}

View file

@ -25,8 +25,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.common.collect.ImmutableSet;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.BaseEncoding;
import com.google.common.logging.FormattingLogger;
import com.googlecode.objectify.Key;
import google.registry.config.RegistryConfig.Config;
import google.registry.flows.ServerTridProvider;
@ -67,7 +67,7 @@ import javax.xml.stream.XMLStreamException;
*/
public class RdeImportUtils {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Ofy ofy;
private final Clock clock;
@ -121,11 +121,9 @@ public class RdeImportUtils {
.add(resource)
.addAll(createIndexesForEppResource(resource))
.build());
logger.infofmt(
logger.atInfo().log(
"Imported %s resource - ROID=%s, id=%s",
resource.getClass().getSimpleName(),
resource.getRepoId(),
resource.getForeignKey());
resource.getClass().getSimpleName(), resource.getRepoId(), resource.getForeignKey());
}
/**