Update donut to new changes at minio-io/donut

This commit is contained in:
Harshavardhana
2015-04-02 18:36:16 -07:00
parent 7cf882f33e
commit cbbe7bd8b2
10 changed files with 208 additions and 106 deletions
+2 -2
View File
@@ -7,8 +7,8 @@
"Deps": [
{
"ImportPath": "github.com/minio-io/cli",
"Comment": "1.2.0-100-g6d6f8d3",
"Rev": "6d6f8d3cc162bfcb60379888e2f37d73ff6a6253"
"Comment": "1.2.0-101-g1a25bbd",
"Rev": "1a25bbdce2344b0063ea0476bceb4a4adbe4492a"
},
{
"ImportPath": "github.com/minio-io/erasure",
+1 -1
View File
@@ -61,7 +61,7 @@ docs-deploy:
install: test-all
@echo "Installing donut-cli:"
@godep go install github.com/minio-io/donut/cmd/donut-cli
@godep go install -a github.com/minio-io/donut/cmd/donut-cli
@mkdir -p $(HOME)/.minio/donut
clean:
+5 -3
View File
@@ -19,7 +19,7 @@ func (b bucket) decodeData(totalLeft, blockSize int64, readers []io.ReadCloser,
if err != nil {
return nil, err
}
encodedBytes := make([][]byte, 16)
encodedBytes := make([][]byte, len(readers))
for i, reader := range readers {
var bytesBuffer bytes.Buffer
_, err := io.CopyN(&bytesBuffer, reader, int64(curChunkSize))
@@ -45,13 +45,14 @@ func (b bucket) metadata2Values(donutObjectMetadata map[string]string) (totalChu
}
func (b bucket) getDiskReaders(objectName, objectMeta string) ([]io.ReadCloser, error) {
readers := make([]io.ReadCloser, 16)
var readers []io.ReadCloser
nodeSlice := 0
for _, node := range b.nodes {
disks, err := node.ListDisks()
if err != nil {
return nil, err
}
readers = make([]io.ReadCloser, len(disks))
for _, disk := range disks {
bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder())
objectPath := path.Join(b.donutName, bucketSlice, objectName, objectMeta)
@@ -67,13 +68,14 @@ func (b bucket) getDiskReaders(objectName, objectMeta string) ([]io.ReadCloser,
}
func (b bucket) getDiskWriters(objectName, objectMeta string) ([]io.WriteCloser, error) {
writers := make([]io.WriteCloser, 16)
var writers []io.WriteCloser
nodeSlice := 0
for _, node := range b.nodes {
disks, err := node.ListDisks()
if err != nil {
return nil, err
}
writers = make([]io.WriteCloser, len(disks))
for _, disk := range disks {
bucketSlice := fmt.Sprintf("%s$%d$%d", b.name, nodeSlice, disk.GetOrder())
objectPath := path.Join(b.donutName, bucketSlice, objectName, objectMeta)
@@ -0,0 +1,88 @@
/*
* Minimalist Object Storage, (C) 2014,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 main
import (
"log"
"os"
"strings"
"text/tabwriter"
"text/template"
"github.com/minio-io/cli"
"github.com/minio-io/donut"
)
var infoTemplate = `
{{range $donutName, $nodes := .}}
DONUTNAME: {{$donutName}}
{{range $nodeName, $disks := $nodes}}
NODE: {{$nodeName}}
DISKS: {{$disks}}
{{end}}
{{end}}
`
var infoPrinter = func(templ string, data interface{}) {
funcMap := template.FuncMap{
"join": strings.Join,
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
err := t.Execute(w, data)
if err != nil {
panic(err)
}
w.Flush()
}
// doInfoDonutCmd
func doInfoDonutCmd(c *cli.Context) {
if !c.Args().Present() {
log.Fatalln("no args?")
}
if len(c.Args()) != 1 {
log.Fatalln("invalid number of args")
}
donutName := c.Args().First()
if !isValidDonutName(donutName) {
log.Fatalln("Invalid donutName")
}
mcDonutConfigData, err := loadDonutConfig()
if err != nil {
log.Fatalln(err)
}
if _, ok := mcDonutConfigData.Donuts[donutName]; !ok {
log.Fatalln("donut does not exist")
}
nodes := make(map[string][]string)
for k, v := range mcDonutConfigData.Donuts[donutName].Node {
nodes[k] = v.ActiveDisks
}
d, err := donut.NewDonut(donutName, nodes)
if err != nil {
log.Fatalln(err)
}
donutNodes := make(map[string]map[string][]string)
donutNodes[donutName], err = d.Info()
if err != nil {
log.Fatalln(err)
}
infoPrinter(infoTemplate, donutNodes)
}
@@ -19,41 +19,18 @@ package main
import (
"fmt"
"log"
"strings"
"net/url"
"github.com/minio-io/cli"
"github.com/minio-io/donut"
)
// doMakeDonutBucketCmd creates a new bucket
func doMakeDonutBucketCmd(c *cli.Context) {
if !c.Args().Present() {
log.Fatalln("no args?")
}
urlArg1, err := url.Parse(c.Args().First())
if err != nil {
log.Fatalln(err)
}
// doListDonutCmd creates a new bucket
func doListDonutCmd(c *cli.Context) {
mcDonutConfigData, err := loadDonutConfig()
if err != nil {
log.Fatalln(err)
}
if _, ok := mcDonutConfigData.Donuts[urlArg1.Host]; !ok {
msg := fmt.Sprintf("requested donut: <%s> does not exist", urlArg1.Host)
log.Fatalln(msg)
}
nodes := make(map[string][]string)
for k, v := range mcDonutConfigData.Donuts[urlArg1.Host].Node {
nodes[k] = v.ActiveDisks
}
d, err := donut.NewDonut(urlArg1.Host, nodes)
if err != nil {
log.Fatalln(err)
}
err = d.MakeBucket(strings.TrimPrefix(urlArg1.Path, "/"))
if err != nil {
log.Fatalln(err)
for k := range mcDonutConfigData.Donuts {
fmt.Println(k)
}
}
@@ -27,6 +27,13 @@ var makeDonutCmd = cli.Command{
Action: doMakeDonutCmd,
}
var listDonutCmd = cli.Command{
Name: "list",
Usage: "list donuts",
Description: "list all donuts locally or remote",
Action: doListDonutCmd,
}
var attachDiskCmd = cli.Command{
Name: "attach",
Usage: "attach disk",
@@ -67,12 +74,21 @@ var rebalanceDonutCmd = cli.Command{
Action: doRebalanceDonutCmd,
}
var infoDonutCmd = cli.Command{
Name: "info",
Usage: "information about donut",
Description: "Pretty print donut information",
Action: doInfoDonutCmd,
}
var donutOptions = []cli.Command{
makeDonutCmd,
listDonutCmd,
attachDiskCmd,
detachDiskCmd,
healDonutCmd,
rebalanceDonutCmd,
infoDonutCmd,
}
func doHealDonutCmd(c *cli.Context) {
+14 -2
View File
@@ -134,8 +134,20 @@ func (d donut) Rebalance() error {
return errors.New("Not Implemented")
}
func (d donut) Info() error {
return errors.New("Not Implemented")
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, err
}
diskList := make([]string, len(disks))
for diskName, disk := range disks {
diskList[disk.GetOrder()] = diskName
}
nodeDiskMap[nodeName] = diskList
}
return nodeDiskMap, nil
}
func (d donut) AttachNode(node Node) error {
+1 -1
View File
@@ -14,7 +14,7 @@ type Donut interface {
Heal() error
Rebalance() error
Info() error
Info() (map[string][]string, error)
AttachNode(node Node) error
DetachNode(node Node) error