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

Fix issue 414 CLC-418 #417

Merged
merged 7 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion base/commands/migration/migration_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ 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)
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The else is not necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

else is not necessary.

return errors.New(errs)
}
}
if Status(status) == StatusInProgress {
return nil
}
Expand Down Expand Up @@ -235,7 +243,7 @@ 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)
q := fmt.Sprintf(`SELECT JSON_QUERY(this, '$.errors' WITH WRAPPER) FROM %s WHERE __key='%s'`, StatusMapName, migrationID)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is WITH WRAPPER ?

Choose a reason for hiding this comment

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

res, err := ci.Client().SQL().Execute(ctx, q)
if err != nil {
return "", err
Expand Down
9 changes: 5 additions & 4 deletions base/commands/migration/start_stages_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member Author

Choose a reason for hiding this comment

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

this is done by goland automatically and I can't prevent it doing that :D

)

func TestMigrationStages(t *testing.T) {
Expand All @@ -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\"]"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this error message is not optimal.
Can't we keep the original string?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would rewrite fetchMigrationErrors function like:

func fetchMigrationErrors(ctx context.Context, ci *hazelcast.ClientInternal, migrationID string) (string, error) {
	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
	}
	// ex. converts ["some error", "another error"] -> some error\nanother error
	r := strings.Split(
		strings.ReplaceAll(
			strings.ReplaceAll(
				strings.ReplaceAll(string(row.(serialization.JSON)), `"`, ``),
				"[", ""),
			"]", ""),
		",")
	return strings.Join(r, "\n"), nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is possible to iterate errors it would be more convenient of course.

},
}
for _, tc := range testCases {
Expand Down
Loading