Skip to content

Commit

Permalink
rewrite using two boolean variable to divide
Browse files Browse the repository at this point in the history
cluster config and instance script loading

fix
  • Loading branch information
patapenka-alexey committed Jan 14, 2025
1 parent 45bf3b8 commit cafd354
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 84 deletions.
3 changes: 1 addition & 2 deletions cli/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func NewBuildCmd() *cobra.Command {
args []string,
toComplete string) ([]string, cobra.ShellCompDirective) {
var runningCtx running.RunningCtx
err := running.FillCtx(
cliOpts, &cmdCtx, &runningCtx, nil, running.ConfigLoadSkip)
err := running.FillCtx(cliOpts, &cmdCtx, &runningCtx, nil, false, false)
if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func internalCheckModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true, true)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func internalCleanModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadIgnoreErrors)
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false, false)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cli/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ func parseAppStr(cmdCtx *cmdcontext.CmdCtx, appStr string) (string, string, stri
// Fill context for the entire application.
// publish app:inst can work even if the `inst` instance doesn't exist right now.
var runningCtx running.RunningCtx
err := running.FillCtx(
cliOpts, cmdCtx, &runningCtx, []string{appName}, running.ConfigLoadSkip)
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{appName}, false, false)
if err != nil {
return "", "", "", err
}
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func resolveConnectOpts(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts,

// FillCtx returns error if no instances found.
var runningCtx running.RunningCtx
if fillErr := running.FillCtx(
cliOpts, cmdCtx, &runningCtx, []string{target}, running.ConfigLoadAll); fillErr == nil {
fillErr := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{target}, true, false)
if fillErr == nil {
if len(runningCtx.Instances) > 1 {
err = fmt.Errorf("specify instance name")
return
Expand Down
3 changes: 1 addition & 2 deletions cli/cmd/internal/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func ValidArgsFunction(
directive = cobra.ShellCompDirectiveNoFileComp

var runningCtx running.RunningCtx
if err := running.FillCtx(
cliOpts, cmdCtx, &runningCtx, nil, running.ConfigLoadSkip); err != nil {
if err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, nil, false, false); err != nil {
return
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func internalKillModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
if confirm {
var runningCtx running.RunningCtx
if err = running.FillCtx(
cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip); err != nil {
cliOpts, cmdCtx, &runningCtx, args, false, false); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func internalLogModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {

var err error
var runningCtx running.RunningCtx
err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
err = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/logrotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func internalLogrotateModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadIgnoreErrors)
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func internalPlayModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
// FillCtx returns error if no instances found.
var runningCtx running.RunningCtx
err := running.FillCtx(
cliOpts, cmdCtx, &runningCtx, []string{args[0]}, running.ConfigLoadAll)
cliOpts, cmdCtx, &runningCtx, []string{args[0]}, true, true)
if err == nil {
if len(runningCtx.Instances) > 1 {
return util.InternalError(
Expand Down
31 changes: 15 additions & 16 deletions cli/cmd/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ type replicasetCtx struct {

// replicasetFillCtx fills the replicaset command context.
func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target string,
isRunningCtxRequired bool, loadConfig running.ConfigLoad) error {
isRunningCtxRequired bool, configRequired bool, scriptRequired bool) error {
var err error
ctx.Orchestrator, err = getOrchestrator()
if err != nil {
Expand All @@ -491,9 +491,9 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
SslCiphers: replicasetSslCiphers,
}
var connOpts connector.ConnectOpts

if err := running.FillCtx(
cliOpts, cmdCtx, &ctx.RunningCtx, []string{target}, loadConfig); err == nil {
err = running.FillCtx(cliOpts, cmdCtx, &ctx.RunningCtx, []string{target},
configRequired, scriptRequired)
if err == nil {
ctx.IsApplication = true
if len(ctx.RunningCtx.Instances) == 1 {
if connectCtx.Username != "" || connectCtx.Password != "" {
Expand All @@ -515,7 +515,7 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
// Re-fill context for an application.
ctx.InstName = instName
err := running.FillCtx(
cliOpts, cmdCtx, &ctx.RunningCtx, []string{appName}, loadConfig)
cliOpts, cmdCtx, &ctx.RunningCtx, []string{appName}, true, true)
if err != nil {
// Should not happen.
return err
Expand Down Expand Up @@ -573,7 +573,7 @@ func replicasetFillCtx(cmdCtx *cmdcontext.CmdCtx, ctx *replicasetCtx, target str
// internalReplicasetUpgradeModule is a "upgrade" command for the replicaset module.
func internalReplicasetUpgradeModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand Down Expand Up @@ -608,7 +608,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
downgradeVersion := args[1]

var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand Down Expand Up @@ -641,7 +641,7 @@ func internalReplicasetDowngradeModule(cmdCtx *cmdcontext.CmdCtx, args []string)
// internalReplicasetPromoteModule is a "promote" command for the replicaset module.
func internalReplicasetPromoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
return err
}
if !ctx.IsInstanceConnect {
Expand Down Expand Up @@ -671,7 +671,7 @@ func internalReplicasetPromoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) e
// internalReplicasetDemoteModule is a "demote" command for the replicaset module.
func internalReplicasetDemoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, true, true); err != nil {
return err
}
if !ctx.IsApplication {
Expand Down Expand Up @@ -703,8 +703,7 @@ func internalReplicasetDemoteModule(cmdCtx *cmdcontext.CmdCtx, args []string) er
// internalReplicasetStatusModule is a "status" command for the replicaset module.
func internalReplicasetStatusModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(
cmdCtx, &ctx, args[0], false, running.ConfigLoadIgnoreErrors); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, false, false); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand All @@ -724,7 +723,7 @@ func internalReplicasetExpelModule(cmdCtx *cmdcontext.CmdCtx, args []string) err
return fmt.Errorf("the command expects argument application_name:instance_name")
}
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, true, true); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand All @@ -751,7 +750,7 @@ func internalReplicasetExpelModule(cmdCtx *cmdcontext.CmdCtx, args []string) err
// the "replicaset vshard" module.
func internalReplicasetBootstrapVShardModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand All @@ -778,7 +777,7 @@ func internalReplicasetBootstrapModule(cmdCtx *cmdcontext.CmdCtx, args []string)
_, instName, found := strings.Cut(args[0], string(running.InstanceDelimiter))

var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, running.ConfigLoadAll); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], true, true, true); err != nil {
return err
}
if ctx.IsInstanceConnect {
Expand Down Expand Up @@ -840,7 +839,7 @@ func internalReplicasetRebootstrapModule(cmdCtx *cmdcontext.CmdCtx, args []strin
// internalReplicasetRolesAddModule is a "roles add" command for the replicaset module.
func internalReplicasetRolesAddModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
return err
}
defer ctx.Conn.Close()
Expand Down Expand Up @@ -883,7 +882,7 @@ func internalReplicasetRolesAddModule(cmdCtx *cmdcontext.CmdCtx, args []string)
// internalReplicasetRolesRemoveModule is a "roles remove" command for the replicaset module.
func internalReplicasetRolesRemoveModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var ctx replicasetCtx
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, running.ConfigLoadAll); err != nil {
if err := replicasetFillCtx(cmdCtx, &ctx, args[0], false, true, true); err != nil {
return err
}
defer ctx.Conn.Close()
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func internalStartModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadAll)
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, true, false)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func internalStatusModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
if err := running.FillCtx(
cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadIgnoreErrors); err != nil {
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false, false)
if err != nil {
return err
}

err := status.Status(runningCtx, opts)
err = status.Status(runningCtx, opts)
return err
}
3 changes: 1 addition & 2 deletions cli/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ func internalStopModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

var runningCtx running.RunningCtx
var err error = running.FillCtx(
cliOpts, cmdCtx, &runningCtx, args, running.ConfigLoadSkip)
var err error = running.FillCtx(cliOpts, cmdCtx, &runningCtx, args, false, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/instances/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ListInstances(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts) error {
fmt.Printf("instances enabled directory: %s\n", cliOpts.Env.InstancesEnabled)

applications, err := running.CollectInstancesForApps(appList, cliOpts, cmdCtx.Cli.ConfigDir,
cmdCtx.Integrity, running.ConfigLoadSkip)
cmdCtx.Integrity, false, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/pack/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func initAppsInfo(cliOpts *config.CliOpts, cmdCtx *cmdcontext.CmdCtx, packCtx *P
}
packCtx.AppList = appList
packCtx.AppsInfo, err = running.CollectInstancesForApps(packCtx.AppList, cliOpts,
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, running.ConfigLoadSkip)
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, false, false)
if err != nil {
return fmt.Errorf("failed to collect applications info: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/replicaset/rebootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func cleanDataFiles(instCtx running.InstanceCtx) error {
// and starting it again.
func Rebootstrap(cmdCtx cmdcontext.CmdCtx, cliOpts config.CliOpts, rbCtx RebootstrapCtx) error {
apps, err := running.CollectInstancesForApps([]string{rbCtx.AppName}, &cliOpts,
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, running.ConfigLoadAll)
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, true, true)
if err != nil {
return fmt.Errorf("cannot collect application instances info: %s", err)
}
Expand Down
Loading

0 comments on commit cafd354

Please sign in to comment.