yangwwei commented on a change in pull request #216:
URL:
https://github.com/apache/incubator-yunikorn-core/pull/216#discussion_r505079790
##########
File path: pkg/webservice/dao/partition_info.go
##########
@@ -24,6 +24,14 @@ type PartitionDAOInfo struct {
Queues QueueDAOInfo `json:"queues"`
}
+type PartitionInfo struct {
+ Name string `json:"name"`
+ Capacity PartitionCapacity `json:"capacity"`
+ IsPremptable bool `json:"isPremptable"`
+ NodeSortingPolicy string `json:"nodeSortingPolicy"`
+ Applications Applications `json:"applications"`
+}
+
type PartitionCapacity struct {
Capacity string `json:"capacity"`
UsedCapacity string `json:"usedcapacity"`
Review comment:
usedcapacity -> usedCapacity
and another thing is the usedCapacity seems to be skipped in the API
I think it can be retrieved via: `partition.Root.GetAllocatedResource()`
##########
File path: pkg/webservice/dao/partition_info.go
##########
@@ -33,3 +41,11 @@ type NodeInfo struct {
NodeID string `json:"nodeId"`
Review comment:
this is not needed
maybe we can change this to display the number of nodes in this partition?
##########
File path: pkg/webservice/routes.go
##########
@@ -126,6 +126,14 @@ var webRoutes = routes{
getContainerHistory,
},
+ //
+ route{
+ "Partitions",
+ "GET",
+ "/ws/v1/partitions",
+ getPartitions,
+ },
Review comment:
Are we going to support the sub-path `ws/v1/partitions/{partitionName}`?
##########
File path: pkg/webservice/handlers.go
##########
@@ -527,3 +527,47 @@ 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
+ capacityInfo := dao.PartitionCapacity{}
+ capacityInfo.Capacity =
partitionContext.GetTotalPartitionResource().String()
+ partitionInfo.Capacity = capacityInfo
+ partitionInfo.IsPremptable = partitionContext.NeedPreemption()
+ partitionInfo.NodeSortingPolicy =
partitionContext.GetNodeSortingPolicy().String()
+
+ applicationsInfo := dao.Applications{}
+ appList := partitionContext.GetApplications()
+ for _, app := range appList {
+ if app.IsRunning() {
+ applicationsInfo.Running++
+ applicationsInfo.Total++
+ } else if app.IsWaiting() || app.IsNew() || app.IsStarting() ||
app.IsAccepted() {
+ applicationsInfo.Pending++
+ applicationsInfo.Total++
+ } else if app.IsCompleted() {
+ applicationsInfo.Completed++
+ applicationsInfo.Total++
+ } else if app.IsKilled() || app.IsRejected() {
+ applicationsInfo.Failed++
+ applicationsInfo.Total++
+ }
Review comment:
Instead of doing these `if-else`. Maybe we can simply do the math based
on key-value
for applications, we just need to have a `map[string]int`, then we can
aggregate the app numbers by state
##########
File path: pkg/webservice/handlers.go
##########
@@ -527,3 +527,47 @@ 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
+ capacityInfo := dao.PartitionCapacity{}
+ capacityInfo.Capacity =
partitionContext.GetTotalPartitionResource().String()
+ partitionInfo.Capacity = capacityInfo
+ partitionInfo.IsPremptable = partitionContext.NeedPreemption()
Review comment:
can we remove this for now?
the preemption related code may need some refactoring, this property might
be gone in future
##########
File path: pkg/webservice/dao/partition_info.go
##########
@@ -24,6 +24,14 @@ type PartitionDAOInfo struct {
Queues QueueDAOInfo `json:"queues"`
}
+type PartitionInfo struct {
+ Name string `json:"name"`
+ Capacity PartitionCapacity `json:"capacity"`
+ IsPremptable bool `json:"isPremptable"`
Review comment:
remove this
##########
File path: pkg/webservice/dao/partition_info.go
##########
@@ -24,6 +24,14 @@ type PartitionDAOInfo struct {
Queues QueueDAOInfo `json:"queues"`
}
+type PartitionInfo struct {
Review comment:
Can we add some fields about the partition state?
- state
- lastStateTransitionTime
----------------------------------------------------------------
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]