Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLC-425]: Print Warnings Before Exit #420

Merged
merged 5 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions base/commands/migration/migration_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ func finalizeMigration(ctx context.Context, ec plug.ExecContext, ci *hazelcast.C
return nil
}

func maybePrintWarnings(ctx context.Context, ec plug.ExecContext, ci *hazelcast.ClientInternal, migrationID string) {
q := fmt.Sprintf(`SELECT JSON_QUERY(this, '$.warnings' WITH WRAPPER) FROM %s WHERE __key='%s'`, StatusMapName, migrationID)
row, err := querySingleRow(ctx, ci, q)
if err != nil {
ec.Logger().Error(err)
return
}
var warnings []string
err = json.Unmarshal(row.(serialization.JSON), &warnings)
if err != nil {
ec.Logger().Error(err)
return
}
if len(warnings) <= 5 {
ec.PrintlnUnnecessary("* " + strings.Join(warnings, "\n* "))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a else block that says "you have x warnings that you can find in your migration report" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

func querySingleRow(ctx context.Context, ci *hazelcast.ClientInternal, query string) (any, error) {
res, err := ci.Client().SQL().Execute(ctx, query)
if err != nil {
Expand All @@ -288,6 +306,9 @@ func querySingleRow(ctx context.Context, ci *hazelcast.ClientInternal, query str
if err != nil {
return "", err
}
if r == nil {
return nil, errors.New("no rows found")
}
return r, nil
}
return nil, errors.New("no rows found")
Expand Down
1 change: 1 addition & 0 deletions base/commands/migration/migration_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Selected data structures in the source cluster will be migrated to the target cl
ec.PrintlnUnnecessary("")
mID := MakeMigrationID()
defer func() {
maybePrintWarnings(ctx, ec, ci, mID)
finalizeErr := finalizeMigration(ctx, ec, ci, mID, ec.Props().GetString(flagOutputDir))
if err == nil {
err = finalizeErr
Expand Down
1 change: 1 addition & 0 deletions base/commands/migration/migration_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (s StatusCmd) Exec(ctx context.Context, ec plug.ExecContext) (err error) {
return err
}
defer func() {
maybePrintWarnings(ctx, ec, ci, mID.(string))
finalizeErr := finalizeMigration(ctx, ec, ci, mID.(string), ec.Props().GetString(flagOutputDir))
if err == nil {
err = finalizeErr
Expand Down
Loading