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/11/12 10:16:52 UTC
[incubator-dlab] 04/04: Code review
This is an automated email from the ASF dual-hosted git repository.
bhliva pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
commit 91332dd9d50b5dbf56c25d3d9ff7da0dc18f7d6e
Author: Oleh Fuks <ol...@gmail.com>
AuthorDate: Mon Nov 11 17:58:24 2019 +0200
Code review
---
.../azure/AzureBillableResourcesService.java | 30 ++++++++++++----------
1 file changed, 17 insertions(+), 13 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 ae9ff1c..c4ee5b4 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
@@ -37,6 +37,7 @@ import org.bson.Document;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import static com.mongodb.client.model.Projections.exclude;
@@ -164,23 +165,26 @@ public class AzureBillableResourcesService {
.collect(Collectors.toMap(key -> key.getString("name").toLowerCase(),
value -> (List<Document>) value.get("endpoints")));
- Set<AzureDlabBillableResource> edgeInfo = projectEndpoints.entrySet()
+ return projectEndpoints.entrySet()
.stream()
- .flatMap(e -> e.getValue().stream().map(endpoint -> {
+ .flatMap(projectEndpoint -> getEdgeAndStoragePerProject(projectEndpoint.getKey(), projectEndpoint.getValue()))
+ .collect(Collectors.toSet());
+ }
+
+ private Stream<AzureDlabBillableResource> getEdgeAndStoragePerProject(String projectName, List<Document> endpoints) {
+ return endpoints
+ .stream()
+ .flatMap(endpoint -> {
try {
- return getEdgeAndStorageAccount(e.getKey(), objectMapper.readValue(objectMapper.writeValueAsString(endpoint.get("edgeInfo")),
+ return getEdgeAndStorageAccount(projectName, objectMapper.readValue(
+ objectMapper.writeValueAsString(endpoint.get("edgeInfo")),
new com.fasterxml.jackson.core.type.TypeReference<EdgeInfoAzure>() {
- }));
- } catch (IOException ex) {
- ex.printStackTrace();
+ })).stream();
+ } catch (IOException e) {
+ log.error("Error during preparation of billable resources", e);
}
- return null;
- }))
- .filter(Objects::nonNull)
- .flatMap(Set::stream)
- .collect(Collectors.toSet());
-
- return new HashSet<>(edgeInfo);
+ return Stream.empty();
+ });
}
private Set<AzureDlabBillableResource> getEdgeAndStorageAccount(String projectName, EdgeInfoAzure edgeInfoAzure) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org