Make everything as packages
- minio-io/erasure - minio-io/donut
This commit is contained in:
Generated
+6
-2
@@ -27,8 +27,12 @@
|
||||
"Rev": "1ee5c115af7856a16f133e2f2d3d9f91895c2ddb"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio-io/iodine",
|
||||
"Rev": "8c8985d5a45e388dccb5ca280c897672abb18278"
|
||||
"ImportPath": "github.com/minio-io/donut",
|
||||
"Rev": "6590e6727612b90b4373e4f42b898ee159251cde"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio-io/erasure",
|
||||
"Rev": "6e3a142ee5ce194be6339cdde8e89c094b2ec7fd"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio-io/minio/pkg/utils/split",
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
donut
|
||||
build-constants.go
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"ImportPath": "github.com/minio-io/donut",
|
||||
"GoVersion": "go1.4",
|
||||
"Packages": [
|
||||
"./..."
|
||||
],
|
||||
"Deps": [
|
||||
{
|
||||
"ImportPath": "github.com/minio-io/cli",
|
||||
"Comment": "1.2.0-99-g1ee5c11",
|
||||
"Rev": "1ee5c115af7856a16f133e2f2d3d9f91895c2ddb"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio-io/erasure",
|
||||
"Rev": "6e3a142ee5ce194be6339cdde8e89c094b2ec7fd"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio-io/minio/pkg/utils/split",
|
||||
"Rev": "936520e6e0fc5dd4ce8d04504ee991084555e57a"
|
||||
}
|
||||
]
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
This directory tree is generated automatically by godep.
|
||||
|
||||
Please do not edit.
|
||||
|
||||
See https://github.com/tools/godep for more information.
|
||||
Generated
Vendored
+71
@@ -0,0 +1,71 @@
|
||||
MINIOPATH=$(GOPATH)/src/github.com/minio-io/donut
|
||||
|
||||
all: getdeps install
|
||||
|
||||
checkdeps:
|
||||
@echo "Checking deps:"
|
||||
@(env bash $(PWD)/buildscripts/checkdeps.sh)
|
||||
|
||||
checkgopath:
|
||||
@echo "Checking if project is at ${MINIOPATH}"
|
||||
@if [ ! -d ${MINIOPATH} ]; then echo "Project not found in $GOPATH, please follow instructions provided at https://github.com/Minio-io/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" && exit 1; fi
|
||||
|
||||
getdeps: checkdeps checkgopath
|
||||
@go get github.com/tools/godep && echo "Installed godep:"
|
||||
@go get github.com/golang/lint/golint && echo "Installed golint:"
|
||||
@go get golang.org/x/tools/cmd/vet && echo "Installed vet:"
|
||||
@go get github.com/fzipp/gocyclo && echo "Installed gocyclo:"
|
||||
|
||||
verifiers: getdeps vet fmt lint cyclo
|
||||
|
||||
vet:
|
||||
@echo "Running $@:"
|
||||
@go vet ./...
|
||||
fmt:
|
||||
@echo "Running $@:"
|
||||
@test -z "$$(gofmt -s -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)" || \
|
||||
echo "+ please format Go code with 'gofmt -s'"
|
||||
lint:
|
||||
@echo "Running $@:"
|
||||
@test -z "$$(golint ./... | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
|
||||
|
||||
cyclo:
|
||||
@echo "Running $@:"
|
||||
@test -z "$$(gocyclo -over 15 . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
|
||||
|
||||
pre-build:
|
||||
@echo "Running pre-build:"
|
||||
@(env bash $(PWD)/buildscripts/git-commit-id.sh)
|
||||
|
||||
|
||||
build-all: getdeps verifiers
|
||||
@echo "Building Libraries:"
|
||||
@godep go generate github.com/minio-io/erasure
|
||||
@godep go generate ./...
|
||||
@godep go build ./...
|
||||
|
||||
test-all: pre-build build-all
|
||||
@echo "Running Test Suites:"
|
||||
@godep go test -race ./...
|
||||
|
||||
save: restore
|
||||
@godep save ./...
|
||||
|
||||
restore:
|
||||
@godep restore
|
||||
|
||||
env:
|
||||
@godep go env
|
||||
|
||||
docs-deploy:
|
||||
@mkdocs gh-deploy --clean
|
||||
|
||||
install: test-all
|
||||
@echo "Installing donut-cli:"
|
||||
@godep go install github.com/minio-io/donut/cmd/donut-cli
|
||||
@mkdir -p $(HOME)/.minio/donut
|
||||
|
||||
clean:
|
||||
@rm -fv cover.out
|
||||
@rm -fv erasure/*.syso
|
||||
@rm -fv build-constants.go
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# Donut
|
||||
|
||||
donut - Donut (do not delete) on disk format implementation released under [Apache license v2](./LICENSE).
|
||||
Generated
Vendored
Generated
Vendored
+201
@@ -0,0 +1,201 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Minio Commander, (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.
|
||||
#
|
||||
|
||||
_init() {
|
||||
## Minimum required versions for build dependencies
|
||||
GCC_VERSION="4.0"
|
||||
CLANG_VERSION="3.5"
|
||||
YASM_VERSION="1.2.0"
|
||||
GIT_VERSION="1.0"
|
||||
GO_VERSION="1.4"
|
||||
OSX_VERSION="10.8"
|
||||
UNAME=$(uname -sm)
|
||||
|
||||
## Check all dependencies are present
|
||||
MISSING=""
|
||||
}
|
||||
|
||||
###
|
||||
#
|
||||
# Takes two arguments
|
||||
# arg1: version number in `x.x.x` format
|
||||
# arg2: version number in `x.x.x` format
|
||||
#
|
||||
# example: check_version "$version1" "$version2"
|
||||
#
|
||||
# returns:
|
||||
# 0 - Installed version is equal to required
|
||||
# 1 - Installed version is greater than required
|
||||
# 2 - Installed version is lesser than required
|
||||
# 3 - If args have length zero
|
||||
#
|
||||
####
|
||||
check_version () {
|
||||
## validate args
|
||||
[[ -z "$1" ]] && return 3
|
||||
[[ -z "$2" ]] && return 3
|
||||
|
||||
if [[ $1 == $2 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local IFS=.
|
||||
local i ver1=($1) ver2=($2)
|
||||
# fill empty fields in ver1 with zeros
|
||||
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
|
||||
ver1[i]=0
|
||||
done
|
||||
for ((i=0; i<${#ver1[@]}; i++)); do
|
||||
if [[ -z ${ver2[i]} ]]; then
|
||||
# fill empty fields in ver2 with zeros
|
||||
ver2[i]=0
|
||||
fi
|
||||
if ((10#${ver1[i]} > 10#${ver2[i]})); then
|
||||
|
||||
return 1
|
||||
fi
|
||||
if ((10#${ver1[i]} < 10#${ver2[i]})); then
|
||||
## Installed version is lesser than required - Bad condition
|
||||
return 2
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
check_golang_env() {
|
||||
echo ${GOROOT:?} 2>&1 >/dev/null
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "ERROR"
|
||||
echo "GOROOT environment variable missing, please refer to Go installation document"
|
||||
echo "https://github.com/Minio-io/minio/blob/master/BUILDDEPS.md#install-go-13"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ${GOPATH:?} 2>&1 >/dev/null
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "ERROR"
|
||||
echo "GOPATH environment variable missing, please refer to Go installation document"
|
||||
echo "https://github.com/Minio-io/minio/blob/master/BUILDDEPS.md#install-go-13"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
is_supported_os() {
|
||||
case ${UNAME%% *} in
|
||||
"Linux")
|
||||
os="linux"
|
||||
;;
|
||||
"Darwin")
|
||||
osx_host_version=$(env sw_vers -productVersion)
|
||||
check_version "${osx_host_version}" "${OSX_VERSION}"
|
||||
[[ $? -ge 2 ]] && die "Minimum OSX version supported is ${OSX_VERSION}"
|
||||
;;
|
||||
"*")
|
||||
echo "Exiting.. unsupported operating system found"
|
||||
exit 1;
|
||||
esac
|
||||
}
|
||||
|
||||
is_supported_arch() {
|
||||
local supported
|
||||
case ${UNAME##* } in
|
||||
"x86_64")
|
||||
supported=1
|
||||
;;
|
||||
*)
|
||||
supported=0
|
||||
;;
|
||||
esac
|
||||
if [ $supported -eq 0 ]; then
|
||||
echo "Invalid arch: ${UNAME} not supported, please use x86_64/amd64"
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
check_deps() {
|
||||
check_version "$(env go version 2>/dev/null | sed 's/^.* go\([0-9.]*\).*$/\1/')" "${GO_VERSION}"
|
||||
if [ $? -ge 2 ]; then
|
||||
MISSING="${MISSING} golang(1.4)"
|
||||
fi
|
||||
|
||||
check_version "$(env git --version 2>/dev/null | sed -e 's/^.* \([0-9.\].*\).*$/\1/' -e 's/^\([0-9.\]*\).*/\1/g')" "${GIT_VERSION}"
|
||||
if [ $? -ge 2 ]; then
|
||||
MISSING="${MISSING} git"
|
||||
fi
|
||||
|
||||
case ${UNAME%% *} in
|
||||
"Linux")
|
||||
check_version "$(env gcc --version 2>/dev/null | sed 's/^.* \([0-9.]*\).*$/\1/' | head -1)" "${GCC_VERSION}"
|
||||
if [ $? -ge 2 ]; then
|
||||
MISSING="${MISSING} build-essential"
|
||||
fi
|
||||
;;
|
||||
"Darwin")
|
||||
check_version "$(env gcc --version 2>/dev/null | sed 's/^.* \([0-9.]*\).*$/\1/' | head -1)" "${CLANG_VERSION}"
|
||||
if [ $? -ge 2 ]; then
|
||||
MISSING="${MISSING} xcode-cli"
|
||||
fi
|
||||
;;
|
||||
"*")
|
||||
;;
|
||||
esac
|
||||
|
||||
check_version "$(env yasm --version 2>/dev/null | sed 's/^.* \([0-9.]*\).*$/\1/' | head -1)" "${YASM_VERSION}"
|
||||
if [ $? -ge 2 ]; then
|
||||
MISSING="${MISSING} yasm(1.2.0)"
|
||||
fi
|
||||
|
||||
env mkdocs help >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
MISSING="${MISSING} mkdocs"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
echo -n "Check for supported arch.. "
|
||||
is_supported_arch
|
||||
|
||||
echo -n "Check for supported os.. "
|
||||
is_supported_os
|
||||
|
||||
echo -n "Checking if proper environment variables are set.. "
|
||||
check_golang_env
|
||||
|
||||
echo "Done"
|
||||
echo "Using GOPATH=${GOPATH} and GOROOT=${GOROOT}"
|
||||
|
||||
echo -n "Checking dependencies for Minio.. "
|
||||
check_deps
|
||||
|
||||
## If dependencies are missing, warn the user and abort
|
||||
if [ "x${MISSING}" != "x" ]; then
|
||||
echo "ERROR"
|
||||
echo
|
||||
echo "The following build tools are missing:"
|
||||
echo
|
||||
echo "** ${MISSING} **"
|
||||
echo
|
||||
echo "Please install them "
|
||||
echo "${MISSING}"
|
||||
echo
|
||||
echo "Follow https://github.com/Minio-io/minio/blob/master/BUILDDEPS.md for further instructions"
|
||||
exit 1
|
||||
fi
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
_init && main "$@"
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CONST_FILE=${PWD}/cmd/donut-cli/build-constants.go
|
||||
|
||||
cat > $CONST_FILE <<EOF
|
||||
/*
|
||||
* ** DO NOT EDIT THIS FILE. THIS FILE IS AUTO GENERATED BY RUNNING MAKE **
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
gitCommitHash = "__GIT_COMMIT_HASH__"
|
||||
)
|
||||
EOF
|
||||
|
||||
commit_id=$(git log --format="%H" -n 1)
|
||||
sed -i "s/__GIT_COMMIT_HASH__/$commit_id/" $CONST_FILE
|
||||
@@ -0,0 +1 @@
|
||||
donut-cli
|
||||
Generated
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
func doAttachDiskCmd(c *cli.Context) {
|
||||
if !c.Args().Present() {
|
||||
log.Fatalln("no args?")
|
||||
}
|
||||
disks := c.Args()
|
||||
mcDonutConfigData, err := loadDonutConfig()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
donutName := c.String("name")
|
||||
if donutName == "" {
|
||||
log.Fatalln("Invalid --donut <name> is needed for attach")
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName]; !ok {
|
||||
log.Fatalf("Requested donut name %s does not exist, please use ``mc donut make`` first\n", donutName)
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName].Node["localhost"]; !ok {
|
||||
log.Fatalln("Corrupted donut config, please consult donut experts")
|
||||
}
|
||||
activeDisks := mcDonutConfigData.Donuts[donutName].Node["localhost"].ActiveDisks
|
||||
inactiveDisks := mcDonutConfigData.Donuts[donutName].Node["localhost"].InactiveDisks
|
||||
for _, disk := range disks {
|
||||
activeDisks = appendUniq(activeDisks, disk)
|
||||
inactiveDisks = deleteFromSlice(inactiveDisks, disk)
|
||||
}
|
||||
|
||||
mcDonutConfigData.Donuts[donutName].Node["localhost"] = nodeConfig{
|
||||
ActiveDisks: activeDisks,
|
||||
InactiveDisks: inactiveDisks,
|
||||
}
|
||||
if err := saveDonutConfig(mcDonutConfigData); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// url2Object converts URL to bucket and objectname
|
||||
func url2Object(urlStr string) (bucketName, objectName string, err error) {
|
||||
u, err := url.Parse(urlStr)
|
||||
if u.Path == "" {
|
||||
// No bucket name passed. It is a valid case
|
||||
return "", "", nil
|
||||
}
|
||||
splits := strings.SplitN(u.Path, "/", 3)
|
||||
switch len(splits) {
|
||||
case 0, 1:
|
||||
bucketName = ""
|
||||
objectName = ""
|
||||
case 2:
|
||||
bucketName = splits[1]
|
||||
objectName = ""
|
||||
case 3:
|
||||
bucketName = splits[1]
|
||||
objectName = splits[2]
|
||||
}
|
||||
return bucketName, objectName, nil
|
||||
}
|
||||
|
||||
func isStringInSlice(items []string, item string) bool {
|
||||
for _, s := range items {
|
||||
if s == item {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func deleteFromSlice(items []string, item string) []string {
|
||||
var newitems []string
|
||||
for _, s := range items {
|
||||
if s == item {
|
||||
continue
|
||||
}
|
||||
newitems = append(newitems, s)
|
||||
}
|
||||
return newitems
|
||||
}
|
||||
|
||||
func appendUniq(slice []string, i string) []string {
|
||||
for _, ele := range slice {
|
||||
if ele == i {
|
||||
return slice
|
||||
}
|
||||
}
|
||||
return append(slice, i)
|
||||
}
|
||||
|
||||
// Is alphanumeric?
|
||||
func isalnum(c rune) bool {
|
||||
return '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'
|
||||
}
|
||||
|
||||
// isValidDonutName - verify donutName to be valid
|
||||
func isValidDonutName(donutName string) bool {
|
||||
if len(donutName) > 1024 || len(donutName) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, char := range donutName {
|
||||
if isalnum(char) {
|
||||
continue
|
||||
}
|
||||
switch char {
|
||||
case '-':
|
||||
case '.':
|
||||
case '_':
|
||||
case '~':
|
||||
continue
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Generated
Vendored
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
const (
|
||||
donutConfigDir = ".minio/donut"
|
||||
donutConfigFilename = "donuts.json"
|
||||
)
|
||||
|
||||
type nodeConfig struct {
|
||||
ActiveDisks []string
|
||||
InactiveDisks []string
|
||||
}
|
||||
|
||||
type donutConfig struct {
|
||||
Node map[string]nodeConfig
|
||||
}
|
||||
|
||||
type mcDonutConfig struct {
|
||||
Donuts map[string]donutConfig
|
||||
}
|
||||
|
||||
func getDonutConfigDir() string {
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Unable to obtain user's home directory. \nError: %s", err)
|
||||
log.Fatalln(msg)
|
||||
}
|
||||
|
||||
return path.Join(u.HomeDir, donutConfigDir)
|
||||
}
|
||||
|
||||
func getDonutConfigFilename() string {
|
||||
return path.Join(getDonutConfigDir(), "donuts.json")
|
||||
}
|
||||
|
||||
// saveDonutConfig writes configuration data in json format to donut config file.
|
||||
func saveDonutConfig(donutConfigData *mcDonutConfig) error {
|
||||
jsonConfig, err := json.MarshalIndent(donutConfigData, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.MkdirAll(getDonutConfigDir(), 0755)
|
||||
if !os.IsExist(err) && err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configFile, err := os.OpenFile(getDonutConfigFilename(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer configFile.Close()
|
||||
|
||||
_, err = configFile.Write(jsonConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadDonutConfig() (donutConfigData *mcDonutConfig, err error) {
|
||||
configFile := getDonutConfigFilename()
|
||||
_, err = os.Stat(configFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
configBytes, err := ioutil.ReadFile(configFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(configBytes, &donutConfigData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return donutConfigData, nil
|
||||
}
|
||||
Generated
Vendored
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
func doDetachDiskCmd(c *cli.Context) {
|
||||
if !c.Args().Present() {
|
||||
log.Fatalln("no args?")
|
||||
}
|
||||
disks := c.Args()
|
||||
mcDonutConfigData, err := loadDonutConfig()
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
donutName := c.String("name")
|
||||
if donutName == "" {
|
||||
log.Fatalln("Invalid --donut <name> is needed for attach")
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName]; !ok {
|
||||
msg := fmt.Sprintf("Requested donut name <%s> does not exist, please use ``mc donut make`` first", donutName)
|
||||
log.Fatalln(msg)
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName].Node["localhost"]; !ok {
|
||||
msg := fmt.Sprintf("Corrupted donut config, please consult donut experts")
|
||||
log.Fatalln(msg)
|
||||
}
|
||||
|
||||
inactiveDisks := mcDonutConfigData.Donuts[donutName].Node["localhost"].InactiveDisks
|
||||
activeDisks := mcDonutConfigData.Donuts[donutName].Node["localhost"].ActiveDisks
|
||||
for _, disk := range disks {
|
||||
if isStringInSlice(activeDisks, disk) {
|
||||
activeDisks = deleteFromSlice(activeDisks, disk)
|
||||
inactiveDisks = appendUniq(inactiveDisks, disk)
|
||||
} else {
|
||||
msg := fmt.Sprintf("Cannot detach disk: <%s>, not part of donut <%s>", disk, donutName)
|
||||
log.Println(msg)
|
||||
}
|
||||
}
|
||||
mcDonutConfigData.Donuts[donutName].Node["localhost"] = nodeConfig{
|
||||
ActiveDisks: activeDisks,
|
||||
InactiveDisks: inactiveDisks,
|
||||
}
|
||||
if err := saveDonutConfig(mcDonutConfigData); err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
func newDonutConfig(donutName string) (*mcDonutConfig, error) {
|
||||
mcDonutConfigData := new(mcDonutConfig)
|
||||
mcDonutConfigData.Donuts = make(map[string]donutConfig)
|
||||
mcDonutConfigData.Donuts[donutName] = donutConfig{
|
||||
Node: make(map[string]nodeConfig),
|
||||
}
|
||||
mcDonutConfigData.Donuts[donutName].Node["localhost"] = nodeConfig{
|
||||
ActiveDisks: make([]string, 0),
|
||||
InactiveDisks: make([]string, 0),
|
||||
}
|
||||
return mcDonutConfigData, nil
|
||||
}
|
||||
|
||||
// doMakeDonutCmd creates a new donut
|
||||
func doMakeDonutCmd(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 os.IsNotExist(err) {
|
||||
mcDonutConfigData, err = newDonutConfig(donutName)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
if err := saveDonutConfig(mcDonutConfigData); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
return
|
||||
} else if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
if _, ok := mcDonutConfigData.Donuts[donutName]; !ok {
|
||||
mcDonutConfigData.Donuts[donutName] = donutConfig{
|
||||
Node: make(map[string]nodeConfig),
|
||||
}
|
||||
mcDonutConfigData.Donuts[donutName].Node["localhost"] = nodeConfig{
|
||||
ActiveDisks: make([]string, 0),
|
||||
InactiveDisks: make([]string, 0),
|
||||
}
|
||||
if err := saveDonutConfig(mcDonutConfigData); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
} else {
|
||||
msg := fmt.Sprintf("donut: %s already exists", donutName)
|
||||
log.Println(msg)
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 (
|
||||
"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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 main
|
||||
|
||||
import (
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
var makeDonutCmd = cli.Command{
|
||||
Name: "make",
|
||||
Usage: "make donut",
|
||||
Description: "Make a new donut",
|
||||
Action: doMakeDonutCmd,
|
||||
}
|
||||
|
||||
var attachDiskCmd = cli.Command{
|
||||
Name: "attach",
|
||||
Usage: "attach disk",
|
||||
Description: "Attach disk to an existing donut",
|
||||
Action: doAttachDiskCmd,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "Donut name",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var detachDiskCmd = cli.Command{
|
||||
Name: "detach",
|
||||
Usage: "detach disk",
|
||||
Description: "Detach disk from an existing donut",
|
||||
Action: doDetachDiskCmd,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "Donut name",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var healDonutCmd = cli.Command{
|
||||
Name: "heal",
|
||||
Usage: "heal donut",
|
||||
Description: "Heal donut with any errors",
|
||||
Action: doHealDonutCmd,
|
||||
}
|
||||
|
||||
var rebalanceDonutCmd = cli.Command{
|
||||
Name: "rebalance",
|
||||
Usage: "rebalance donut",
|
||||
Description: "Rebalance data on donut after adding disks",
|
||||
Action: doRebalanceDonutCmd,
|
||||
}
|
||||
|
||||
var donutOptions = []cli.Command{
|
||||
makeDonutCmd,
|
||||
attachDiskCmd,
|
||||
detachDiskCmd,
|
||||
healDonutCmd,
|
||||
rebalanceDonutCmd,
|
||||
}
|
||||
|
||||
func doHealDonutCmd(c *cli.Context) {
|
||||
}
|
||||
|
||||
func doRebalanceDonutCmd(c *cli.Context) {
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 (
|
||||
"os"
|
||||
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Usage = ""
|
||||
app.Version = gitCommitHash
|
||||
app.Commands = donutOptions
|
||||
app.Author = "Minio.io"
|
||||
app.EnableBashCompletion = true
|
||||
app.Run(os.Args)
|
||||
}
|
||||
Generated
Vendored
Generated
Vendored
Generated
Vendored
+1
-1
@@ -3,7 +3,7 @@ package donut
|
||||
import (
|
||||
"errors"
|
||||
|
||||
encoding "github.com/minio-io/mc/pkg/encoding/erasure"
|
||||
encoding "github.com/minio-io/erasure"
|
||||
)
|
||||
|
||||
type encoder struct {
|
||||
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Generated
Vendored
Generated
Vendored
Generated
Vendored
+4
-4
@@ -1,4 +1,5 @@
|
||||
Apache License
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
@@ -178,7 +179,7 @@ Apache License
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
@@ -186,7 +187,7 @@ Apache License
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -199,4 +200,3 @@ Apache License
|
||||
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.
|
||||
|
||||
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Minimalist Object Storage, (C) 2014 Minio, Inc.
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
Generated
Vendored
@@ -1,24 +0,0 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
# iodine
|
||||
Iodine is an error logging framework for tracing errors.
|
||||
-198
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Iodine, (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 iodine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// WrappedError is the iodine error which contains a pointer to the original error
|
||||
// and stack traces.
|
||||
type WrappedError struct {
|
||||
EmbeddedError error `json:"-"`
|
||||
ErrorMessage string
|
||||
|
||||
Stack []StackEntry
|
||||
}
|
||||
|
||||
// StackEntry contains the entry in the stack trace
|
||||
type StackEntry struct {
|
||||
Host string
|
||||
File string
|
||||
Line int
|
||||
Data map[string]string
|
||||
}
|
||||
|
||||
var gopath string
|
||||
|
||||
var globalState = struct {
|
||||
sync.RWMutex
|
||||
m map[string]string
|
||||
}{m: make(map[string]string)}
|
||||
|
||||
// SetGlobalState - set global state
|
||||
func SetGlobalState(key, value string) {
|
||||
globalState.Lock()
|
||||
globalState.m[key] = value
|
||||
globalState.Unlock()
|
||||
}
|
||||
|
||||
// ClearGlobalState - clear info in globalState struct
|
||||
func ClearGlobalState() {
|
||||
globalState.Lock()
|
||||
for k := range globalState.m {
|
||||
delete(globalState.m, k)
|
||||
}
|
||||
globalState.Unlock()
|
||||
}
|
||||
|
||||
// GetGlobalState - get map from globalState struct
|
||||
func GetGlobalState() map[string]string {
|
||||
result := make(map[string]string)
|
||||
globalState.RLock()
|
||||
for k, v := range globalState.m {
|
||||
result[k] = v
|
||||
}
|
||||
globalState.RUnlock()
|
||||
return result
|
||||
}
|
||||
|
||||
// GetGlobalStateKey - get value for key from globalState struct
|
||||
func GetGlobalStateKey(k string) string {
|
||||
result, ok := globalState.m[k]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Error - instantiate an error, turning it into an iodine error.
|
||||
// Adds an initial stack trace.
|
||||
func Error(err error, data map[string]string) error {
|
||||
if err != nil {
|
||||
entry := createStackEntry()
|
||||
var newErr WrappedError
|
||||
|
||||
// check if error is wrapped
|
||||
switch typedError := err.(type) {
|
||||
case WrappedError:
|
||||
{
|
||||
newErr = typedError
|
||||
}
|
||||
default:
|
||||
{
|
||||
newErr = WrappedError{
|
||||
EmbeddedError: err,
|
||||
ErrorMessage: err.Error(),
|
||||
Stack: []StackEntry{},
|
||||
}
|
||||
}
|
||||
}
|
||||
for k, v := range data {
|
||||
entry.Data[k] = v
|
||||
}
|
||||
newErr.Stack = append(newErr.Stack, entry)
|
||||
return newErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// createStackEntry - create stack entries
|
||||
func createStackEntry() StackEntry {
|
||||
host, _ := os.Hostname()
|
||||
_, file, line, _ := runtime.Caller(2)
|
||||
file = strings.TrimPrefix(file, gopath) // trim gopath from file
|
||||
|
||||
data := GetGlobalState()
|
||||
for k, v := range getSystemData() {
|
||||
data[k] = v
|
||||
}
|
||||
|
||||
entry := StackEntry{
|
||||
Host: host,
|
||||
File: file,
|
||||
Line: line,
|
||||
Data: data,
|
||||
}
|
||||
return entry
|
||||
}
|
||||
|
||||
func getSystemData() map[string]string {
|
||||
host, err := os.Hostname()
|
||||
if err != nil {
|
||||
host = ""
|
||||
}
|
||||
memstats := &runtime.MemStats{}
|
||||
runtime.ReadMemStats(memstats)
|
||||
return map[string]string{
|
||||
"sys.host": host,
|
||||
"sys.os": runtime.GOOS,
|
||||
"sys.arch": runtime.GOARCH,
|
||||
"sys.go": runtime.Version(),
|
||||
"sys.cpus": strconv.Itoa(runtime.NumCPU()),
|
||||
"sys.mem.used": strconv.FormatUint(memstats.Alloc, 10),
|
||||
"sys.mem.allocated": strconv.FormatUint(memstats.TotalAlloc, 10),
|
||||
"sys.mem.heap.used": strconv.FormatUint(memstats.HeapAlloc, 10),
|
||||
"sys.mem.heap.allocated": strconv.FormatUint(memstats.HeapSys, 10),
|
||||
}
|
||||
}
|
||||
|
||||
// Annotate an error with a stack entry and returns itself
|
||||
//func (err *WrappedError) Annotate(info map[string]string) *WrappedError {
|
||||
// entry := createStackEntry()
|
||||
// for k, v := range info {
|
||||
// entry.Data[k] = v
|
||||
// }
|
||||
// err.Stack = append(err.Stack, entry)
|
||||
// return err
|
||||
//}
|
||||
|
||||
// EmitJSON writes JSON output for the error
|
||||
func (err WrappedError) EmitJSON() ([]byte, error) {
|
||||
return json.Marshal(err)
|
||||
}
|
||||
|
||||
// EmitHumanReadable returns a human readable error message
|
||||
func (err WrappedError) EmitHumanReadable() string {
|
||||
var errorBuffer bytes.Buffer
|
||||
fmt.Fprintln(&errorBuffer, err.ErrorMessage)
|
||||
for i, entry := range err.Stack {
|
||||
fmt.Fprintln(&errorBuffer, "-", i, entry.Host+":"+entry.File+":"+strconv.Itoa(entry.Line), entry.Data)
|
||||
}
|
||||
return string(errorBuffer.Bytes())
|
||||
}
|
||||
|
||||
// Emits the original error message
|
||||
func (err WrappedError) Error() string {
|
||||
return err.EmitHumanReadable()
|
||||
}
|
||||
|
||||
func init() {
|
||||
_, iodineFile, _, _ := runtime.Caller(0)
|
||||
iodineFile = path.Dir(iodineFile) // trim iodine.go
|
||||
iodineFile = path.Dir(iodineFile) // trim iodine
|
||||
iodineFile = path.Dir(iodineFile) // trim minio-io
|
||||
gopath = path.Dir(iodineFile) + "/" // trim github.com
|
||||
}
|
||||
-103
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Iodine, (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 iodine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIodine(t *testing.T) {
|
||||
iodineError := Error(errors.New("Hello"), nil)
|
||||
iodineError = Error(iodineError, nil)
|
||||
iodineError = Error(iodineError, nil)
|
||||
iodineError = Error(iodineError, nil)
|
||||
switch typedError := iodineError.(type) {
|
||||
case WrappedError:
|
||||
{
|
||||
if len(typedError.Stack) != 4 {
|
||||
t.Fail()
|
||||
}
|
||||
jsonResult, err := typedError.EmitJSON()
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
var prettyBuffer bytes.Buffer
|
||||
json.Indent(&prettyBuffer, jsonResult, "", " ")
|
||||
if prettyBuffer.String() == "" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
default:
|
||||
{
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestState(t *testing.T) {
|
||||
SetGlobalState("hello", "world")
|
||||
result := GetGlobalStateKey("hello")
|
||||
if result != "world" {
|
||||
t.Error("global state not set: hello->world")
|
||||
t.Fail()
|
||||
}
|
||||
ClearGlobalState()
|
||||
if len(GetGlobalState()) != 0 {
|
||||
t.Fail()
|
||||
}
|
||||
SetGlobalState("foo", "bar")
|
||||
err := Error(errors.New("a simple error"), nil)
|
||||
switch typedError := err.(type) {
|
||||
case WrappedError:
|
||||
{
|
||||
if res, ok := typedError.Stack[0].Data["foo"]; ok {
|
||||
if res != "bar" {
|
||||
t.Error("global state not set: foo->bar")
|
||||
}
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
typedError = Error(typedError, map[string]string{"foo2": "bar2"}).(WrappedError)
|
||||
if res, ok := typedError.Stack[0].Data["foo"]; ok {
|
||||
if res != "bar" {
|
||||
t.Error("annotate should not modify previous data entries")
|
||||
}
|
||||
} else {
|
||||
t.Error("annotate should not remove previous data entries")
|
||||
}
|
||||
if res, ok := typedError.Stack[1].Data["foo"]; ok {
|
||||
if res != "bar" {
|
||||
t.Error("global state should set value properly in annotate")
|
||||
}
|
||||
} else {
|
||||
t.Error("global state should set key properly in annotate")
|
||||
}
|
||||
if res, ok := typedError.Stack[1].Data["foo2"]; ok {
|
||||
if res != "bar2" {
|
||||
// typedError = Error(typedError, nil).(WrappedError)
|
||||
t.Error("foo2 -> bar should be set")
|
||||
}
|
||||
} else {
|
||||
// typedError = Error(typedError, nil).(WrappedError)
|
||||
t.Error("foo2 should be set")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ pre-build:
|
||||
|
||||
build-all: getdeps verifiers
|
||||
@echo "Building Libraries:"
|
||||
@godep go generate github.com/minio-io/erasure
|
||||
@godep go generate ./...
|
||||
@godep go build ./...
|
||||
|
||||
@@ -61,10 +62,9 @@ docs-deploy:
|
||||
|
||||
install: test-all
|
||||
@echo "Installing mc:"
|
||||
@godep go install github.com/minio-io/mc
|
||||
@godep go install github.com/minio-io/mc
|
||||
@mkdir -p $(HOME)/.minio/mc
|
||||
|
||||
clean:
|
||||
@rm -fv cover.out
|
||||
@rm -fv pkg/encoding/erasure/*.syso
|
||||
@rm -fv build-constants.go
|
||||
|
||||
Reference in New Issue
Block a user