Skip to content

Commit

Permalink
[CLC-425]: Print Warnings Before Exit (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanmetin authored Nov 3, 2023
1 parent 8966ce1 commit b9e7c18
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions base/commands/migration/migration_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,26 @@ 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* "))
} else {
ec.PrintlnUnnecessary(fmt.Sprintf("You have %d warnings that you can find in your migration report.", len(warnings)))
}
}

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 @@ -290,6 +310,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

0 comments on commit b9e7c18

Please sign in to comment.