You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by GitBox <gi...@apache.org> on 2020/11/24 04:50:46 UTC

[GitHub] [incubator-yunikorn-core] manirajv06 commented on a change in pull request #216: YUNIKORN-414: Add partitions REST API to fetch list of partitions

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



##########
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 @yangwwei  Sorry for the delay. 
   
   applicationsState in handlers#getPartition() is a map contains the state wise count. 
   
   applicationsInfo ( dao.Applications{} ) in handlers#getPartition() has been used to display the state wise count (after aggregating some app states. For ex, Killed and Rejected as Failed) in JSON output.
   
   I am not sure how defining appCounts map[string]int in PartitionInfo struct helps in this case as we are manipulating some app states. Please correct my understanding if needed.




----------------------------------------------------------------
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:
users@infra.apache.org