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



##########
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:
       could we optimize this code a bit. too much of impl related to 
comparison etc.

##########
File path: pkg/webservice/dao/partition_info.go
##########
@@ -24,12 +24,29 @@ type PartitionDAOInfo struct {
        Queues        QueueDAOInfo      `json:"queues"`
 }
 
+type PartitionInfo struct {
+       Name                    string            `json:"name"`
+       Capacity                PartitionCapacity `json:"capacity"`

Review comment:
       This capacity will be the configured capacity one, correct?

##########
File path: pkg/webservice/dao/partition_info.go
##########
@@ -33,3 +41,11 @@ type NodeInfo struct {
        NodeID     string `json:"nodeId"`

Review comment:
       Lets take this up separate, thats more cleaner and better. 




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