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

@ -11,7 +11,6 @@ java_library(
"@com_google_apis_google_api_services_bigquery",
],
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/config",
"//java/google/registry/gcs",
"//java/google/registry/model",
@ -25,6 +24,8 @@ java_library(
"@com_google_appengine_api_1_0_sdk",
"@com_google_appengine_tools_appengine_gcs_client",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_http_client",
"@javax_servlet_api",

View file

@ -20,7 +20,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.common.collect.ImmutableList;
import com.google.common.io.CharStreams;
import com.google.common.logging.FormattingLogger;
import google.registry.config.RegistryConfig.Config;
import google.registry.gcs.GcsUtils;
import google.registry.reporting.billing.BillingModule.InvoiceDirectoryPrefix;
@ -75,8 +74,6 @@ class BillingEmailUtils {
this.retrier = retrier;
}
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
/** Sends an e-mail to all expected recipients with an attached overall invoice from GCS. */
void emailOverallInvoice() {
try {
@ -114,13 +111,12 @@ class BillingEmailUtils {
IOException.class,
MessagingException.class);
} catch (Throwable e) {
logger.severe(e, "Emailing invoice failed");
// Strip one layer, because callWithRetry wraps in a RuntimeException
sendAlertEmail(
String.format(
"Emailing invoice failed due to %s",
getRootCause(e).getMessage()));
throw e;
throw new RuntimeException("Emailing invoice failed", e);
}
}
@ -139,8 +135,7 @@ class BillingEmailUtils {
},
MessagingException.class);
} catch (Throwable e) {
logger.severe(e, "The alert e-mail system failed.");
throw e;
throw new RuntimeException("The alert e-mail system failed.", e);
}
}
}

View file

@ -21,8 +21,8 @@ import static javax.servlet.http.HttpServletResponse.SC_OK;
import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.common.collect.ImmutableList;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.ByteStreams;
import com.google.common.logging.FormattingLogger;
import com.google.common.net.MediaType;
import google.registry.config.RegistryConfig.Config;
import google.registry.gcs.GcsUtils;
@ -44,7 +44,7 @@ public final class CopyDetailReportsAction implements Runnable {
public static final String PATH = "/_dr/task/copyDetailReports";
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final String billingBucket;
private final String invoiceDirectoryPrefix;
@ -83,7 +83,7 @@ public final class CopyDetailReportsAction implements Runnable {
.filter(objectName -> objectName.startsWith(BillingModule.DETAIL_REPORT_PREFIX))
.collect(ImmutableList.toImmutableList());
} catch (IOException e) {
logger.severe(e, "Copying registrar detail report failed");
logger.atSevere().withCause(e).log("Copying registrar detail report failed");
response.setStatus(SC_INTERNAL_SERVER_ERROR);
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
response.setPayload(String.format("Failure, encountered %s", e.getMessage()));
@ -95,13 +95,13 @@ public final class CopyDetailReportsAction implements Runnable {
String registrarId = detailReportName.split("_")[3];
Optional<Registrar> registrar = Registrar.loadByClientId(registrarId);
if (!registrar.isPresent()) {
logger.warningfmt(
logger.atWarning().log(
"Registrar %s not found in database for file %s", registrar, detailReportName);
continue;
}
String driveFolderId = registrar.get().getDriveFolderId();
if (driveFolderId == null) {
logger.warningfmt("Drive folder id not found for registrar %s", registrarId);
logger.atWarning().log("Drive folder id not found for registrar %s", registrarId);
continue;
}
// Attempt to copy each detail report to its associated registrar's drive folder.
@ -116,7 +116,7 @@ public final class CopyDetailReportsAction implements Runnable {
MediaType.CSV_UTF_8,
driveFolderId,
ByteStreams.toByteArray(input));
logger.infofmt(
logger.atInfo().log(
"Published detail report for %s to folder %s using GCS file gs://%s/%s.",
registrarId, driveFolderId, billingBucket, detailReportName);
}

View file

@ -27,7 +27,7 @@ import com.google.api.services.dataflow.model.RuntimeEnvironment;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.common.collect.ImmutableMap;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.common.net.MediaType;
import google.registry.config.RegistryConfig.Config;
import google.registry.request.Action;
@ -50,7 +50,7 @@ import org.joda.time.YearMonth;
@Action(path = GenerateInvoicesAction.PATH, method = POST, auth = Auth.AUTH_INTERNAL_ONLY)
public class GenerateInvoicesAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
static final String PATH = "/_dr/task/generateInvoices";
@ -85,7 +85,7 @@ public class GenerateInvoicesAction implements Runnable {
@Override
public void run() {
logger.infofmt("Launching invoicing pipeline for %s", yearMonth);
logger.atInfo().log("Launching invoicing pipeline for %s", yearMonth);
try {
LaunchTemplateParameters params =
new LaunchTemplateParameters()
@ -102,13 +102,13 @@ public class GenerateInvoicesAction implements Runnable {
.launch(projectId, params)
.setGcsPath(invoiceTemplateUrl)
.execute();
logger.infofmt("Got response: %s", launchResponse.getJob().toPrettyString());
logger.atInfo().log("Got response: %s", launchResponse.getJob().toPrettyString());
String jobId = launchResponse.getJob().getId();
if (shouldPublish) {
enqueuePublishTask(jobId);
}
} catch (IOException e) {
logger.warning(e, "Template Launch failed");
logger.atWarning().withCause(e).log("Template Launch failed");
emailUtils.sendAlertEmail(String.format("Template Launch failed due to %s", e.getMessage()));
response.setStatus(SC_INTERNAL_SERVER_ERROR);
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);

View file

@ -25,7 +25,7 @@ import com.google.api.services.dataflow.Dataflow;
import com.google.api.services.dataflow.model.Job;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.common.net.MediaType;
import google.registry.config.RegistryConfig.Config;
import google.registry.request.Action;
@ -48,7 +48,7 @@ import org.joda.time.YearMonth;
@Action(path = PublishInvoicesAction.PATH, method = POST, auth = Auth.AUTH_INTERNAL_OR_ADMIN)
public class PublishInvoicesAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String JOB_DONE = "JOB_STATE_DONE";
private static final String JOB_FAILED = "JOB_STATE_FAILED";
@ -80,24 +80,24 @@ public class PublishInvoicesAction implements Runnable {
@Override
public void run() {
try {
logger.info("Starting publish job.");
logger.atInfo().log("Starting publish job.");
Job job = dataflow.projects().jobs().get(projectId, jobId).execute();
String state = job.getCurrentState();
switch (state) {
case JOB_DONE:
logger.infofmt("Dataflow job %s finished successfully, publishing results.", jobId);
logger.atInfo().log("Dataflow job %s finished successfully, publishing results.", jobId);
response.setStatus(SC_OK);
enqueueCopyDetailReportsTask();
emailUtils.emailOverallInvoice();
break;
case JOB_FAILED:
logger.severefmt("Dataflow job %s finished unsuccessfully.", jobId);
logger.atSevere().log("Dataflow job %s finished unsuccessfully.", jobId);
response.setStatus(SC_NO_CONTENT);
emailUtils.sendAlertEmail(
String.format("Dataflow job %s ended in status failure.", jobId));
break;
default:
logger.infofmt("Job in non-terminal state %s, retrying:", state);
logger.atInfo().log("Job in non-terminal state %s, retrying:", state);
response.setStatus(SC_NOT_MODIFIED);
break;
}