Skip to content

Commit

Permalink
add flag for output dir of report file
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanmetin committed Sep 18, 2023
1 parent dc45c7a commit 243f7b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions base/commands/migration/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ const (
StatusFailed Status = "FAILED"
StatusInProgress Status = "IN_PROGRESS"
)

const flagOutputDir = "output-dir"
3 changes: 2 additions & 1 deletion base/commands/migration/migration_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (StartCmd) Init(cc plug.InitContext) error {
cc.SetCommandHelp(help, help)
cc.SetPositionalArgCount(1, 1)
cc.AddBoolFlag(clc.FlagAutoYes, "", false, false, "start the migration without confirmation")
cc.AddStringFlag(flagOutputDir, "o", "", false, "output directory for the migration report, if not given current directory is used")
return nil
}

Expand All @@ -47,7 +48,7 @@ Selected data structures in the source cluster will be migrated to the target cl
}
ec.PrintlnUnnecessary("")
var updateTopic *hazelcast.Topic
sts := NewStartStages(updateTopic, MakeMigrationID(), ec.Args()[0])
sts := NewStartStages(updateTopic, MakeMigrationID(), ec.Args()[0], ec.Props().GetString(flagOutputDir))
if !sts.topicListenerID.Default() && sts.updateTopic != nil {
if err := sts.updateTopic.RemoveListener(ctx, sts.topicListenerID); err != nil {
return err
Expand Down
15 changes: 10 additions & 5 deletions base/commands/migration/start_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ type StartStages struct {
updateTopic *hazelcast.Topic
topicListenerID types.UUID
updateMsgChan chan UpdateMessage
reportOutputDir string
}

var timeoutErr = fmt.Errorf("migration could not be completed: reached timeout while reading status: "+
"please ensure that you are using Hazelcast's migration cluster distribution and your DMT config points to that cluster: %w",
context.DeadlineExceeded)

func NewStartStages(updateTopic *hazelcast.Topic, migrationID, configDir string) *StartStages {
func NewStartStages(updateTopic *hazelcast.Topic, migrationID, configDir, reportOutputDir string) *StartStages {
if migrationID == "" {
panic("migrationID is required")
}
return &StartStages{
updateTopic: updateTopic,
migrationID: migrationID,
configDir: configDir,
updateTopic: updateTopic,
migrationID: migrationID,
configDir: configDir,
reportOutputDir: reportOutputDir,
}
}

Expand Down Expand Up @@ -162,7 +164,10 @@ func (st *StartStages) handleUpdateMessage(ctx context.Context, ec plug.ExecCont
return true, fmt.Errorf("reading status: %w", err)
}
ec.PrintlnUnnecessary(ms.Report)
name := fmt.Sprintf("migration_report_%s", st.migrationID)
var name string
if st.reportOutputDir == "" {
name = fmt.Sprintf("migration_report_%s", st.migrationID)
}
if err = saveReportToFile(name, ms.Report); err != nil {
return true, fmt.Errorf("writing report to file: %w", err)
}
Expand Down

0 comments on commit 243f7b1

Please sign in to comment.