You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.9 KiB
109 lines
2.9 KiB
10 years ago
|
/*
|
||
|
* Minimalist Object Storage, (C) 2015 Minio, Inc.
|
||
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
10 years ago
|
package donut
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
10 years ago
|
"path/filepath"
|
||
10 years ago
|
|
||
10 years ago
|
"github.com/minio/minio/pkg/donut/disk"
|
||
10 years ago
|
"github.com/minio/minio/pkg/iodine"
|
||
10 years ago
|
)
|
||
|
|
||
10 years ago
|
// Heal - heal a donut and fix bad data blocks
|
||
10 years ago
|
func (donut API) Heal() error {
|
||
10 years ago
|
return iodine.New(NotImplemented{Function: "Heal"}, nil)
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
// Info - return info about donut configuration
|
||
10 years ago
|
func (donut API) Info() (nodeDiskMap map[string][]string, err error) {
|
||
10 years ago
|
nodeDiskMap = make(map[string][]string)
|
||
10 years ago
|
for nodeName, node := range donut.nodes {
|
||
10 years ago
|
disks, err := node.ListDisks()
|
||
|
if err != nil {
|
||
10 years ago
|
return nil, iodine.New(err, nil)
|
||
10 years ago
|
}
|
||
|
diskList := make([]string, len(disks))
|
||
10 years ago
|
for diskOrder, disk := range disks {
|
||
|
diskList[diskOrder] = disk.GetPath()
|
||
10 years ago
|
}
|
||
|
nodeDiskMap[nodeName] = diskList
|
||
|
}
|
||
|
return nodeDiskMap, nil
|
||
|
}
|
||
|
|
||
10 years ago
|
// AttachNode - attach node
|
||
10 years ago
|
func (donut API) AttachNode(hostname string, disks []string) error {
|
||
10 years ago
|
if hostname == "" || len(disks) == 0 {
|
||
10 years ago
|
return iodine.New(InvalidArgument{}, nil)
|
||
10 years ago
|
}
|
||
10 years ago
|
node, err := newNode(hostname)
|
||
|
if err != nil {
|
||
|
return iodine.New(err, nil)
|
||
|
}
|
||
10 years ago
|
donut.nodes[hostname] = node
|
||
10 years ago
|
for i, d := range disks {
|
||
|
newDisk, err := disk.New(d)
|
||
|
if err != nil {
|
||
|
return iodine.New(err, nil)
|
||
|
}
|
||
10 years ago
|
if err := newDisk.MakeDir(donut.config.DonutName); err != nil {
|
||
10 years ago
|
return iodine.New(err, nil)
|
||
|
}
|
||
|
if err := node.AttachDisk(newDisk, i); err != nil {
|
||
|
return iodine.New(err, nil)
|
||
|
}
|
||
|
}
|
||
10 years ago
|
return nil
|
||
|
}
|
||
10 years ago
|
|
||
|
// DetachNode - detach node
|
||
10 years ago
|
func (donut API) DetachNode(hostname string) error {
|
||
|
delete(donut.nodes, hostname)
|
||
10 years ago
|
return nil
|
||
|
}
|
||
|
|
||
10 years ago
|
// SaveConfig - save donut configuration
|
||
10 years ago
|
func (donut API) SaveConfig() error {
|
||
10 years ago
|
nodeDiskMap := make(map[string][]string)
|
||
10 years ago
|
for hostname, node := range donut.nodes {
|
||
10 years ago
|
disks, err := node.ListDisks()
|
||
|
if err != nil {
|
||
10 years ago
|
return iodine.New(err, nil)
|
||
10 years ago
|
}
|
||
10 years ago
|
for order, disk := range disks {
|
||
10 years ago
|
donutConfigPath := filepath.Join(donut.config.DonutName, donutConfig)
|
||
10 years ago
|
donutConfigWriter, err := disk.CreateFile(donutConfigPath)
|
||
10 years ago
|
defer donutConfigWriter.Close()
|
||
|
if err != nil {
|
||
10 years ago
|
return iodine.New(err, nil)
|
||
10 years ago
|
}
|
||
10 years ago
|
nodeDiskMap[hostname][order] = disk.GetPath()
|
||
10 years ago
|
jenc := json.NewEncoder(donutConfigWriter)
|
||
|
if err := jenc.Encode(nodeDiskMap); err != nil {
|
||
10 years ago
|
return iodine.New(err, nil)
|
||
10 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
10 years ago
|
// LoadConfig - load configuration
|
||
10 years ago
|
func (donut API) LoadConfig() error {
|
||
10 years ago
|
return iodine.New(NotImplemented{Function: "LoadConfig"}, nil)
|
||
10 years ago
|
}
|