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 (
"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 serverCmd = cli.Command{
Name: "server",
Description: "Server mode",
Action: runServer,
CustomHelpTemplate: `NAME:
minio {{.Name}} - {{.Description}}
USAGE:
minio {{.Name}}
var modeCmd = cli.Command{
Name: "mode",
Subcommands: modeCommands,
Description: "Mode of execution",
EXAMPLES:
1. Start in server mode
$ minio server
`,
}
var donutCmd = cli.Command{
Name: "donut",
Description: "[status: EXPERIMENTAL]. Path to donut volume.",
Action: runDonut,
var controlCmd = cli.Command{
Name: "control",
Description: "Control mode",
Action: runController,
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 controller mode
$ minio control
`,
}
func runDonut(c *cli.Context) {
var err error
u, err := user.Current()
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())
cli.ShowCommandHelpAndExit(c, "server", 1) // last argument is exit code
}
args = args.Tail()
maxMemorySet = true
apiServerConfig := getAPIServerConfig(c)
s := server.Factory{
Config: apiServerConfig,
}
case "expire":
{
if expirationSet {
Fatalln("Expiration should be set only once")
apiServer := s.GetStartServerFunc()
// webServer := getWebServerConfigFunc(c)
servers := []server.StartServerFunc{apiServer} //, webServer}
server.StartMinio(servers)
}
args = args.Tail()
expiration, err = time.ParseDuration(args.First())
func runController(c *cli.Context) {
_, err := user.Current()
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")
Fatalf("Unable to determine current user. Reason: %s\n", err)
}
if pathSet == false {
Fatalln("Path must be set")
if len(c.Args()) < 1 {
cli.ShowCommandHelpAndExit(c, "control", 1) // last argument is exit code
}
apiServerConfig := getAPIServerConfig(c)
donutDriver := server.Factory{
s := server.Factory{
Config: apiServerConfig,
Paths: paths,
MaxMemory: maxMemory,
Expiration: expiration,
}
apiServer := donutDriver.GetStartServerFunc()
apiServer := s.GetStartServerFunc()
// webServer := getWebServerConfigFunc(c)
servers := []server.StartServerFunc{apiServer} //, webServer}
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