You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by bh...@apache.org on 2019/09/10 13:45:55 UTC

[incubator-dlab] branch bil-2 updated: DLAB-23 added project to billable resource

This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a commit to branch bil-2
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/bil-2 by this push:
     new 461b6b7  DLAB-23 added project to billable resource
461b6b7 is described below

commit 461b6b746c3dda02659bd720f5b19079ba08e274
Author: bhliva <bo...@epam.com>
AuthorDate: Tue Sep 10 16:45:45 2019 +0300

    DLAB-23 added project to billable resource
---
 .../dlab/billing/gcp/documents/UserInstance.java   |   1 +
 .../epam/dlab/billing/gcp/model/BillingData.java   |   1 +
 .../billing/gcp/service/BillingServiceImpl.java    |   1 +
 .../epam/dlab/billing/gcp/util/BillingUtils.java   | 120 ++++++++++-----------
 4 files changed, 60 insertions(+), 63 deletions(-)

diff --git a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/documents/UserInstance.java b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/documents/UserInstance.java
index 0bb051e..b5a61ba 100644
--- a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/documents/UserInstance.java
+++ b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/documents/UserInstance.java
@@ -39,6 +39,7 @@ public class UserInstance {
     private String exploratoryName;
     @Field("exploratory_id")
     private String exploratoryId;
+    private String project;
     private List<BillingData> billing;
     private String cost;
     @Field("computational_resources")
diff --git a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/model/BillingData.java b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/model/BillingData.java
index b966f7b..32a98ed 100644
--- a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/model/BillingData.java
+++ b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/model/BillingData.java
@@ -48,6 +48,7 @@ public class BillingData {
     private Double cost;
     @Field("currency_code")
     private String currency;
+    private String project;
     private String exploratoryName;
     private String computationalName;
     @Field("dlab_id")
diff --git a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/service/BillingServiceImpl.java b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/service/BillingServiceImpl.java
index 223f3b2..9fc57e0 100644
--- a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/service/BillingServiceImpl.java
+++ b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/service/BillingServiceImpl.java
@@ -159,6 +159,7 @@ public class BillingServiceImpl implements BillingService {
 				.cost(bd.getCost().doubleValue())
 				.currency(bd.getCurrency())
 				.product(bd.getProduct())
+				.project(billableResource.getProject())
 				.usageDateTo(bd.getUsageDateTo())
 				.usageDateFrom(bd.getUsageDateFrom())
 				.usageDate(bd.getUsageDateFrom().format((DateTimeFormatter.ofPattern(DATE_FORMAT))))
diff --git a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/util/BillingUtils.java b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/util/BillingUtils.java
index 9e21a92..d94559c 100644
--- a/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/util/BillingUtils.java
+++ b/services/billing-gcp/src/main/java/com/epam/dlab/billing/gcp/util/BillingUtils.java
@@ -22,77 +22,71 @@ package com.epam.dlab.billing.gcp.util;
 import com.epam.dlab.billing.gcp.documents.UserInstance;
 import com.epam.dlab.billing.gcp.model.BillingData;
 
-import java.util.UUID;
 import java.util.stream.Stream;
 
 public class BillingUtils {
 
-    private static final String EDGE_FORMAT = "%s-%s-edge";
-    private static final String EDGE_VOLUME_FORMAT = "%s-%s-edge-volume-primary";
-    private static final String EDGE_BUCKET_FORMAT = "%s-%s-bucket";
-    private static final String VOLUME_PRIMARY_FORMAT = "%s-volume-primary";
-    private static final String VOLUME_SECONDARY_FORMAT = "%s-volume-secondary";
-    private static final String VOLUME_PRIMARY = "Volume primary";
-    private static final String VOLUME_SECONDARY = "Volume secondary";
-    private static final String SHARED_RESOURCE = "Shared resource";
+	private static final String EDGE_FORMAT = "%s-%s-edge";
+	private static final String EDGE_VOLUME_FORMAT = "%s-%s-edge-volume-primary";
+	private static final String EDGE_BUCKET_FORMAT = "%s-%s-bucket";
+	private static final String VOLUME_PRIMARY_FORMAT = "%s-volume-primary";
+	private static final String VOLUME_SECONDARY_FORMAT = "%s-volume-secondary";
+	private static final String VOLUME_PRIMARY = "Volume primary";
+	private static final String VOLUME_SECONDARY = "Volume secondary";
+	private static final String SHARED_RESOURCE = "Shared resource";
 
-    public static Stream<BillingData> edgeBillingDataStream(String project, String sbn) {
-        final String userEdgeId = String.format(EDGE_FORMAT, sbn, project);
-        final String edgeVolumeId = String.format(EDGE_VOLUME_FORMAT, sbn, project);
-        final String edgeBucketId = String.format(EDGE_BUCKET_FORMAT, sbn, project);
-        return Stream.of(
-                BillingData.builder().displayName("EDGE node").user(SHARED_RESOURCE).dlabId(userEdgeId).resourceType(BillingData.ResourceType.EDGE).build(),
-                BillingData.builder().displayName("EDGE volume").user(SHARED_RESOURCE).dlabId(edgeVolumeId).resourceType(BillingData.ResourceType.VOLUME).build(),
-                BillingData.builder().displayName("EDGE bucket").user(SHARED_RESOURCE).dlabId(edgeBucketId).resourceType(BillingData.ResourceType.EDGE_BUCKET).build()
-        );
-    }
+	public static Stream<BillingData> edgeBillingDataStream(String project, String sbn) {
+		final String userEdgeId = String.format(EDGE_FORMAT, sbn, project);
+		final String edgeVolumeId = String.format(EDGE_VOLUME_FORMAT, sbn, project);
+		final String edgeBucketId = String.format(EDGE_BUCKET_FORMAT, sbn, project);
+		return Stream.of(
+				BillingData.builder().displayName("EDGE node").user(SHARED_RESOURCE).project(project).dlabId(userEdgeId).resourceType(BillingData.ResourceType.EDGE).build(),
+				BillingData.builder().displayName("EDGE volume").user(SHARED_RESOURCE).project(project).dlabId(edgeVolumeId).resourceType(BillingData.ResourceType.VOLUME).build(),
+				BillingData.builder().displayName("EDGE bucket").user(SHARED_RESOURCE).project(project).dlabId(edgeBucketId).resourceType(BillingData.ResourceType.EDGE_BUCKET).build()
+		);
+	}
 
-    public static Stream<BillingData> ssnBillingDataStream(String sbn) {
-        final String ssnId = sbn + "-ssn";
-        final String bucketName = sbn.replaceAll("_", "-");
-        return Stream.of(
-                BillingData.builder().user(SHARED_RESOURCE).displayName("SSN").dlabId(ssnId).resourceType(BillingData.ResourceType.SSN).build(),
-                BillingData.builder().user(SHARED_RESOURCE).displayName("SSN Volume").dlabId(String.format(VOLUME_PRIMARY_FORMAT, ssnId)).resourceType(BillingData.ResourceType.VOLUME).build(),
-                BillingData.builder().user(SHARED_RESOURCE).displayName("SSN bucket").dlabId(bucketName + "-ssn" +
-                        "-bucket").resourceType(BillingData.ResourceType.SSN_BUCKET).build(),
-                BillingData.builder().user(SHARED_RESOURCE).displayName("Collaboration bucket").dlabId(bucketName +
-                        "-shared-bucket").resourceType(BillingData.ResourceType.SHARED_BUCKET).build()
-        );
-    }
+	public static Stream<BillingData> ssnBillingDataStream(String sbn) {
+		final String ssnId = sbn + "-ssn";
+		final String bucketName = sbn.replaceAll("_", "-");
+		return Stream.of(
+				BillingData.builder().user(SHARED_RESOURCE).displayName("SSN").dlabId(ssnId).resourceType(BillingData.ResourceType.SSN).build(),
+				BillingData.builder().user(SHARED_RESOURCE).displayName("SSN Volume").dlabId(String.format(VOLUME_PRIMARY_FORMAT, ssnId)).resourceType(BillingData.ResourceType.VOLUME).build(),
+				BillingData.builder().user(SHARED_RESOURCE).displayName("SSN bucket").dlabId(bucketName + "-ssn" +
+						"-bucket").resourceType(BillingData.ResourceType.SSN_BUCKET).build(),
+				BillingData.builder().user(SHARED_RESOURCE).displayName("Collaboration bucket").dlabId(bucketName +
+						"-shared-bucket").resourceType(BillingData.ResourceType.SHARED_BUCKET).build()
+		);
+	}
 
-    public static Stream<BillingData> exploratoryBillingDataStream(UserInstance userInstance) {
-        final Stream<BillingData> computationalStream = userInstance.getComputationalResources()
-                .stream()
-                .flatMap(cr -> Stream.of(computationalBillableResource(userInstance, cr)));
-        final String exploratoryId = userInstance.getExploratoryId();
-        final String primaryVolumeId = String.format(VOLUME_PRIMARY_FORMAT, exploratoryId);
-        final String secondaryVolumeId = String.format(VOLUME_SECONDARY_FORMAT, exploratoryId);
-        final Stream<BillingData> exploratoryStream = Stream.of(
-                withExploratoryName(userInstance).displayName(userInstance.getExploratoryName()).dlabId(exploratoryId).resourceType(BillingData.ResourceType.EXPLORATORY).build(),
-                withExploratoryName(userInstance).displayName(VOLUME_PRIMARY).dlabId(primaryVolumeId).resourceType(BillingData.ResourceType.VOLUME).build(),
-                withExploratoryName(userInstance).displayName(VOLUME_SECONDARY).dlabId(secondaryVolumeId).resourceType(BillingData.ResourceType.VOLUME).build());
-        return Stream.concat(computationalStream, exploratoryStream);
-    }
+	public static Stream<BillingData> exploratoryBillingDataStream(UserInstance userInstance) {
+		final Stream<BillingData> computationalStream = userInstance.getComputationalResources()
+				.stream()
+				.flatMap(cr -> Stream.of(computationalBillableResource(userInstance, cr)));
+		final String exploratoryId = userInstance.getExploratoryId();
+		final String primaryVolumeId = String.format(VOLUME_PRIMARY_FORMAT, exploratoryId);
+		final String secondaryVolumeId = String.format(VOLUME_SECONDARY_FORMAT, exploratoryId);
+		final Stream<BillingData> exploratoryStream = Stream.of(
+				withExploratoryName(userInstance).displayName(userInstance.getExploratoryName()).dlabId(exploratoryId).resourceType(BillingData.ResourceType.EXPLORATORY).build(),
+				withExploratoryName(userInstance).displayName(VOLUME_PRIMARY).dlabId(primaryVolumeId).resourceType(BillingData.ResourceType.VOLUME).build(),
+				withExploratoryName(userInstance).displayName(VOLUME_SECONDARY).dlabId(secondaryVolumeId).resourceType(BillingData.ResourceType.VOLUME).build());
+		return Stream.concat(computationalStream, exploratoryStream);
+	}
 
-    private static BillingData computationalBillableResource(UserInstance userInstance,
-                                                             UserInstance.ComputationalResource cr) {
-        return withExploratoryName(userInstance)
-                .dlabId(cr.getComputationalId())
-                .displayName(cr.getComputationalName())
-                .resourceType(BillingData.ResourceType.COMPUTATIONAL)
-                .computationalName(cr.getComputationalName())
-                .build();
-    }
+	private static BillingData computationalBillableResource(UserInstance userInstance,
+															 UserInstance.ComputationalResource cr) {
+		return withExploratoryName(userInstance)
+				.dlabId(cr.getComputationalId())
+				.displayName(cr.getComputationalName())
+				.resourceType(BillingData.ResourceType.COMPUTATIONAL)
+				.computationalName(cr.getComputationalName())
+				.project(userInstance.getProject())
+				.build();
+	}
 
-    private static BillingData.BillingDataBuilder withExploratoryName(UserInstance userInstance) {
-        return BillingData.builder().user(userInstance.getUser()).exploratoryName(userInstance.getExploratoryName());
-    }
-
-    private static String adjustUserName(int maxLength, String userName) {
-        String newName = userName.replaceAll("\\s", "_").replaceAll("@.*", "");
-
-        return newName.length() > maxLength ?
-                UUID.nameUUIDFromBytes(newName.getBytes()).toString().substring(0, maxLength) : newName;
-    }
+	private static BillingData.BillingDataBuilder withExploratoryName(UserInstance userInstance) {
+		return BillingData.builder().user(userInstance.getUser()).exploratoryName(userInstance.getExploratoryName())
+				.project(userInstance.getProject());
+	}
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org