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/14 14:40:11 UTC
[incubator-dlab] 01/03: fixed billing issues
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
commit fc9e515e7cf67ec0a9a1a4ec702cf76a3425f81a
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Tue Apr 14 15:02:17 2020 +0300
fixed billing issues
---
.../java/com/epam/dlab/BillingServiceImpl.java | 2 +-
.../billing/azure/CalculateBillingServiceImpl.java | 2 +-
.../billing/gcp/dao/impl/BigQueryBillingDAO.java | 2 +-
.../service/impl/BillingServiceImpl.java | 22 ++++++++++------------
.../epam/dlab/backendapi/util/BillingUtils.java | 14 +++++++-------
5 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/services/billing-aws/src/main/java/com/epam/dlab/BillingServiceImpl.java b/services/billing-aws/src/main/java/com/epam/dlab/BillingServiceImpl.java
index d474790..8ac6c48 100644
--- a/services/billing-aws/src/main/java/com/epam/dlab/BillingServiceImpl.java
+++ b/services/billing-aws/src/main/java/com/epam/dlab/BillingServiceImpl.java
@@ -76,7 +76,7 @@ public class BillingServiceImpl implements BillingService {
private BillingData toBillingData(Document billingData) {
return BillingData.builder()
- .tag(billingData.getString(FIELD_DLAB_ID))
+ .tag(billingData.getString(FIELD_DLAB_ID).toLowerCase())
.usageDateFrom(Optional.ofNullable(billingData.getString(FIELD_USAGE_DATE)).map(LocalDate::parse).orElse(null))
.usageDateTo(Optional.ofNullable(billingData.getString(FIELD_USAGE_DATE)).map(LocalDate::parse).orElse(null))
.usageDate(billingData.getString(FIELD_USAGE_DATE))
diff --git a/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/CalculateBillingServiceImpl.java b/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/CalculateBillingServiceImpl.java
index de38aff..3b3d60b 100644
--- a/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/CalculateBillingServiceImpl.java
+++ b/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/CalculateBillingServiceImpl.java
@@ -233,7 +233,7 @@ public class CalculateBillingServiceImpl implements CalculateBillingService {
private BillingData toBillingData(AzureDailyResourceInvoice billingData) {
return BillingData.builder()
- .tag(billingData.getDlabId())
+ .tag(billingData.getDlabId().toLowerCase())
.usageDateFrom(Optional.ofNullable(billingData.getUsageStartDate()).map(LocalDate::parse).orElse(null))
.usageDateTo(Optional.ofNullable(billingData.getUsageEndDate()).map(LocalDate::parse).orElse(null))
.usageDate(billingData.getDay())
diff --git a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/dao/impl/BigQueryBillingDAO.java b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/dao/impl/BigQueryBillingDAO.java
index 6949d95..061283d 100644
--- a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/dao/impl/BigQueryBillingDAO.java
+++ b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/dao/impl/BigQueryBillingDAO.java
@@ -120,7 +120,7 @@ public class BigQueryBillingDAO implements BillingDAO {
.product(fields.get("product").getStringValue())
.usageType(fields.get("usageType").getStringValue())
.currency(fields.get("currency").getStringValue())
- .tag(fields.get("value").getStringValue())
+ .tag(fields.get("value").getStringValue().toLowerCase())
.usageDate(toLocalDate(fields, "usage_date_from").format((DateTimeFormatter.ofPattern(DATE_FORMAT))))
.build();
}
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 3d0ecea..ce88cb9 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
@@ -164,19 +164,16 @@ public class BillingServiceImpl implements BillingService {
billingDataMap.forEach((endpointDTO, billingData) -> {
log.info("Updating billing information for endpoint {}. Billing data {}", endpointDTO.getName(), billingData);
- updateBillingData(userInfo, endpointDTO, billingData);
+ try {
+ updateBillingData(endpointDTO, billingData);
+ } catch (Exception e) {
+ log.error("Something went wrong while trying to update billing for {}. {}", endpointDTO.getName(), e.getMessage());
+ }
});
}
- private Map<String, BillingReportLine> getBillableResources(UserInfo userInfo) {
- Set<ProjectDTO> projects;
- if (isFullReport(userInfo)) {
- projects = new HashSet<>(projectService.getProjects());
- } else {
- projects = new HashSet<>(projectService.getProjects(userInfo));
- projects.addAll(projectService.getUserProjects(userInfo, false));
- }
-
+ private Map<String, BillingReportLine> getBillableResources() {
+ Set<ProjectDTO> projects = new HashSet<>(projectService.getProjects());
final Stream<BillingReportLine> ssnBillingDataStream = BillingUtils.ssnBillingDataStream(sbn);
final Stream<BillingReportLine> billableEdges = projects
.stream()
@@ -211,10 +208,10 @@ public class BillingServiceImpl implements BillingService {
.flatMap(endpoint -> BillingUtils.edgeBillingDataStream(projectName, serviceBaseName, endpoint.getName()));
}
- private void updateBillingData(UserInfo userInfo, EndpointDTO endpointDTO, List<BillingData> billingData) {
+ private void updateBillingData(EndpointDTO endpointDTO, List<BillingData> billingData) {
final String endpointName = endpointDTO.getName();
final CloudProvider cloudProvider = endpointDTO.getCloudProvider();
- final Map<String, BillingReportLine> billableResources = getBillableResources(userInfo);
+ final Map<String, BillingReportLine> billableResources = getBillableResources();
final Stream<BillingReportLine> billingReportLineStream = billingData
.stream()
.peek(bd -> bd.setApplication(endpointName))
@@ -333,6 +330,7 @@ public class BillingServiceImpl implements BillingService {
.resourceType(billingReportLine.getResourceType())
.resourceName(billingReportLine.getResourceName())
.shape(billingReportLine.getShape())
+ .exploratoryName(billingReportLine.getExploratoryName())
.build();
}
}
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java
index da59725..5ac725c 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/util/BillingUtils.java
@@ -70,9 +70,9 @@ public class BillingUtils {
private static final String DATAENGINE_SERVICE_NAME_FORMAT = "Master: %s%sSlave: %d x %s";
public static Stream<BillingReportLine> edgeBillingDataStream(String project, String sbn, String endpoint) {
- final String userEdgeId = String.format(EDGE_FORMAT, sbn, project.toLowerCase(), endpoint);
- final String edgeVolumeId = String.format(EDGE_VOLUME_FORMAT, sbn, project.toLowerCase(), endpoint);
- final String endpointBucketId = String.format(PROJECT_ENDPOINT_BUCKET_FORMAT, sbn, project.toLowerCase(), endpoint);
+ final String userEdgeId = String.format(EDGE_FORMAT, sbn, project, endpoint).toLowerCase();
+ final String edgeVolumeId = String.format(EDGE_VOLUME_FORMAT, sbn, project, endpoint).toLowerCase();
+ final String endpointBucketId = String.format(PROJECT_ENDPOINT_BUCKET_FORMAT, sbn, project, endpoint).toLowerCase();
return Stream.concat(Stream.of(
BillingReportLine.builder().resourceName(endpoint).user(SHARED_RESOURCE).project(project).dlabId(userEdgeId).resourceType(EDGE).build(),
@@ -92,8 +92,8 @@ public class BillingUtils {
}
public static Stream<BillingReportLine> sharedEndpointBillingDataStream(String endpoint, String sbn) {
- final String projectEndpointBucketId = String.format(ENDPOINT_SHARED_BUCKET_FORMAT, sbn, endpoint.toLowerCase());
- final String endpointId = String.format(ENDPOINT_FORMAT, sbn, endpoint.toLowerCase());
+ final String projectEndpointBucketId = String.format(ENDPOINT_SHARED_BUCKET_FORMAT, sbn, endpoint).toLowerCase();
+ final String endpointId = String.format(ENDPOINT_FORMAT, sbn, endpoint).toLowerCase();
return Stream.of(
BillingReportLine.builder().resourceName("Endpoint shared bucket").user(SHARED_RESOURCE).project(SHARED_RESOURCE).dlabId(projectEndpointBucketId).resourceType(BUCKET).build(),
BillingReportLine.builder().resourceName("Endpoint").user(SHARED_RESOURCE).project(SHARED_RESOURCE).dlabId(endpointId).resourceType(ENDPOINT).build()
@@ -128,7 +128,7 @@ public class BillingUtils {
}
public static Stream<BillingReportLine> customImageBillingDataStream(ImageInfoRecord image, String sbn) {
- String imageId = String.format(IMAGE_CUSTOM_FORMAT, sbn, image.getProject(), image.getEndpoint(), image.getApplication(), image.getName());
+ String imageId = String.format(IMAGE_CUSTOM_FORMAT, sbn, image.getProject(), image.getEndpoint(), image.getApplication(), image.getName()).toLowerCase();
return Stream.of(
BillingReportLine.builder().resourceName(IMAGE_NAME).project(image.getProject()).dlabId(imageId).resourceType(IMAGE).build()
);
@@ -158,7 +158,7 @@ public class BillingUtils {
public static Stream<BillingReportLine> standardImageBillingDataStream(String sbn, String project, String endpoint) {
List<BillingReportLine> list = new ArrayList<>();
for (String notebook : AVAILABLE_NOTEBOOKS) {
- list.add(BillingReportLine.builder().resourceName(IMAGE_NAME).dlabId(String.format(IMAGE_STANDARD_FORMAT1, sbn, project, endpoint, notebook))
+ list.add(BillingReportLine.builder().resourceName(IMAGE_NAME).dlabId(String.format(IMAGE_STANDARD_FORMAT1, sbn, project, endpoint, notebook).toLowerCase())
.project(SHARED_RESOURCE).resourceType(IMAGE).build());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org