Merge pull request #18 from fkautz/pr_out_bucket_manager_is_now_configurable_as_gatewayconfig_bucketservicedriver

This commit is contained in:
Frederick F. Kautz IV 2014-11-13 22:23:08 -08:00
commit c4d2292a7d
3 changed files with 16 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import (
// Stores system configuration, populated from CLI or test runner
type GatewayConfig struct {
StorageDriver StorageDriver
BucketDriver BucketDriver
requestBucketChan chan BucketRequest
}
@ -32,6 +33,9 @@ type Bucket interface {
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
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) {
config.requestBucketChan = make(chan BucketRequest)
go SynchronizedBucketService(config)
go config.BucketDriver(config)
getHandler := GatewayGetHandler{config}
putHandler := GatewayPutHandler{config}
router.Handle("/{bucket}/{path:.*}", getHandler).Methods("GET")
router.Handle("/{bucket}/{path:.*}", putHandler).Methods("PUT")
}
func SynchronizedBucketService(config GatewayConfig) {
func SynchronizedBucketDriver(config GatewayConfig) {
buckets := make(map[string]*SynchronizedBucket)
for request := range config.requestBucketChan {
if buckets[request.name] == nil {

View File

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

View File

@ -26,7 +26,10 @@ func main() {
Name: "gateway",
Usage: "Start a gateway node",
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
},
},