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;
}

View file

@ -9,7 +9,6 @@ java_library(
srcs = glob(["*.java"]),
resources = glob(["sql/*"]),
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/bigquery",
"//java/google/registry/config",
"//java/google/registry/gcs",
@ -26,6 +25,8 @@ java_library(
"@com_google_appengine_tools_appengine_gcs_client",
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_http_client",
"@com_google_http_client_jackson2",

View file

@ -27,8 +27,8 @@ import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpTransport;
import com.google.common.base.Ascii;
import com.google.common.base.Splitter;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.ByteStreams;
import com.google.common.logging.FormattingLogger;
import google.registry.config.RegistryConfig.Config;
import google.registry.keyring.api.KeyModule.Key;
import google.registry.reporting.icann.IcannReportingModule.ReportType;
@ -57,7 +57,7 @@ import org.joda.time.format.DateTimeFormat;
*/
public class IcannHttpReporter {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Inject HttpTransport httpTransport;
@Inject @Key("icannReportingPassword") String password;
@ -81,9 +81,8 @@ public class IcannHttpReporter {
request.setFollowRedirects(false);
HttpResponse response = null;
logger.infofmt(
"Sending report to %s with content length %s",
uploadUrl.toString(), request.getContent().getLength());
logger.atInfo().log(
"Sending report to %s with content length %d", uploadUrl, request.getContent().getLength());
boolean success = true;
try {
response = request.execute();
@ -93,25 +92,22 @@ public class IcannHttpReporter {
} finally {
response.getContent().close();
}
logger.infofmt(
"Received response code %s with content %s",
logger.atInfo().log(
"Received response code %d with content %s",
response.getStatusCode(), new String(content, UTF_8));
XjcIirdeaResult result = parseResult(content);
if (result.getCode().getValue() != 1000) {
success = false;
logger.warningfmt(
logger.atWarning().log(
"PUT rejected, status code %s:\n%s\n%s",
result.getCode(),
result.getMsg(),
result.getDescription());
result.getCode(), result.getMsg(), result.getDescription());
}
} finally {
if (response != null) {
response.disconnect();
} else {
success = false;
logger.warningfmt(
"Received null response from ICANN server at %s", uploadUrl.toString());
logger.atWarning().log("Received null response from ICANN server at %s", uploadUrl);
}
}
return success;

View file

@ -30,7 +30,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.ListMultimap;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.bigquery.BigqueryConnection;
import google.registry.bigquery.BigqueryUtils.TableType;
import google.registry.config.RegistryConfig.Config;
@ -58,7 +58,7 @@ import org.joda.time.format.DateTimeFormat;
*/
public class IcannReportingStager {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Inject @Config("icannReportingBucket") String reportingBucket;
@ -105,7 +105,7 @@ public class IcannReportingStager {
private void createIntermediaryTableView(String queryName, String query, ReportType reportType)
throws ExecutionException, InterruptedException {
// Later views depend on the results of earlier ones, so query everything synchronously
logger.infofmt("Generating intermediary view %s", queryName);
logger.atInfo().log("Generating intermediary view %s", queryName);
bigquery.query(
query,
bigquery.buildDestinationTable(queryName)
@ -247,10 +247,7 @@ public class IcannReportingStager {
String reportBucketname = String.format("%s/%s", reportingBucket, subdir);
final GcsFilename gcsFilename = new GcsFilename(reportBucketname, reportFilename);
gcsUtils.createFromBytes(gcsFilename, reportBytes);
logger.infofmt(
"Wrote %d bytes to file location %s",
reportBytes.length,
gcsFilename.toString());
logger.atInfo().log("Wrote %d bytes to file location %s", reportBytes.length, gcsFilename);
return reportFilename;
}
@ -261,7 +258,6 @@ public class IcannReportingStager {
StringBuilder manifestString = new StringBuilder();
filenames.forEach((filename) -> manifestString.append(filename).append("\n"));
gcsUtils.createFromBytes(gcsFilename, manifestString.toString().getBytes(UTF_8));
logger.infofmt(
"Wrote %d filenames to manifest at %s", filenames.size(), gcsFilename.toString());
logger.atInfo().log("Wrote %d filenames to manifest at %s", filenames.size(), gcsFilename);
}
}

View file

@ -24,7 +24,7 @@ import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.appengine.api.taskqueue.TaskOptions.Method;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.common.net.MediaType;
import google.registry.bigquery.BigqueryJobFailureException;
import google.registry.reporting.icann.IcannReportingModule.ReportType;
@ -60,7 +60,7 @@ public final class IcannReportingStagingAction implements Runnable {
static final String PATH = "/_dr/task/icannReportingStaging";
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String CRON_QUEUE = "retryable-cron-tasks";
@Inject YearMonth yearMonth;
@ -84,7 +84,7 @@ public final class IcannReportingStagingAction implements Runnable {
ImmutableList<String> manifestedFiles = manifestedFilesBuilder.build();
stager.createAndUploadManifest(manifestedFiles);
logger.infofmt("Completed staging %d report files.", manifestedFiles.size());
logger.atInfo().log("Completed staging %d report files.", manifestedFiles.size());
emailUtils.emailResults(
"ICANN Monthly report staging summary [SUCCESS]",
String.format(
@ -95,7 +95,7 @@ public final class IcannReportingStagingAction implements Runnable {
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
response.setPayload("Completed staging action.");
logger.infofmt("Enqueueing report upload :");
logger.atInfo().log("Enqueueing report upload :");
TaskOptions uploadTask =
TaskOptions.Builder.withUrl(IcannReportingUploadAction.PATH)
.method(Method.POST)
@ -111,14 +111,13 @@ public final class IcannReportingStagingAction implements Runnable {
String.format(
"Staging failed due to %s, check logs for more details.",
getRootCause(e).toString()));
logger.severe(e, "Staging action failed.");
response.setStatus(SC_INTERNAL_SERVER_ERROR);
response.setContentType(MediaType.PLAIN_TEXT_UTF_8);
response.setPayload(
String.format(
"Staging failed due to %s",
getRootCause(e).toString()));
throw e;
throw new RuntimeException("Staging action failed.", e);
}
}
}

View file

@ -25,8 +25,8 @@ import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.ByteStreams;
import com.google.common.logging.FormattingLogger;
import google.registry.config.RegistryConfig.Config;
import google.registry.gcs.GcsUtils;
import google.registry.reporting.icann.IcannReportingModule.ReportingSubdir;
@ -57,7 +57,7 @@ public final class IcannReportingUploadAction implements Runnable {
static final String PATH = "/_dr/task/icannReportingUpload";
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Inject
@Config("icannReportingBucket")
@ -82,7 +82,8 @@ public final class IcannReportingUploadAction implements Runnable {
ImmutableMap.Builder<String, Boolean> reportSummaryBuilder = new ImmutableMap.Builder<>();
// Report on all manifested files
for (String reportFilename : manifestedFiles) {
logger.infofmt("Reading ICANN report %s from bucket %s", reportFilename, reportBucketname);
logger.atInfo().log(
"Reading ICANN report %s from bucket %s", reportFilename, reportBucketname);
final GcsFilename gcsFilename = new GcsFilename(reportBucketname, reportFilename);
verifyFileExists(gcsFilename);
boolean success = false;
@ -95,7 +96,7 @@ public final class IcannReportingUploadAction implements Runnable {
},
IOException.class);
} catch (RuntimeException e) {
logger.warningfmt(e, "Upload to %s failed.", gcsFilename.toString());
logger.atWarning().withCause(e).log("Upload to %s failed.", gcsFilename);
}
reportSummaryBuilder.put(reportFilename, success);
}

View file

@ -14,7 +14,7 @@
package google.registry.reporting.icann;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.config.RegistryConfig.Config;
import google.registry.util.SendEmailService;
import javax.inject.Inject;
@ -30,19 +30,19 @@ public class ReportingEmailUtils {
@Inject SendEmailService emailService;
@Inject ReportingEmailUtils() {}
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
void emailResults(String subject, String body) {
try {
Message msg = emailService.createMessage();
logger.infofmt("Emailing %s", recipient);
logger.atInfo().log("Emailing %s", recipient);
msg.setFrom(new InternetAddress(sender));
msg.addRecipient(RecipientType.TO, new InternetAddress(recipient));
msg.setSubject(subject);
msg.setText(body);
emailService.sendMessage(msg);
} catch (Exception e) {
logger.warning(e, "E-mail service failed.");
logger.atWarning().withCause(e).log("E-mail service failed.");
}
}
}