|
|
@ -18,6 +18,7 @@ package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
|
|
|
|
"net" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
"os" |
|
|
|
"os" |
|
|
@ -173,16 +174,20 @@ func (s *controllerRPCService) ResetAuth(r *http.Request, args *AuthArgs, reply |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func proxyRequest(method, host string, ssl bool, res interface{}) *probe.Error { |
|
|
|
func proxyRequest(method, host string, ssl bool, res interface{}) *probe.Error { |
|
|
|
u := &url.URL{ |
|
|
|
u := &url.URL{} |
|
|
|
Scheme: func() string { |
|
|
|
|
|
|
|
if ssl { |
|
|
|
if ssl { |
|
|
|
return "https" |
|
|
|
u.Scheme = "https" |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
u.Scheme = "http" |
|
|
|
} |
|
|
|
} |
|
|
|
return "http" |
|
|
|
u.Host = host |
|
|
|
}(), |
|
|
|
if _, _, err := net.SplitHostPort(host); err == nil { |
|
|
|
Host: host, |
|
|
|
u.Host = host |
|
|
|
Path: "/rpc", |
|
|
|
} else { |
|
|
|
|
|
|
|
u.Host = host + ":9002" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
u.Path = "/rpc" |
|
|
|
|
|
|
|
|
|
|
|
op := rpcOperation{ |
|
|
|
op := rpcOperation{ |
|
|
|
Method: method, |
|
|
|
Method: method, |
|
|
|
Request: ServerArg{}, |
|
|
|
Request: ServerArg{}, |
|
|
@ -203,47 +208,36 @@ func proxyRequest(method, host string, ssl bool, res interface{}) *probe.Error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *controllerRPCService) AddServer(r *http.Request, args *ControllerArgs, res *ServerRep) error { |
|
|
|
func (s *controllerRPCService) AddServer(r *http.Request, args *ControllerArgs, res *ServerRep) error { |
|
|
|
for _, host := range args.Hosts { |
|
|
|
err := proxyRequest("Server.Add", args.Host, args.SSL, res) |
|
|
|
err := proxyRequest("Server.Add", host, args.SSL, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return probe.WrapError(err) |
|
|
|
return probe.WrapError(err) |
|
|
|
} |
|
|
|
} |
|
|
|
s.serverList = append(s.serverList, *res) |
|
|
|
s.serverList = append(s.serverList, *res) |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *controllerRPCService) GetServerMemStats(r *http.Request, args *ControllerArgs, res *MemStatsRep) error { |
|
|
|
func (s *controllerRPCService) GetServerMemStats(r *http.Request, args *ControllerArgs, res *MemStatsRep) error { |
|
|
|
for _, host := range args.Hosts { |
|
|
|
err := proxyRequest("Server.MemStats", args.Host, args.SSL, res) |
|
|
|
err := proxyRequest("Server.MemStats", host, args.SSL, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return probe.WrapError(err) |
|
|
|
return probe.WrapError(err) |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
return errors.New("Invalid argument") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *controllerRPCService) GetServerDiskStats(r *http.Request, args *ControllerArgs, res *DiskStatsRep) error { |
|
|
|
func (s *controllerRPCService) GetServerDiskStats(r *http.Request, args *ControllerArgs, res *DiskStatsRep) error { |
|
|
|
for _, host := range args.Hosts { |
|
|
|
err := proxyRequest("Server.DiskStats", args.Host, args.SSL, res) |
|
|
|
err := proxyRequest("Server.DiskStats", host, args.SSL, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return probe.WrapError(err) |
|
|
|
return probe.WrapError(err) |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
return errors.New("Invalid argument") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *controllerRPCService) GetServerSysInfo(r *http.Request, args *ControllerArgs, res *SysInfoRep) error { |
|
|
|
func (s *controllerRPCService) GetServerSysInfo(r *http.Request, args *ControllerArgs, res *SysInfoRep) error { |
|
|
|
for _, host := range args.Hosts { |
|
|
|
err := proxyRequest("Server.SysInfo", args.Host, args.SSL, res) |
|
|
|
err := proxyRequest("Server.SysInfo", host, args.SSL, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return probe.WrapError(err) |
|
|
|
return probe.WrapError(err) |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
return errors.New("Invalid argument") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *controllerRPCService) ListServers(r *http.Request, args *ControllerArgs, res *ListRep) error { |
|
|
|
func (s *controllerRPCService) ListServers(r *http.Request, args *ControllerArgs, res *ListRep) error { |
|
|
@ -252,12 +246,9 @@ func (s *controllerRPCService) ListServers(r *http.Request, args *ControllerArgs |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *controllerRPCService) GetServerVersion(r *http.Request, args *ControllerArgs, res *VersionRep) error { |
|
|
|
func (s *controllerRPCService) GetServerVersion(r *http.Request, args *ControllerArgs, res *VersionRep) error { |
|
|
|
for _, host := range args.Hosts { |
|
|
|
err := proxyRequest("Server.Version", args.Host, args.SSL, res) |
|
|
|
err := proxyRequest("Server.Version", host, args.SSL, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return probe.WrapError(err) |
|
|
|
return probe.WrapError(err) |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
return errors.New("Invalid argument") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|