From 07c2824d940245f44fd597c128f4bb9f643a5279 Mon Sep 17 00:00:00 2001 From: Yingrong Zhao Date: Tue, 14 Jan 2020 12:23:09 -0500 Subject: [PATCH] storagenode/gracefulexit: fix exit-status command output When exit succeeded, cli should display `Y` in Successful column and `100%` in PercentComplete. Change-Id: I6093eca207ecd618bb332af12e5e455bc8224dde --- storagenode/gracefulexit/endpoint.go | 9 +++++---- storagenode/satellites/satellites.go | 1 + storagenode/storagenodedb/satellites.go | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/storagenode/gracefulexit/endpoint.go b/storagenode/gracefulexit/endpoint.go index f07e31390..c481584e7 100644 --- a/storagenode/gracefulexit/endpoint.go +++ b/storagenode/gracefulexit/endpoint.go @@ -133,13 +133,14 @@ func (e *Endpoint) GetExitProgress(ctx context.Context, req *pb.GetExitProgressR } var percentCompleted float32 - var hasCompleted bool + var exitSucceeded bool if progress.StartingDiskUsage != 0 { percentCompleted = (float32(progress.BytesDeleted) / float32(progress.StartingDiskUsage)) * 100 } - if progress.CompletionReceipt != nil { - hasCompleted = true + if progress.Status == satellites.ExitSucceeded { + exitSucceeded = true + percentCompleted = float32(100) } resp.Progress = append(resp.Progress, @@ -147,7 +148,7 @@ func (e *Endpoint) GetExitProgress(ctx context.Context, req *pb.GetExitProgressR DomainName: domain, NodeId: progress.SatelliteID, PercentComplete: percentCompleted, - Successful: hasCompleted, + Successful: exitSucceeded, CompletionReceipt: progress.CompletionReceipt, }, ) diff --git a/storagenode/satellites/satellites.go b/storagenode/satellites/satellites.go index 2a998021d..cea1db2a9 100644 --- a/storagenode/satellites/satellites.go +++ b/storagenode/satellites/satellites.go @@ -34,6 +34,7 @@ type ExitProgress struct { StartingDiskUsage int64 BytesDeleted int64 CompletionReceipt []byte + Status int32 } // Satellite contains the satellite and status diff --git a/storagenode/storagenodedb/satellites.go b/storagenode/storagenodedb/satellites.go index c16f1630b..d7904a594 100644 --- a/storagenode/storagenodedb/satellites.go +++ b/storagenode/storagenodedb/satellites.go @@ -94,7 +94,7 @@ func (db *satellitesDB) CompleteGracefulExit(ctx context.Context, satelliteID st func (db *satellitesDB) ListGracefulExits(ctx context.Context) (exitList []satellites.ExitProgress, err error) { defer mon.Task()(&ctx)(&err) - query := `SELECT satellite_id, initiated_at, finished_at, starting_disk_usage, bytes_deleted, completion_receipt FROM satellite_exit_progress` + query := `SELECT satellite_id, initiated_at, finished_at, starting_disk_usage, bytes_deleted, completion_receipt, status FROM satellite_exit_progress INNER JOIN satellites ON satellite_exit_progress.satellite_id = satellites.node_id` rows, err := db.QueryContext(ctx, query) if err != nil { return nil, ErrSatellitesDB.Wrap(err) @@ -105,7 +105,7 @@ func (db *satellitesDB) ListGracefulExits(ctx context.Context) (exitList []satel for rows.Next() { var exit satellites.ExitProgress - err := rows.Scan(&exit.SatelliteID, &exit.InitiatedAt, &exit.FinishedAt, &exit.StartingDiskUsage, &exit.BytesDeleted, &exit.CompletionReceipt) + err := rows.Scan(&exit.SatelliteID, &exit.InitiatedAt, &exit.FinishedAt, &exit.StartingDiskUsage, &exit.BytesDeleted, &exit.CompletionReceipt, &exit.Status) if err != nil { return nil, err }