govind-menon 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_r409153634
 
 

 ##########
 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:
   If you see the example in the link it's a slightly different way to add the 
key, value pairs of a Map but it's not an issue. You can keep this as is.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to