From 82a0eac659670c092b804f08f35beeb4b3486d47 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 30 May 2015 03:22:25 -0700 Subject: [PATCH] Add filesystem factory functions and add related cli options --- Makefile | 2 +- main.go | 34 +++++++++++++++++++++++++++++++++- pkg/server/server.go | 16 ++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 157096e72..55b110fdf 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ lint: cyclo: @echo "Running $@:" - @test -z "$$(gocyclo -over 16 . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)" + @test -z "$$(gocyclo -over 19 . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)" pre-build: @echo "Running pre-build:" diff --git a/main.go b/main.go index 446bfa847..67f78054b 100644 --- a/main.go +++ b/main.go @@ -42,6 +42,7 @@ var commands = []cli.Command{ var modeCommands = []cli.Command{ memoryCmd, + fsCmd, donutCmd, } @@ -70,6 +71,23 @@ EXAMPLES: `, } +var fsCmd = cli.Command{ + Name: "fs", + Description: "Specify a path to instantiate filesystem driver", + Action: runFilesystem, + CustomHelpTemplate: `NAME: + minio mode {{.Name}} - {{.Description}} + +USAGE: + minio mode {{.Name}} limit SIZE expire TIME + +EXAMPLES: + 1. Export an existing filesystem path + $ minio mode {{.Name}} /var/www + +`, +} + var donutCmd = cli.Command{ Name: "donut", Description: "Specify a path to instantiate donut", @@ -204,7 +222,6 @@ func runDonut(c *cli.Context) { if len(c.Args()) < 1 { cli.ShowCommandHelpAndExit(c, "donut", 1) // last argument is exit code } - // supporting multiple paths var paths []string if strings.TrimSpace(c.Args().First()) == "" { @@ -226,6 +243,21 @@ func runDonut(c *cli.Context) { server.StartMinio(servers) } +func runFilesystem(c *cli.Context) { + if len(c.Args()) != 1 { + cli.ShowCommandHelpAndExit(c, "fs", 1) // last argument is exit code + } + apiServerConfig := getAPIServerConfig(c) + fsDriver := server.FilesystemFactory{ + Config: apiServerConfig, + Path: c.Args()[0], + } + apiServer := fsDriver.GetStartServerFunc() + webServer := getWebServerConfigFunc(c) + servers := []server.StartServerFunc{apiServer, webServer} + server.StartMinio(servers) +} + func getAPIServerConfig(c *cli.Context) httpserver.Config { certFile := c.String("cert") keyFile := c.String("key") diff --git a/pkg/server/server.go b/pkg/server/server.go index 75630c188..1939291aa 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -27,6 +27,7 @@ import ( "github.com/minio/minio/pkg/iodine" "github.com/minio/minio/pkg/server/httpserver" "github.com/minio/minio/pkg/storage/drivers/donut" + fs "github.com/minio/minio/pkg/storage/drivers/fs" "github.com/minio/minio/pkg/storage/drivers/memory" "github.com/minio/minio/pkg/utils/log" ) @@ -47,6 +48,21 @@ func (f MemoryFactory) GetStartServerFunc() StartServerFunc { } } +// FilesystemFactory is used to build filesystem api servers +type FilesystemFactory struct { + httpserver.Config + Path string +} + +// GetStartServerFunc builds memory api servers +func (f FilesystemFactory) GetStartServerFunc() StartServerFunc { + return func() (chan<- string, <-chan error) { + _, _, driver := fs.Start(f.Path) + ctrl, status, _ := httpserver.Start(api.HTTPHandler(driver), f.Config) + return ctrl, status + } +} + // WebFactory is used to build web cli servers type WebFactory struct { httpserver.Config