yangwwei commented on a change in pull request #216:
URL: 
https://github.com/apache/incubator-yunikorn-core/pull/216#discussion_r510586876



##########
File path: pkg/webservice/handlers.go
##########
@@ -527,3 +527,45 @@ func updateConfiguration(conf string) (string, error) {
        }
        return "", fmt.Errorf("config plugin not found")
 }
+
+func getPartitions(w http.ResponseWriter, r *http.Request) {
+       writeHeaders(w)
+
+       lists := gClusterInfo.ListPartitions()
+       for _, k := range lists {
+               partitionInfo := getPartition(k)
+
+               if err := json.NewEncoder(w).Encode(partitionInfo); err != nil {
+                       http.Error(w, err.Error(), 
http.StatusInternalServerError)
+               }
+       }
+}
+
+func getPartition(name string) *dao.PartitionInfo {
+       partitionInfo := &dao.PartitionInfo{}
+       partitionContext := gClusterInfo.GetPartition(name)
+       partitionInfo.Name = partitionContext.Name
+       partitionInfo.State = partitionContext.StateMachine.Current()
+       partitionInfo.LastStateTransitionTime = 
partitionContext.StateTime.String()
+
+       capacityInfo := dao.PartitionCapacity{}
+       capacityInfo.Capacity = 
partitionContext.GetTotalPartitionResource().String()
+       capacityInfo.UsedCapacity = 
partitionContext.Root.GetAllocatedResource().String()
+       partitionInfo.Capacity = capacityInfo
+       partitionInfo.NodeSortingPolicy = 
partitionContext.GetNodeSortingPolicy().String()
+
+       applicationsInfo := dao.Applications{}
+       appList := partitionContext.GetApplications()
+       applicationsState := make(map[string]int)
+
+       for _, app := range appList {
+               applicationsState[app.GetApplicationState()]++
+       }
+       applicationsInfo.Running = applicationsState["Running"]

Review comment:
       hi @manirajv06  for this part. Can we avoid using hardcoded states for 
Applications struct.
   Maybe we can change it to
   
   ```
   type PartitionInfo struct {
      ...
      appCounts map[string]int
   }
   ```
   then we can simply aggregate the count of apps by their state. What do you 
think?
   
   
     




----------------------------------------------------------------
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]


Reply via email to