in src/main/java/com/amazonaws/partners/saasfactory/metering/aggregation/StripeBillingPublish.java [337:401]
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) {
if (this.tableConfig.getTableName().isEmpty() || this.tableConfig.getIndexName().isEmpty()) {
return;
}
if (this.billingConfig.getApiKey().isEmpty()) {
return;
}
this.logger.info("Fetching tenant IDs in table {}", this.tableConfig.getTableName());
List<TenantConfiguration> tenantConfigurations = TenantConfiguration.getTenantConfigurations(this.tableConfig, ddb, this.logger);
if (tenantConfigurations.isEmpty()) {
this.logger.info("No tenant configurations found in table {}",
this.tableConfig.getTableName());
return;
}
this.logger.info("Resolved tenant IDs in table {}", this.tableConfig.getTableName());
for (TenantConfiguration tenant: tenantConfigurations) {
// Check for the existence of the invoice expiration time or if it is expired
// If it doesn't exist or is expired, retrieve and store it
if (tenant.getInvoiceClosingTime() == null) {
this.logger.info("No invoice closing time found for tenant {}", tenant.getTenantID());
Instant invoiceClosingTime = updateInvoice(tenant);
if (invoiceClosingTime == null) {
this.logger.info("Unable to update invoice closing time for tenant {}", tenant.getTenantID());
continue;
}
tenant.setInvoiceClosingTime(invoiceClosingTime);
}
if (!tenant.isInvoiceClosed()) {
this.logger.info("Invoice for tenant {} is still open", tenant.getTenantID());
continue;
}
this.logger.info("Invoice closed for tenant {}", tenant.getTenantID());
List<AggregationEntry> aggregationEntries = getAggregationEntries(tenant.getTenantID());
if (aggregationEntries.isEmpty()) {
this.logger.info("No unpublished aggregation entries found for tenant {}",
tenant.getTenantID());
} else {
if (aggregationEntries.size() == 1) {
this.logger.info("Found {} an unpublished aggregation entry for tenant {}",
aggregationEntries.size(),
tenant.getTenantID());
} else{
this.logger.info("Found {} unpublished aggregation entries for tenant {}",
aggregationEntries.size(),
tenant.getTenantID());
}
for (AggregationEntry entry : aggregationEntries) {
String subscriptionID = tenant.getExternalSubscriptionIdentifier();
if (subscriptionID == null) {
this.logger.error("No subscription ID found associated with tenant {}",
tenant.getTenantID());
String aggregationEntryString = formatAggregationEntry(entry.getPeriodStart().toEpochMilli());
this.logger.error("Unable to publish aggregation entry {} associated with tenant {}",
aggregationEntryString,
tenant.getTenantID());
continue;
}
addUsageToSubscriptionItem(tenant.getExternalSubscriptionIdentifier(), entry);
}
}
}
}