minio/pkg/donut/management.go

82 lines
2.1 KiB
Go
Raw Normal View History

2015-06-25 15:55:13 -04:00
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
2015-06-25 15:55:13 -04:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package donut
import (
"github.com/minio/minio/pkg/donut/disk"
2015-08-03 19:17:21 -04:00
"github.com/minio/minio/pkg/probe"
)
// Info - return info about donut configuration
2015-08-03 19:17:21 -04:00
func (donut API) Info() (nodeDiskMap map[string][]string, err *probe.Error) {
nodeDiskMap = make(map[string][]string)
for nodeName, n := range donut.nodes {
disks, err := n.ListDisks()
if err != nil {
2015-08-03 19:17:21 -04:00
return nil, err.Trace()
}
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
2015-08-03 19:17:21 -04:00
func (donut API) AttachNode(hostname string, disks []string) *probe.Error {
2015-06-25 15:55:13 -04:00
if hostname == "" || len(disks) == 0 {
return probe.NewError(InvalidArgument{})
}
n, err := newNode(hostname)
2015-06-25 15:55:13 -04:00
if err != nil {
2015-08-03 19:17:21 -04:00
return err.Trace()
2015-06-25 15:55:13 -04:00
}
donut.nodes[hostname] = n
2015-06-25 15:55:13 -04:00
for i, d := range disks {
newDisk, err := disk.New(d)
if err != nil {
continue
2015-06-25 15:55:13 -04:00
}
if err := newDisk.MakeDir(donut.config.DonutName); err != nil {
2015-08-03 19:17:21 -04:00
return err.Trace()
2015-06-25 15:55:13 -04:00
}
if err := n.AttachDisk(newDisk, i); err != nil {
2015-08-03 19:17:21 -04:00
return err.Trace()
2015-06-25 15:55:13 -04:00
}
}
return nil
}
// DetachNode - detach node
2015-08-03 19:17:21 -04:00
func (donut API) DetachNode(hostname string) *probe.Error {
delete(donut.nodes, hostname)
return nil
}
// Rebalance - rebalance an existing donut with new disks and nodes
2015-08-03 19:17:21 -04:00
func (donut API) Rebalance() *probe.Error {
return probe.NewError(APINotImplemented{API: "management.Rebalance"})
}
// Heal - heal your donuts
2015-08-03 19:17:21 -04:00
func (donut API) Heal() *probe.Error {
// TODO handle data heal
return donut.healBuckets()
}