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 a424388 Added custom image format
a424388 is described below
commit a4243886ca4bd458c93ddf1eef6cfef0885b7737
Author: Oleh Fuks <[email protected]>
AuthorDate: Tue Mar 31 17:09:28 2020 +0300
Added custom image format
---
.../backendapi/service/impl/BillingServiceImpl.java | 12 ++++++++++--
.../com/epam/dlab/backendapi/util/BillingUtils.java | 18 +++++++++++++++---
2 files changed, 25 insertions(+), 5 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 22a4a13..0d77367 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
@@ -21,6 +21,7 @@ package com.epam.dlab.backendapi.service.impl;
import com.epam.dlab.auth.UserInfo;
import com.epam.dlab.backendapi.conf.SelfServiceApplicationConfiguration;
+import com.epam.dlab.backendapi.dao.ImageExploratoryDao;
import com.epam.dlab.backendapi.domain.BillingReport;
import com.epam.dlab.backendapi.domain.BillingReportLine;
import com.epam.dlab.backendapi.domain.EndpointDTO;
@@ -79,17 +80,19 @@ public class BillingServiceImpl implements BillingService {
private final ExploratoryService exploratoryService;
private final SelfServiceApplicationConfiguration configuration;
private final RESTService provisioningService;
+ private final ImageExploratoryDao imageExploratoryDao;
private final String sbn;
@Inject
public BillingServiceImpl(ProjectService projectService, EndpointService
endpointService,
ExploratoryService exploratoryService,
SelfServiceApplicationConfiguration configuration,
- @Named(ServiceConsts.PROVISIONING_SERVICE_NAME)
RESTService provisioningService) {
+ @Named(ServiceConsts.PROVISIONING_SERVICE_NAME)
RESTService provisioningService, ImageExploratoryDao imageExploratoryDao) {
this.projectService = projectService;
this.endpointService = endpointService;
this.exploratoryService = exploratoryService;
this.configuration = configuration;
this.provisioningService = provisioningService;
+ this.imageExploratoryDao = imageExploratoryDao;
sbn = configuration.getServiceBaseName();
}
@@ -151,6 +154,11 @@ public class BillingServiceImpl implements BillingService {
.stream()
.filter(userInstance ->
Objects.nonNull(userInstance.getExploratoryId()))
.flatMap(ui -> BillingUtils.exploratoryBillingDataStream(ui,
configuration.getMaxSparkInstanceCount(), sbn));
+ final Stream<BillingReportLine> billingReportLineStream = projects
+ .stream()
+ .map(p -> imageExploratoryDao.getImagesForProject(p.getName()))
+ .flatMap(Collection::stream)
+ .flatMap(i -> BillingUtils.customImageBillingDataStream(i,
sbn));
if (UserRoles.isAdmin(user)) {
final Stream<BillingReportLine> billableEdges = projects
@@ -168,7 +176,7 @@ public class BillingServiceImpl implements BillingService {
.flatMap(s -> s);
}
- final Map<String, BillingReportLine> billableResources =
Stream.of(billableUserInstances, billableAdminResources)
+ final Map<String, BillingReportLine> billableResources =
Stream.of(billableUserInstances, billingReportLineStream,
billableAdminResources)
.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 54489b2..4995de4 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
@@ -20,6 +20,7 @@
package com.epam.dlab.backendapi.util;
import com.epam.dlab.backendapi.domain.BillingReportLine;
+import com.epam.dlab.backendapi.resources.dto.ImageInfoRecord;
import com.epam.dlab.dto.UserInstanceDTO;
import com.epam.dlab.dto.UserInstanceStatus;
import com.epam.dlab.dto.base.DataEngineType;
@@ -59,7 +60,9 @@ public class BillingUtils {
private static final String VOLUME_PRIMARY_COMPUTATIONAL_FORMAT =
"%s-%s-volume-primary";
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_FORMAT =
"%s-%s-%s-%s-notebook-image";
+ 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";
@@ -114,17 +117,26 @@ public class BillingUtils {
getSlaveVolumes(userInstance, cr,
maxSparkInstanceCount)
));
final String exploratoryId = userInstance.getExploratoryId();
- final String imageId = String.format(IMAGE_STANDARD_FORMAT, sbn,
userInstance.getProject(), userInstance.getEndpoint(),
userInstance.getImageName().replace(IMAGE_NAME_PREFIX, ""));
+ final String imageId1 = String.format(IMAGE_STANDARD_FORMAT1, sbn,
userInstance.getProject(), userInstance.getEndpoint(),
userInstance.getImageName().replace(IMAGE_NAME_PREFIX, ""));
+ final String imageId2 = String.format(IMAGE_STANDARD_FORMAT2, sbn,
userInstance.getEndpoint(),
userInstance.getImageName().replace(IMAGE_NAME_PREFIX, ""));
final String primaryVolumeId = String.format(VOLUME_PRIMARY_FORMAT,
exploratoryId);
final String secondaryVolumeId =
String.format(VOLUME_SECONDARY_FORMAT, exploratoryId);
final Stream<BillingReportLine> exploratoryStream = Stream.of(
withUserProject(userInstance).resourceName(userInstance.getExploratoryName()).dlabId(exploratoryId).resourceType(EXPLORATORY).status(UserInstanceStatus.of(userInstance.getStatus())).shape(userInstance.getShape()).build(),
-
withUserProject(userInstance).resourceName(IMAGE_NAME).dlabId(imageId).resourceType(IMAGE).build(),
+
BillingReportLine.builder().resourceName(IMAGE_NAME).dlabId(imageId1).project(userInstance.getProject()).resourceType(IMAGE).build(),
+
BillingReportLine.builder().resourceName(IMAGE_NAME).dlabId(imageId2).project(userInstance.getProject()).resourceType(IMAGE).build(),
withUserProject(userInstance).resourceName(VOLUME_PRIMARY).dlabId(primaryVolumeId).resourceType(VOLUME).build(),
withUserProject(userInstance).resourceName(VOLUME_SECONDARY).dlabId(secondaryVolumeId).resourceType(VOLUME).build());
return Stream.concat(computationalStream, exploratoryStream);
}
+ 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());
+ return Stream.of(
+
BillingReportLine.builder().resourceName(IMAGE_NAME).project(image.getProject()).dlabId(imageId).resourceType(IMAGE).build()
+ );
+ }
+
private static Stream<BillingReportLine> getSlaveVolumes(UserInstanceDTO
userInstance, UserComputationalResource cr, Integer maxSparkInstanceCount) {
List<BillingReportLine> list = new ArrayList<>();
for (int i = 1; i <= maxSparkInstanceCount; i++) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]