2015-04-07 00:42:54 -04:00
|
|
|
package donut
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2015-06-18 19:02:34 -04:00
|
|
|
"path/filepath"
|
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 {
|
2015-06-23 14:44:32 -04:00
|
|
|
return iodine.New(NotImplemented{Function: "Heal"}, nil)
|
2015-04-07 00:42:54 -04:00
|
|
|
}
|
|
|
|
|
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-06-23 14:44:32 -04:00
|
|
|
return iodine.New(InvalidArgument{}, 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 {
|
2015-06-18 19:02:34 -04:00
|
|
|
donutConfigPath := filepath.Join(d.name, donutConfig)
|
2015-04-07 00:42:54 -04:00
|
|
|
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 {
|
2015-06-23 14:44:32 -04:00
|
|
|
return iodine.New(NotImplemented{Function: "LoadConfig"}, nil)
|
2015-04-07 00:42:54 -04:00
|
|
|
}
|