Make BillingModule.OVERALL_INVOICE_PREFIX configurable

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=221700223
This commit is contained in:
shicong 2018-11-15 15:20:53 -08:00 committed by jianglai
parent 45f63cbecf
commit 36c6265980
8 changed files with 31 additions and 11 deletions

View file

@ -75,6 +75,10 @@ public class InvoicingPipeline implements Serializable {
@Config("billingBucketUrl")
String billingBucketUrl;
@Inject
@Config("invoiceFilePrefix")
String invoiceFilePrefix;
@Inject
InvoicingPipeline() {}
@ -164,7 +168,7 @@ public class InvoicingPipeline implements Serializable {
billingBucketUrl,
BillingModule.INVOICES_DIRECTORY,
yearMonth,
BillingModule.OVERALL_INVOICE_PREFIX,
invoiceFilePrefix,
yearMonth)))
.withHeader(InvoiceGroupingKey.invoiceHeader())
.withoutSharding()

View file

@ -692,6 +692,18 @@ public final class RegistryConfig {
return ImmutableList.copyOf(config.billing.invoiceEmailRecipients);
}
/**
* Returns the file prefix for the invoice CSV file.
*
* @see google.registry.beam.invoicing.InvoicingPipeline
* @see google.registry.reporting.billing.BillingEmailUtils
*/
@Provides
@Config("invoiceFilePrefix")
public static String provideInvoiceFilePrefix(RegistryConfigSettings config) {
return config.billing.invoiceFilePrefix;
}
/**
* Returns the Google Cloud Storage bucket for staging escrow deposits pending upload.
*

View file

@ -131,6 +131,7 @@ public class RegistryConfigSettings {
/** Configuration for monthly invoices. */
public static class Billing {
public List<String> invoiceEmailRecipients;
public String invoiceFilePrefix;
}
/** Configuration for Registry Data Escrow (RDE). */

View file

@ -293,6 +293,7 @@ icannReporting:
billing:
invoiceEmailRecipients: []
invoiceFilePrefix: REG-INV
rde:
# URL prefix of ICANN's server to upload RDE reports to. Nomulus adds /TLD/ID

View file

@ -48,6 +48,7 @@ class BillingEmailUtils {
private final String alertRecipientAddress;
private final ImmutableList<String> invoiceEmailRecipients;
private final String billingBucket;
private final String invoiceFilePrefix;
private final String invoiceDirectoryPrefix;
private final GcsUtils gcsUtils;
private final Retrier retrier;
@ -60,6 +61,7 @@ class BillingEmailUtils {
@Config("alertRecipientEmailAddress") String alertRecipientAddress,
@Config("invoiceEmailRecipients") ImmutableList<String> invoiceEmailRecipients,
@Config("billingBucket") String billingBucket,
@Config("invoiceFilePrefix") String invoiceFilePrefix,
@InvoiceDirectoryPrefix String invoiceDirectoryPrefix,
GcsUtils gcsUtils,
Retrier retrier) {
@ -69,6 +71,7 @@ class BillingEmailUtils {
this.alertRecipientAddress = alertRecipientAddress;
this.invoiceEmailRecipients = invoiceEmailRecipients;
this.billingBucket = billingBucket;
this.invoiceFilePrefix = invoiceFilePrefix;
this.invoiceDirectoryPrefix = invoiceDirectoryPrefix;
this.gcsUtils = gcsUtils;
this.retrier = retrier;
@ -80,8 +83,7 @@ class BillingEmailUtils {
retrier.callWithRetry(
() -> {
String invoiceFile =
String.format(
"%s-%s.csv", BillingModule.OVERALL_INVOICE_PREFIX, yearMonth.toString());
String.format("%s-%s.csv", invoiceFilePrefix, yearMonth);
GcsFilename invoiceFilename =
new GcsFilename(billingBucket, invoiceDirectoryPrefix + invoiceFile);
try (InputStream in = gcsUtils.openInputStream(invoiceFilename)) {
@ -91,12 +93,12 @@ class BillingEmailUtils {
msg.addRecipient(RecipientType.TO, new InternetAddress(recipient));
}
msg.setSubject(
String.format("Domain Registry invoice data %s", yearMonth.toString()));
String.format("Domain Registry invoice data %s", yearMonth));
Multipart multipart = new MimeMultipart();
BodyPart textPart = new MimeBodyPart();
textPart.setText(
String.format(
"Attached is the %s invoice for the domain registry.", yearMonth.toString()));
"Attached is the %s invoice for the domain registry.", yearMonth));
multipart.addBodyPart(textPart);
BodyPart invoicePart = new MimeBodyPart();
String invoiceData = CharStreams.toString(new InputStreamReader(in, UTF_8));
@ -128,7 +130,7 @@ class BillingEmailUtils {
Message msg = emailService.createMessage();
msg.setFrom(new InternetAddress(outgoingEmailAddress));
msg.addRecipient(RecipientType.TO, new InternetAddress(alertRecipientAddress));
msg.setSubject(String.format("Billing Pipeline Alert: %s", yearMonth.toString()));
msg.setSubject(String.format("Billing Pipeline Alert: %s", yearMonth));
msg.setText(body);
emailService.sendMessage(msg);
return null;

View file

@ -32,8 +32,6 @@ import org.joda.time.YearMonth;
public final class BillingModule {
public static final String DETAIL_REPORT_PREFIX = "invoice_details";
// TODO(b/119551360): This should be configurable, not hard-coded to Charleston Road Registry.
public static final String OVERALL_INVOICE_PREFIX = "CRR-INV";
public static final String INVOICES_DIRECTORY = "invoices";
static final String PARAM_SHOULD_PUBLISH = "shouldPublish";