-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The cmd/storagenode/main.go is a big mess right now with so many unneeded config structures initialized and shared by several subcommands. There are many instances where the config structure of one subcommand is mistakenly used for another subcommand. This changes is an attempt to clean up the main.go by moving the subcommands to a separate `cmd_*.go` files with separate config structures for each subcommand. Resolves #5756 Change-Id: I85adf2439acba271c023c269739f7fa3c6d49f9d
- Loading branch information
Showing
14 changed files
with
736 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (C) 2020 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"storj.io/common/fpath" | ||
"storj.io/private/cfgstruct" | ||
"storj.io/private/process" | ||
) | ||
|
||
func newConfigCmd(f *Factory) *cobra.Command { | ||
var cfg setupCfg | ||
|
||
cmd := &cobra.Command{ | ||
Use: "config", | ||
Short: "Edit config files", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
setupDir, err := filepath.Abs(f.ConfDir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cfg.SetupDir = setupDir | ||
return cmdConfig(cmd, &cfg) | ||
}, | ||
Annotations: map[string]string{"type": "setup"}, | ||
} | ||
|
||
process.Bind(cmd, &cfg, f.Defaults, cfgstruct.ConfDir(f.ConfDir), cfgstruct.IdentityDir(f.IdentityDir), cfgstruct.SetupMode()) | ||
|
||
return cmd | ||
} | ||
|
||
func cmdConfig(cmd *cobra.Command, cfg *setupCfg) (err error) { | ||
setupDir, err := filepath.Abs(cfg.SetupDir) | ||
if err != nil { | ||
return err | ||
} | ||
// run setup if we can't access the config file | ||
conf := filepath.Join(setupDir, "config.yaml") | ||
if _, err := os.Stat(conf); err != nil { | ||
return cmdSetup(cmd, cfg) | ||
} | ||
|
||
return fpath.EditFile(conf) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (C) 2020 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
"text/tabwriter" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/zeebo/errs" | ||
"go.uber.org/zap" | ||
|
||
"storj.io/common/memory" | ||
"storj.io/common/storj" | ||
"storj.io/private/cfgstruct" | ||
"storj.io/private/process" | ||
"storj.io/storj/storagenode" | ||
"storj.io/storj/storagenode/storagenodedb" | ||
) | ||
|
||
type diagCfg struct { | ||
storagenode.Config | ||
|
||
DiagDir string `internal:"true"` | ||
} | ||
|
||
func newDiagCmd(f *Factory) *cobra.Command { | ||
var diagCfg diagCfg | ||
cmd := &cobra.Command{ | ||
Use: "diag", | ||
Short: "Diagnostic Tool support", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
diagDir, err := filepath.Abs(f.ConfDir) | ||
if err != nil { | ||
return err | ||
} | ||
diagCfg.DiagDir = diagDir | ||
return cmdDiag(cmd, &diagCfg) | ||
}, | ||
Annotations: map[string]string{"type": "helper"}, | ||
} | ||
|
||
process.Bind(cmd, &diagCfg, f.Defaults, cfgstruct.ConfDir(f.ConfDir), cfgstruct.IdentityDir(f.IdentityDir)) | ||
|
||
return cmd | ||
} | ||
|
||
func cmdDiag(cmd *cobra.Command, cfg *diagCfg) (err error) { | ||
ctx, _ := process.Ctx(cmd) | ||
|
||
// check if the directory exists | ||
_, err = os.Stat(cfg.DiagDir) | ||
if err != nil { | ||
fmt.Println("storage node directory doesn't exist", cfg.DiagDir) | ||
return err | ||
} | ||
|
||
db, err := storagenodedb.OpenExisting(ctx, zap.L().Named("db"), cfg.DatabaseConfig()) | ||
if err != nil { | ||
return errs.New("Error starting master database on storage node: %v", err) | ||
} | ||
defer func() { | ||
err = errs.Combine(err, db.Close()) | ||
}() | ||
|
||
summaries, err := db.Bandwidth().SummaryBySatellite(ctx, time.Time{}, time.Now()) | ||
if err != nil { | ||
fmt.Printf("unable to get bandwidth summary: %v\n", err) | ||
return err | ||
} | ||
|
||
satellites := storj.NodeIDList{} | ||
for id := range summaries { | ||
satellites = append(satellites, id) | ||
} | ||
sort.Sort(satellites) | ||
|
||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', tabwriter.AlignRight|tabwriter.Debug) | ||
defer func() { err = errs.Combine(err, w.Flush()) }() | ||
|
||
fmt.Fprint(w, "Satellite\tTotal\tPut\tGet\tDelete\tAudit Get\tRepair Get\tRepair Put\n") | ||
|
||
for _, id := range satellites { | ||
summary := summaries[id] | ||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n", | ||
id, | ||
memory.Size(summary.Total()), | ||
memory.Size(summary.Put), | ||
memory.Size(summary.Get), | ||
memory.Size(summary.Delete), | ||
memory.Size(summary.GetAudit), | ||
memory.Size(summary.GetRepair), | ||
memory.Size(summary.PutRepair), | ||
) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
3cf8963
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has been mentioned on Storj Community Forum (official). There might be relevant details there:
https://forum.storj.io/t/error-dashboard-sh-v1-77-2/22374/4