2015-04-05 04:53:41 -04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package donut
|
|
|
|
|
2015-04-07 18:55:44 -04:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/minio-io/iodine"
|
|
|
|
)
|
2015-04-05 04:53:41 -04:00
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// donut struct internal data
|
2015-04-05 04:53:41 -04:00
|
|
|
type donut struct {
|
|
|
|
name string
|
|
|
|
buckets map[string]Bucket
|
|
|
|
nodes map[string]Node
|
|
|
|
}
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// config files used inside Donut
|
2015-04-07 18:55:44 -04:00
|
|
|
const (
|
|
|
|
donutObjectMetadataConfig = "donutObjectMetadata.json"
|
|
|
|
objectMetadataConfig = "objectMetadata.json"
|
|
|
|
donutConfig = "donutMetadata.json"
|
|
|
|
)
|
|
|
|
|
2015-04-05 04:53:41 -04:00
|
|
|
// attachDonutNode - wrapper function to instantiate a new node for associated donut
|
2015-04-08 19:28:14 -04:00
|
|
|
// based on the provided configuration
|
2015-04-05 04:53:41 -04:00
|
|
|
func (d donut) attachDonutNode(hostname string, disks []string) error {
|
|
|
|
node, err := NewNode(hostname)
|
|
|
|
if err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(err, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
for i, disk := range disks {
|
|
|
|
// Order is necessary for maps, keep order number separately
|
|
|
|
newDisk, err := NewDisk(disk, i)
|
|
|
|
if err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(err, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
if err := newDisk.MakeDir(d.name); err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(err, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
if err := node.AttachDisk(newDisk); err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(err, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := d.AttachNode(node); err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return iodine.New(err, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewDonut - instantiate a new donut
|
|
|
|
func NewDonut(donutName string, nodeDiskMap map[string][]string) (Donut, error) {
|
|
|
|
if donutName == "" || len(nodeDiskMap) == 0 {
|
2015-04-07 18:55:44 -04:00
|
|
|
return nil, iodine.New(errors.New("invalid argument"), nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
nodes := make(map[string]Node)
|
|
|
|
buckets := make(map[string]Bucket)
|
|
|
|
d := donut{
|
|
|
|
name: donutName,
|
|
|
|
nodes: nodes,
|
|
|
|
buckets: buckets,
|
|
|
|
}
|
|
|
|
for k, v := range nodeDiskMap {
|
|
|
|
if len(v) == 0 {
|
2015-04-07 18:55:44 -04:00
|
|
|
return nil, iodine.New(errors.New("invalid number of disks per node"), nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
err := d.attachDonutNode(k, v)
|
|
|
|
if err != nil {
|
2015-04-07 18:55:44 -04:00
|
|
|
return nil, iodine.New(err, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return d, nil
|
|
|
|
}
|