Add server and control command

master
Harshavardhana 10 years ago
parent 101784bc44
commit c2031ca066
  1. 153
      commands.go
  2. 30
      pkg/featureflags/featureflag.go
  3. 22
      pkg/featureflags/featureflag_test.go
  4. 6
      pkg/featureflags/features.go

@ -2,146 +2,93 @@ package main
import ( import (
"os/user" "os/user"
"path/filepath"
"strings"
"time"
"github.com/dustin/go-humanize"
"github.com/minio/cli" "github.com/minio/cli"
"github.com/minio/minio/pkg/iodine"
"github.com/minio/minio/pkg/server" "github.com/minio/minio/pkg/server"
) )
func appendUniq(slice []string, i string) []string { func removeDuplicates(slice []string) []string {
for _, ele := range slice { newSlice := []string{}
if ele == i { seen := make(map[string]struct{})
return slice for _, val := range slice {
if _, ok := seen[val]; !ok {
newSlice = append(newSlice, val)
seen[val] = struct{}{}
} }
} }
return append(slice, i) return newSlice
} }
var commands = []cli.Command{ var commands = []cli.Command{
modeCmd, serverCmd,
controlCmd,
} }
var modeCommands = []cli.Command{ var serverCmd = cli.Command{
donutCmd, Name: "server",
} Description: "Server mode",
Action: runServer,
CustomHelpTemplate: `NAME:
minio {{.Name}} - {{.Description}}
USAGE:
minio {{.Name}}
var modeCmd = cli.Command{ EXAMPLES:
Name: "mode", 1. Start in server mode
Subcommands: modeCommands, $ minio server
Description: "Mode of execution",
`,
} }
var donutCmd = cli.Command{ var controlCmd = cli.Command{
Name: "donut", Name: "control",
Description: "[status: EXPERIMENTAL]. Path to donut volume.", Description: "Control mode",
Action: runDonut, Action: runController,
CustomHelpTemplate: `NAME: CustomHelpTemplate: `NAME:
minio mode {{.Name}} - {{.Description}} minio {{.Name}} - {{.Description}}
USAGE: USAGE:
minio mode {{.Name}} PATH minio {{.Name}}
EXAMPLES: EXAMPLES:
1. Create a donut volume under "/mnt/backup", with a cache limit of 64MB with 1hr expiration 1. Start in controller mode
$ minio mode {{.Name}} limit 64MB expire 1h paths /mnt/backup $ minio control
2. Create a donut volume under collection of paths, put a cache limit of 512MB
$ minio mode {{.Name}} limit 512MB paths ""
`, `,
} }
func runDonut(c *cli.Context) { func runServer(c *cli.Context) {
var err error _, err := user.Current()
u, err := user.Current()
if err != nil { if err != nil {
Fatalf("Unable to determine current user. Reason: %s\n", err) Fatalf("Unable to determine current user. Reason: %s\n", err)
} }
if len(c.Args()) < 1 { if len(c.Args()) < 1 {
cli.ShowCommandHelpAndExit(c, "donut", 1) // last argument is exit code cli.ShowCommandHelpAndExit(c, "server", 1) // last argument is exit code
}
var maxMemory uint64
maxMemorySet := false
var expiration time.Duration
expirationSet := false
var paths []string
pathSet := false
args := c.Args()
for len(args) > 0 {
switch args.First() {
case "limit":
{
if maxMemorySet {
Fatalln("Limit should be set only once")
}
args = args.Tail()
maxMemory, err = humanize.ParseBytes(args.First())
if err != nil {
Fatalf("Invalid memory size [%s] passed. Reason: %s\n", args.First(), iodine.New(err, nil))
}
if maxMemory < 1024*1024*10 {
Fatalf("Invalid memory size [%s] passed. Should be greater than 10M\n", args.First())
} }
args = args.Tail() apiServerConfig := getAPIServerConfig(c)
maxMemorySet = true s := server.Factory{
Config: apiServerConfig,
} }
case "expire": apiServer := s.GetStartServerFunc()
{ // webServer := getWebServerConfigFunc(c)
if expirationSet { servers := []server.StartServerFunc{apiServer} //, webServer}
Fatalln("Expiration should be set only once") server.StartMinio(servers)
} }
args = args.Tail()
expiration, err = time.ParseDuration(args.First()) func runController(c *cli.Context) {
_, err := user.Current()
if err != nil { if err != nil {
Fatalf("Invalid expiration time [%s] passed. Reason: %s\n", args.First(), iodine.New(err, nil)) Fatalf("Unable to determine current user. Reason: %s\n", err)
}
args = args.Tail()
expirationSet = true
}
case "paths":
if pathSet {
Fatalln("Path should be set only once")
}
// supporting multiple paths
args = args.Tail()
if strings.TrimSpace(args.First()) == "" {
p := filepath.Join(u.HomeDir, "minio-storage", "donut")
paths = appendUniq(paths, p)
} else {
for _, arg := range args {
paths = appendUniq(paths, strings.TrimSpace(arg))
}
}
args = args.Tail()
pathSet = true
default:
{
cli.ShowCommandHelpAndExit(c, "donut", 1) // last argument is exit code
}
}
}
if maxMemorySet == false {
Fatalln("Memory limit must be set")
} }
if pathSet == false { if len(c.Args()) < 1 {
Fatalln("Path must be set") cli.ShowCommandHelpAndExit(c, "control", 1) // last argument is exit code
} }
apiServerConfig := getAPIServerConfig(c) apiServerConfig := getAPIServerConfig(c)
donutDriver := server.Factory{ s := server.Factory{
Config: apiServerConfig, Config: apiServerConfig,
Paths: paths,
MaxMemory: maxMemory,
Expiration: expiration,
} }
apiServer := donutDriver.GetStartServerFunc() apiServer := s.GetStartServerFunc()
// webServer := getWebServerConfigFunc(c) // webServer := getWebServerConfigFunc(c)
servers := []server.StartServerFunc{apiServer} //, webServer} servers := []server.StartServerFunc{apiServer} //, webServer}
server.StartMinio(servers) server.StartMinio(servers)

@ -1,30 +0,0 @@
package featureflags
import (
"sync"
)
var features = make(map[string]bool)
var lock = &sync.RWMutex{}
// Get feature will return true if the feature is enabled, otherwise false
func Get(feature string) bool {
lock.RLock()
defer lock.RUnlock()
res := features[feature]
return res
}
// Enable a feature
func Enable(feature string) {
lock.Lock()
defer lock.Unlock()
features[feature] = true
}
// Disable a feature
func Disable(feature string) {
lock.Lock()
defer lock.Unlock()
features[feature] = false
}

@ -1,22 +0,0 @@
package featureflags
import (
"testing"
)
func TestFeatureFlag(t *testing.T) {
foo := Get("foo")
if foo {
t.Fail()
}
Enable("foo")
foo = Get("foo")
if !foo {
t.Fail()
}
Disable("foo")
foo = Get("foo")
if foo {
t.Fail()
}
}

@ -1,6 +0,0 @@
package featureflags
const (
// MultipartPutObject ...
MultipartPutObject = "minio.multipart_put_object"
)
Loading…
Cancel
Save