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") @Config("billingBucketUrl")
String billingBucketUrl; String billingBucketUrl;
@Inject
@Config("invoiceFilePrefix")
String invoiceFilePrefix;
@Inject @Inject
InvoicingPipeline() {} InvoicingPipeline() {}
@ -164,7 +168,7 @@ public class InvoicingPipeline implements Serializable {
billingBucketUrl, billingBucketUrl,
BillingModule.INVOICES_DIRECTORY, BillingModule.INVOICES_DIRECTORY,
yearMonth, yearMonth,
BillingModule.OVERALL_INVOICE_PREFIX, invoiceFilePrefix,
yearMonth))) yearMonth)))
.withHeader(InvoiceGroupingKey.invoiceHeader()) .withHeader(InvoiceGroupingKey.invoiceHeader())
.withoutSharding() .withoutSharding()

View file

@ -692,6 +692,18 @@ public final class RegistryConfig {
return ImmutableList.copyOf(config.billing.invoiceEmailRecipients); 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. * 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. */ /** Configuration for monthly invoices. */
public static class Billing { public static class Billing {
public List<String> invoiceEmailRecipients; public List<String> invoiceEmailRecipients;
public String invoiceFilePrefix;
} }
/** Configuration for Registry Data Escrow (RDE). */ /** Configuration for Registry Data Escrow (RDE). */

View file

@ -293,6 +293,7 @@ icannReporting:
billing: billing:
invoiceEmailRecipients: [] invoiceEmailRecipients: []
invoiceFilePrefix: REG-INV
rde: rde:
# URL prefix of ICANN's server to upload RDE reports to. Nomulus adds /TLD/ID # 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 String alertRecipientAddress;
private final ImmutableList<String> invoiceEmailRecipients; private final ImmutableList<String> invoiceEmailRecipients;
private final String billingBucket; private final String billingBucket;
private final String invoiceFilePrefix;
private final String invoiceDirectoryPrefix; private final String invoiceDirectoryPrefix;
private final GcsUtils gcsUtils; private final GcsUtils gcsUtils;
private final Retrier retrier; private final Retrier retrier;
@ -60,6 +61,7 @@ class BillingEmailUtils {
@Config("alertRecipientEmailAddress") String alertRecipientAddress, @Config("alertRecipientEmailAddress") String alertRecipientAddress,
@Config("invoiceEmailRecipients") ImmutableList<String> invoiceEmailRecipients, @Config("invoiceEmailRecipients") ImmutableList<String> invoiceEmailRecipients,
@Config("billingBucket") String billingBucket, @Config("billingBucket") String billingBucket,
@Config("invoiceFilePrefix") String invoiceFilePrefix,
@InvoiceDirectoryPrefix String invoiceDirectoryPrefix, @InvoiceDirectoryPrefix String invoiceDirectoryPrefix,
GcsUtils gcsUtils, GcsUtils gcsUtils,
Retrier retrier) { Retrier retrier) {
@ -69,6 +71,7 @@ class BillingEmailUtils {
this.alertRecipientAddress = alertRecipientAddress; this.alertRecipientAddress = alertRecipientAddress;
this.invoiceEmailRecipients = invoiceEmailRecipients; this.invoiceEmailRecipients = invoiceEmailRecipients;
this.billingBucket = billingBucket; this.billingBucket = billingBucket;
this.invoiceFilePrefix = invoiceFilePrefix;
this.invoiceDirectoryPrefix = invoiceDirectoryPrefix; this.invoiceDirectoryPrefix = invoiceDirectoryPrefix;
this.gcsUtils = gcsUtils; this.gcsUtils = gcsUtils;
this.retrier = retrier; this.retrier = retrier;
@ -80,8 +83,7 @@ class BillingEmailUtils {
retrier.callWithRetry( retrier.callWithRetry(
() -> { () -> {
String invoiceFile = String invoiceFile =
String.format( String.format("%s-%s.csv", invoiceFilePrefix, yearMonth);
"%s-%s.csv", BillingModule.OVERALL_INVOICE_PREFIX, yearMonth.toString());
GcsFilename invoiceFilename = GcsFilename invoiceFilename =
new GcsFilename(billingBucket, invoiceDirectoryPrefix + invoiceFile); new GcsFilename(billingBucket, invoiceDirectoryPrefix + invoiceFile);
try (InputStream in = gcsUtils.openInputStream(invoiceFilename)) { try (InputStream in = gcsUtils.openInputStream(invoiceFilename)) {
@ -91,12 +93,12 @@ class BillingEmailUtils {
msg.addRecipient(RecipientType.TO, new InternetAddress(recipient)); msg.addRecipient(RecipientType.TO, new InternetAddress(recipient));
} }
msg.setSubject( msg.setSubject(
String.format("Domain Registry invoice data %s", yearMonth.toString())); String.format("Domain Registry invoice data %s", yearMonth));
Multipart multipart = new MimeMultipart(); Multipart multipart = new MimeMultipart();
BodyPart textPart = new MimeBodyPart(); BodyPart textPart = new MimeBodyPart();
textPart.setText( textPart.setText(
String.format( 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); multipart.addBodyPart(textPart);
BodyPart invoicePart = new MimeBodyPart(); BodyPart invoicePart = new MimeBodyPart();
String invoiceData = CharStreams.toString(new InputStreamReader(in, UTF_8)); String invoiceData = CharStreams.toString(new InputStreamReader(in, UTF_8));
@ -128,7 +130,7 @@ class BillingEmailUtils {
Message msg = emailService.createMessage(); Message msg = emailService.createMessage();
msg.setFrom(new InternetAddress(outgoingEmailAddress)); msg.setFrom(new InternetAddress(outgoingEmailAddress));
msg.addRecipient(RecipientType.TO, new InternetAddress(alertRecipientAddress)); 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); msg.setText(body);
emailService.sendMessage(msg); emailService.sendMessage(msg);
return null; return null;

View file

@ -32,8 +32,6 @@ import org.joda.time.YearMonth;
public final class BillingModule { public final class BillingModule {
public static final String DETAIL_REPORT_PREFIX = "invoice_details"; 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"; public static final String INVOICES_DIRECTORY = "invoices";
static final String PARAM_SHOULD_PUBLISH = "shouldPublish"; static final String PARAM_SHOULD_PUBLISH = "shouldPublish";

View file

@ -62,6 +62,7 @@ public class InvoicingPipelineTest {
invoicingPipeline.projectId = "test-project"; invoicingPipeline.projectId = "test-project";
File beamTempFolder = tempFolder.newFolder(); File beamTempFolder = tempFolder.newFolder();
invoicingPipeline.beamBucketUrl = beamTempFolder.getAbsolutePath(); invoicingPipeline.beamBucketUrl = beamTempFolder.getAbsolutePath();
invoicingPipeline.invoiceFilePrefix = "REG-INV";
invoicingPipeline.beamStagingUrl = beamTempFolder.getAbsolutePath() + "/staging"; invoicingPipeline.beamStagingUrl = beamTempFolder.getAbsolutePath() + "/staging";
invoicingPipeline.invoiceTemplateUrl = invoicingPipeline.invoiceTemplateUrl =
beamTempFolder.getAbsolutePath() + "/templates/invoicing"; beamTempFolder.getAbsolutePath() + "/templates/invoicing";
@ -196,7 +197,7 @@ public class InvoicingPipelineTest {
.containsExactlyElementsIn(entry.getValue()); .containsExactlyElementsIn(entry.getValue());
} }
ImmutableList<String> overallInvoice = resultFileContents("CRR-INV-2017-10.csv"); ImmutableList<String> overallInvoice = resultFileContents("REG-INV-2017-10.csv");
assertThat(overallInvoice.get(0)) assertThat(overallInvoice.get(0))
.isEqualTo( .isEqualTo(
"StartDate,EndDate,ProductAccountKey,Amount,AmountCurrency,BillingProductCode," "StartDate,EndDate,ProductAccountKey,Amount,AmountCurrency,BillingProductCode,"

View file

@ -67,7 +67,7 @@ public class BillingEmailUtilsTest {
when(emailService.createMessage()) when(emailService.createMessage())
.thenReturn(new MimeMessage(Session.getDefaultInstance(new Properties(), null))); .thenReturn(new MimeMessage(Session.getDefaultInstance(new Properties(), null)));
gcsUtils = mock(GcsUtils.class); gcsUtils = mock(GcsUtils.class);
when(gcsUtils.openInputStream(new GcsFilename("test-bucket", "results/CRR-INV-2017-10.csv"))) when(gcsUtils.openInputStream(new GcsFilename("test-bucket", "results/REG-INV-2017-10.csv")))
.thenReturn( .thenReturn(
new ByteArrayInputStream("test,data\nhello,world".getBytes(StandardCharsets.UTF_8))); new ByteArrayInputStream("test,data\nhello,world".getBytes(StandardCharsets.UTF_8)));
msgCaptor = ArgumentCaptor.forClass(Message.class); msgCaptor = ArgumentCaptor.forClass(Message.class);
@ -80,6 +80,7 @@ public class BillingEmailUtilsTest {
"my-receiver@test.com", "my-receiver@test.com",
ImmutableList.of("hello@world.com", "hola@mundo.com"), ImmutableList.of("hello@world.com", "hola@mundo.com"),
"test-bucket", "test-bucket",
"REG-INV",
"results/", "results/",
gcsUtils, gcsUtils,
new Retrier(new FakeSleeper(new FakeClock()), RETRY_COUNT)); new Retrier(new FakeSleeper(new FakeClock()), RETRY_COUNT));
@ -109,7 +110,7 @@ public class BillingEmailUtilsTest {
.isEqualTo("Attached is the 2017-10 invoice for the domain registry."); .isEqualTo("Attached is the 2017-10 invoice for the domain registry.");
assertThat(contents.getBodyPart(1)).isInstanceOf(BodyPart.class); assertThat(contents.getBodyPart(1)).isInstanceOf(BodyPart.class);
BodyPart attachmentPart = contents.getBodyPart(1); BodyPart attachmentPart = contents.getBodyPart(1);
assertThat(attachmentPart.getContentType()).endsWith("name=CRR-INV-2017-10.csv"); assertThat(attachmentPart.getContentType()).endsWith("name=REG-INV-2017-10.csv");
assertThat(attachmentPart.getContent().toString()).isEqualTo("test,data\nhello,world"); assertThat(attachmentPart.getContent().toString()).isEqualTo("test,data\nhello,world");
} }