mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Enable ability to generate invoices without publishing
This adds a parameter to control invoice reporting, which defaults to false for now (since we plan on manually adjusting the invoice next month). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=193708323
This commit is contained in:
parent
4151660dab
commit
139c8e190d
4 changed files with 75 additions and 6 deletions
|
@ -590,6 +590,18 @@ public final class RegistryConfig {
|
||||||
return "gs://" + billingBucket;
|
return "gs://" + billingBucket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not we should publish invoices to partners automatically by default.
|
||||||
|
*
|
||||||
|
* @see google.registry.reporting.billing.BillingModule
|
||||||
|
*/
|
||||||
|
@Provides
|
||||||
|
@Config("defaultShouldPublishInvoices")
|
||||||
|
public static boolean provideDefaultShouldPublishInvoices() {
|
||||||
|
// TODO(b/78278360): Make the default 'true' once we're done with SUNRISE.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of addresses that receive monthly invoicing emails.
|
* Returns the list of addresses that receive monthly invoicing emails.
|
||||||
*
|
*
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
package google.registry.reporting.billing;
|
package google.registry.reporting.billing;
|
||||||
|
|
||||||
|
import static google.registry.request.RequestParameters.extractOptionalBooleanParameter;
|
||||||
import static google.registry.request.RequestParameters.extractRequiredParameter;
|
import static google.registry.request.RequestParameters.extractRequiredParameter;
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
@ -43,6 +44,7 @@ public final class BillingModule {
|
||||||
public static final String INVOICES_DIRECTORY = "invoices";
|
public static final String INVOICES_DIRECTORY = "invoices";
|
||||||
|
|
||||||
static final String PARAM_JOB_ID = "jobId";
|
static final String PARAM_JOB_ID = "jobId";
|
||||||
|
static final String PARAM_SHOULD_PUBLISH = "shouldPublish";
|
||||||
static final String BILLING_QUEUE = "billing";
|
static final String BILLING_QUEUE = "billing";
|
||||||
static final String CRON_QUEUE = "retryable-cron-tasks";
|
static final String CRON_QUEUE = "retryable-cron-tasks";
|
||||||
|
|
||||||
|
@ -56,6 +58,15 @@ public final class BillingModule {
|
||||||
return extractRequiredParameter(req, PARAM_JOB_ID);
|
return extractRequiredParameter(req, PARAM_JOB_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Parameter(PARAM_SHOULD_PUBLISH)
|
||||||
|
static boolean provideShouldPublish(
|
||||||
|
HttpServletRequest req,
|
||||||
|
@Config("defaultShouldPublishInvoices") boolean defaultShouldPublishInvoices) {
|
||||||
|
return extractOptionalBooleanParameter(req, PARAM_SHOULD_PUBLISH)
|
||||||
|
.orElse(defaultShouldPublishInvoices);
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@InvoiceDirectoryPrefix
|
@InvoiceDirectoryPrefix
|
||||||
static String provideDirectoryPrefix(YearMonth yearMonth) {
|
static String provideDirectoryPrefix(YearMonth yearMonth) {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package google.registry.reporting.billing;
|
package google.registry.reporting.billing;
|
||||||
|
|
||||||
import static google.registry.reporting.ReportingModule.PARAM_YEAR_MONTH;
|
import static google.registry.reporting.ReportingModule.PARAM_YEAR_MONTH;
|
||||||
|
import static google.registry.reporting.billing.BillingModule.PARAM_SHOULD_PUBLISH;
|
||||||
import static google.registry.request.Action.Method.POST;
|
import static google.registry.request.Action.Method.POST;
|
||||||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||||
|
@ -29,6 +30,7 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
|
import google.registry.request.Parameter;
|
||||||
import google.registry.request.Response;
|
import google.registry.request.Response;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
|
@ -55,6 +57,7 @@ public class GenerateInvoicesAction implements Runnable {
|
||||||
private final String projectId;
|
private final String projectId;
|
||||||
private final String beamBucketUrl;
|
private final String beamBucketUrl;
|
||||||
private final String invoiceTemplateUrl;
|
private final String invoiceTemplateUrl;
|
||||||
|
private final boolean shouldPublish;
|
||||||
private final YearMonth yearMonth;
|
private final YearMonth yearMonth;
|
||||||
private final Dataflow dataflow;
|
private final Dataflow dataflow;
|
||||||
private final Response response;
|
private final Response response;
|
||||||
|
@ -65,6 +68,7 @@ public class GenerateInvoicesAction implements Runnable {
|
||||||
@Config("projectId") String projectId,
|
@Config("projectId") String projectId,
|
||||||
@Config("apacheBeamBucketUrl") String beamBucketUrl,
|
@Config("apacheBeamBucketUrl") String beamBucketUrl,
|
||||||
@Config("invoiceTemplateUrl") String invoiceTemplateUrl,
|
@Config("invoiceTemplateUrl") String invoiceTemplateUrl,
|
||||||
|
@Parameter(PARAM_SHOULD_PUBLISH) boolean shouldPublish,
|
||||||
YearMonth yearMonth,
|
YearMonth yearMonth,
|
||||||
Dataflow dataflow,
|
Dataflow dataflow,
|
||||||
Response response,
|
Response response,
|
||||||
|
@ -72,6 +76,7 @@ public class GenerateInvoicesAction implements Runnable {
|
||||||
this.projectId = projectId;
|
this.projectId = projectId;
|
||||||
this.beamBucketUrl = beamBucketUrl;
|
this.beamBucketUrl = beamBucketUrl;
|
||||||
this.invoiceTemplateUrl = invoiceTemplateUrl;
|
this.invoiceTemplateUrl = invoiceTemplateUrl;
|
||||||
|
this.shouldPublish = shouldPublish;
|
||||||
this.yearMonth = yearMonth;
|
this.yearMonth = yearMonth;
|
||||||
this.dataflow = dataflow;
|
this.dataflow = dataflow;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
|
@ -99,7 +104,9 @@ public class GenerateInvoicesAction implements Runnable {
|
||||||
.execute();
|
.execute();
|
||||||
logger.infofmt("Got response: %s", launchResponse.getJob().toPrettyString());
|
logger.infofmt("Got response: %s", launchResponse.getJob().toPrettyString());
|
||||||
String jobId = launchResponse.getJob().getId();
|
String jobId = launchResponse.getJob().getId();
|
||||||
enqueuePublishTask(jobId);
|
if (shouldPublish) {
|
||||||
|
enqueuePublishTask(jobId);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warning(e, "Template Launch failed");
|
logger.warning(e, "Template Launch failed");
|
||||||
emailUtils.sendAlertEmail(String.format("Template Launch failed due to %s", e.getMessage()));
|
emailUtils.sendAlertEmail(String.format("Template Launch failed due to %s", e.getMessage()));
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package google.registry.reporting.billing;
|
package google.registry.reporting.billing;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
||||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
@ -54,7 +55,7 @@ public class GenerateInvoicesActionTest {
|
||||||
private Launch launch;
|
private Launch launch;
|
||||||
private FakeResponse response;
|
private FakeResponse response;
|
||||||
private BillingEmailUtils emailUtils;
|
private BillingEmailUtils emailUtils;
|
||||||
private GenerateInvoicesAction action;
|
GenerateInvoicesAction action;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws IOException {
|
||||||
|
@ -73,20 +74,20 @@ public class GenerateInvoicesActionTest {
|
||||||
Job job = new Job();
|
Job job = new Job();
|
||||||
job.setId("12345");
|
job.setId("12345");
|
||||||
when(launch.execute()).thenReturn(new LaunchTemplateResponse().setJob(job));
|
when(launch.execute()).thenReturn(new LaunchTemplateResponse().setJob(job));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchTemplateJob_withPublish() throws Exception {
|
||||||
action =
|
action =
|
||||||
new GenerateInvoicesAction(
|
new GenerateInvoicesAction(
|
||||||
"test-project",
|
"test-project",
|
||||||
"gs://test-project-beam",
|
"gs://test-project-beam",
|
||||||
"gs://test-project-beam/templates/invoicing",
|
"gs://test-project-beam/templates/invoicing",
|
||||||
|
true,
|
||||||
new YearMonth(2017, 10),
|
new YearMonth(2017, 10),
|
||||||
dataflow,
|
dataflow,
|
||||||
response,
|
response,
|
||||||
emailUtils);
|
emailUtils);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLaunchTemplateJob() throws Exception {
|
|
||||||
action.run();
|
action.run();
|
||||||
LaunchTemplateParameters expectedParams =
|
LaunchTemplateParameters expectedParams =
|
||||||
new LaunchTemplateParameters()
|
new LaunchTemplateParameters()
|
||||||
|
@ -110,9 +111,47 @@ public class GenerateInvoicesActionTest {
|
||||||
assertTasksEnqueued("billing", matcher);
|
assertTasksEnqueued("billing", matcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchTemplateJob_withoutPublish() throws Exception {
|
||||||
|
action =
|
||||||
|
new GenerateInvoicesAction(
|
||||||
|
"test-project",
|
||||||
|
"gs://test-project-beam",
|
||||||
|
"gs://test-project-beam/templates/invoicing",
|
||||||
|
false,
|
||||||
|
new YearMonth(2017, 10),
|
||||||
|
dataflow,
|
||||||
|
response,
|
||||||
|
emailUtils);
|
||||||
|
action.run();
|
||||||
|
LaunchTemplateParameters expectedParams =
|
||||||
|
new LaunchTemplateParameters()
|
||||||
|
.setJobName("invoicing-2017-10")
|
||||||
|
.setEnvironment(
|
||||||
|
new RuntimeEnvironment()
|
||||||
|
.setZone("us-east1-c")
|
||||||
|
.setTempLocation("gs://test-project-beam/temporary"))
|
||||||
|
.setParameters(ImmutableMap.of("yearMonth", "2017-10"));
|
||||||
|
verify(templates).launch("test-project", expectedParams);
|
||||||
|
verify(launch).setGcsPath("gs://test-project-beam/templates/invoicing");
|
||||||
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
assertThat(response.getPayload()).isEqualTo("Launched dataflow template.");
|
||||||
|
assertNoTasksEnqueued();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCaughtIOException() throws IOException {
|
public void testCaughtIOException() throws IOException {
|
||||||
when(launch.execute()).thenThrow(new IOException("expected"));
|
when(launch.execute()).thenThrow(new IOException("expected"));
|
||||||
|
action =
|
||||||
|
new GenerateInvoicesAction(
|
||||||
|
"test-project",
|
||||||
|
"gs://test-project-beam",
|
||||||
|
"gs://test-project-beam/templates/invoicing",
|
||||||
|
true,
|
||||||
|
new YearMonth(2017, 10),
|
||||||
|
dataflow,
|
||||||
|
response,
|
||||||
|
emailUtils);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(500);
|
assertThat(response.getStatus()).isEqualTo(500);
|
||||||
assertThat(response.getPayload()).isEqualTo("Template launch failed: expected");
|
assertThat(response.getPayload()).isEqualTo("Template launch failed: expected");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue