From b9e7c186c8ab865ed55c473fca6f4f660198bb1d Mon Sep 17 00:00:00 2001 From: Kutluhan Metin Date: Fri, 3 Nov 2023 18:21:50 +0300 Subject: [PATCH] [CLC-425]: Print Warnings Before Exit (#420) --- base/commands/migration/migration_stages.go | 23 +++++++++++++++++++++ base/commands/migration/migration_start.go | 1 + base/commands/migration/migration_status.go | 1 + 3 files changed, 25 insertions(+) diff --git a/base/commands/migration/migration_stages.go b/base/commands/migration/migration_stages.go index 6cb16763..b2fbc090 100644 --- a/base/commands/migration/migration_stages.go +++ b/base/commands/migration/migration_stages.go @@ -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 { @@ -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") diff --git a/base/commands/migration/migration_start.go b/base/commands/migration/migration_start.go index 84368199..fdb7cfe5 100644 --- a/base/commands/migration/migration_start.go +++ b/base/commands/migration/migration_start.go @@ -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 diff --git a/base/commands/migration/migration_status.go b/base/commands/migration/migration_status.go index aeba1993..40cf9e71 100644 --- a/base/commands/migration/migration_status.go +++ b/base/commands/migration/migration_status.go @@ -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