// SetHostAttribute is a utility method that allows per-host key-value store. func (this *HttpAgentsAPI) SetHostAttribute(params martini.Params, r render.Render, req *http.Request) { err := attributes.SetHostAttributes(params["host"], params["attrVame"], params["attrValue"]) if err != nil { r.JSON(200, &APIResponse{Code: ERROR, Message: fmt.Sprintf("%+v", err)}) return } r.JSON(200, (err == nil)) }
// GetHostAttributeByAttributeName returns a host attribute func (this *HttpAgentsAPI) GetHostAttributeByAttributeName(params martini.Params, r render.Render, req *http.Request) { output, err := attributes.GetHostAttributesByAttribute(params["attr"], req.URL.Query().Get("valueMatch")) if err != nil { r.JSON(200, &APIResponse{Code: ERROR, Message: fmt.Sprintf("%+v", err)}) return } r.JSON(200, output) }
func (this *HttpWeb) ClusterByAlias(params martini.Params, r render.Render, req *http.Request, user auth.User) { clusterName, err := inst.GetClusterByAlias(params["clusterAlias"]) // Willing to accept the case of multiple clusters; we just present one if clusterName == "" && err != nil { r.JSON(200, &APIResponse{Code: ERROR, Message: fmt.Sprintf("%+v", err)}) return } params["clusterName"] = clusterName this.Cluster(params, r, req, user) }
// AgentsInstances provides list of assumed MySQL instances (host:port) func (this *HttpAgentsAPI) AgentsInstances(params martini.Params, r render.Render, req *http.Request) string { agents, err := agent.ReadAgents() hostnames := []string{} for _, agent := range agents { hostnames = append(hostnames, fmt.Sprintf("%s:%d", agent.Hostname, agent.MySQLPort)) } if err != nil { r.JSON(200, &APIResponse{Code: ERROR, Message: fmt.Sprintf("%+v", err)}) return "" } if req.URL.Query().Get("format") == "txt" { return strings.Join(hostnames, "\n") } else { r.JSON(200, hostnames) } return "" }
// SubmitAgent registeres an agent. It is initiated by an agent to register itself. func (this *HttpAgentsAPI) SubmitAgent(params martini.Params, r render.Render) { port, err := strconv.Atoi(params["port"]) if err != nil { r.JSON(200, &APIResponse{Code: ERROR, Message: err.Error()}) return } output, err := agent.SubmitAgent(params["host"], port, params["token"]) if err != nil { r.JSON(200, &APIResponse{Code: ERROR, Message: err.Error()}) return } r.JSON(200, output) }
func (this *HttpWeb) ClusterByInstance(params martini.Params, r render.Render, req *http.Request, user auth.User) { instanceKey, err := this.getInstanceKey(params["host"], params["port"]) if err != nil { r.JSON(200, &APIResponse{Code: ERROR, Message: err.Error()}) return } instance, found, err := inst.ReadInstance(&instanceKey) if (!found) || (err != nil) { r.JSON(200, &APIResponse{Code: ERROR, Message: fmt.Sprintf("Cannot read instance: %+v", instanceKey)}) return } // Willing to accept the case of multiple clusters; we just present one if instance.ClusterName == "" && err != nil { r.JSON(200, &APIResponse{Code: ERROR, Message: fmt.Sprintf("%+v", err)}) return } params["clusterName"] = instance.ClusterName this.Cluster(params, r, req, user) }
func (this *HttpAgentsAPI) AgentPing(params martini.Params, r render.Render, req *http.Request) { r.JSON(200, "OK") }