Skip to content

Commit

Permalink
[feat]CurveadmConfig: add debug mode
Browse files Browse the repository at this point in the history
Signed-off-by: sjf <[email protected]>
  • Loading branch information
Songjf-ttk committed Sep 20, 2023
1 parent 7d3bd4b commit a96ce9e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 19 deletions.
27 changes: 20 additions & 7 deletions cli/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"github.com/fatih/color"
"github.com/kpango/glg"
"github.com/opencurve/curveadm/cli/cli"
comm "github.com/opencurve/curveadm/internal/common"
"github.com/opencurve/curveadm/internal/configure/topology"
Expand Down Expand Up @@ -111,6 +112,7 @@ type deployOptions struct {
insecure bool
poolset string
poolsetDiskType string
debug bool
}

func checkDeployOptions(options deployOptions) error {
Expand Down Expand Up @@ -145,6 +147,7 @@ func NewDeployCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags.BoolVarP(&options.insecure, "insecure", "k", false, "Deploy without precheck")
flags.StringVar(&options.poolset, "poolset", "default", "poolset name")
flags.StringVar(&options.poolsetDiskType, "poolset-disktype", "ssd", "Specify the disk type of physical pool")
flags.BoolVar(&options.debug, "debug", false, "Debug deploy progress")
return cmd
}

Expand Down Expand Up @@ -214,6 +217,7 @@ func genDeployPlaybook(curveadm *cli.CurveAdm,
steps = skipDeploySteps(steps, options)
poolset := options.poolset
diskType := options.poolsetDiskType
debug := options.debug

pb := playbook.NewPlaybook(curveadm)
for _, step := range steps {
Expand All @@ -237,6 +241,8 @@ func genDeployPlaybook(curveadm *cli.CurveAdm,
options[comm.POOLSET_DISK_TYPE] = diskType
} else if step == CREATE_LOGICAL_POOL {
options[comm.KEY_CREATE_POOL_TYPE] = comm.POOL_TYPE_LOGICAL
} else if step == CREATE_CONTAINER {
options[comm.DEBUG_MODE] = debug
}

pb.AddStep(&playbook.PlaybookStep{
Expand Down Expand Up @@ -299,36 +305,43 @@ func displayDeployTitle(curveadm *cli.CurveAdm, dcs []*topology.DeployConfig) {
* 6) balance leader rapidly
*/
func runDeploy(curveadm *cli.CurveAdm, options deployOptions) error {
// 1) parse cluster topology

// 1) check debug mode
debug := options.debug
if debug {
glg.Get().SetLevel(glg.DEBG)
}

// 2) parse cluster topology
dcs, err := curveadm.ParseTopology()
if err != nil {
return err
}

// 2) skip service role
// 3) skip service role
dcs = skipServiceRole(dcs, options)

// 3) precheck before deploy
// 4) precheck before deploy
err = precheckBeforeDeploy(curveadm, dcs, options)
if err != nil {
return err
}

// 4) generate deploy playbook
// 5) generate deploy playbook
pb, err := genDeployPlaybook(curveadm, dcs, options)
if err != nil {
return err
}

// 5) display title
// 6) display title
displayDeployTitle(curveadm, dcs)

// 6) run playground
// 7) run playground
if err = pb.Run(); err != nil {
return err
}

// 7) print success prompt
// 8) print success prompt
curveadm.WriteOutln("")
curveadm.WriteOutln(color.GreenString("Cluster '%s' successfully deployed ^_^."), curveadm.ClusterName())
return nil
Expand Down
62 changes: 52 additions & 10 deletions cli/command/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package command
import (
"fmt"

"github.com/kpango/glg"
"github.com/opencurve/curveadm/cli/cli"
comm "github.com/opencurve/curveadm/internal/common"
"github.com/opencurve/curveadm/internal/configure"
Expand All @@ -41,7 +42,14 @@ const (
FORMAT_EXAMPLE = `Examples:
$ curveadm format -f /path/to/format.yaml # Format chunkfile pool with specified configure file
$ curveadm format --status -f /path/to/format.yaml # Display formatting status
$ curveadm format --stop -f /path/to/format.yaml # Stop formatting progress`
$ curveadm format --stop -f /path/to/format.yaml # Stop formatting progress
$ curveadm format --debug -f /path/to/format.yaml # Format chunkfile with debug mode`
)

const (
FORMAT_CHUNKFILE_POOL = playbook.FORMAT_CHUNKFILE_POOL
GET_FORMAT_STATUS = playbook.GET_FORMAT_STATUS
STOP_FORMAT = playbook.STOP_FORMAT
)

var (
Expand All @@ -59,9 +67,27 @@ var (
)

type formatOptions struct {
filename string
showStatus bool
stopFormat bool
filename string
showStatus bool
stopFormat bool
debug bool
}

func checkFormatOptions(options formatOptions) error {
showStatus := options.showStatus
stopFormat := options.stopFormat
debug := options.debug
if showStatus && stopFormat {
return errno.ERR_UNSUPPORT_CONFIGURE_VALUE_TYPE
}
if showStatus && debug {
return errno.ERR_UNSUPPORT_CONFIGURE_VALUE_TYPE
}
if stopFormat && debug {
return errno.ERR_UNSUPPORT_CONFIGURE_VALUE_TYPE
}

return nil
}

func NewFormatCommand(curveadm *cli.CurveAdm) *cobra.Command {
Expand All @@ -72,6 +98,9 @@ func NewFormatCommand(curveadm *cli.CurveAdm) *cobra.Command {
Short: "Format chunkfile pool",
Args: cliutil.NoArgs,
Example: FORMAT_EXAMPLE,
PreRunE: func(cmd *cobra.Command, args []string) error {
return checkFormatOptions(options)
},
RunE: func(cmd *cobra.Command, args []string) error {
return runFormat(curveadm, options)
},
Expand All @@ -82,6 +111,7 @@ func NewFormatCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags.StringVarP(&options.filename, "formatting", "f", "format.yaml", "Specify the configure file for formatting chunkfile pool")
flags.BoolVar(&options.showStatus, "status", false, "Show formatting status")
flags.BoolVar(&options.stopFormat, "stop", false, "Stop formatting progress")
flags.BoolVar(&options.debug, "debug", false, "Debug formatting progress")

return cmd
}
Expand All @@ -93,25 +123,32 @@ func genFormatPlaybook(curveadm *cli.CurveAdm,
return nil, errno.ERR_NO_DISK_FOR_FORMATTING
}

if options.showStatus && options.stopFormat {
return nil, errno.ERR_UNSUPPORT_CONFIGURE_VALUE_TYPE
}
showStatus := options.showStatus
stopFormat := options.stopFormat
debug := options.debug

steps := FORMAT_PLAYBOOK_STEPS
if options.showStatus {
if showStatus {
steps = FORMAT_STATUS_PLAYBOOK_STEPS
}
if options.stopFormat {
if stopFormat {
steps = FORMAT_STOP_PLAYBOOK_STEPS
}

pb := playbook.NewPlaybook(curveadm)
for _, step := range steps {
// options
options := map[string]interface{}{}
if step == FORMAT_CHUNKFILE_POOL {
options[comm.DEBUG_MODE] = debug
}
pb.AddStep(&playbook.PlaybookStep{
Type: step,
Configs: fcs,
ExecOptions: playbook.ExecOptions{
SilentSubBar: options.showStatus,
SilentSubBar: showStatus,
},
Options: options,
})
}
return pb, nil
Expand All @@ -133,6 +170,11 @@ func runFormat(curveadm *cli.CurveAdm, options formatOptions) error {
var err error
var fcs []*configure.FormatConfig
diskRecords := curveadm.DiskRecords()
debug := options.debug

if debug {
glg.Get().SetLevel(glg.DEBG)
}

// 1) parse format config from yaml file or database
if len(diskRecords) == 0 {
Expand Down
1 change: 1 addition & 0 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
POOL_TYPE_PHYSICAL = "physicalpool"
POOLSET = "poolset"
POOLSET_DISK_TYPE = "poolset-disktype"
DEBUG_MODE = "DEBUG_MODE"

// disk
DISK_DEFAULT_NULL_SIZE = "-"
Expand Down
4 changes: 3 additions & 1 deletion internal/task/task/bs/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"time"

"github.com/opencurve/curveadm/cli/cli"
comm "github.com/opencurve/curveadm/internal/common"
"github.com/opencurve/curveadm/internal/configure"
"github.com/opencurve/curveadm/internal/configure/disks"
os "github.com/opencurve/curveadm/internal/configure/os"
Expand Down Expand Up @@ -247,6 +248,7 @@ func NewFormatChunkfilePoolTask(curveadm *cli.CurveAdm, fc *configure.FormatConf
formatScriptPath := fmt.Sprintf("%s/format.sh", layout.ToolsBinDir)
formatCommand := fmt.Sprintf("%s %s %d %d %s %s", formatScriptPath, layout.FormatBinaryPath,
usagePercent, DEFAULT_CHUNKFILE_SIZE, layout.ChunkfilePoolDir, layout.ChunkfilePoolMetaPath)
debug := curveadm.MemStorage().Get(comm.DEBUG_MODE).(bool)

// 1: skip if formating container exist
t.AddStep(&step.ListContainers{
Expand Down Expand Up @@ -319,7 +321,7 @@ func NewFormatChunkfilePoolTask(curveadm *cli.CurveAdm, fc *configure.FormatConf
Command: formatCommand,
Entrypoint: "/bin/bash",
Name: containerName,
Remove: true,
Remove: !debug,
Volumes: []step.Volume{{HostPath: mountPoint, ContainerPath: chunkfilePoolRootDir}},
Out: &containerId,
ExecOptions: curveadm.ExecOptions(),
Expand Down
2 changes: 1 addition & 1 deletion internal/task/task/checker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (s *step2StopContainer) Execute(ctx *context.Context) error {
ExecOptions: s.curveadm.ExecOptions(),
})
steps = append(steps, &step.RemoveContainer{
Success: &success, // FIXME(P1): rmeove iff container exist
Success: &success, // FIXME(P1): remove if container exist
ContainerId: *s.containerId,
ExecOptions: s.curveadm.ExecOptions(),
})
Expand Down

0 comments on commit a96ce9e

Please sign in to comment.