Implement a new Donut service on server side

master
Harshavardhana 9 years ago
parent c92145c3df
commit cc223b5278
  1. 56
      controller-rpc.go
  2. 67
      donut-rpc.go
  3. 38
      rpc-definitions.go
  4. 1
      server-router.go
  5. 2
      server-rpc.go

@ -26,7 +26,6 @@ import (
"github.com/gorilla/rpc/v2/json" "github.com/gorilla/rpc/v2/json"
"github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/auth"
"github.com/minio/minio/pkg/donut"
"github.com/minio/minio/pkg/probe" "github.com/minio/minio/pkg/probe"
) )
@ -34,43 +33,6 @@ type controllerRPCService struct {
serverList []ServerRep 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 // generateAuth generate new auth keys for a user
func generateAuth(args *AuthArgs, reply *AuthRep) *probe.Error { func generateAuth(args *AuthArgs, reply *AuthRep) *probe.Error {
config, err := auth.LoadConfig() config, err := auth.LoadConfig()
@ -222,6 +184,24 @@ func proxyRequest(method, host string, ssl bool, res interface{}) *probe.Error {
return nil 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 { func (s *controllerRPCService) AddServer(r *http.Request, args *ControllerArgs, res *ServerRep) error {
err := proxyRequest("Server.Add", args.Host, args.SSL, res) err := proxyRequest("Server.Add", args.Host, args.SSL, res)
if err != nil { if err != nil {

@ -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
}

@ -25,13 +25,8 @@ type AuthArgs struct {
User string `json:"user"` User string `json:"user"`
} }
// DonutArgs collections of disks and name to initialize donut // DonutArg donut params
type DonutArgs struct { type DonutArg struct{}
Name string
MaxSize uint64
Hostname string
Disks []string
}
// ServerArg server params // ServerArg server params
type ServerArg struct{} type ServerArg struct{}
@ -75,7 +70,7 @@ type MemStatsRep struct {
// Network metadata of a server // Network metadata of a server
type Network struct { type Network struct {
IP string `json:"address"` Address string `json:"address"`
NetMask string `json:"netmask"` NetMask string `json:"netmask"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
Ethernet string `json:"networkInterface"` Ethernet string `json:"networkInterface"`
@ -116,19 +111,34 @@ type AuthRep struct {
SecretAccessKey string `json:"secretAccessKey"` SecretAccessKey string `json:"secretAccessKey"`
} }
// BucketStorage bucket-name and storage used // BucketStats bucket name and total used by the bucket
type BucketStorage struct { type BucketStats struct {
Name string `json:"name"` Name string `json:"name"`
Used uint64 `json:"used"` Used uint64 `json:"used"`
} }
// StorageStatsRep array of buckets-storage-stats // StorageStatsRep array of BucketStats
type StorageStatsRep struct { type StorageStatsRep struct {
Buckets []BucketStorage `json:"buckets"` Buckets []BucketStats `json:"bucketStats"`
} }
// RebalanceStatsRep rebalance information // RebalanceStatsRep rebalance information
type RebalanceStatsRep struct { type RebalanceStatsRep struct {
Inprogress []string `json:"inprogress"` State map[string]string `json:"rebalanceState"`
Done []string `json:"done"` }
// 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"`
} }

@ -99,6 +99,7 @@ func getServerRPCHandler() http.Handler {
s := jsonrpc.NewServer() s := jsonrpc.NewServer()
s.RegisterCodec(json.NewCodec(), "application/json") s.RegisterCodec(json.NewCodec(), "application/json")
s.RegisterService(new(serverRPCService), "Server") s.RegisterService(new(serverRPCService), "Server")
s.RegisterService(new(donutRPCService), "Donut")
mux := router.NewRouter() mux := router.NewRouter()
mux.Handle("/rpc", s) mux.Handle("/rpc", s)
return mux return mux

@ -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 { func (s *serverRPCService) NetStats(r *http.Request, arg *ServerArg, rep *NetStatsRep) error {
rep.Interfaces = make([]Network, 0) 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 return nil
} }

Loading…
Cancel
Save