Add dummy driver for community to submit new drivers

master
Harshavardhana 10 years ago
parent 12de98fb62
commit ab6e16bb41
  1. 86
      commands.go
  2. 4
      pkg/api/api_test.go
  3. 19
      pkg/server/server.go
  4. 1
      pkg/storage/drivers/dummy/README.md
  5. 108
      pkg/storage/drivers/dummy/dummy.go

@ -26,7 +26,6 @@ var commands = []cli.Command{
}
var modeCommands = []cli.Command{
memoryCmd,
donutCmd,
}
@ -36,25 +35,6 @@ var modeCmd = cli.Command{
Description: "Mode of execution",
}
var memoryCmd = cli.Command{
Name: "memory",
Description: "Limit maximum memory usage to SIZE in [B, KB, MB, GB]",
Action: runMemory,
CustomHelpTemplate: `NAME:
minio mode {{.Name}} - {{.Description}}
USAGE:
minio mode {{.Name}} limit SIZE expire TIME
EXAMPLES:
1. Limit maximum memory usage to 64MB with 1 hour expiration
$ minio mode {{.Name}} limit 64MB expire 1h
2. Limit maximum memory usage to 4GB with no expiration
$ minio mode {{.Name}} limit 4GB
`,
}
var donutCmd = cli.Command{
Name: "donut",
Description: "[status: EXPERIMENTAL]. Path to donut volume.",
@ -75,72 +55,6 @@ EXAMPLES:
`,
}
func runMemory(c *cli.Context) {
if len(c.Args()) == 0 || len(c.Args())%2 != 0 {
cli.ShowCommandHelpAndExit(c, "memory", 1) // last argument is exit code
}
apiServerConfig := getAPIServerConfig(c)
var maxMemory uint64
maxMemorySet := false
var expiration time.Duration
expirationSet := false
var err error
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
}
default:
{
cli.ShowCommandHelpAndExit(c, "memory", 1) // last argument is exit code
}
}
}
if maxMemorySet == false {
Fatalln("Memory limit must be set")
}
memoryDriver := server.MemoryFactory{
Config: apiServerConfig,
MaxMemory: maxMemory,
Expiration: expiration,
}
apiServer := memoryDriver.GetStartServerFunc()
// webServer := getWebServerConfigFunc(c)
servers := []server.StartServerFunc{apiServer} //, webServer}
server.StartMinio(servers)
}
func runDonut(c *cli.Context) {
var err error

@ -33,8 +33,8 @@ import (
"net/http/httptest"
"github.com/minio/minio/pkg/storage/drivers"
"github.com/minio/minio/pkg/storage/drivers/cache"
"github.com/minio/minio/pkg/storage/drivers/donut"
"github.com/minio/minio/pkg/storage/drivers/memory"
"github.com/minio/minio/pkg/storage/drivers/mocks"
"github.com/stretchr/testify/mock"
@ -58,7 +58,7 @@ var _ = Suite(&MySuite{
var _ = Suite(&MySuite{
initDriver: func() (drivers.Driver, string) {
driver, _ := memory.NewDriver(10000, 3*time.Hour)
driver, _ := cache.NewDriver(10000, 3*time.Hour)
return driver, ""
},
})

@ -27,28 +27,9 @@ import (
"github.com/minio/minio/pkg/iodine"
"github.com/minio/minio/pkg/server/httpserver"
"github.com/minio/minio/pkg/storage/drivers/donut"
"github.com/minio/minio/pkg/storage/drivers/memory"
"github.com/minio/minio/pkg/utils/log"
)
// MemoryFactory is used to build memory api server
type MemoryFactory struct {
httpserver.Config
MaxMemory uint64
Expiration time.Duration
}
// GetStartServerFunc builds memory api server
func (f MemoryFactory) GetStartServerFunc() StartServerFunc {
return func() (chan<- string, <-chan error) {
driver, _ := memory.NewDriver(f.MaxMemory, f.Expiration)
conf := api.Config{RateLimit: f.RateLimit}
conf.SetDriver(driver)
ctrl, status, _ := httpserver.Start(api.HTTPHandler(conf), f.Config)
return ctrl, status
}
}
// WebFactory is used to build web cli server
type WebFactory struct {
httpserver.Config

@ -0,0 +1 @@
This is a dummy driver which is a pass through driver, useful if some one wants to contribute code.

@ -0,0 +1,108 @@
/*
* Minimalist Object 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 dummy
import (
"io"
"github.com/minio/minio/pkg/storage/drivers"
)
// dummyDriver
type dummyDriver struct {
driver drivers.Driver
}
// NewDriver provides a new dummy driver
func NewDriver(driver drivers.Driver) drivers.Driver {
return dummyDriver{driver: driver}
}
// ListBuckets
func (dummy dummyDriver) ListBuckets() ([]drivers.BucketMetadata, error) {
return dummy.driver.ListBuckets()
}
// CreateBucket
func (dummy dummyDriver) CreateBucket(bucket, acl string) error {
return dummy.driver.CreateBucket(bucket, acl)
}
// GetBucketMetadata
func (dummy dummyDriver) GetBucketMetadata(bucket string) (drivers.BucketMetadata, error) {
return dummy.driver.GetBucketMetadata(bucket)
}
// SetBucketMetadata
func (dummy dummyDriver) SetBucketMetadata(bucket, acl string) error {
return dummy.driver.SetBucketMetadata(bucket, acl)
}
// GetObject
func (dummy dummyDriver) GetObject(w io.Writer, bucket, object string) (int64, error) {
return dummy.driver.GetObject(w, bucket, object)
}
// GetPartialObject
func (dummy dummyDriver) GetPartialObject(w io.Writer, bucket, object string, start int64, length int64) (int64, error) {
return dummy.driver.GetPartialObject(w, bucket, object, start, length)
}
// GetObjectMetadata
func (dummy dummyDriver) GetObjectMetadata(bucket, object string) (drivers.ObjectMetadata, error) {
return dummy.driver.GetObjectMetadata(bucket, object)
}
// ListObjects
func (dummy dummyDriver) ListObjects(bucket string, resources drivers.BucketResourcesMetadata) ([]drivers.ObjectMetadata, drivers.BucketResourcesMetadata, error) {
return dummy.driver.ListObjects(bucket, resources)
}
// CreateObject
func (dummy dummyDriver) CreateObject(bucket, key, contentType, md5sum string, size int64, data io.Reader) (string, error) {
return dummy.driver.CreateObject(bucket, key, contentType, md5sum, size, data)
}
// NewMultipartUpload
func (dummy dummyDriver) NewMultipartUpload(bucket, key, contentType string) (string, error) {
return dummy.driver.NewMultipartUpload(bucket, key, contentType)
}
// CreateObjectPart
func (dummy dummyDriver) CreateObjectPart(bucket, key, uploadID string, partID int, contentType string, md5sum string, size int64, data io.Reader) (string, error) {
return dummy.driver.CreateObjectPart(bucket, key, uploadID, partID, contentType, md5sum, size, data)
}
// CompleteMultipartUpload
func (dummy dummyDriver) CompleteMultipartUpload(bucket, key, uploadID string, parts map[int]string) (string, error) {
return dummy.driver.CompleteMultipartUpload(bucket, key, uploadID, parts)
}
// ListObjectParts
func (dummy dummyDriver) ListObjectParts(bucket, key string, resources drivers.ObjectResourcesMetadata) (drivers.ObjectResourcesMetadata, error) {
return dummy.driver.ListObjectParts(bucket, key, resources)
}
// ListMultipartUploads
func (dummy dummyDriver) ListMultipartUploads(bucket string, resources drivers.BucketMultipartResourcesMetadata) (drivers.BucketMultipartResourcesMetadata, error) {
return dummy.driver.ListMultipartUploads(bucket, resources)
}
// AbortMultipartUpload
func (dummy dummyDriver) AbortMultipartUpload(bucket, key, uploadID string) error {
return dummy.driver.AbortMultipartUpload(bucket, key, uploadID)
}
Loading…
Cancel
Save