return idle status when worker has nothing to do
This commit is contained in:
parent
793defef72
commit
8d5faaa5a5
|
|
@ -202,9 +202,15 @@ func (s *Server) workers(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
resp, err = s.controller.ListQueue(uint32(workerID))
|
resp, err = s.controller.ListQueue(uint32(workerID))
|
||||||
} else if matches := util.FindNamedStringSubmatch(workerStatusURL, req.URL.Path); matches != nil {
|
} else if matches := util.FindNamedStringSubmatch(workerStatusURL, req.URL.Path); matches != nil {
|
||||||
workerID, _ := strconv.Atoi(matches["id"])
|
var workerStatus *spec.WorkerStatus
|
||||||
|
|
||||||
resp, err = s.controller.WorkerStatus(uint32(workerID))
|
workerID, _ := strconv.Atoi(matches["id"])
|
||||||
|
workerStatus, err = s.controller.WorkerStatus(uint32(workerID))
|
||||||
|
if workerStatus == nil {
|
||||||
|
resp = "idle"
|
||||||
|
} else {
|
||||||
|
resp = workerStatus
|
||||||
|
}
|
||||||
} else if workerAllStatus.MatchString(req.URL.Path) {
|
} else if workerAllStatus.MatchString(req.URL.Path) {
|
||||||
s.allWorkers(w, req)
|
s.allWorkers(w, req)
|
||||||
return
|
return
|
||||||
|
|
@ -234,14 +240,19 @@ func (s *Server) allQueues(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (s *Server) allWorkers(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) allWorkers(w http.ResponseWriter, r *http.Request) {
|
||||||
workersCnt := s.controller.GetWorkersCnt()
|
workersCnt := s.controller.GetWorkersCnt()
|
||||||
resp := make(map[uint32]*spec.WorkerStatus, workersCnt)
|
resp := make(map[uint32]interface{}, workersCnt)
|
||||||
for i := uint32(0); i < workersCnt; i++ {
|
for i := uint32(0); i < workersCnt; i++ {
|
||||||
status, err := s.controller.WorkerStatus(i)
|
status, err := s.controller.WorkerStatus(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
s.respond(nil, err, w)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
resp[i] = status
|
if status == nil {
|
||||||
|
resp[i] = "idle"
|
||||||
|
} else {
|
||||||
|
resp[i] = status
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.respond(resp, nil, w)
|
s.respond(resp, nil, w)
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ type Cluster struct {
|
||||||
teamsAPIClient *teams.API
|
teamsAPIClient *teams.API
|
||||||
KubeClient k8sutil.KubernetesClient //TODO: move clients to the better place?
|
KubeClient k8sutil.KubernetesClient //TODO: move clients to the better place?
|
||||||
currentProcess spec.Process
|
currentProcess spec.Process
|
||||||
processMu sync.RWMutex
|
processMu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type compareStatefulsetResult struct {
|
type compareStatefulsetResult struct {
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ package cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"strings"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
remotecommandconsts "k8s.io/apimachinery/pkg/util/remotecommand"
|
remotecommandconsts "k8s.io/apimachinery/pkg/util/remotecommand"
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ func (c *Controller) GetWorkersCnt() uint32 {
|
||||||
func (c *Controller) WorkerStatus(workerID uint32) (*spec.WorkerStatus, error) {
|
func (c *Controller) WorkerStatus(workerID uint32) (*spec.WorkerStatus, error) {
|
||||||
obj, ok := c.curWorkerCluster.Load(workerID)
|
obj, ok := c.curWorkerCluster.Load(workerID)
|
||||||
if !ok || obj == nil {
|
if !ok || obj == nil {
|
||||||
return nil, fmt.Errorf("worker has no status")
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cl, ok := obj.(*cluster.Cluster)
|
cl, ok := obj.(*cluster.Cluster)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue