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
+1 -1
View File
@@ -28,7 +28,7 @@
},
{
"ImportPath": "github.com/minio-io/donut",
"Rev": "015ee96537c51e28b086edac90117e585b4b459a"
"Rev": "a2932a1269212cb6aed1851b3e95a0e2094f4a7a"
},
{
"ImportPath": "github.com/minio-io/erasure",
+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
+75 -68
View File
@@ -22,18 +22,20 @@ import (
"github.com/minio-io/cli"
)
var cpCmd = cli.Command{
Name: "cp",
Usage: "copy objects and files",
Description: "Copy files and objects recursively between Amazon S3, Donut and Filesystem",
Action: doCopyCmd,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "recursive, r",
Usage: "recursively crawls a given directory or bucket",
// List of commands
var (
cpCmd = cli.Command{
Name: "cp",
Usage: "copy objects and files",
Description: "Copy files and objects recursively between Amazon S3, Donut and Filesystem",
Action: doCopyCmd,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "recursive, r",
Usage: "recursively crawls a given directory or bucket",
},
},
},
CustomHelpTemplate: `NAME:
CustomHelpTemplate: `NAME:
mc {{.Name}} - {{.Usage}}
USAGE:
@@ -56,14 +58,14 @@ EXAMPLES:
$ mc {{.Name}} --recursive backup/ donut://archive/backup/ https://s3.amazonaws.com/backup/
`,
}
}
var lsCmd = cli.Command{
Name: "ls",
Usage: "list files and objects",
Description: `List files and objects recursively between Amazon S3, Donut and Filesystem`,
Action: doListCmd,
CustomHelpTemplate: `NAME:
lsCmd = cli.Command{
Name: "ls",
Usage: "list files and objects",
Description: `List files and objects recursively between Amazon S3, Donut and Filesystem`,
Action: doListCmd,
CustomHelpTemplate: `NAME:
mc {{.Name}} - {{.Usage}}
USAGE:
@@ -88,53 +90,54 @@ EXAMPLES:
2015-01-15 00:05:40 PST zek
`,
}
}
var mbCmd = cli.Command{
Name: "mb",
Usage: "makes a bucket",
Description: "Creates an S3 bucket",
Action: doMakeBucketCmd,
}
mbCmd = cli.Command{
Name: "mb",
Usage: "makes a bucket",
Description: "Creates an S3 bucket",
Action: doMakeBucketCmd,
}
var configCmd = cli.Command{
Name: "config",
Usage: "Generate configuration \"" + getMcConfigFilename() + "\" file.",
Description: `Configure minio client configuration data. If your config
configCmd = cli.Command{
Name: "config",
Usage: "Generate configuration \"" + getMcConfigFilename() + "\" file.",
Description: `Configure minio client configuration data. If your config
file does not exist (the default location is ~/.auth), it will be
automatically created for you. Note that the configure command only writes
values to the config file. It does not use any configuration values from
the environment variables.`,
Action: doConfigCmd,
Flags: []cli.Flag{
cli.StringFlag{
Name: "accesskeyid, a",
Value: "",
Usage: "AWS access key ID",
Action: doConfigCmd,
Flags: []cli.Flag{
cli.StringFlag{
Name: "accesskeyid, a",
Value: "",
Usage: "AWS access key ID",
},
cli.StringFlag{
Name: "secretkey, s",
Value: "",
Usage: "AWS secret access key",
},
cli.StringFlag{
Name: "alias",
Value: "",
Usage: "Add aliases into config",
},
cli.BoolFlag{
Name: "completion",
Usage: "Generate bash completion \"" + getMcBashCompletionFilename() + "\" file.",
},
},
cli.StringFlag{
Name: "secretkey, s",
Value: "",
Usage: "AWS secret access key",
},
cli.StringFlag{
Name: "alias",
Value: "",
Usage: "Add aliases into config",
},
cli.BoolFlag{
Name: "completion",
Usage: "Generate bash completion \"" + getMcBashCompletionFilename() + "\" file.",
},
},
}
}
var donutCmd = cli.Command{
Name: "donut",
Usage: "donut admin",
Description: "",
Subcommands: donutOptions,
}
donutCmd = cli.Command{
Name: "donut",
Usage: "donut admin",
Description: "",
Subcommands: donutOptions,
}
)
type object struct {
scheme string // protocol type: possible values are http, https, donut, nil
@@ -160,18 +163,21 @@ var options = []cli.Command{
configCmd,
}
var flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "enable HTTP tracing",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "disable chatty output, such as the progress bar",
},
}
var (
flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "enable HTTP tracing",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "disable chatty output, such as the progress bar",
},
}
)
var mcBashCompletion = `#!/bin/bash
var (
mcBashCompletion = `#!/bin/bash
_mc_completion() {
local cur prev opts base
@@ -185,3 +191,4 @@ _mc_completion() {
complete -F _mc_completion mc
`
)