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 757261106f6d51a705f9aa025d22431a9587f6e4
Author: Oleh Fuks <olegfuk...@gmail.com>
AuthorDate: Fri Apr 3 18:10:21 2020 +0300

    Remote billing
---
 .../epam/dlab/backendapi/dao/UserRoleDaoImpl.java  |  2 +-
 .../service/impl/BillingServiceImpl.java           | 33 +++++++++-------------
 .../epam/dlab/backendapi/util/BillingUtils.java    |  4 ---
 3 files changed, 14 insertions(+), 25 deletions(-)

diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDaoImpl.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDaoImpl.java
index 7bd7b94..174e71f 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDaoImpl.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/dao/UserRoleDaoImpl.java
@@ -108,7 +108,7 @@ public class UserRoleDaoImpl extends BaseDAO implements 
UserRoleDao {
                                                .noneMatch(id -> 
id.equals(u.getId())))
                                .forEach(this::insert);
 
-               addGroupToRole(aggregateRolesByGroup()
+               addGroupToRole(aggregateRolesByGroup(false)
                                                .stream()
                                                .map(UserGroupDto::getGroup)
                                                .collect(Collectors.toSet()),
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 794ac33..7d6ab11 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
@@ -140,7 +140,7 @@ public class BillingServiceImpl implements BillingService {
             projects.addAll(projectService.getUserProjects(user, false));
         }
 
-        final Map<String, BillingReportLine> billableResources = 
getBillableResources(user, projects);
+        final Map<String, BillingReportLine> billableResources = 
getBillableResources(projects);
 
         List<BillingReportLine> billingReport = getRemoteBillingData(user, 
filter)
                 .stream()
@@ -153,8 +153,17 @@ public class BillingServiceImpl implements BillingService {
         return billingReport;
     }
 
-    private Map<String, BillingReportLine> getBillableResources(UserInfo user, 
Set<ProjectDTO> projects) {
-        Stream<BillingReportLine> billableAdminResources = Stream.empty();
+    private Map<String, BillingReportLine> 
getBillableResources(Set<ProjectDTO> projects) {
+        final Stream<BillingReportLine> ssnBillingDataStream = 
BillingUtils.ssnBillingDataStream(sbn);
+        final Stream<BillingReportLine> billableEdges = projects
+                .stream()
+                .collect(Collectors.toMap(ProjectDTO::getName, 
ProjectDTO::getEndpoints))
+                .entrySet()
+                .stream()
+                .flatMap(e -> projectEdges(sbn, e.getKey(), e.getValue()));
+        final Stream<BillingReportLine> billableSharedEndpoints = 
endpointService.getEndpoints()
+                .stream()
+                .flatMap(endpoint -> 
BillingUtils.sharedEndpointBillingDataStream(endpoint.getName(), sbn));
         final Stream<BillingReportLine> billableUserInstances = 
exploratoryService.findAll(projects)
                 .stream()
                 .filter(userInstance -> 
Objects.nonNull(userInstance.getExploratoryId()))
@@ -165,23 +174,7 @@ public class BillingServiceImpl implements BillingService {
                 .flatMap(Collection::stream)
                 .flatMap(i -> BillingUtils.customImageBillingDataStream(i, 
sbn));
 
-        if (UserRoles.isAdmin(user)) {
-            final Stream<BillingReportLine> ssnBillingDataStream = 
BillingUtils.ssnBillingDataStream(sbn);
-            final Stream<BillingReportLine> billableEdges = projects
-                    .stream()
-                    .collect(Collectors.toMap(ProjectDTO::getName, 
ProjectDTO::getEndpoints))
-                    .entrySet()
-                    .stream()
-                    .flatMap(e -> projectEdges(sbn, e.getKey(), e.getValue()));
-            final Stream<BillingReportLine> billableSharedEndpoints = 
endpointService.getEndpoints()
-                    .stream()
-                    .flatMap(endpoint -> 
BillingUtils.sharedEndpointBillingDataStream(endpoint.getName(), sbn));
-
-            billableAdminResources = Stream.of(billableEdges, 
ssnBillingDataStream, billableSharedEndpoints)
-                    .flatMap(s -> s);
-        }
-
-        final Map<String, BillingReportLine> billableResources = 
Stream.of(billableUserInstances, customImages, billableAdminResources)
+        final Map<String, BillingReportLine> billableResources = 
Stream.of(ssnBillingDataStream, billableEdges, billableSharedEndpoints, 
billableUserInstances, customImages)
                 .flatMap(s -> s)
                 .collect(Collectors.toMap(BillingReportLine::getDlabId, b -> 
b));
         log.debug("Billable resources are: {}", billableResources);
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 cc77ff1..c8454b2 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
@@ -62,9 +62,7 @@ public class BillingUtils {
     private static final String VOLUME_SECONDARY_FORMAT = 
"%s-volume-secondary";
     private static final String VOLUME_SECONDARY_COMPUTATIONAL_FORMAT = 
"%s-%s-volume-secondary";
     private static final String IMAGE_STANDARD_FORMAT1 = 
"%s-%s-%s-%s-notebook-image";
-    private static final String IMAGE_STANDARD_FORMAT2 = 
"%s-%s-%s-notebook-image";
     private static final String IMAGE_CUSTOM_FORMAT = "%s-%s-%s-%s-%s";
-    private static final String IMAGE_NAME_PREFIX = "docker.dlab-";
 
     private static final String VOLUME_PRIMARY = "Volume primary";
     private static final String VOLUME_SECONDARY = "Volume secondary";
@@ -171,8 +169,6 @@ public class BillingUtils {
         for (String notebook : AVAILABLE_NOTEBOOKS) {
             
list.add(BillingReportLine.builder().resourceName(IMAGE_NAME).dlabId(String.format(IMAGE_STANDARD_FORMAT1,
 sbn, project, endpoint, notebook))
                     .project(SHARED_RESOURCE).resourceType(IMAGE).build());
-            
list.add(BillingReportLine.builder().resourceName(IMAGE_NAME).dlabId(String.format(IMAGE_STANDARD_FORMAT2,
 sbn, endpoint, notebook))
-                    .project(SHARED_RESOURCE).resourceType(IMAGE).build());
         }
 
         return list.stream();


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

Reply via email to