2015-04-07 00:42:54 -04:00
|
|
|
package donut
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"path"
|
2015-04-07 18:55:44 -04:00
|
|
|
|
2015-05-11 19:23:10 -04:00
|
|
|
"github.com/minio/minio/pkg/iodine"
|
2015-04-07 00:42:54 -04:00
|
|
|
)
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// Heal - heal a donut and fix bad data blocks
|
2015-04-07 00:42:54 -04:00
|
|
|
func (d donut) Heal() error {
|
|
|
|
return errors.New("Not Implemented")
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// Info - return info about donut configuration
|
2015-04-07 00:42:54 -04:00
|
|
|
func (d donut) Info() (nodeDiskMap map[string][]string, err error) {
|
|
|
|
nodeDiskMap = make(map[string][]string)
|
|
|
|
for nodeName, node := range d.nodes {
|
|
|
|
disks, err := node.ListDisks()
|
|
|
|
if err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return nil, iodine.New(err, nil)
|
2015-04-07 00:42:54 -04:00
|
|
|
}
|
|
|
|
diskList := make([]string, len(disks))
|
|
|
|
for diskName, disk := range disks {
|
|
|
|
diskList[disk.GetOrder()] = diskName
|
|
|
|
}
|
|
|
|
nodeDiskMap[nodeName] = diskList
|
|
|
|
}
|
|
|
|
return nodeDiskMap, nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// AttachNode - attach node
|
2015-04-07 00:42:54 -04:00
|
|
|
func (d donut) AttachNode(node Node) error {
|
|
|
|
if node == nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(errors.New("invalid argument"), nil)
|
2015-04-07 00:42:54 -04:00
|
|
|
}
|
|
|
|
d.nodes[node.GetNodeName()] = node
|
|
|
|
return nil
|
|
|
|
}
|
2015-04-08 19:28:14 -04:00
|
|
|
|
|
|
|
// DetachNode - detach node
|
2015-04-07 00:42:54 -04:00
|
|
|
func (d donut) DetachNode(node Node) error {
|
|
|
|
delete(d.nodes, node.GetNodeName())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// SaveConfig - save donut configuration
|
2015-04-07 00:42:54 -04:00
|
|
|
func (d donut) SaveConfig() error {
|
|
|
|
nodeDiskMap := make(map[string][]string)
|
|
|
|
for hostname, node := range d.nodes {
|
|
|
|
disks, err := node.ListDisks()
|
|
|
|
if err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(err, nil)
|
2015-04-07 00:42:54 -04:00
|
|
|
}
|
|
|
|
for _, disk := range disks {
|
|
|
|
donutConfigPath := path.Join(d.name, donutConfig)
|
|
|
|
donutConfigWriter, err := disk.MakeFile(donutConfigPath)
|
|
|
|
defer donutConfigWriter.Close()
|
|
|
|
if err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(err, nil)
|
2015-04-07 00:42:54 -04:00
|
|
|
}
|
|
|
|
nodeDiskMap[hostname][disk.GetOrder()] = disk.GetPath()
|
|
|
|
jenc := json.NewEncoder(donutConfigWriter)
|
|
|
|
if err := jenc.Encode(nodeDiskMap); err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(err, nil)
|
2015-04-07 00:42:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// LoadConfig - load configuration
|
2015-04-07 00:42:54 -04:00
|
|
|
func (d donut) LoadConfig() error {
|
|
|
|
return errors.New("Not Implemented")
|
|
|
|
}
|