feat: Introduce 'mc batch' command (#4225)

This commit is contained in:
Harshavardhana
2022-10-09 14:10:59 -07:00
committed by GitHub
parent 02da50b05e
commit 6398b00a24
20 changed files with 780 additions and 68 deletions
+9 -7
View File
@@ -119,18 +119,20 @@ type clusterStruct struct {
}
// String provides colorized info messages depending on the type of a server
// FS server non-FS server
//
// FS server non-FS server
//
// ============================== ===================================
// ● <ip>:<port> ● <ip>:<port>
// Uptime: xxx Uptime: xxx
// Version: xxx Version: xxx
// Network: X/Y OK Network: X/Y OK
//
// Uptime: xxx Uptime: xxx
// Version: xxx Version: xxx
// Network: X/Y OK Network: X/Y OK
//
// U Used, B Buckets, O Objects Drives: N/N OK
//
// U Used, B Buckets, O Objects
// N drives online, K drives offline
//
// U Used, B Buckets, O Objects
// N drives online, K drives offline
func (u clusterStruct) String() (msg string) {
// Check cluster level "Status" field for error
if u.Status == "error" {
+4 -1
View File
@@ -267,8 +267,8 @@ func matchingOpts(ctx *cli.Context) (opts matchOpts) {
// Calculate tracing options for command line flags
func tracingOpts(ctx *cli.Context, apis []string) (opts madmin.ServiceTraceOpts, e error) {
opts.OnlyErrors = ctx.Bool("errors")
opts.Threshold = ctx.Duration("response-threshold")
opts.OnlyErrors = ctx.Bool("errors")
if ctx.Bool("all") {
opts.S3 = true
@@ -278,6 +278,7 @@ func tracingOpts(ctx *cli.Context, apis []string) (opts madmin.ServiceTraceOpts,
opts.Scanner = true
opts.Decommission = true
opts.Healing = true
opts.BatchReplication = true
return
}
@@ -304,6 +305,8 @@ func tracingOpts(ctx *cli.Context, apis []string) (opts madmin.ServiceTraceOpts,
opts.Healing = true
case "decom", "decommission":
opts.Decommission = true
case "batch-replication":
opts.BatchReplication = true
}
}
+9 -4
View File
@@ -443,10 +443,15 @@ var completeCmds = map[string]complete.Predictor{
"/license/info": aliasCompleter,
"/license/update": aliasCompleter,
"/update": nil,
"/ready": nil,
"/ping": nil,
"/od": nil,
"/update": nil,
"/ready": aliasCompleter,
"/ping": aliasCompleter,
"/od": nil,
"/batch/generate": aliasCompleter,
"/batch/start": aliasCompleter,
"/batch/list": aliasCompleter,
"/batch/status": aliasCompleter,
"/batch/describe": aliasCompleter,
}
// flagsToCompleteFlags transforms a cli.Flag to complete.Flags
+78
View File
@@ -0,0 +1,78 @@
// Copyright (c) 2015-2022 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"context"
"fmt"
"github.com/minio/cli"
"github.com/minio/mc/pkg/probe"
)
var batchDescribeCmd = cli.Command{
Name: "describe",
Usage: "describe job definition for a job",
Action: mainBatchDescribe,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: globalFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET JOBID
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Describe current batch job definition:
{{.Prompt}} {{.HelpName}} myminio KwSysDpxcBU9FNhGkn2dCf
`,
}
// checkBatchDescribeSyntax - validate all the passed arguments
func checkBatchDescribeSyntax(ctx *cli.Context) {
if len(ctx.Args()) != 2 {
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
}
}
// mainBatchDescribe is the handle for "mc batch create" command.
func mainBatchDescribe(ctx *cli.Context) error {
checkBatchDescribeSyntax(ctx)
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
jobID := args.Get(1)
// Start a new MinIO Admin Client
adminClient, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
ctxt, cancel := context.WithCancel(globalContext)
defer cancel()
job, e := adminClient.DescribeBatchJob(ctxt, jobID)
fatalIf(probe.NewError(e), "Unable to fetch the job definition")
fmt.Println(job)
return nil
}
+81
View File
@@ -0,0 +1,81 @@
// Copyright (c) 2015-2022 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"fmt"
"github.com/minio/cli"
"github.com/minio/madmin-go"
"github.com/minio/mc/pkg/probe"
)
var batchGenerateCmd = cli.Command{
Name: "generate",
Usage: "generate a new batch job definition",
Action: mainBatchGenerate,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: globalFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET JOBTYPE
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Generate a new batch 'replication' job definition:
{{.Prompt}} {{.HelpName}} myminio replicate > replication.yaml
`,
}
// checkBatchGenerateSyntax - validate all the passed arguments
func checkBatchGenerateSyntax(ctx *cli.Context) {
if len(ctx.Args()) != 2 {
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
}
}
// mainBatchGenerate is the handle for "mc batch generate" command.
func mainBatchGenerate(ctx *cli.Context) error {
checkBatchGenerateSyntax(ctx)
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
jobType := args.Get(1)
// Start a new MinIO Admin Client
adminClient, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
switch jobType {
case string(madmin.BatchJobReplicate):
default:
fatalIf(errInvalidArgument().Trace(jobType), "Unable to generate a job template for the specified job type")
}
out, e := adminClient.GenerateBatchJob(globalContext, madmin.GenerateBatchJobOpts{})
fatalIf(probe.NewError(e), "Unable to generate %s", args.Get(1))
fmt.Println(string(out))
return nil
}
+152
View File
@@ -0,0 +1,152 @@
// Copyright (c) 2015-2022 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"context"
"strings"
humanize "github.com/dustin/go-humanize"
"github.com/minio/cli"
json "github.com/minio/colorjson"
"github.com/minio/madmin-go"
"github.com/minio/mc/pkg/probe"
"github.com/olekukonko/tablewriter"
)
var batchListFlags = []cli.Flag{
cli.StringFlag{
Name: "type",
Usage: "list all current batch jobs via job type",
},
}
var batchListCmd = cli.Command{
Name: "list",
ShortName: "ls",
Usage: "list all current batch jobs",
Action: mainBatchList,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(batchListFlags, globalFlags...),
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. List all current batch jobs:
{{.Prompt}} {{.HelpName}} myminio
2. List all current batch jobs of type 'replicate':
{{.Prompt}} {{.HelpName}} myminio/ --type "replicate"
`,
}
// batchListMessage container for file batchList messages
type batchListMessage struct {
Status string `json:"status"`
Jobs []madmin.BatchJobResult `json:"jobs"`
}
// String colorized batchList message
func (c batchListMessage) String() string {
if len(c.Jobs) == 0 {
return "currently no jobs are running"
}
var s strings.Builder
// Set table header
table := tablewriter.NewWriter(&s)
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding("\t") // pad with tabs
table.SetNoWhiteSpace(true)
table.SetHeader([]string{"ID", "TYPE", "USER", "STARTED"})
data := make([][]string, 0, 4)
for _, job := range c.Jobs {
data = append(data, []string{
job.ID,
string(job.Type),
job.User,
humanize.Time(job.Started),
})
}
table.AppendBulk(data)
table.Render()
return s.String()
}
// JSON jsonified batchList message
func (c batchListMessage) JSON() string {
c.Status = "success"
batchListMessageBytes, e := json.MarshalIndent(c, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(batchListMessageBytes)
}
// checkBatchListSyntax - validate all the passed arguments
func checkBatchListSyntax(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
}
}
// mainBatchList is the handle for "mc batch create" command.
func mainBatchList(ctx *cli.Context) error {
checkBatchListSyntax(ctx)
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
// Start a new MinIO Admin Client
adminClient, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
ctxt, cancel := context.WithCancel(globalContext)
defer cancel()
res, e := adminClient.ListBatchJobs(ctxt, &madmin.ListBatchJobsFilter{
ByJobType: ctx.String("type"),
})
fatalIf(probe.NewError(e), "Unable to list jobs")
printMsg(batchListMessage{
Status: "success",
Jobs: res.Jobs,
})
return nil
}
+47
View File
@@ -0,0 +1,47 @@
// Copyright (c) 2015-2022 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import "github.com/minio/cli"
var batchSubcommands = []cli.Command{
batchGenerateCmd,
batchStartCmd,
batchListCmd,
batchStatusCmd,
batchDescribeCmd,
// batchSuspendResumeCmd,
// batchStopCmd,
}
var batchCmd = cli.Command{
Name: "batch",
Usage: "manage batch jobs",
Action: mainBatch,
Before: setGlobalsFromContext,
Flags: globalFlags,
Subcommands: batchSubcommands,
HideHelpCommand: true,
}
// mainBatch is the handle for "mc batch" command.
func mainBatch(ctx *cli.Context) error {
commandNotFound(ctx, batchSubcommands)
return nil
// Sub-commands like "generate", "list", "info" have their own main.
}
+110
View File
@@ -0,0 +1,110 @@
// Copyright (c) 2015-2022 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"context"
"fmt"
"io/ioutil"
"github.com/fatih/color"
"github.com/minio/cli"
json "github.com/minio/colorjson"
"github.com/minio/madmin-go"
"github.com/minio/mc/pkg/probe"
"github.com/minio/pkg/console"
)
var batchStartCmd = cli.Command{
Name: "start",
Usage: "start a new batch job",
Action: mainBatchStart,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: globalFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET JOBFILE
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Start a new batch 'replication' job:
{{.Prompt}} {{.HelpName}} myminio ./replication.yaml
`,
}
// batchStartMessage container for file batchStart messages
type batchStartMessage struct {
Status string `json:"status"`
Result madmin.BatchJobResult `json:"result"`
}
// String colorized batchStart message
func (c batchStartMessage) String() string {
return console.Colorize("BatchStart", fmt.Sprintf("Successfully started '%s' job `%s` on '%s'", c.Result.Type, c.Result.ID, c.Result.Started))
}
// JSON jsonified batchStart message
func (c batchStartMessage) JSON() string {
c.Status = "success"
batchStartMessageBytes, e := json.MarshalIndent(c, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(batchStartMessageBytes)
}
// checkBatchStartSyntax - validate all the passed arguments
func checkBatchStartSyntax(ctx *cli.Context) {
if len(ctx.Args()) != 2 {
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
}
}
// mainBatchStart is the handle for "mc batch create" command.
func mainBatchStart(ctx *cli.Context) error {
checkBatchStartSyntax(ctx)
console.SetColor("BatchStart", color.New(color.FgGreen, color.Bold))
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
// Start a new MinIO Admin Client
adminClient, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
buf, e := ioutil.ReadFile(args.Get(1))
fatalIf(probe.NewError(e), "Unable to read %s", args.Get(1))
ctxt, cancel := context.WithCancel(globalContext)
defer cancel()
res, e := adminClient.StartBatchJob(ctxt, string(buf))
fatalIf(probe.NewError(e), "Unable to start job")
printMsg(batchStartMessage{
Status: "success",
Result: res,
})
return nil
}
+218
View File
@@ -0,0 +1,218 @@
package cmd
import (
"context"
"errors"
"fmt"
"os"
"strings"
"time"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/dustin/go-humanize"
"github.com/minio/cli"
"github.com/minio/madmin-go"
"github.com/minio/mc/pkg/probe"
"github.com/olekukonko/tablewriter"
)
var batchStatusCmd = cli.Command{
Name: "status",
Usage: "summarize job events on MinIO server in real-time",
Action: mainBatchStatus,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: globalFlags,
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET JOBID
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Display current in-progress JOB events.
{{.Prompt}} {{.HelpName}} myminio/ KwSysDpxcBU9FNhGkn2dCf
`,
}
// checkBatchStatusSyntax - validate all the passed arguments
func checkBatchStatusSyntax(ctx *cli.Context) {
if len(ctx.Args()) != 2 {
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
}
}
func mainBatchStatus(ctx *cli.Context) error {
checkBatchStatusSyntax(ctx)
aliasedURL := ctx.Args().Get(0)
jobID := ctx.Args().Get(1)
// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
ctxt, cancel := context.WithCancel(globalContext)
defer cancel()
done := make(chan struct{})
_, e := client.DescribeBatchJob(ctxt, jobID)
fatalIf(probe.NewError(e), "Unable to lookup job status")
ui := tea.NewProgram(initBatchJobMetricsUI(jobID))
if !globalJSON {
go func() {
if e := ui.Start(); e != nil {
cancel()
os.Exit(1)
}
close(done)
}()
}
go func() {
opts := madmin.MetricsOptions{
Type: madmin.MetricsBatchJobs,
ByJobID: jobID,
}
e := client.Metrics(ctxt, opts, func(metrics madmin.RealtimeMetrics) {
if globalJSON {
printMsg(metricsMessage{RealtimeMetrics: metrics})
return
}
if metrics.Aggregated.BatchJobs != nil {
job := metrics.Aggregated.BatchJobs.Jobs[jobID]
ui.Send(job)
if job.Complete {
cancel()
}
}
})
if e != nil && !errors.Is(e, context.Canceled) {
fatalIf(probe.NewError(e).Trace(ctx.Args()...), "Unable to get current status")
}
}()
<-done
return nil
}
func initBatchJobMetricsUI(jobID string) *batchJobMetricsUI {
s := spinner.New()
s.Spinner = spinner.Points
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
return &batchJobMetricsUI{
spinner: s,
jobID: jobID,
}
}
type batchJobMetricsUI struct {
current madmin.JobMetric
spinner spinner.Model
quitting bool
jobID string
}
func (m *batchJobMetricsUI) Init() tea.Cmd {
return m.spinner.Tick
}
func (m *batchJobMetricsUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c":
m.quitting = true
return m, tea.Quit
default:
return m, nil
}
case madmin.JobMetric:
m.current = msg
if msg.Complete {
m.quitting = true
return m, tea.Quit
}
return m, nil
case spinner.TickMsg:
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
return m, cmd
default:
return m, nil
}
}
func (m *batchJobMetricsUI) View() string {
var s strings.Builder
// Set table header
table := tablewriter.NewWriter(&s)
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding("\t") // pad with tabs
table.SetNoWhiteSpace(true)
var data [][]string
addLine := func(prefix string, value interface{}) {
data = append(data, []string{
prefix,
whiteStyle.Render(fmt.Sprint(value)),
})
}
if !m.quitting {
s.WriteString(m.spinner.View())
} else {
if m.current.Complete {
if m.current.Replicate.ObjectsFailed == 0 {
s.WriteString(m.spinner.Style.Render((tickCell + tickCell + tickCell)))
} else {
s.WriteString(m.spinner.Style.Render((crossTickCell + crossTickCell + crossTickCell)))
}
}
}
s.WriteString("\n")
switch m.current.JobType {
case string(madmin.BatchJobReplicate):
accElapsedTime := m.current.LastUpdate.Sub(m.current.StartTime)
addLine("JobType: ", m.current.JobType)
addLine("Objects: ", m.current.Replicate.Objects)
addLine("Versions: ", m.current.Replicate.Objects)
addLine("FailedObjects: ", m.current.Replicate.ObjectsFailed)
if accElapsedTime > 0 {
bytesTransferredPerSec := float64(int64(time.Second)*m.current.Replicate.BytesTransferred) / float64(accElapsedTime)
objectsPerSec := float64(int64(time.Second)*m.current.Replicate.Objects) / float64(accElapsedTime)
addLine("Throughput: ", fmt.Sprintf("%s/s", humanize.IBytes(uint64(bytesTransferredPerSec))))
addLine("IOPs: ", fmt.Sprintf("%.2f objs/s", objectsPerSec))
}
addLine("Transferred: ", fmt.Sprintf("%s", humanize.IBytes(uint64(m.current.Replicate.BytesTransferred))))
addLine("Elapsed: ", fmt.Sprintf("%s", accElapsedTime))
addLine("CurrObjName: ", m.current.Replicate.Object)
}
table.AppendBulk(data)
table.Render()
if m.quitting {
s.WriteString("\n")
}
return s.String()
}
+1 -1
View File
@@ -49,7 +49,7 @@ type ConfigAnyVersion struct {
Version string
}
/////////////////// Broken Config V3 ///////////////////
// ///////////////// Broken Config V3 ///////////////////
type brokenHostConfigV3 struct {
AccessKeyID string
SecretAccessKey string
+9 -9
View File
@@ -17,7 +17,7 @@
package cmd
/////////////////// Config V1 ///////////////////
// ///////////////// Config V1 ///////////////////
type hostConfigV1 struct {
AccessKeyID string
SecretAccessKey string
@@ -40,7 +40,7 @@ func newConfigV1() *configV1 {
return conf
}
/////////////////// Config V101 ///////////////////
// ///////////////// Config V101 ///////////////////
type hostConfigV101 hostConfigV1
type configV101 struct {
@@ -58,7 +58,7 @@ func newConfigV101() *configV101 {
return conf
}
/////////////////// Config V2 ///////////////////
// ///////////////// Config V2 ///////////////////
type hostConfigV2 hostConfigV1
type configV2 struct {
@@ -76,7 +76,7 @@ func newConfigV2() *configV2 {
return conf
}
/////////////////// Config V3 ///////////////////
// ///////////////// Config V3 ///////////////////
type hostConfigV3 struct {
AccessKeyID string `json:"access-key-id"`
SecretAccessKey string `json:"secret-access-key"`
@@ -97,7 +97,7 @@ func newConfigV3() *configV3 {
return conf
}
/////////////////// Config V4 ///////////////////
// ///////////////// Config V4 ///////////////////
type hostConfigV4 struct {
AccessKeyID string `json:"accessKeyId"`
SecretAccessKey string `json:"secretAccessKey"`
@@ -118,7 +118,7 @@ func newConfigV4() *configV4 {
return conf
}
/////////////////// Config V5 ///////////////////
// ///////////////// Config V5 ///////////////////
type hostConfigV5 struct {
AccessKeyID string `json:"accessKeyId"`
SecretAccessKey string `json:"secretAccessKey"`
@@ -139,7 +139,7 @@ func newConfigV5() *configV5 {
return conf
}
/////////////////// Config V6 ///////////////////
// ///////////////// Config V6 ///////////////////
type hostConfigV6 struct {
AccessKeyID string `json:"accessKeyId"`
SecretAccessKey string `json:"secretAccessKey"`
@@ -161,7 +161,7 @@ func newConfigV6() *configV6 {
return conf
}
/////////////////// Config V6 ///////////////////
// ///////////////// Config V6 ///////////////////
// hostConfig configuration of a host - version '7'.
type hostConfigV7 struct {
URL string `json:"url"`
@@ -241,7 +241,7 @@ func (c *configV7) setHost(alias string, cfg hostConfigV7) {
}
}
/////////////////// Config V8 ///////////////////
// ///////////////// Config V8 ///////////////////
// configV8 config version.
// hostConfig configuration of a host.
type hostConfigV8 struct {
+16 -12
View File
@@ -58,19 +58,23 @@ func (f findMessage) JSON() string {
// also proceed to look for similar strings alone and print it.
//
// pattern:
// { term }
// term:
// '*' matches any sequence of non-Separator characters
// '?' matches any single non-Separator character
// '[' [ '^' ] { character-range } ']'
// character class (must be non-empty)
// c matches character c (c != '*', '?', '\\', '[')
// '\\' c matches character c
// character-range:
// c matches character c (c != '\\', '-', ']')
// '\\' c matches character c
// lo '-' hi matches character c for lo <= c <= hi
//
// { term }
//
// term:
//
// '*' matches any sequence of non-Separator characters
// '?' matches any single non-Separator character
// '[' [ '^' ] { character-range } ']'
// character class (must be non-empty)
// c matches character c (c != '*', '?', '\\', '[')
// '\\' c matches character c
//
// character-range:
//
// c matches character c (c != '\\', '-', ']')
// '\\' c matches character c
// lo '-' hi matches character c for lo <= c <= hi
func nameMatch(pattern, path string) bool {
matched, e := filepath.Match(pattern, filepath.Base(path))
errorIf(probe.NewError(e).Trace(pattern, path), "Unable to match with input pattern.")
+1
View File
@@ -457,6 +457,7 @@ var appCmds = []cli.Command{
readyCmd,
pingCmd,
odCmd,
batchCmd,
}
func printMCVersion(c *cli.Context) {
+1 -1
View File
@@ -128,7 +128,7 @@ var (
}
)
// Mirror folders recursively from a single source to many destinations
// Mirror folders recursively from a single source to many destinations
var mirrorCmd = cli.Command{
Name: "mirror",
Usage: "synchronize object(s) to a remote site",
+4 -3
View File
@@ -390,9 +390,10 @@ func printDryRunMsg(content *ClientContent) {
}
// listAndRemove uses listing before removal, it can list recursively or not, with versions or not.
// Use cases:
// * Remove objects recursively
// * Remove all versions of a single object
//
// Use cases:
// * Remove objects recursively
// * Remove all versions of a single object
func listAndRemove(url string, opts removeOpts) error {
ctx, cancelRemove := context.WithCancel(globalContext)
defer cancelRemove()
+1 -1
View File
@@ -26,7 +26,7 @@ import (
"github.com/minio/pkg/quick"
)
/////////////////// Session V6 ///////////////////
// ///////////////// Session V6 ///////////////////
// sessionV6Header for resumable sessions.
type sessionV6Header struct {
Version string `json:"version"`
+2 -3
View File
@@ -155,8 +155,7 @@ func GetCurrentReleaseTime() (releaseTime time.Time, err *probe.Error) {
//
// https://github.com/moby/moby/blob/master/daemon/initlayer/setup_unix.go#L25
//
// "/.dockerenv": "file",
//
// "/.dockerenv": "file",
func IsDocker() bool {
_, e := os.Stat("/.dockerenv")
if os.IsNotExist(e) {
@@ -192,7 +191,7 @@ func IsSourceBuild() bool {
// DO NOT CHANGE USER AGENT STYLE.
// The style should be
//
// mc (<OS>; <ARCH>[; dcos][; kubernetes][; docker][; source]) mc/<VERSION> mc/<RELEASE-TAG> mc/<COMMIT-ID>
// mc (<OS>; <ARCH>[; dcos][; kubernetes][; docker][; source]) mc/<VERSION> mc/<RELEASE-TAG> mc/<COMMIT-ID>
//
// Any change here should be discussed by opening an issue at
// https://github.com/minio/mc/issues.
+8 -6
View File
@@ -1,9 +1,9 @@
module github.com/minio/mc
go 1.17
go 1.18
require (
github.com/charmbracelet/bubbletea v0.19.3
github.com/charmbracelet/bubbletea v0.22.1
github.com/cheggaaa/pb v1.0.29
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.13.0
@@ -15,7 +15,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/klauspost/compress v1.15.9
github.com/mattn/go-ieproxy v0.0.1
github.com/mattn/go-isatty v0.0.14
github.com/mattn/go-isatty v0.0.16
github.com/minio/cli v1.24.0
github.com/minio/colorjson v1.0.2
github.com/minio/filepath v1.0.0
@@ -60,7 +60,7 @@ require (
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/containerd/console v1.0.2 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
@@ -81,12 +81,14 @@ require (
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/philhofer/fwd v1.1.2-0.20210722190033-5c56ac6d0bb9 // indirect
github.com/pkg/errors v0.9.1 // indirect
@@ -107,7 +109,7 @@ require (
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
google.golang.org/genproto v0.0.0-20220302033224-9aa15565e42a // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
+15 -6
View File
@@ -64,8 +64,9 @@ github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cb
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/charmbracelet/bubbles v0.10.0 h1:ZYqBwnmFGp91HSRRbhxKq5jr6bUPsVUBdkrGGWtv0Wk=
github.com/charmbracelet/bubbles v0.10.0/go.mod h1:4tiDrWzH1MTD4t5NnrcthaedmI3MxU0FIutax7//dvk=
github.com/charmbracelet/bubbletea v0.19.3 h1:OKeO/Y13rQQqt4snX+lePB0QrnW80UdrMNolnCcmoAw=
github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA=
github.com/charmbracelet/bubbletea v0.22.1 h1:z66q0LWdJNOWEH9zadiAIXp2GN1AWrwNXU8obVY9X24=
github.com/charmbracelet/bubbletea v0.22.1/go.mod h1:8/7hVvbPN6ZZPkczLiB8YpLkLJ0n7DMho5Wvfd2X1C0=
github.com/charmbracelet/harmonica v0.1.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/lipgloss v0.3.0/go.mod h1:VkhdBS2eNAmRkTwRKLJCFhCOVkjntMusBDxv7TXahuk=
github.com/charmbracelet/lipgloss v0.4.1-0.20220204041308-bf2912e703f6 h1:IO2ebJMUU2hixsAEBb80TyLTQQEqXIomwzd61rGzzAk=
@@ -83,8 +84,9 @@ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XP
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/containerd/console v1.0.2 h1:Pi6D+aZXM+oUw1czuKgH5IJ+y0jhYcwBJfx5/Ghn9dE=
github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
@@ -318,8 +320,11 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
@@ -373,13 +378,16 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/termenv v0.8.1/go.mod h1:kzt/D/4a88RoheZmwfqorY3A+tnsSMA9HJC/fQSFKo0=
github.com/muesli/termenv v0.9.0/go.mod h1:R/LzAKf+suGs4IsO95y7+7DpFHO0KABgnZqtlyx2mBw=
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0 h1:STjmj0uFfRryL9fzRA/OupNppeAID6QJYPMavTL7jtY=
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1EESqrE0gZw0/AJNYzIvoGLhIoVYtluI=
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/navidys/tvxwidgets v0.1.0 h1:cY9pU5ww+hbpwMAYC2eTEX5tKF3KD/ku7gu/XMnSulk=
@@ -727,12 +735,13 @@ golang.org/x/sys v0.0.0-20211213223007-03aa0b5f6827/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+14 -14
View File
@@ -52,8 +52,9 @@ func Init() {
// SetAppInfo sets app speific key:value to report additionally during call trace dump.
// Eg. SetAppInfo("ReleaseTag", "RELEASE_42_0")
// SetAppInfo("Version", "42.0")
// SetAppInfo("Commit", "00611fb")
//
// SetAppInfo("Version", "42.0")
// SetAppInfo("Commit", "00611fb")
func SetAppInfo(key, value string) {
appInfo[key] = value
}
@@ -96,23 +97,22 @@ type Error struct {
}
// NewError function instantiates an error probe for tracing.
// Default ``error`` (golang's error interface) is injected in
// Default “error“ (golang's error interface) is injected in
// only once. Rest of the time, you trace the return path with
// ``probe.Trace`` and finally handling them at top level
// “probe.Trace“ and finally handling them at top level
//
// Following dummy code talks about how one can pass up the
// errors and put them in CallTrace.
//
// func sendError() *probe.Error {
// return probe.NewError(errors.New("Help Needed"))
// }
// func recvError() *probe.Error {
// return sendError().Trace()
// }
// if err := recvError(); err != nil {
// log.Fatalln(err.Trace())
// }
//
// func sendError() *probe.Error {
// return probe.NewError(errors.New("Help Needed"))
// }
// func recvError() *probe.Error {
// return sendError().Trace()
// }
// if err := recvError(); err != nil {
// log.Fatalln(err.Trace())
// }
func NewError(e error) *Error {
if e == nil {
return nil