Consolidate controller, move rpc package into controller - remove dangling code in pkg/server

This commit is contained in:
Harshavardhana
2015-09-15 19:38:30 -07:00
parent 8d5f6e0b96
commit 3f4b98ca4c
13 changed files with 9 additions and 36 deletions

View File

@@ -1,55 +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 rpc
import (
"net/http"
"github.com/minio/minio/pkg/auth"
"github.com/minio/minio/pkg/probe"
)
// AuthService auth service
type AuthService struct{}
// AuthReply reply with new access keys and secret ids
type AuthReply struct {
AccessKeyID string `json:"accesskey"`
SecretAccessKey string `json:"secretaccesskey"`
}
func getAuth(reply *AuthReply) *probe.Error {
accessID, err := auth.GenerateAccessKeyID()
if err != nil {
return err.Trace()
}
reply.AccessKeyID = string(accessID)
secretID, err := auth.GenerateSecretAccessKey()
if err != nil {
return err.Trace()
}
reply.SecretAccessKey = string(secretID)
return nil
}
// Get auth keys
func (s *AuthService) Get(r *http.Request, args *Args, reply *AuthReply) error {
if err := getAuth(reply); err != nil {
return probe.WrapError(err)
}
return nil
}

View File

@@ -1,63 +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 rpc
import (
"net/http"
"github.com/minio/minio/pkg/donut"
"github.com/minio/minio/pkg/probe"
)
// DonutService donut service
type DonutService struct{}
// DonutArgs collections of disks and name to initialize donut
type DonutArgs struct {
Name string
MaxSize uint64
Hostname string
Disks []string
}
// Reply reply for successful or failed Set operation
type Reply struct {
Message string `json:"message"`
Error error `json:"error"`
}
func setDonut(args *DonutArgs, reply *Reply) *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
}
// Set method
func (s *DonutService) Set(r *http.Request, args *DonutArgs, reply *Reply) error {
if err := setDonut(args, reply); err != nil {
return probe.WrapError(err)
}
return nil
}

View File

@@ -1,79 +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 rpc
import (
"bytes"
"net/http"
"github.com/gorilla/rpc/v2/json"
"github.com/minio/minio/pkg/probe"
)
// Operation RPC operation
type Operation struct {
Method string
Request interface{}
}
// Request rpc client request
type Request struct {
req *http.Request
transport http.RoundTripper
}
// NewRequest initiate a new client RPC request
func NewRequest(url string, op Operation, transport http.RoundTripper) (*Request, *probe.Error) {
params, err := json.EncodeClientRequest(op.Method, op.Request)
if err != nil {
return nil, probe.NewError(err)
}
req, err := http.NewRequest("POST", url, bytes.NewReader(params))
if err != nil {
return nil, probe.NewError(err)
}
rpcReq := &Request{}
rpcReq.req = req
rpcReq.req.Header.Set("Content-Type", "application/json")
if transport == nil {
transport = http.DefaultTransport
}
rpcReq.transport = transport
return rpcReq, nil
}
// Do - make a http connection
func (r Request) Do() (*http.Response, *probe.Error) {
resp, err := r.transport.RoundTrip(r.req)
if err != nil {
if err, ok := probe.UnwrapError(err); ok {
return nil, err.Trace()
}
return nil, probe.NewError(err)
}
return resp, nil
}
// Get - get value of requested header
func (r Request) Get(key string) string {
return r.req.Header.Get(key)
}
// Set - set value of a header key
func (r *Request) Set(key, value string) {
r.req.Header.Set(key, value)
}

View File

@@ -1,51 +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 rpc
import (
"net/http"
"github.com/gorilla/rpc/v2"
"github.com/gorilla/rpc/v2/json"
)
// Server rpc server container
type Server struct {
RPCServer *rpc.Server
}
// RegisterJSONCodec - register standard json codec
func (s Server) RegisterJSONCodec() {
s.RPCServer.RegisterCodec(json.NewCodec(), "application/json")
}
// RegisterService - register new services
func (s Server) RegisterService(recv interface{}, name string) {
s.RPCServer.RegisterService(recv, name)
}
// NewServer - provide a new instance of RPC server
func NewServer() *Server {
s := &Server{}
s.RPCServer = rpc.NewServer()
return s
}
// ServeHTTP wrapper method for http.Handler interface
func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.RPCServer.ServeHTTP(w, r)
}

View File

@@ -1,84 +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 rpc
import (
"net/http"
"os"
"runtime"
"github.com/minio/minio/pkg/probe"
)
// SysInfoService -
type SysInfoService struct{}
// SysInfoReply -
type SysInfoReply 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"`
}
// MemStatsService -
type MemStatsService struct{}
// MemStatsReply -
type MemStatsReply struct {
runtime.MemStats `json:"memstats"`
}
func setSysInfoReply(sis *SysInfoReply) *probe.Error {
sis.SysARCH = runtime.GOARCH
sis.SysOS = runtime.GOOS
sis.SysCPUS = runtime.NumCPU()
sis.Routines = runtime.NumGoroutine()
sis.GOVersion = runtime.Version()
var err error
sis.Hostname, err = os.Hostname()
if err != nil {
return probe.NewError(err)
}
return nil
}
func setMemStatsReply(sis *MemStatsReply) *probe.Error {
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
sis.MemStats = memStats
return nil
}
// Get method
func (s *SysInfoService) Get(r *http.Request, args *Args, reply *SysInfoReply) error {
if err := setSysInfoReply(reply); err != nil {
return probe.WrapError(err)
}
return nil
}
// Get method
func (s *MemStatsService) Get(r *http.Request, args *Args, reply *MemStatsReply) error {
if err := setMemStatsReply(reply); err != nil {
return probe.WrapError(err)
}
return nil
}

View File

@@ -1,55 +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 rpc
import (
"net/http"
"time"
)
// Args basic json RPC params
type Args struct {
Request string
}
// VersionReply version reply
type VersionReply struct {
Version string `json:"version"`
BuildDate string `json:"build-date"`
}
// VersionService -
type VersionService struct{}
func getVersion() string {
return "0.0.1"
}
func getBuildDate() string {
return time.Now().UTC().Format(http.TimeFormat)
}
func setVersionReply(reply *VersionReply) {
reply.Version = getVersion()
reply.BuildDate = getBuildDate()
return
}
// Get method
func (v *VersionService) Get(r *http.Request, args *Args, reply *VersionReply) error {
setVersionReply(reply)
return nil
}