diff --git a/commands.go b/commands.go index 27cd5efa2..748f17c3e 100644 --- a/commands.go +++ b/commands.go @@ -2,146 +2,93 @@ package main import ( "os/user" - "path/filepath" - "strings" - "time" - "github.com/dustin/go-humanize" "github.com/minio/cli" - "github.com/minio/minio/pkg/iodine" "github.com/minio/minio/pkg/server" ) -func appendUniq(slice []string, i string) []string { - for _, ele := range slice { - if ele == i { - return slice +func removeDuplicates(slice []string) []string { + newSlice := []string{} + seen := make(map[string]struct{}) + 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{ - modeCmd, + serverCmd, + controlCmd, } -var modeCommands = []cli.Command{ - donutCmd, -} - -var modeCmd = cli.Command{ - Name: "mode", - Subcommands: modeCommands, - Description: "Mode of execution", -} - -var donutCmd = cli.Command{ - Name: "donut", - Description: "[status: EXPERIMENTAL]. Path to donut volume.", - Action: runDonut, +var serverCmd = cli.Command{ + Name: "server", + Description: "Server mode", + Action: runServer, CustomHelpTemplate: `NAME: - minio mode {{.Name}} - {{.Description}} + minio {{.Name}} - {{.Description}} USAGE: - minio mode {{.Name}} PATH + minio {{.Name}} EXAMPLES: - 1. Create a donut volume under "/mnt/backup", with a cache limit of 64MB with 1hr expiration - $ minio mode {{.Name}} limit 64MB expire 1h paths /mnt/backup - - 2. Create a donut volume under collection of paths, put a cache limit of 512MB - $ minio mode {{.Name}} limit 512MB paths "" + 1. Start in server mode + $ minio server `, } -func runDonut(c *cli.Context) { - var err error +var controlCmd = cli.Command{ + Name: "control", + Description: "Control mode", + Action: runController, + CustomHelpTemplate: `NAME: + minio {{.Name}} - {{.Description}} - u, err := user.Current() +USAGE: + minio {{.Name}} + +EXAMPLES: + 1. Start in controller mode + $ minio control + +`, +} + +func runServer(c *cli.Context) { + _, err := user.Current() if err != nil { Fatalf("Unable to determine current user. Reason: %s\n", err) } if len(c.Args()) < 1 { - cli.ShowCommandHelpAndExit(c, "donut", 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() - maxMemorySet = true - } - case "expire": - { - if expirationSet { - Fatalln("Expiration should be set only once") - } - args = args.Tail() - expiration, err = time.ParseDuration(args.First()) - if err != nil { - Fatalf("Invalid expiration time [%s] passed. Reason: %s\n", args.First(), iodine.New(err, nil)) - } - 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 { - Fatalln("Path must be set") + cli.ShowCommandHelpAndExit(c, "server", 1) // last argument is exit code } apiServerConfig := getAPIServerConfig(c) - donutDriver := server.Factory{ - Config: apiServerConfig, - Paths: paths, - MaxMemory: maxMemory, - Expiration: expiration, + s := server.Factory{ + Config: apiServerConfig, } - apiServer := donutDriver.GetStartServerFunc() + apiServer := s.GetStartServerFunc() + // webServer := getWebServerConfigFunc(c) + servers := []server.StartServerFunc{apiServer} //, webServer} + server.StartMinio(servers) +} + +func runController(c *cli.Context) { + _, err := user.Current() + if err != nil { + Fatalf("Unable to determine current user. Reason: %s\n", err) + } + if len(c.Args()) < 1 { + cli.ShowCommandHelpAndExit(c, "control", 1) // last argument is exit code + } + apiServerConfig := getAPIServerConfig(c) + s := server.Factory{ + Config: apiServerConfig, + } + apiServer := s.GetStartServerFunc() // webServer := getWebServerConfigFunc(c) servers := []server.StartServerFunc{apiServer} //, webServer} server.StartMinio(servers) diff --git a/pkg/featureflags/featureflag.go b/pkg/featureflags/featureflag.go deleted file mode 100644 index 9a7bd3904..000000000 --- a/pkg/featureflags/featureflag.go +++ /dev/null @@ -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 -} diff --git a/pkg/featureflags/featureflag_test.go b/pkg/featureflags/featureflag_test.go deleted file mode 100644 index ff5de5d3a..000000000 --- a/pkg/featureflags/featureflag_test.go +++ /dev/null @@ -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() - } -} diff --git a/pkg/featureflags/features.go b/pkg/featureflags/features.go deleted file mode 100644 index da85bc1e1..000000000 --- a/pkg/featureflags/features.go +++ /dev/null @@ -1,6 +0,0 @@ -package featureflags - -const ( - // MultipartPutObject ... - MultipartPutObject = "minio.multipart_put_object" -)