RuiLi8080 commented on a change in pull request #3213: [STORM-3588] add 
GenericResourceAwareSchedulingPriorityStrategy to accommodate generic resource 
in grading topologies
URL: https://github.com/apache/storm/pull/3213#discussion_r407854697
 
 

 ##########
 File path: storm-server/src/main/java/org/apache/storm/scheduler/Cluster.java
 ##########
 @@ -873,20 +897,38 @@ public NormalizedResourceOffer 
getNonBlacklistedClusterAvailableResources(Collec
 
     @Override
     public double getClusterTotalCpuResource() {
-        double sum = 0.0;
-        for (SupervisorDetails sup : supervisors.values()) {
-            sum += sup.getTotalCpu();
-        }
-        return sum;
+        return this.totalCpuResource;
+    }
+
+    private double computeClusterCpuResource() {
+        return supervisors.values().stream()
+            .mapToDouble(SupervisorDetails::getTotalCpu)
+            .sum();
+
     }
 
     @Override
     public double getClusterTotalMemoryResource() {
-        double sum = 0.0;
-        for (SupervisorDetails sup : supervisors.values()) {
-            sum += sup.getTotalMemory();
-        }
-        return sum;
+        return this.totalMemoryResource;
+    }
+
+
+    private double computeClusterMemoryResource() {
+        return supervisors.values().stream()
+            .mapToDouble(SupervisorDetails::getTotalMemory)
+            .sum();
+    }
+
+    @Override
+    public Map<String, Double> getClusterTotalGenericResources() {
+        return this.totalGenericResources;
+    }
+
+    private Map<String, Double> computeClusterGenericResources() {
+        return supervisors.values().stream()
+            .map(sup -> sup.getTotalGenericResources().entrySet())
+            .flatMap(Set::stream)
+            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, 
Double::sum));
 
 Review comment:
   Sorry I didn't think of a way to further simplify, could you elaborate? 
`supervisors.values().stream()` will create Stream<SupervisorDetails>. I don't 
how `Stream.of` can help here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to