mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Add etcd handling for web-handler methods
This commit is contained in:
parent
481390d51a
commit
f30c95a301
@ -624,7 +624,7 @@ type bucketForwardingHandler struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if globalDNSConfig == nil || globalDomainName == "" {
|
if globalDNSConfig == nil || globalDomainName == "" || guessIsBrowserReq(r) || guessIsHealthCheckReq(r) || guessIsMetricsReq(r) || guessIsRPCReq(r) {
|
||||||
f.handler.ServeHTTP(w, r)
|
f.handler.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -67,3 +67,6 @@ var errNotFirstDisk = errors.New("Not first disk")
|
|||||||
|
|
||||||
// error returned by first disk waiting to initialize other servers.
|
// error returned by first disk waiting to initialize other servers.
|
||||||
var errFirstDiskWait = errors.New("Waiting on other disks")
|
var errFirstDiskWait = errors.New("Waiting on other disks")
|
||||||
|
|
||||||
|
// error returned when a bucket already exists
|
||||||
|
var errBucketAlreadyExists = errors.New("Your previous request to create the named bucket succeeded and you already own it")
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
etcd "github.com/coreos/etcd/client"
|
||||||
humanize "github.com/dustin/go-humanize"
|
humanize "github.com/dustin/go-humanize"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/gorilla/rpc/v2/json2"
|
"github.com/gorilla/rpc/v2/json2"
|
||||||
@ -135,6 +136,26 @@ func (web *webAPIHandlers) MakeBucket(r *http.Request, args *MakeBucketArgs, rep
|
|||||||
return toJSONError(errInvalidBucketName)
|
return toJSONError(errInvalidBucketName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if globalDNSConfig != nil {
|
||||||
|
if _, err := globalDNSConfig.Get(args.BucketName); err != nil {
|
||||||
|
if etcd.IsKeyNotFound(err) {
|
||||||
|
// Proceed to creating a bucket.
|
||||||
|
if err = objectAPI.MakeBucketWithLocation(context.Background(), args.BucketName, globalServerConfig.GetRegion()); err != nil {
|
||||||
|
return toJSONError(err)
|
||||||
|
}
|
||||||
|
if err = globalDNSConfig.Put(args.BucketName); err != nil {
|
||||||
|
objectAPI.DeleteBucket(context.Background(), args.BucketName)
|
||||||
|
return toJSONError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
reply.UIVersion = browser.UIVersion
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return toJSONError(err)
|
||||||
|
}
|
||||||
|
return toJSONError(errBucketAlreadyExists)
|
||||||
|
}
|
||||||
|
|
||||||
if err := objectAPI.MakeBucketWithLocation(context.Background(), args.BucketName, globalServerConfig.GetRegion()); err != nil {
|
if err := objectAPI.MakeBucketWithLocation(context.Background(), args.BucketName, globalServerConfig.GetRegion()); err != nil {
|
||||||
return toJSONError(err, args.BucketName)
|
return toJSONError(err, args.BucketName)
|
||||||
}
|
}
|
||||||
@ -176,6 +197,14 @@ func (web *webAPIHandlers) DeleteBucket(r *http.Request, args *RemoveBucketArgs,
|
|||||||
logger.LogIf(ctx, nerr.Err)
|
logger.LogIf(ctx, nerr.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if globalDNSConfig != nil {
|
||||||
|
if err := globalDNSConfig.Delete(args.BucketName); err != nil {
|
||||||
|
// Deleting DNS entry failed, attempt to create the bucket again.
|
||||||
|
objectAPI.MakeBucketWithLocation(ctx, args.BucketName, "")
|
||||||
|
return toJSONError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reply.UIVersion = browser.UIVersion
|
reply.UIVersion = browser.UIVersion
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -208,16 +237,32 @@ func (web *webAPIHandlers) ListBuckets(r *http.Request, args *WebGenericArgs, re
|
|||||||
if authErr != nil {
|
if authErr != nil {
|
||||||
return toJSONError(authErr)
|
return toJSONError(authErr)
|
||||||
}
|
}
|
||||||
buckets, err := listBuckets(context.Background())
|
// If etcd, dns federation configured list buckets from etcd.
|
||||||
if err != nil {
|
if globalDNSConfig != nil {
|
||||||
return toJSONError(err)
|
dnsBuckets, err := globalDNSConfig.List()
|
||||||
}
|
if err != nil {
|
||||||
for _, bucket := range buckets {
|
return toJSONError(err)
|
||||||
reply.Buckets = append(reply.Buckets, WebBucketInfo{
|
}
|
||||||
Name: bucket.Name,
|
for _, dnsRecord := range dnsBuckets {
|
||||||
CreationDate: bucket.Created,
|
bucketName := strings.Trim(dnsRecord.Key, "/")
|
||||||
})
|
reply.Buckets = append(reply.Buckets, WebBucketInfo{
|
||||||
|
Name: bucketName,
|
||||||
|
CreationDate: dnsRecord.CreationDate,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buckets, err := listBuckets(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
return toJSONError(err)
|
||||||
|
}
|
||||||
|
for _, bucket := range buckets {
|
||||||
|
reply.Buckets = append(reply.Buckets, WebBucketInfo{
|
||||||
|
Name: bucket.Name,
|
||||||
|
CreationDate: bucket.Created,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reply.UIVersion = browser.UIVersion
|
reply.UIVersion = browser.UIVersion
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ NOTE: `mybucket` only exists on one cluster either `cluster1` or `cluster2` this
|
|||||||
is decided by how `domain.com` gets resolved, if there is a round-robin DNS on `domain.com` then
|
is decided by how `domain.com` gets resolved, if there is a round-robin DNS on `domain.com` then
|
||||||
it is randomized which cluster might provision the bucket.
|
it is randomized which cluster might provision the bucket.
|
||||||
|
|
||||||
TODO: For now the control to create the bucket from a client to the right cluster using `region` paramter
|
TODO: For now the control to create the bucket from a client to the right cluster using `region` parameter
|
||||||
is not implemented yet.
|
is not implemented yet.
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user