Integrate comments from code reviews

This commit is contained in:
Sergey Dudoladov 2017-12-22 12:53:57 +01:00
parent 011458fb05
commit b8bf97ab76
2 changed files with 8 additions and 4 deletions

View File

@ -37,7 +37,7 @@ type controllerInformer interface {
ListQueue(workerID uint32) (*spec.QueueDump, error) ListQueue(workerID uint32) (*spec.QueueDump, error)
GetWorkersCnt() uint32 GetWorkersCnt() uint32
WorkerStatus(workerID uint32) (*spec.WorkerStatus, error) WorkerStatus(workerID uint32) (*spec.WorkerStatus, error)
GetClusterDatabasesMap() map[string][]string ClusterDatabasesMap() map[string][]string
} }
// Server describes HTTP API server // Server describes HTTP API server
@ -226,7 +226,7 @@ func (s *Server) workers(w http.ResponseWriter, req *http.Request) {
func (s *Server) databases(w http.ResponseWriter, req *http.Request) { func (s *Server) databases(w http.ResponseWriter, req *http.Request) {
databaseNamesPerCluster := s.controller.GetClusterDatabasesMap() databaseNamesPerCluster := s.controller.ClusterDatabasesMap()
s.respond(databaseNamesPerCluster, nil, w) s.respond(databaseNamesPerCluster, nil, w)
return return

View File

@ -32,16 +32,20 @@ func (c *Controller) ClusterStatus(team, cluster string) (*spec.ClusterStatus, e
return status, nil return status, nil
} }
// GetClusterDatabasesMap returns for each cluster the list of databases running there // ClusterDatabasesMap returns for each cluster the list of databases running there
func (c *Controller) GetClusterDatabasesMap() map[string][]string { func (c *Controller) ClusterDatabasesMap() map[string][]string {
m := make(map[string][]string) m := make(map[string][]string)
c.clustersMu.RLock()
for _, cluster := range c.clusters { for _, cluster := range c.clusters {
cluster.Lock()
for database := range cluster.Postgresql.Spec.Databases { for database := range cluster.Postgresql.Spec.Databases {
m[cluster.Name] = append(m[cluster.Name], database) m[cluster.Name] = append(m[cluster.Name], database)
} }
cluster.Unlock()
} }
c.clustersMu.RUnlock()
return m return m
} }