Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanmetin committed Nov 6, 2023
1 parent dd7c1dc commit 6f6427b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion base/commands/migration/migration_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var migrationStatusNotFoundErr = fmt.Errorf("migration status not found")

var migrationReportNotFoundErr = "migration report cannot be found: %w"

var noDataStructuresFoundErr = errors.New("no datastructures found to migrate")

var progressMsg = "Migrating %s: %s"

func createMigrationStages(ctx context.Context, ec plug.ExecContext, ci *hazelcast.ClientInternal, migrationID string) ([]stage.Stage[any], error) {
Expand Down Expand Up @@ -154,12 +156,15 @@ func getDataStructuresToBeMigrated(ctx context.Context, ec plug.ExecContext, mig
if err != nil {
return nil, err
}
if rr == nil {
return nil, noDataStructuresFoundErr
}
var status OverallMigrationStatus
if err = json.Unmarshal(rr.(serialization.JSON), &status); err != nil {
return nil, err
}
if len(status.Migrations) == 0 {
return nil, errors.New("no datastructures found to migrate")
return nil, noDataStructuresFoundErr
}
for _, m := range status.Migrations {
dss = append(dss, DataStructureInfo{
Expand Down Expand Up @@ -254,6 +259,9 @@ func fetchMigrationStatus(ctx context.Context, ci *hazelcast.ClientInternal, mig
if err != nil {
return "", migrationStatusNotFoundErr
}
if rr == nil {
return "", migrationStatusNotFoundErr
}
return strings.TrimSuffix(strings.TrimPrefix(string(rr.(serialization.JSON)), `"`), `"`), nil
}

Expand All @@ -263,6 +271,9 @@ func fetchOverallProgress(ctx context.Context, ci *hazelcast.ClientInternal, mig
if err != nil {
return 0, 0, err
}
if r == nil {
return 0, 0, errors.New("overall progress not found")
}
remainingTime, err := r.Get(0)
if err != nil {
return 0, 0, err
Expand Down Expand Up @@ -295,6 +306,9 @@ func fetchMigrationReport(ctx context.Context, ci *hazelcast.ClientInternal, mig
if err != nil {
return "", fmt.Errorf(migrationReportNotFoundErr, err)
}
if r == nil {
return "", errors.New("migration report not found")
}
rr, err := r.Get(0)
if err != nil {
return "", fmt.Errorf(migrationReportNotFoundErr, err)
Expand All @@ -310,6 +324,9 @@ func fetchMigrationErrors(ctx context.Context, ci *hazelcast.ClientInternal, mig
if err != nil {
return "", err
}
if r == nil {
return "", errors.New("could not fetch migration errors")
}
rr, err := r.Get(0)
if err != nil {
return "", err
Expand Down Expand Up @@ -362,6 +379,10 @@ func maybePrintWarnings(ctx context.Context, ec plug.ExecContext, ci *hazelcast.
ec.Logger().Error(err)
return
}
if r == nil {
ec.Logger().Info("could not find any warnings")
return
}
rr, err := r.Get(0)
if err != nil {
ec.Logger().Error(err)
Expand Down

0 comments on commit 6f6427b

Please sign in to comment.