diff --git a/base/commands/migration/const.go b/base/commands/migration/const.go index b1f320b4..6c584a41 100644 --- a/base/commands/migration/const.go +++ b/base/commands/migration/const.go @@ -19,3 +19,5 @@ const ( StatusFailed Status = "FAILED" StatusInProgress Status = "IN_PROGRESS" ) + +const flagOutputDir = "output-dir" diff --git a/base/commands/migration/migration_start.go b/base/commands/migration/migration_start.go index 01c642ee..7beea3a3 100644 --- a/base/commands/migration/migration_start.go +++ b/base/commands/migration/migration_start.go @@ -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 } @@ -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 diff --git a/base/commands/migration/start_stages.go b/base/commands/migration/start_stages.go index 9f6697d5..fc913ee0 100644 --- a/base/commands/migration/start_stages.go +++ b/base/commands/migration/start_stages.go @@ -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, } } @@ -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) }