Skip to content

Commit

Permalink
fix Yuce's PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanmetin committed Nov 4, 2023
1 parent e4a7c2c commit 0433098
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions base/commands/migration/estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Estimation usually ends within 15 seconds.`, banner))
}
resArr := res.([]string)
ec.PrintlnUnnecessary("")
ec.PrintlnUnnecessary(fmt.Sprintf("OK %s", resArr[0]))
ec.PrintlnUnnecessary(fmt.Sprintf("OK %s", resArr[1]))
ec.PrintlnUnnecessary(resArr[0])
ec.PrintlnUnnecessary(resArr[1])
ec.PrintlnUnnecessary("")
ec.PrintlnUnnecessary("OK Estimation completed successfully.")
return nil
Expand Down
25 changes: 22 additions & 3 deletions base/commands/migration/estimate_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"context"
"errors"
"fmt"
"strconv"
"time"

"github.com/hazelcast/hazelcast-commandline-client/clc/ux/stage"
"github.com/hazelcast/hazelcast-commandline-client/internal/log"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
"github.com/hazelcast/hazelcast-commandline-client/internal/str"
"github.com/hazelcast/hazelcast-go-client"
"github.com/hazelcast/hazelcast-go-client/serialization"
)
Expand Down Expand Up @@ -146,15 +146,34 @@ func fetchEstimationResults(ctx context.Context, ci *hazelcast.ClientInternal, m
if err != nil {
return nil, err
}
et, err := str.MsToSecs(estimatedTime.(serialization.JSON).String())
et, err := MsToSecs(estimatedTime.(serialization.JSON).String())
if err != nil {
return nil, err
}
es, err := str.BytesToMegabytes(estimatedSize.(serialization.JSON).String())
es, err := BytesToMegabytes(estimatedSize.(serialization.JSON).String())
if err != nil {
return nil, err
}
return []string{fmt.Sprintf("Estimated Size: %s ", es), fmt.Sprintf("Estimated Time: %s", et)}, nil
}
return nil, errors.New("no rows found")
}

func BytesToMegabytes(bytesStr string) (string, error) {
bytes, err := strconv.ParseFloat(bytesStr, 64)
if err != nil {
return "", err
}
mb := bytes / (1024.0 * 1024.0)
return fmt.Sprintf("%.2f MBs", mb), nil
}

func MsToSecs(ms string) (string, error) {
milliseconds, err := strconv.ParseInt(ms, 10, 64)
if err != nil {
return "", err
}
seconds := float64(milliseconds) / 1000.0
secondsStr := fmt.Sprintf("%.1f sec", seconds)
return secondsStr, nil
}
19 changes: 0 additions & 19 deletions internal/str/str.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,3 @@ func Colorize(text string) string {
}
return text
}

func BytesToMegabytes(bytesStr string) (string, error) {
bytes, err := strconv.ParseFloat(bytesStr, 64)
if err != nil {
return "", err
}
mb := bytes / (1024.0 * 1024.0)
return fmt.Sprintf("%.2f MBs", mb), nil
}

func MsToSecs(ms string) (string, error) {
milliseconds, err := strconv.ParseInt(ms, 10, 64)
if err != nil {
return "", err
}
seconds := float64(milliseconds) / 1000.0
secondsStr := fmt.Sprintf("%.1f sec", seconds)
return secondsStr, nil
}

0 comments on commit 0433098

Please sign in to comment.