diff --git a/controller-rpc.go b/controller-rpc.go index 56cee5f0d..fb5d0d498 100644 --- a/controller-rpc.go +++ b/controller-rpc.go @@ -26,7 +26,6 @@ import ( "github.com/gorilla/rpc/v2/json" "github.com/minio/minio/pkg/auth" - "github.com/minio/minio/pkg/donut" "github.com/minio/minio/pkg/probe" ) @@ -34,43 +33,6 @@ type controllerRPCService struct { serverList []ServerRep } -const tb = (1024 * 1024 * 1024 * 1024) - -func makeDonut(args *DonutArgs, reply *DefaultRep) *probe.Error { - conf := &donut.Config{Version: "0.0.1"} - conf.DonutName = args.Name - conf.MaxSize = args.MaxSize - conf.NodeDiskMap = make(map[string][]string) - conf.NodeDiskMap[args.Hostname] = args.Disks - if err := donut.SaveConfig(conf); err != nil { - return err.Trace() - } - reply.Message = "success" - reply.Error = nil - return nil -} - -// MakeDonut method -func (s *controllerRPCService) MakeDonut(r *http.Request, args *DonutArgs, reply *DefaultRep) error { - if err := makeDonut(args, reply); err != nil { - return probe.WrapError(err) - } - return nil -} - -// StorageStats returns dummy storage stats -func (s *controllerRPCService) StorageStats(r *http.Request, args *DonutArgs, reply *StorageStatsRep) error { - reply.Buckets = []BucketStorage{{"bucket1", 4 * tb}, {"bucket2", 120 * tb}, {"bucket3", 45 * tb}} - return nil -} - -// RebalaceStats returns dummy rebalance stats -func (s *controllerRPCService) RebalanceStats(r *http.Request, args *DonutArgs, reply *RebalanceStatsRep) error { - reply.Inprogress = []string{"bucket1/obj1", "bucket2/obj2", "bucket3/obj3"} - reply.Done = []string{"bucket1/rebobj1", "bucket2/rebobj2", "bucket3/rebobj3"} - return nil -} - // generateAuth generate new auth keys for a user func generateAuth(args *AuthArgs, reply *AuthRep) *probe.Error { config, err := auth.LoadConfig() @@ -222,6 +184,24 @@ func proxyRequest(method, host string, ssl bool, res interface{}) *probe.Error { return nil } +// StorageStats returns dummy storage stats +func (s *controllerRPCService) StorageStats(r *http.Request, args *ControllerArgs, reply *StorageStatsRep) error { + err := proxyRequest("Donut.StorageStats", args.Host, args.SSL, reply) + if err != nil { + return probe.WrapError(err) + } + return nil +} + +// RebalaceStats returns dummy rebalance stats +func (s *controllerRPCService) RebalanceStats(r *http.Request, args *ControllerArgs, reply *RebalanceStatsRep) error { + err := proxyRequest("Donut.RebalanceStats", args.Host, args.SSL, reply) + if err != nil { + return probe.WrapError(err) + } + return nil +} + func (s *controllerRPCService) AddServer(r *http.Request, args *ControllerArgs, res *ServerRep) error { err := proxyRequest("Server.Add", args.Host, args.SSL, res) if err != nil { diff --git a/donut-rpc.go b/donut-rpc.go new file mode 100644 index 000000000..3e27fa74a --- /dev/null +++ b/donut-rpc.go @@ -0,0 +1,67 @@ +/* + * Minio Cloud Storage, (C) 2015 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "net/http" + "runtime" +) + +type donutRPCService struct{} + +func (s *donutRPCService) ListNodes(r *http.Request, arg *DonutArg, rep *ListNodesRep) error { + rep.Nodes = []struct { + Hostname string `json:"hostname"` + Address string `json:"address"` + ID string `json:"id"` + }{ + { + Hostname: "localhost", + Address: "192.168.1.102:9000", + ID: "6F27CB16-493D-40FA-B035-2A2E5646066A", + }, + } + return nil +} + +// Usage bytes +const ( + PB = 1024 * 1024 * 1024 * 1024 + TB = 1024 * 1024 * 1024 * 1024 + GB = 1024 * 1024 * 1024 +) + +func (s *donutRPCService) StorageStats(r *http.Request, arg *DonutArg, rep *StorageStatsRep) error { + rep.Buckets = []BucketStats{{"bucket1", 4 * TB}, {"bucket2", 120 * TB}, {"bucket3", 45 * TB}} + return nil +} + +func (s *donutRPCService) RebalanceStats(r *http.Request, arg *DonutArg, rep *RebalanceStatsRep) error { + rep.State = make(map[string]string) + rep.State["bucket1/obj1"] = "inProgress" + rep.State["bucket2/obj2"] = "finished" + rep.State["bucket3/obj3"] = "errored" + rep.State["bucket4/obj4"] = "unknownState" + return nil +} + +func (s *donutRPCService) Version(r *http.Request, arg *ServerArg, rep *DonutVersionRep) error { + rep.Version = "0.1.0" + rep.Architecture = runtime.GOARCH + rep.OperatingSystem = runtime.GOOS + return nil +} diff --git a/rpc-definitions.go b/rpc-definitions.go index 689e80f96..98b9e6dea 100644 --- a/rpc-definitions.go +++ b/rpc-definitions.go @@ -25,13 +25,8 @@ type AuthArgs struct { User string `json:"user"` } -// DonutArgs collections of disks and name to initialize donut -type DonutArgs struct { - Name string - MaxSize uint64 - Hostname string - Disks []string -} +// DonutArg donut params +type DonutArg struct{} // ServerArg server params type ServerArg struct{} @@ -75,7 +70,7 @@ type MemStatsRep struct { // Network metadata of a server type Network struct { - IP string `json:"address"` + Address string `json:"address"` NetMask string `json:"netmask"` Hostname string `json:"hostname"` Ethernet string `json:"networkInterface"` @@ -116,19 +111,34 @@ type AuthRep struct { SecretAccessKey string `json:"secretAccessKey"` } -// BucketStorage bucket-name and storage used -type BucketStorage struct { +// BucketStats bucket name and total used by the bucket +type BucketStats struct { Name string `json:"name"` Used uint64 `json:"used"` } -// StorageStatsRep array of buckets-storage-stats +// StorageStatsRep array of BucketStats type StorageStatsRep struct { - Buckets []BucketStorage `json:"buckets"` + Buckets []BucketStats `json:"bucketStats"` } // RebalanceStatsRep rebalance information type RebalanceStatsRep struct { - Inprogress []string `json:"inprogress"` - Done []string `json:"done"` + State map[string]string `json:"rebalanceState"` +} + +// ListNodesRep all nodes part of donut cluster +type ListNodesRep struct { + Nodes []struct { + Hostname string `json:"hostname"` + Address string `json:"address"` + ID string `json:"id"` + } `json:"nodes"` +} + +// DonutVersionRep reply donut on disk format version +type DonutVersionRep struct { + Version string `json:"version"` + Architecture string `json:"arch"` + OperatingSystem string `json:"os"` } diff --git a/server-router.go b/server-router.go index 8d752187a..6fabd3025 100644 --- a/server-router.go +++ b/server-router.go @@ -99,6 +99,7 @@ func getServerRPCHandler() http.Handler { s := jsonrpc.NewServer() s.RegisterCodec(json.NewCodec(), "application/json") s.RegisterService(new(serverRPCService), "Server") + s.RegisterService(new(donutRPCService), "Donut") mux := router.NewRouter() mux.Handle("/rpc", s) return mux diff --git a/server-rpc.go b/server-rpc.go index 7382d8983..dd95d31b3 100644 --- a/server-rpc.go +++ b/server-rpc.go @@ -59,7 +59,7 @@ func (s *serverRPCService) SysInfo(r *http.Request, arg *ServerArg, rep *SysInfo func (s *serverRPCService) NetStats(r *http.Request, arg *ServerArg, rep *NetStatsRep) error { rep.Interfaces = make([]Network, 0) - rep.Interfaces = append(rep.Interfaces, Network{IP: "192.168.1.1", NetMask: "255.255.255.0", Hostname: "hostname1", Ethernet: "eth0"}) + rep.Interfaces = append(rep.Interfaces, Network{Address: "192.168.1.1", NetMask: "255.255.255.0", Hostname: "hostname1", Ethernet: "eth0"}) return nil }