This is an automated email from the ASF dual-hosted git repository. ofuks pushed a commit to branch DLAB-1230 in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/DLAB-1230 by this push: new bb4f91f [DLAB-1230] Fixed billing issues with edges [Azure] bb4f91f is described below commit bb4f91fa417dc96c11adac41d622abf4b668e74e Author: Oleh Fuks <olegfuk...@gmail.com> AuthorDate: Mon Nov 11 13:30:35 2019 +0200 [DLAB-1230] Fixed billing issues with edges [Azure] --- .../azure/AzureBillableResourcesService.java | 40 ++++++++++------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/AzureBillableResourcesService.java b/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/AzureBillableResourcesService.java index 7b5fd61..fa3a518 100644 --- a/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/AzureBillableResourcesService.java +++ b/services/billing-azure/src/main/java/com/epam/dlab/billing/azure/AzureBillableResourcesService.java @@ -161,31 +161,26 @@ public class AzureBillableResourcesService { private Set<AzureDlabBillableResource> getEdgeAndStorageAccount() { Set<AzureDlabBillableResource> billableResources = new HashSet<>(); - try { - - final FindIterable<Document> prjDocuments = mongoDbBillingClient.getDatabase() - .getCollection("Projects").find(); - final List<Document> edges = StreamSupport.stream(prjDocuments.spliterator(), false) - .flatMap(d -> ((List<Document>) d.get("endpoints")).stream()) - .map(d -> (Document) d.get("edgeInfo")) - .collect(Collectors.toList()); - List<EdgeInfoAzure> edgeInfoList = objectMapper.readValue( - objectMapper.writeValueAsString(edges), - new com.fasterxml.jackson.core.type.TypeReference<List<EdgeInfoAzure>>() { - }); - - Optional.ofNullable(edgeInfoList).ifPresent(e -> e.stream().filter(Objects::nonNull).forEach( - edgeInfoAzure -> billableResources.addAll(getEdgeAndStorageAccount(edgeInfoAzure)))); + Map<String, List<Document>> projectEndpoints = StreamSupport.stream(mongoDbBillingClient.getDatabase() + .getCollection("Projects").find().spliterator(), false) + .collect(Collectors.toMap(key -> key.getString("name").toLowerCase(), + value -> (List<Document>) value.get("endpoints"))); + + projectEndpoints.forEach((key, value) -> value.forEach(endpoint -> { + try { + billableResources.addAll(getEdgeAndStorageAccount(key, objectMapper.readValue( + objectMapper.writeValueAsString(endpoint.get("edgeInfo")), + new com.fasterxml.jackson.core.type.TypeReference<EdgeInfoAzure>() { + }))); + } catch (IOException ex) { + log.error("Error during preparation of billable resources", ex); + } + })); - return billableResources; - } catch (IOException e) { - log.error("Error during preparation of billable resources", e); - } return billableResources; } - private Set<AzureDlabBillableResource> getEdgeAndStorageAccount(EdgeInfoAzure edgeInfoAzure) { - + private Set<AzureDlabBillableResource> getEdgeAndStorageAccount(String projectName, EdgeInfoAzure edgeInfoAzure) { Set<AzureDlabBillableResource> billableResources = new HashSet<>(); if (StringUtils.isNotEmpty(edgeInfoAzure.getUserContainerName())) { @@ -193,6 +188,7 @@ public class AzureBillableResourcesService { .id(edgeInfoAzure.getUserStorageAccountTagName()) .type(DlabResourceType.EDGE_STORAGE_ACCOUNT) .user(SHARED_RESOURCE) + .project(projectName) .build()); } @@ -201,12 +197,14 @@ public class AzureBillableResourcesService { .id(edgeInfoAzure.getInstanceId()) .type(DlabResourceType.EDGE) .user(SHARED_RESOURCE) + .project(projectName) .build()); billableResources.add(AzureDlabBillableResource.builder() .id(edgeInfoAzure.getInstanceId() + "-volume-primary") .type(DlabResourceType.VOLUME) .user(SHARED_RESOURCE) + .project(projectName) .build()); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org For additional commands, e-mail: commits-h...@dlab.apache.org