Skip to content

Commit

Permalink
Merge pull request #602 from 0chain/reset-blobber-stats
Browse files Browse the repository at this point in the history
reset blobber stats command
  • Loading branch information
dabasov authored Mar 13, 2024
2 parents 29a58ed + 480d3cc commit 46cf85d
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,81 @@ var blobberUpdateCmd = &cobra.Command{
},
}

var resetBlobberStatsCmd = &cobra.Command{
Use: "reset-blobber-stats",
Short: "Reset blobber stats",
Long: `Reset blobber stats`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
var (
flags = cmd.Flags()

blobberID string
prevAllocated int64
prevSavedData int64
newAllocated int64
newSavedData int64
err error
)

if !flags.Changed("blobber_id") {
log.Fatal("missing required 'blobber_id' flag")
}
if blobberID, err = flags.GetString("blobber_id"); err != nil {
log.Fatal("error in 'blobber_id' flag: ", err)
}

if !flags.Changed("prev_allocated") {
log.Fatal("missing required 'prev_allocated' flag")
}
if prevAllocated, err = flags.GetInt64("prev_allocated"); err != nil {
log.Fatal("error in 'prev_allocated' flag: ", err)
}

if !flags.Changed("prev_saved_data") {
log.Fatal("missing required 'prev_saved_data' flag")
}
if prevSavedData, err = flags.GetInt64("prev_saved_data"); err != nil {
log.Fatal("error in 'prev_saved_data' flag: ", err)
}

if !flags.Changed("new_allocated") {
log.Fatal("missing required 'new_allocated' flag")
}
if newAllocated, err = flags.GetInt64("new_allocated"); err != nil {
log.Fatal("error in 'new_allocated' flag: ", err)
}

if !flags.Changed("new_saved_data") {
log.Fatal("missing required 'new_saved_data' flag")
}
if newSavedData, err = flags.GetInt64("new_saved_data"); err != nil {
log.Fatal("error in 'new_saved_data' flag: ", err)
}

resetBlobberStatsDto := &sdk.ResetBlobberStatsDto {
BlobberID: blobberID,
PrevAllocated: prevAllocated,
PrevSavedData: prevSavedData,
NewAllocated: newAllocated,
NewSavedData: newSavedData,
}
fmt.Println(*resetBlobberStatsDto)

_, _, err = sdk.ResetBlobberStats(resetBlobberStatsDto)
if err != nil {
log.Fatal(err)
}
fmt.Println("reset blobber stats successfully")
},
}

func init() {
rootCmd.AddCommand(scConfig)
rootCmd.AddCommand(lsBlobers)
rootCmd.AddCommand(blobberInfoCmd)
rootCmd.AddCommand(blobberUpdateCmd)
rootCmd.AddCommand(resetBlobberStatsCmd)

scConfig.Flags().Bool("json", false, "(default false) pass this option to print response as json data")
lsBlobers.Flags().Bool("json", false, "(default false) pass this option to print response as json data")
Expand All @@ -324,4 +394,15 @@ func init() {
buf.Bool("not_available", true, "(default false) set blobber's availability for new allocations")
buf.String("url", "", "update the url of the blobber, optional")
blobberUpdateCmd.MarkFlagRequired("blobber_id")

resetBlobberStatsCmd.Flags().String("blobber_id", "", "blobber_id is required")
resetBlobberStatsCmd.Flags().Int64("prev_allocated", 0, "prev_allocated is required")
resetBlobberStatsCmd.Flags().Int64("prev_saved_data", 0, "prev_saved_data is required")
resetBlobberStatsCmd.Flags().Int64("new_allocated", 0, "new_allocated is required")
resetBlobberStatsCmd.Flags().Int64("new_saved_data", 0, "new_saved_data is required")
resetBlobberStatsCmd.MarkFlagRequired("blobber_id")
resetBlobberStatsCmd.MarkFlagRequired("prev_allocated")
resetBlobberStatsCmd.MarkFlagRequired("prev_saved_data")
resetBlobberStatsCmd.MarkFlagRequired("new_allocated")
resetBlobberStatsCmd.MarkFlagRequired("new_saved_data")
}

0 comments on commit 46cf85d

Please sign in to comment.