diff --git a/base/commands/migration/migration_stages.go b/base/commands/migration/migration_stages.go index 685041dfe..1d24c133c 100644 --- a/base/commands/migration/migration_stages.go +++ b/base/commands/migration/migration_stages.go @@ -12,11 +12,12 @@ import ( "strings" "time" + "github.com/hazelcast/hazelcast-go-client" + "github.com/hazelcast/hazelcast-go-client/serialization" + "github.com/hazelcast/hazelcast-commandline-client/clc/ux/stage" clcerrors "github.com/hazelcast/hazelcast-commandline-client/errors" "github.com/hazelcast/hazelcast-commandline-client/internal/plug" - "github.com/hazelcast/hazelcast-go-client" - "github.com/hazelcast/hazelcast-go-client/serialization" ) var timeoutErr = fmt.Errorf("migration could not be completed: reached timeout while reading status: "+ @@ -188,6 +189,13 @@ func WaitForMigrationToBeInProgress(ctx context.Context, ci *hazelcast.ClientInt } return err } + if Status(status) == StatusFailed { + errs, err := fetchMigrationErrors(ctx, ci, migrationID) + if err != nil { + return fmt.Errorf("migration failed and dmt cannot fetch migration errors: %w", err) + } + return errors.New(errs) + } if Status(status) == StatusInProgress { return nil } @@ -235,28 +243,17 @@ func fetchMigrationReport(ctx context.Context, ci *hazelcast.ClientInternal, mig } func fetchMigrationErrors(ctx context.Context, ci *hazelcast.ClientInternal, migrationID string) (string, error) { - q := fmt.Sprintf(`SELECT JSON_QUERY(this, '$.errors') FROM %s WHERE __key='%s'`, StatusMapName, migrationID) - res, err := ci.Client().SQL().Execute(ctx, q) + q := fmt.Sprintf(`SELECT JSON_QUERY(this, '$.errors' WITH WRAPPER) FROM %s WHERE __key='%s'`, StatusMapName, migrationID) + row, err := querySingleRow(ctx, ci, q) if err != nil { return "", err } - it, err := res.Iterator() + var errs []string + err = json.Unmarshal(row.(serialization.JSON), &errs) if err != nil { return "", err } - var errs []string - for it.HasNext() { - row, err := it.Next() - if err != nil { - return "", err - } - r, err := row.Get(0) - if err != nil { - return "", err - } - errs = append(errs, strings.TrimPrefix(strings.TrimSuffix(string(r.(serialization.JSON)), `"`), `"`)) - } - return strings.Join(errs, "\n"), nil + return "* " + strings.Join(errs, "\n* "), nil } func finalizeMigration(ctx context.Context, ec plug.ExecContext, ci *hazelcast.ClientInternal, migrationID, reportOutputDir string) error { diff --git a/base/commands/migration/start_stages_it_test.go b/base/commands/migration/start_stages_it_test.go index 568172ecb..d3b6ac7c7 100644 --- a/base/commands/migration/start_stages_it_test.go +++ b/base/commands/migration/start_stages_it_test.go @@ -12,15 +12,16 @@ import ( "testing" "time" + hz "github.com/hazelcast/hazelcast-go-client" + "github.com/hazelcast/hazelcast-go-client/serialization" + "github.com/stretchr/testify/require" + _ "github.com/hazelcast/hazelcast-commandline-client/base" _ "github.com/hazelcast/hazelcast-commandline-client/base/commands" "github.com/hazelcast/hazelcast-commandline-client/base/commands/migration" "github.com/hazelcast/hazelcast-commandline-client/clc/paths" . "github.com/hazelcast/hazelcast-commandline-client/internal/check" "github.com/hazelcast/hazelcast-commandline-client/internal/it" - hz "github.com/hazelcast/hazelcast-go-client" - "github.com/hazelcast/hazelcast-go-client/serialization" - "github.com/stretchr/testify/require" ) func TestMigrationStages(t *testing.T) { @@ -42,7 +43,7 @@ func TestMigrationStages(t *testing.T) { "testdata/start/migration_success_initial.json", "testdata/start/migration_success_failure.json", }, - expectedErr: errors.New("Failed migrating IMAP: imap5: some error"), + expectedErr: errors.New("Failed migrating IMAP: imap5: * some error\n* another error"), }, } for _, tc := range testCases { diff --git a/base/commands/migration/testdata/start/migration_success_failure.json b/base/commands/migration/testdata/start/migration_success_failure.json index e4ae91f55..eb29fba2e 100644 --- a/base/commands/migration/testdata/start/migration_success_failure.json +++ b/base/commands/migration/testdata/start/migration_success_failure.json @@ -66,6 +66,6 @@ } ], "logs": ["some user friendly log message", "another user friendly log message"], - "errors": ["some error"], + "errors": ["some error", "another error"], "report": "failed migration report" } \ No newline at end of file