minio/pkg/storage/donut/management.go

76 lines
1.8 KiB
Go
Raw Normal View History

package donut
import (
"encoding/json"
"path/filepath"
2015-05-11 19:23:10 -04:00
"github.com/minio/minio/pkg/iodine"
)
// Heal - heal a donut and fix bad data blocks
func (d donut) Heal() error {
return iodine.New(NotImplemented{Function: "Heal"}, nil)
}
// Info - return info about donut configuration
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 {
return nil, iodine.New(err, nil)
}
diskList := make([]string, len(disks))
2015-06-24 23:34:20 -04:00
for diskOrder, disk := range disks {
diskList[diskOrder] = disk.GetPath()
}
nodeDiskMap[nodeName] = diskList
}
return nodeDiskMap, nil
}
// AttachNode - attach node
func (d donut) AttachNode(node Node) error {
if node == nil {
return iodine.New(InvalidArgument{}, nil)
}
d.nodes[node.GetNodeName()] = node
return nil
}
// DetachNode - detach node
func (d donut) DetachNode(node Node) error {
delete(d.nodes, node.GetNodeName())
return nil
}
// SaveConfig - save donut configuration
func (d donut) SaveConfig() error {
nodeDiskMap := make(map[string][]string)
for hostname, node := range d.nodes {
disks, err := node.ListDisks()
if err != nil {
return iodine.New(err, nil)
}
2015-06-24 23:34:20 -04:00
for order, disk := range disks {
donutConfigPath := filepath.Join(d.name, donutConfig)
2015-06-24 23:34:20 -04:00
donutConfigWriter, err := disk.CreateFile(donutConfigPath)
defer donutConfigWriter.Close()
if err != nil {
return iodine.New(err, nil)
}
2015-06-24 23:34:20 -04:00
nodeDiskMap[hostname][order] = disk.GetPath()
jenc := json.NewEncoder(donutConfigWriter)
if err := jenc.Encode(nodeDiskMap); err != nil {
return iodine.New(err, nil)
}
}
}
return nil
}
// LoadConfig - load configuration
func (d donut) LoadConfig() error {
return iodine.New(NotImplemented{Function: "LoadConfig"}, nil)
}