func doClusters(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) { cfgStore := s.ConfigurationStore() cm := cfgStore.ConfigurationManager() switch req.Method { case "GET": return cm.GetClusters() case "POST": cluster, err := getClusterFromRequest(req) if err != nil { return nil, err } return cfgStore.ConfigurationManager().AddCluster(cluster) default: return nil, nil } }
func doCluster(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) { vars := mux.Vars(req) name := vars["cluster"] cfgStore := s.ConfigurationStore() cluster, err := cfgStore.ClusterByName(name) if err != nil { return nil, err } switch req.Method { case "GET": return cluster, nil case "DELETE": return cfgStore.ConfigurationManager().RemoveCluster(cluster) default: return nil, nil } }
func doNodes(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) { vars := mux.Vars(req) name := vars["cluster"] cfgStore := s.ConfigurationStore() cluster, err := cfgStore.ClusterByName(name) if err != nil || cluster == nil { return cluster, err } switch req.Method { case "GET": return cluster.ClusterManager().GetQueryNodes() case "POST": node, err := getNodeFromRequest(req) if err != nil { return nil, err } return cluster.ClusterManager().AddQueryNode(node) default: return nil, nil } }
func doConfig(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) { if localConfig.myConfig != nil { return localConfig.myConfig, nil } var self clustering.QueryNode ip, err := util.ExternalIP() if err != nil { return nil, err } name, er := os.Hostname() if er != nil { return nil, err } cm := s.ConfigurationStore().ConfigurationManager() clusters, err := cm.GetClusters() if err != nil { return nil, err } for _, c := range clusters { clm := c.ClusterManager() queryNodes, err := clm.GetQueryNodes() if err != nil { return nil, err } for _, qryNode := range queryNodes { if qryNode.Name() == ip || qryNode.Name() == name { self = qryNode break } } } localConfig.Lock() defer localConfig.Unlock() localConfig.myConfig = self return localConfig.myConfig, nil }