Add a REST endpoint to list databases in all clusters
This commit is contained in:
parent
15c278d4e8
commit
011458fb05
|
|
@ -37,6 +37,7 @@ type controllerInformer interface {
|
|||
ListQueue(workerID uint32) (*spec.QueueDump, error)
|
||||
GetWorkersCnt() uint32
|
||||
WorkerStatus(workerID uint32) (*spec.WorkerStatus, error)
|
||||
GetClusterDatabasesMap() map[string][]string
|
||||
}
|
||||
|
||||
// Server describes HTTP API server
|
||||
|
|
@ -78,6 +79,7 @@ func New(controller controllerInformer, port int, logger *logrus.Logger) *Server
|
|||
|
||||
mux.HandleFunc("/clusters/", s.clusters)
|
||||
mux.HandleFunc("/workers/", s.workers)
|
||||
mux.HandleFunc("/databases/", s.databases)
|
||||
|
||||
s.http = http.Server{
|
||||
Addr: fmt.Sprintf(":%d", port),
|
||||
|
|
@ -222,6 +224,14 @@ func (s *Server) workers(w http.ResponseWriter, req *http.Request) {
|
|||
s.respond(resp, err, w)
|
||||
}
|
||||
|
||||
func (s *Server) databases(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
databaseNamesPerCluster := s.controller.GetClusterDatabasesMap()
|
||||
s.respond(databaseNamesPerCluster, nil, w)
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) allQueues(w http.ResponseWriter, r *http.Request) {
|
||||
workersCnt := s.controller.GetWorkersCnt()
|
||||
resp := make(map[uint32]*spec.QueueDump, workersCnt)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,20 @@ func (c *Controller) ClusterStatus(team, cluster string) (*spec.ClusterStatus, e
|
|||
return status, nil
|
||||
}
|
||||
|
||||
// GetClusterDatabasesMap returns for each cluster the list of databases running there
|
||||
func (c *Controller) GetClusterDatabasesMap() map[string][]string {
|
||||
|
||||
m := make(map[string][]string)
|
||||
|
||||
for _, cluster := range c.clusters {
|
||||
for database := range cluster.Postgresql.Spec.Databases {
|
||||
m[cluster.Name] = append(m[cluster.Name], database)
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// TeamClusterList returns team-clusters map
|
||||
func (c *Controller) TeamClusterList() map[string][]spec.NamespacedName {
|
||||
return c.teamClusters
|
||||
|
|
|
|||
Loading…
Reference in New Issue