You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by of...@apache.org on 2020/04/08 15:40:12 UTC
[incubator-dlab] branch DLAB-1571 updated: billing self-service
This is an automated email from the ASF dual-hosted git repository.
ofuks pushed a commit to branch DLAB-1571
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/DLAB-1571 by this push:
new 61df0d8 billing self-service
61df0d8 is described below
commit 61df0d89b3a98528d0ec50fb4cbf9f4653576818
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Wed Apr 8 18:39:52 2020 +0300
billing self-service
---
.../service/impl/BillingServiceImpl.java | 27 +++++++++++++++-------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImpl.java
index fdbb789..c54d624 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/BillingServiceImpl.java
@@ -63,6 +63,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+
@Slf4j
public class BillingServiceImpl implements BillingService {
private static final String BILLING_PATH = "/api/billing";
@@ -214,17 +215,23 @@ public class BillingServiceImpl implements BillingService {
private void updateBillingData(UserInfo userInfo, EndpointDTO endpointDTO, List<BillingData> billingData) {
final String endpointName = endpointDTO.getName();
+ final CloudProvider cloudProvider = endpointDTO.getCloudProvider();
final Map<String, BillingReportLine> billableResources = getBillableResources(userInfo);
- if (endpointDTO.getCloudProvider() == CloudProvider.GCP) {
- final Map<String, List<BillingReportLine>> gcpBillingData = billingData
- .stream()
- .filter(bd -> billableResources.containsKey(bd.getTag()))
- .peek(bd -> bd.setApplication(endpointName))
- .map(bd -> toBillingData(bd, billableResources.get(bd.getTag())))
- .collect(Collectors.groupingBy(bd -> bd.getUsageDate().substring(0, USAGE_DATE_FORMAT.length())));
+ final Stream<BillingReportLine> billingReportLineStream = billingData
+ .stream()
+ .filter(bd -> billableResources.containsKey(bd.getTag()))
+ .peek(bd -> bd.setApplication(endpointName))
+ .map(bd -> toBillingReport(bd, billableResources.get(bd.getTag())));
+ if (cloudProvider == CloudProvider.GCP) {
+ final Map<String, List<BillingReportLine>> gcpBillingData = billingReportLineStream
+ .collect(Collectors.groupingBy(bd -> bd.getUsageDate().substring(0, USAGE_DATE_FORMAT.length())));
updateGcpBillingData(endpointName, gcpBillingData);
+ } else if (cloudProvider == CloudProvider.AZURE) {
+ List<BillingReportLine> billingReportLines = billingReportLineStream
+ .collect(Collectors.toList());
+ updateAzureBillingData(billingReportLines);
}
}
@@ -235,6 +242,10 @@ public class BillingServiceImpl implements BillingService {
});
}
+ private void updateAzureBillingData(List<BillingReportLine> billingReportLines) {
+ billingDAO.save(billingReportLines);
+ }
+
private String getBillingUrl(String endpointUrl, String path) {
URI uri;
try {
@@ -262,7 +273,7 @@ public class BillingServiceImpl implements BillingService {
}
}
- private BillingReportLine toBillingData(BillingData billingData, BillingReportLine billingReportLine) {
+ private BillingReportLine toBillingReport(BillingData billingData, BillingReportLine billingReportLine) {
return BillingReportLine.builder()
.application(billingData.getApplication())
.cost(BigDecimal.valueOf(billingData.getCost()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org