mirror of
https://github.com/minio/minio.git
synced 2025-01-11 23:13:23 -05:00
Add DiscoverServers and GetControllerNetInfo controller APIs
This commit is contained in:
parent
9d61b2d6db
commit
5ebbc6bb0e
@ -211,6 +211,65 @@ func (s *controllerRPCService) AddServer(r *http.Request, args *ControllerArgs,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *controllerRPCService) DiscoverServers(r *http.Request, args *DiscoverArgs, rep *DiscoverRep) error {
|
||||
c := make(chan DiscoverRepEntry)
|
||||
defer close(c)
|
||||
for _, host := range args.Hosts {
|
||||
go func(c chan DiscoverRepEntry, host string) {
|
||||
u := &url.URL{}
|
||||
if args.SSL {
|
||||
u.Scheme = "https"
|
||||
} else {
|
||||
u.Scheme = "http"
|
||||
}
|
||||
if args.Port != 0 {
|
||||
u.Host = host + ":" + string(args.Port)
|
||||
} else {
|
||||
u.Host = host + ":9002"
|
||||
}
|
||||
u.Path = "/rpc"
|
||||
|
||||
op := rpcOperation{
|
||||
Method: "Server.Version",
|
||||
Request: ServerArg{},
|
||||
}
|
||||
versionrep := VersionRep{}
|
||||
request, err := newRPCRequest(u.String(), op, nil)
|
||||
if err != nil {
|
||||
c <- DiscoverRepEntry{host, err.ToGoError().Error()}
|
||||
return
|
||||
}
|
||||
var resp *http.Response
|
||||
resp, err = request.Do()
|
||||
if err != nil {
|
||||
c <- DiscoverRepEntry{host, err.ToGoError().Error()}
|
||||
return
|
||||
}
|
||||
if err := json.DecodeClientResponse(resp.Body, &versionrep); err != nil {
|
||||
c <- DiscoverRepEntry{host, err.Error()}
|
||||
return
|
||||
}
|
||||
c <- DiscoverRepEntry{host, ""}
|
||||
}(c, host)
|
||||
}
|
||||
for range args.Hosts {
|
||||
entry := <-c
|
||||
rep.Entry = append(rep.Entry, entry)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *controllerRPCService) GetControllerNetInfo(r *http.Request, args *ServerArg, res *ControllerNetInfoRep) error {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
res.NetInfo = append(res.NetInfo, addr.String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *controllerRPCService) GetServerMemStats(r *http.Request, args *ControllerArgs, res *MemStatsRep) error {
|
||||
err := proxyRequest("Server.MemStats", args.Host, args.SSL, res)
|
||||
if err != nil {
|
||||
|
@ -46,6 +46,11 @@ type ServerRep struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// ControllerNetInfoRep array of ip/mask in the form: 172.17.42.1/16
|
||||
type ControllerNetInfoRep struct {
|
||||
NetInfo []string `json:"netinfo"`
|
||||
}
|
||||
|
||||
// DefaultRep default reply
|
||||
type DefaultRep struct {
|
||||
Error error `json:"error"`
|
||||
@ -111,7 +116,25 @@ type AuthRep struct {
|
||||
SecretAccessKey string `json:"secretAccessKey"`
|
||||
}
|
||||
|
||||
// BucketStats bucket name and total used by the bucket
|
||||
// DiscoverArgs array of IP addresses / names to discover
|
||||
type DiscoverArgs struct {
|
||||
Hosts []string `json:"hosts"`
|
||||
Port int `json:"port"`
|
||||
SSL bool `json:"bool"`
|
||||
}
|
||||
|
||||
// DiscoverRepEntry : Error is "" if there is no error
|
||||
type DiscoverRepEntry struct {
|
||||
Host string `json:"host"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// DiscoverRep list of discovered hosts
|
||||
type DiscoverRep struct {
|
||||
Entry []DiscoverRepEntry `json:"entry"`
|
||||
}
|
||||
|
||||
// BucketStats bucket-name and storage used
|
||||
type BucketStats struct {
|
||||
Name string `json:"name"`
|
||||
Used uint64 `json:"used"`
|
||||
|
Loading…
Reference in New Issue
Block a user