Bucket manager is now configurable as GatewayConfig.BucketServiceDriver

master
Frederick F. Kautz IV 10 years ago
parent f46fad48b0
commit 101ce51f78
  1. 8
      gateway.go
  2. 9
      gateway_test.go
  3. 5
      minio/main.go

@ -12,6 +12,7 @@ import (
// Stores system configuration, populated from CLI or test runner // Stores system configuration, populated from CLI or test runner
type GatewayConfig struct { type GatewayConfig struct {
StorageDriver StorageDriver StorageDriver StorageDriver
BucketDriver BucketDriver
requestBucketChan chan BucketRequest requestBucketChan chan BucketRequest
} }
@ -32,6 +33,9 @@ type Bucket interface {
Put(Context, string, []byte) error Put(Context, string, []byte) error
} }
// Bucket driver function, should read from a channel and respond through callback channels
type BucketDriver func(config GatewayConfig)
// Storage driver function, should read from a channel and respond through callback channels // Storage driver function, should read from a channel and respond through callback channels
type StorageDriver func(bucket string, input chan ObjectRequest) type StorageDriver func(bucket string, input chan ObjectRequest)
@ -87,14 +91,14 @@ func (handler GatewayPutHandler) ServeHTTP(w http.ResponseWriter, req *http.Requ
func RegisterGatewayHandlers(router *mux.Router, config GatewayConfig) { func RegisterGatewayHandlers(router *mux.Router, config GatewayConfig) {
config.requestBucketChan = make(chan BucketRequest) config.requestBucketChan = make(chan BucketRequest)
go SynchronizedBucketService(config) go config.BucketDriver(config)
getHandler := GatewayGetHandler{config} getHandler := GatewayGetHandler{config}
putHandler := GatewayPutHandler{config} putHandler := GatewayPutHandler{config}
router.Handle("/{bucket}/{path:.*}", getHandler).Methods("GET") router.Handle("/{bucket}/{path:.*}", getHandler).Methods("GET")
router.Handle("/{bucket}/{path:.*}", putHandler).Methods("PUT") router.Handle("/{bucket}/{path:.*}", putHandler).Methods("PUT")
} }
func SynchronizedBucketService(config GatewayConfig) { func SynchronizedBucketDriver(config GatewayConfig) {
buckets := make(map[string]*SynchronizedBucket) buckets := make(map[string]*SynchronizedBucket)
for request := range config.requestBucketChan { for request := range config.requestBucketChan {
if buckets[request.name] == nil { if buckets[request.name] == nil {

@ -19,7 +19,10 @@ func Test(t *testing.T) { TestingT(t) }
func (s *MySuite) TestPrintsGateway(c *C) { func (s *MySuite) TestPrintsGateway(c *C) {
// set up router with in memory storage driver // set up router with in memory storage driver
router := mux.NewRouter() router := mux.NewRouter()
config := GatewayConfig{StorageDriver: InMemoryStorageDriver} config := GatewayConfig{
StorageDriver: InMemoryStorageDriver,
BucketDriver: SynchronizedBucketDriver,
}
RegisterGatewayHandlers(router, config) RegisterGatewayHandlers(router, config)
server := httptest.NewServer(router) server := httptest.NewServer(router)
defer server.Close() defer server.Close()
@ -62,7 +65,7 @@ func (s *MySuite) TestBucketCreation(c *C) {
requestBucketChan: make(chan BucketRequest), requestBucketChan: make(chan BucketRequest),
} }
defer close(config.requestBucketChan) defer close(config.requestBucketChan)
go SynchronizedBucketService(config) go SynchronizedBucketDriver(config)
context := TestContext{} context := TestContext{}
// get new bucket A // get new bucket A
@ -107,7 +110,7 @@ func (s *MySuite) TestInMemoryBucketOperations(c *C) {
requestBucketChan: make(chan BucketRequest), requestBucketChan: make(chan BucketRequest),
} }
defer close(config.requestBucketChan) defer close(config.requestBucketChan)
go SynchronizedBucketService(config) go SynchronizedBucketDriver(config)
context := TestContext{} context := TestContext{}
// get bucket // get bucket

@ -26,7 +26,10 @@ func main() {
Name: "gateway", Name: "gateway",
Usage: "Start a gateway node", Usage: "Start a gateway node",
Action: func(c *cli.Context) { Action: func(c *cli.Context) {
minio.RegisterGatewayHandlers(router, minio.GatewayConfig{StorageDriver: minio.InMemoryStorageDriver}) minio.RegisterGatewayHandlers(router, minio.GatewayConfig{
StorageDriver: minio.InMemoryStorageDriver,
BucketDriver: minio.SynchronizedBucketDriver,
})
runServer = true runServer = true
}, },
}, },

Loading…
Cancel
Save