Improve code further - this time further simplification of names

master
Harshavardhana 9 years ago
parent 2721bef8da
commit 674631f9d8
  1. 74
      controller-main.go
  2. 7
      controller-router.go
  3. 33
      controller-rpc-server.go
  4. 45
      controller-rpc-version.go
  5. 41
      controller_rpc_test.go
  6. 8
      flags.go
  7. 15
      main.go
  8. 56
      rpc-definitions.go
  9. 69
      server-main.go
  10. 10
      server-router.go
  11. 22
      server-rpc-server.go
  12. 132
      server.go
  13. 5
      server_donut_cache_test.go
  14. 3
      server_donut_test.go
  15. 3
      server_signature_v4_test.go

@ -17,6 +17,7 @@
package main
import (
"crypto/tls"
"fmt"
"net"
"net/http"
@ -45,36 +46,61 @@ EXAMPLES:
`,
}
// getRPCServer instance
func getRPCServer(rpcHandler http.Handler) (*http.Server, *probe.Error) {
// configureControllerRPC instance
func configureControllerRPC(conf minioConfig, rpcHandler http.Handler) (*http.Server, *probe.Error) {
// Minio server config
httpServer := &http.Server{
Addr: ":9001", // TODO make this configurable
rpcServer := &http.Server{
Addr: conf.ControllerAddress,
Handler: rpcHandler,
MaxHeaderBytes: 1 << 20,
}
var hosts []string
addrs, err := net.InterfaceAddrs()
if conf.TLS {
var err error
rpcServer.TLSConfig = &tls.Config{}
rpcServer.TLSConfig.Certificates = make([]tls.Certificate, 1)
rpcServer.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(conf.CertFile, conf.KeyFile)
if err != nil {
return nil, probe.NewError(err)
}
}
host, port, err := net.SplitHostPort(conf.ControllerAddress)
if err != nil {
return nil, probe.NewError(err)
}
for _, addr := range addrs {
if addr.Network() == "ip+net" {
host := strings.Split(addr.String(), "/")[0]
if ip := net.ParseIP(host); ip.To4() != nil {
hosts = append(hosts, host)
var hosts []string
switch {
case host != "":
hosts = append(hosts, host)
default:
addrs, err := net.InterfaceAddrs()
if err != nil {
return nil, probe.NewError(err)
}
for _, addr := range addrs {
if addr.Network() == "ip+net" {
host := strings.Split(addr.String(), "/")[0]
if ip := net.ParseIP(host); ip.To4() != nil {
hosts = append(hosts, host)
}
}
}
}
for _, host := range hosts {
fmt.Printf("Starting minio server on: http://%s:9001/rpc, PID: %d\n", host, os.Getpid())
if conf.TLS {
fmt.Printf("Starting minio controller on: https://%s:%s, PID: %d\n", host, port, os.Getpid())
} else {
fmt.Printf("Starting minio controller on: http://%s:%s, PID: %d\n", host, port, os.Getpid())
}
}
return httpServer, nil
return rpcServer, nil
}
// startController starts a minio controller
func startController() *probe.Error {
rpcServer, err := getRPCServer(getRPCHandler())
func startController(conf minioConfig) *probe.Error {
rpcServer, err := configureControllerRPC(conf, getControllerRPCHandler())
if err != nil {
return err.Trace()
}
@ -85,11 +111,27 @@ func startController() *probe.Error {
return nil
}
func getControllerConfig(c *cli.Context) minioConfig {
certFile := c.GlobalString("cert")
keyFile := c.GlobalString("key")
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
Fatalln("Both certificate and key are required to enable https.")
}
tls := (certFile != "" && keyFile != "")
return minioConfig{
ControllerAddress: c.GlobalString("address-controller"),
TLS: tls,
CertFile: certFile,
KeyFile: keyFile,
RateLimit: c.GlobalInt("ratelimit"),
}
}
func controllerMain(c *cli.Context) {
if c.Args().Present() {
cli.ShowCommandHelpAndExit(c, "controller", 1)
}
err := startController()
err := startController(getControllerConfig(c))
errorIf(err.Trace(), "Failed to start minio controller.", nil)
}

@ -24,14 +24,13 @@ import (
"github.com/gorilla/rpc/v2/json"
)
// getRPCHandler rpc handler
func getRPCCtrlHandler() http.Handler {
// getControllerRPCHandler rpc handler for controller
func getControllerRPCHandler() http.Handler {
s := jsonrpc.NewServer()
s.RegisterCodec(json.NewCodec(), "application/json")
s.RegisterService(new(VersionService), "Version")
s.RegisterService(new(DonutService), "Donut")
s.RegisterService(new(AuthService), "Auth")
s.RegisterService(new(controllerServerRPCService), "Server")
s.RegisterService(new(controllerRPCService), "Server")
// Add new RPC services here
return registerRPC(router.NewRouter(), s)
}

@ -23,17 +23,18 @@ import (
"github.com/minio/minio/pkg/probe"
)
type controllerServerRPCService struct {
type controllerRPCService struct {
serverList []ServerArg
}
func proxyRequest(method string, ip string, arg interface{}, res interface{}) error {
func proxyRequest(method string, url string, arg interface{}, res interface{}) error {
// can be configured to something else in future
namespace := "Server"
op := rpcOperation{
Method: "Server." + method,
Method: namespace + "." + method,
Request: arg,
}
request, _ := newRPCRequest("http://"+ip+":9002/rpc", op, nil)
request, _ := newRPCRequest(url, op, nil)
resp, err := request.Do()
if err != nil {
return probe.WrapError(err)
@ -42,27 +43,31 @@ func proxyRequest(method string, ip string, arg interface{}, res interface{}) er
return decodeerr
}
func (s *controllerServerRPCService) Add(r *http.Request, arg *ServerArg, res *DefaultRep) error {
err := proxyRequest("Add", arg.IP, arg, res)
func (s *controllerRPCService) Add(r *http.Request, arg *ServerArg, res *DefaultRep) error {
err := proxyRequest("Add", arg.URL, arg, res)
if err == nil {
s.serverList = append(s.serverList, *arg)
}
return err
}
func (s *controllerServerRPCService) MemStats(r *http.Request, arg *ServerArg, res *MemStatsRep) error {
return proxyRequest("MemStats", arg.IP, arg, res)
func (s *controllerRPCService) MemStats(r *http.Request, arg *ServerArg, res *MemStatsRep) error {
return proxyRequest("MemStats", arg.URL, arg, res)
}
func (s *controllerServerRPCService) DiskStats(r *http.Request, arg *ServerArg, res *DiskStatsRep) error {
return proxyRequest("DiskStats", arg.IP, arg, res)
func (s *controllerRPCService) DiskStats(r *http.Request, arg *ServerArg, res *DiskStatsRep) error {
return proxyRequest("DiskStats", arg.URL, arg, res)
}
func (s *controllerServerRPCService) SysInfo(r *http.Request, arg *ServerArg, res *SysInfoRep) error {
return proxyRequest("SysInfo", arg.IP, arg, res)
func (s *controllerRPCService) SysInfo(r *http.Request, arg *ServerArg, res *SysInfoRep) error {
return proxyRequest("SysInfo", arg.URL, arg, res)
}
func (s *controllerServerRPCService) List(r *http.Request, arg *ServerArg, res *ListRep) error {
func (s *controllerRPCService) List(r *http.Request, arg *ServerArg, res *ListRep) error {
res.List = s.serverList
return nil
}
func (s *controllerRPCService) Version(r *http.Request, arg *ServerArg, res *VersionRep) error {
return proxyRequest("Version", arg.URL, arg, res)
}

@ -1,45 +0,0 @@
/*
* 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"
)
// VersionArgs basic json RPC params
type VersionArgs struct{}
// VersionService get version service
type VersionService struct{}
// VersionReply version reply
type VersionReply struct {
Version string `json:"version"`
BuildDate string `json:"buildDate"`
Architecture string `json:"arch"`
OperatingSystem string `json:"os"`
}
// Get version
func (v *VersionService) Get(r *http.Request, args *VersionArgs, reply *VersionReply) error {
reply.Version = "0.0.1"
reply.BuildDate = minioVersion
reply.Architecture = runtime.GOARCH
reply.OperatingSystem = runtime.GOOS
return nil
}

@ -1,5 +1,3 @@
// +build ignore
/*
* Minio Cloud Storage, (C) 2014 Minio, Inc.
*
@ -33,26 +31,33 @@ type ControllerRPCSuite struct{}
var _ = Suite(&ControllerRPCSuite{})
var testRPCServer *httptest.Server
var (
testControllerRPC *httptest.Server
testServerRPC *httptest.Server
)
func (s *ControllerRPCSuite) SetUpSuite(c *C) {
root, err := ioutil.TempDir(os.TempDir(), "api-")
c.Assert(err, IsNil)
auth.SetAuthConfigPath(root)
testRPCServer = httptest.NewServer(getRPCCtrlHandler())
testControllerRPC = httptest.NewServer(getControllerRPCHandler())
testServerRPC = httptest.NewUnstartedServer(getServerRPCHandler())
testServerRPC.Config.Addr = ":9002"
testServerRPC.Start()
}
func (s *ControllerRPCSuite) TearDownSuite(c *C) {
testRPCServer.Close()
testServerRPC.Close()
testControllerRPC.Close()
}
func (s *ControllerRPCSuite) TestMemStats(c *C) {
op := rpcOperation{
Method: "Server.MemStats",
Request: ServerArg{},
Request: ServerArg{URL: testServerRPC.URL + "/rpc"},
}
req, err := newRPCRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
@ -68,9 +73,9 @@ func (s *ControllerRPCSuite) TestMemStats(c *C) {
func (s *ControllerRPCSuite) TestSysInfo(c *C) {
op := rpcOperation{
Method: "Server.SysInfo",
Request: ServerArg{},
Request: ServerArg{URL: testServerRPC.URL + "/rpc"},
}
req, err := newRPCRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
@ -86,9 +91,9 @@ func (s *ControllerRPCSuite) TestSysInfo(c *C) {
func (s *ControllerRPCSuite) TestServerList(c *C) {
op := rpcOperation{
Method: "Server.List",
Request: ServerArg{},
Request: ServerArg{URL: testServerRPC.URL + "/rpc"},
}
req, err := newRPCRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
@ -104,9 +109,9 @@ func (s *ControllerRPCSuite) TestServerList(c *C) {
func (s *ControllerRPCSuite) TestServerAdd(c *C) {
op := rpcOperation{
Method: "Server.Add",
Request: ServerArg{},
Request: ServerArg{URL: testServerRPC.URL + "/rpc"},
}
req, err := newRPCRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
@ -124,7 +129,7 @@ func (s *ControllerRPCSuite) TestAuth(c *C) {
Method: "Auth.Generate",
Request: AuthArgs{User: "newuser"},
}
req, err := newRPCRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
@ -143,7 +148,7 @@ func (s *ControllerRPCSuite) TestAuth(c *C) {
Method: "Auth.Fetch",
Request: AuthArgs{User: "newuser"},
}
req, err = newRPCRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
req, err = newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()
@ -162,7 +167,7 @@ func (s *ControllerRPCSuite) TestAuth(c *C) {
Method: "Auth.Reset",
Request: AuthArgs{User: "newuser"},
}
req, err = newRPCRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
req, err = newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()
@ -184,7 +189,7 @@ func (s *ControllerRPCSuite) TestAuth(c *C) {
Method: "Auth.Generate",
Request: AuthArgs{User: "newuser"},
}
req, err = newRPCRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
req, err = newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()
@ -196,7 +201,7 @@ func (s *ControllerRPCSuite) TestAuth(c *C) {
Method: "Auth.Generate",
Request: AuthArgs{User: ""},
}
req, err = newRPCRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
req, err = newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()

@ -28,15 +28,15 @@ var (
Usage: "ADDRESS:PORT for cloud storage access",
}
addressMgmtFlag = cli.StringFlag{
Name: "address-mgmt",
addressControllerFlag = cli.StringFlag{
Name: "address-controller",
Hide: true,
Value: ":9001",
Usage: "ADDRESS:PORT for management console access",
}
addressRPCServerFlag = cli.StringFlag{
Name: "address-rpcserver",
addressServerRPCFlag = cli.StringFlag{
Name: "address-server-rpc",
Hide: true,
Value: ":9002",
Usage: "ADDRESS:PORT for management console access",

@ -27,6 +27,17 @@ import (
"github.com/minio/cli"
)
// minioConfig - http server config
type minioConfig struct {
Address string
ControllerAddress string
RPCAddress string
TLS bool
CertFile string
KeyFile string
RateLimit int
}
func init() {
// Check for the environment early on and gracefuly report.
@ -86,12 +97,12 @@ func registerApp() *cli.App {
// register all flags
registerFlag(addressFlag)
registerFlag(addressMgmtFlag)
registerFlag(addressControllerFlag)
registerFlag(ratelimitFlag)
registerFlag(certFlag)
registerFlag(keyFlag)
registerFlag(debugFlag)
registerFlag(addressRPCServerFlag)
registerFlag(addressServerRPCFlag)
// set up app
app := cli.NewApp()

@ -16,65 +16,73 @@
package main
// Ethernet interface
type Ifc struct {
IP string `json:"ip"`
Mask string `json:"mask"`
Eth string `json:"ifc"`
// Network properties of a server
type Network struct {
IP string `json:"address"`
Mask string `json:"netmask"`
Ethernet string `json:"networkInterface"`
}
// Identify a server
// ServerArg server metadata to identify a server
type ServerArg struct {
Name string `json:"name"`
IP string `json:"ip"`
URL string `json:"url"`
ID string `json:"id"`
}
// Needed for Reply for Server.List
// ServerRep server reply container for Server.List
type ServerRep struct {
Name string `json:"name"`
IP string `json:"ip"`
ID string `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
ID string `json:"id"`
}
// Default reply
// DefaultRep default reply
type DefaultRep struct {
Error int64 `json:"error"`
Message string `json:"message"`
}
// Needed for Reply List
// ServerListRep collection of server replies
type ServerListRep struct {
List []ServerRep
}
// Reply DiskStats
// DiskStatsRep collection of disks
type DiskStatsRep struct {
Disks []string
}
// Reply MemStats
// MemStatsRep memory statistics of a server
type MemStatsRep struct {
Total uint64 `json:"total"`
Free uint64 `json:"free"`
}
// Reply NetStats
// NetStatsRep network statistics of a server
type NetStatsRep struct {
Interfaces []Ifc
Interfaces []Network
}
// Reply SysInfo
// SysInfoRep system information of a server
type SysInfoRep struct {
Hostname string `json:"hostname"`
SysARCH string `json:"sys.arch"`
SysOS string `json:"sys.os"`
SysCPUS int `json:"sys.ncpus"`
Routines int `json:"goroutines"`
GOVersion string `json:"goversion"`
SysARCH string `json:"sysArch"`
SysOS string `json:"sysOS"`
SysCPUS int `json:"sysNcpus"`
Routines int `json:"goRoutines"`
GOVersion string `json:"goVersion"`
}
// Reply List
// ListRep all servers list
type ListRep struct {
List []ServerArg `json:"list"`
}
// VersionRep version reply
type VersionRep struct {
Version string `json:"version"`
BuildDate string `json:"buildDate"`
Architecture string `json:"arch"`
OperatingSystem string `json:"os"`
}

@ -46,19 +46,10 @@ EXAMPLES:
`,
}
// apiConfig - http server config
type apiConfig struct {
Address string
TLS bool
CertFile string
KeyFile string
RateLimit int
}
// getAPI server instance
func getAPIServer(conf apiConfig, apiHandler http.Handler) (*http.Server, *probe.Error) {
// configureAPIServer configure a new server instance
func configureAPIServer(conf minioConfig, apiHandler http.Handler) (*http.Server, *probe.Error) {
// Minio server config
httpServer := &http.Server{
apiServer := &http.Server{
Addr: conf.Address,
Handler: apiHandler,
MaxHeaderBytes: 1 << 20,
@ -66,9 +57,9 @@ func getAPIServer(conf apiConfig, apiHandler http.Handler) (*http.Server, *probe
if conf.TLS {
var err error
httpServer.TLSConfig = &tls.Config{}
httpServer.TLSConfig.Certificates = make([]tls.Certificate, 1)
httpServer.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(conf.CertFile, conf.KeyFile)
apiServer.TLSConfig = &tls.Config{}
apiServer.TLSConfig.Certificates = make([]tls.Certificate, 1)
apiServer.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(conf.CertFile, conf.KeyFile)
if err != nil {
return nil, probe.NewError(err)
}
@ -104,9 +95,29 @@ func getAPIServer(conf apiConfig, apiHandler http.Handler) (*http.Server, *probe
} else {
fmt.Printf("Starting minio server on: http://%s:%s, PID: %d\n", host, port, os.Getpid())
}
}
return apiServer, nil
}
// configureServerRPC configure server rpc port
func configureServerRPC(conf minioConfig, rpcHandler http.Handler) (*http.Server, *probe.Error) {
// Minio server config
rpcServer := &http.Server{
Addr: conf.RPCAddress,
Handler: rpcHandler,
MaxHeaderBytes: 1 << 20,
}
if conf.TLS {
var err error
rpcServer.TLSConfig = &tls.Config{}
rpcServer.TLSConfig.Certificates = make([]tls.Certificate, 1)
rpcServer.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(conf.CertFile, conf.KeyFile)
if err != nil {
return nil, probe.NewError(err)
}
}
return httpServer, nil
return rpcServer, nil
}
// Start ticket master
@ -119,33 +130,37 @@ func startTM(a MinioAPI) {
}
// startServer starts an s3 compatible cloud storage server
func startServer(conf apiConfig) *probe.Error {
apiHandler, minioAPI := getAPIHandler()
apiServer, err := getAPIServer(conf, apiHandler)
func startServer(conf minioConfig) *probe.Error {
minioAPI := getNewAPI()
apiHandler := getAPIHandler(minioAPI)
apiServer, err := configureAPIServer(conf, apiHandler)
if err != nil {
return err.Trace()
}
rpcServer, err := configureServerRPC(conf, getServerRPCHandler())
// start ticket master
go startTM(minioAPI)
if err := minhttp.ListenAndServeLimited(conf.RateLimit, apiServer); err != nil {
if err := minhttp.ListenAndServe(apiServer, rpcServer); err != nil {
return err.Trace()
}
return nil
}
func getServerConfig(c *cli.Context) apiConfig {
func getServerConfig(c *cli.Context) minioConfig {
certFile := c.GlobalString("cert")
keyFile := c.GlobalString("key")
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
Fatalln("Both certificate and key are required to enable https.")
}
tls := (certFile != "" && keyFile != "")
return apiConfig{
Address: c.GlobalString("address"),
TLS: tls,
CertFile: certFile,
KeyFile: keyFile,
RateLimit: c.GlobalInt("ratelimit"),
return minioConfig{
Address: c.GlobalString("address"),
RPCAddress: c.GlobalString("address-server-rpc"),
TLS: tls,
CertFile: certFile,
KeyFile: keyFile,
RateLimit: c.GlobalInt("ratelimit"),
}
}

@ -80,7 +80,7 @@ func getNewAPI() MinioAPI {
}
// getAPIHandler api handler
func getAPIHandler() (http.Handler, MinioAPI) {
func getAPIHandler(minioAPI MinioAPI) http.Handler {
var mwHandlers = []MiddlewareHandler{
ValidContentTypeHandler,
TimeValidityHandler,
@ -89,18 +89,16 @@ func getAPIHandler() (http.Handler, MinioAPI) {
// api.LoggingHandler, // Disabled logging until we bring in external logging support
CorsHandler,
}
mux := router.NewRouter()
minioAPI := getNewAPI()
registerAPI(mux, minioAPI)
apiHandler := registerCustomMiddleware(mux, mwHandlers...)
return apiHandler, minioAPI
return apiHandler
}
func getRPCServerHandler() http.Handler {
func getServerRPCHandler() http.Handler {
s := jsonrpc.NewServer()
s.RegisterCodec(json.NewCodec(), "application/json")
s.RegisterService(new(serverServerService), "Server")
s.RegisterService(new(serverRPCService), "Server")
mux := router.NewRouter()
mux.Handle("/rpc", s)
return mux

@ -24,26 +24,26 @@ import (
"github.com/minio/minio/pkg/probe"
)
type serverServerService struct{}
type serverRPCService struct{}
func (s *serverServerService) Add(r *http.Request, arg *ServerArg, rep *DefaultRep) error {
func (s *serverRPCService) Add(r *http.Request, arg *ServerArg, rep *DefaultRep) error {
rep.Error = 0
rep.Message = "Added successfully"
return nil
}
func (s *serverServerService) MemStats(r *http.Request, arg *ServerArg, rep *MemStatsRep) error {
func (s *serverRPCService) MemStats(r *http.Request, arg *ServerArg, rep *MemStatsRep) error {
rep.Total = 64 * 1024 * 1024 * 1024
rep.Free = 9 * 1024 * 1024 * 1024
return nil
}
func (s *serverServerService) DiskStats(r *http.Request, arg *ServerArg, rep *DiskStatsRep) error {
func (s *serverRPCService) DiskStats(r *http.Request, arg *ServerArg, rep *DiskStatsRep) error {
rep.Disks = []string{"/mnt/disk1", "/mnt/disk2", "/mnt/disk3", "/mnt/disk4", "/mnt/disk5", "/mnt/disk6"}
return nil
}
func (s *serverServerService) SysInfo(r *http.Request, arg *ServerArg, rep *SysInfoRep) error {
func (s *serverRPCService) SysInfo(r *http.Request, arg *ServerArg, rep *SysInfoRep) error {
rep.SysARCH = runtime.GOARCH
rep.SysOS = runtime.GOOS
rep.SysCPUS = runtime.NumCPU()
@ -57,7 +57,15 @@ func (s *serverServerService) SysInfo(r *http.Request, arg *ServerArg, rep *SysI
return nil
}
func (s *serverServerService) NetStats(r *http.Request, arg *ServerArg, rep *NetStatsRep) error {
rep.Interfaces = []Ifc{{"192.168.1.1", "255.255.255.0", "eth0"}}
func (s *serverRPCService) NetStats(r *http.Request, arg *ServerArg, rep *NetStatsRep) error {
rep.Interfaces = []Network{{"192.168.1.1", "255.255.255.0", "eth0"}}
return nil
}
func (s *serverRPCService) Version(r *http.Request, arg *ServerArg, rep *VersionRep) error {
rep.Version = "0.0.1"
rep.BuildDate = minioVersion
rep.Architecture = runtime.GOARCH
rep.OperatingSystem = runtime.GOOS
return nil
}

@ -1,132 +0,0 @@
/*
* Minio Cloud Storage, (C) 2014 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
<<<<<<< HEAD
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"os"
"strings"
"github.com/minio/minio/pkg/minhttp"
"github.com/minio/minio/pkg/probe"
)
func configureServer(conf APIConfig, httpServer *http.Server) *probe.Error {
if conf.TLS {
var err error
httpServer.TLSConfig = &tls.Config{}
httpServer.TLSConfig.Certificates = make([]tls.Certificate, 1)
httpServer.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(conf.CertFile, conf.KeyFile)
if err != nil {
return probe.NewError(err)
}
}
host, port, err := net.SplitHostPort(conf.Address)
if err != nil {
return probe.NewError(err)
}
var hosts []string
switch {
case host != "":
hosts = append(hosts, host)
default:
addrs, err := net.InterfaceAddrs()
if err != nil {
return probe.NewError(err)
}
for _, addr := range addrs {
if addr.Network() == "ip+net" {
host := strings.Split(addr.String(), "/")[0]
if ip := net.ParseIP(host); ip.To4() != nil {
hosts = append(hosts, host)
}
}
}
}
for _, host := range hosts {
if conf.TLS {
fmt.Printf("Starting minio server on: https://%s:%s, PID: %d\n", host, port, os.Getpid())
} else {
fmt.Printf("Starting minio server on: http://%s:%s, PID: %d\n", host, port, os.Getpid())
}
}
return nil
}
// getAPI server instance
func getAPIServer(conf APIConfig, apiHandler http.Handler) (*http.Server, *probe.Error) {
// Minio server config
httpServer := &http.Server{
Addr: conf.Address,
Handler: apiHandler,
MaxHeaderBytes: 1 << 20,
}
if err := configureServer(conf, httpServer); err != nil {
return nil, err
}
return httpServer, nil
}
// Start ticket master
func startTM(a MinioAPI) {
for {
for op := range a.OP {
op.ProceedCh <- struct{}{}
}
}
}
func getServerRPCServer(conf APIConfig, handler http.Handler) (*http.Server, *probe.Error) {
httpServer := &http.Server{
Addr: conf.AddressRPC,
Handler: handler,
MaxHeaderBytes: 1 << 20,
}
if err := configureServer(conf, httpServer); err != nil {
return nil, err
}
return httpServer, nil
}
// Start starts a s3 compatible cloud storage server
func StartServer(conf APIConfig) *probe.Error {
apiHandler, minioAPI := getAPIHandler(conf)
apiServer, err := getAPIServer(conf, apiHandler)
if err != nil {
return err.Trace()
}
// start ticket master
go startTM(minioAPI)
rpcHandler := getRPCServerHandler()
rpcServer, err := getServerRPCServer(conf, rpcHandler)
if err != nil {
return err.Trace()
}
if err := minhttp.ListenAndServeLimited(conf.RateLimit, apiServer, rpcServer); err != nil {
return err.Trace()
}
return nil
}
=======
>>>>>>> Consolidating more codebase and cleanup in server / controller

@ -51,9 +51,10 @@ func (s *MyAPIDonutCacheSuite) SetUpSuite(c *C) {
perr := donut.SaveConfig(conf)
c.Assert(perr, IsNil)
httpHandler, minioAPI := getAPIHandler()
minioAPI := getNewAPI()
apiHandler := getAPIHandler(minioAPI)
go startTM(minioAPI)
testAPIDonutCacheServer = httptest.NewServer(httpHandler)
testAPIDonutCacheServer = httptest.NewServer(apiHandler)
}
func (s *MyAPIDonutCacheSuite) TearDownSuite(c *C) {

@ -70,7 +70,8 @@ func (s *MyAPIDonutSuite) SetUpSuite(c *C) {
perr := donut.SaveConfig(conf)
c.Assert(perr, IsNil)
httpHandler, minioAPI := getAPIHandler()
minioAPI := getNewAPI()
httpHandler := getAPIHandler(minioAPI)
go startTM(minioAPI)
testAPIDonutServer = httptest.NewServer(httpHandler)
}

@ -78,7 +78,8 @@ func (s *MyAPISignatureV4Suite) SetUpSuite(c *C) {
perr = auth.SaveConfig(authConf)
c.Assert(perr, IsNil)
httpHandler, minioAPI := getAPIHandler()
minioAPI := getNewAPI()
httpHandler := getAPIHandler(minioAPI)
go startTM(minioAPI)
testSignatureV4Server = httptest.NewServer(httpHandler)
}

Loading…
Cancel
Save