2015-03-22 03:39:39 -04:00
|
|
|
package donut
|
|
|
|
|
2015-03-24 22:58:03 -04:00
|
|
|
import (
|
|
|
|
"errors"
|
2015-03-25 20:05:23 -04:00
|
|
|
"github.com/minio-io/iodine"
|
2015-03-24 22:58:03 -04:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-03-23 23:40:21 -04:00
|
|
|
type donutBucket struct {
|
2015-03-22 03:39:39 -04:00
|
|
|
nodes []string
|
|
|
|
objects map[string][]byte
|
|
|
|
}
|
|
|
|
|
2015-03-23 23:40:21 -04:00
|
|
|
// GetNodes - get list of associated nodes for a given bucket
|
2015-03-25 22:12:39 -04:00
|
|
|
func (b donutBucket) GetNodes() ([]string, error) {
|
2015-03-22 03:39:39 -04:00
|
|
|
var nodes []string
|
2015-03-22 05:53:21 -04:00
|
|
|
for _, node := range b.nodes {
|
2015-03-22 03:39:39 -04:00
|
|
|
nodes = append(nodes, node)
|
|
|
|
}
|
|
|
|
return nodes, nil
|
|
|
|
}
|
2015-03-24 22:58:03 -04:00
|
|
|
|
2015-03-25 22:12:39 -04:00
|
|
|
// AddNode - adds a node to a bucket
|
|
|
|
func (b donutBucket) AddNode(nodeID, bucketID string) error {
|
2015-03-26 13:02:40 -04:00
|
|
|
errParams := map[string]string{"node": nodeID, "bucketID": bucketID}
|
2015-03-24 22:58:03 -04:00
|
|
|
tokens := strings.Split(bucketID, ":")
|
|
|
|
if len(tokens) != 3 {
|
2015-03-26 18:55:06 -04:00
|
|
|
return iodine.New(errors.New("Bucket ID malformeD: "+bucketID), errParams)
|
2015-03-25 22:12:39 -04:00
|
|
|
|
2015-03-24 22:58:03 -04:00
|
|
|
}
|
|
|
|
// bucketName := tokens[0]
|
|
|
|
// aggregate := tokens[1]
|
|
|
|
// aggregate := "0"
|
|
|
|
part, err := strconv.Atoi(tokens[2])
|
|
|
|
if err != nil {
|
2015-03-26 18:55:06 -04:00
|
|
|
return iodine.New(errors.New("Part malformed: "+tokens[2]), errParams)
|
2015-03-24 22:58:03 -04:00
|
|
|
}
|
|
|
|
b.nodes[part] = nodeID
|
|
|
|
return nil
|
|
|
|
}
|