Skip to content

Commit

Permalink
Add missing AbortRepairRun method
Browse files Browse the repository at this point in the history
  • Loading branch information
adutra committed Jun 4, 2021
1 parent fdaae18 commit 4249ab6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion reaper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ type Client interface {
// in state “ERROR”, picking up where it left off.
StartRepairRun(ctx context.Context, repairRunId uuid.UUID) error

// PauseRepairRun pauses a repair run identified by its id.
// PauseRepairRun pauses a repair run identified by its id. The repair run must be in RUNNING state.
PauseRepairRun(ctx context.Context, repairRunId uuid.UUID) error

// ResumeRepairRun is an alias to StartRepairRun.
ResumeRepairRun(ctx context.Context, repairRunId uuid.UUID) error

// AbortRepairRun aborts a repair run identified bu its id. The repair run must not be in ERROR state.
AbortRepairRun(ctx context.Context, repairRunId uuid.UUID) error

// GetRepairRunSegments returns the list of segments of a repair run identified by its id.
GetRepairRunSegments(ctx context.Context, repairRunId uuid.UUID) (map[uuid.UUID]*RepairSegment, error)

Expand Down
1 change: 1 addition & 0 deletions reaper/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestClient(t *testing.T) {
t.Run("DeleteRepairRunNotFound", run(client, testDeleteRepairRunNotFound))
t.Run("CreateStartFinishRepairRun", run(client, testCreateStartFinishRepairRun))
t.Run("CreateStartPauseUpdateResumeRepairRun", run(client, testCreateStartPauseUpdateResumeRepairRun))
t.Run("CreateAbortRepairRun", run(client, testCreateAbortRepairRun))
t.Run("GetRepairRunSegments", run(client, testGetRepairRunSegments))
t.Run("AbortRepairRunSegments", run(client, testAbortRepairRunSegments))
t.Run("PurgeRepairRun", run(client, testPurgeRepairRun))
Expand Down
9 changes: 9 additions & 0 deletions reaper/repair_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ func (c *client) ResumeRepairRun(ctx context.Context, repairRunId uuid.UUID) err
return fmt.Errorf("failed to resume repair run %v: %w", repairRunId, err)
}

func (c *client) AbortRepairRun(ctx context.Context, repairRunId uuid.UUID) error {
path := fmt.Sprint("/repair_run/", repairRunId, "/state/", RepairRunStateAborted)
_, err := c.doPut(ctx, path, nil, nil, http.StatusOK, http.StatusNoContent)
if err == nil {
return nil
}
return fmt.Errorf("failed to abort repair run %v: %w", repairRunId, err)
}

func (c *client) GetRepairRunSegments(ctx context.Context, repairRunId uuid.UUID) (map[uuid.UUID]*RepairSegment, error) {
path := fmt.Sprint("/repair_run/", repairRunId, "/segments")
res, err := c.doGet(ctx, path, nil, http.StatusOK)
Expand Down
15 changes: 15 additions & 0 deletions reaper/repair_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ func testCreateStartPauseUpdateResumeRepairRun(t *testing.T, client Client) {
}
}

func testCreateAbortRepairRun(t *testing.T, client Client) {
run := createRepairRun(t, client, "cluster-1")
defer deleteRepairRun(t, client, run)
err := client.StartRepairRun(context.Background(), run.Id)
require.Nil(t, err)
started, err := client.GetRepairRun(context.Background(), run.Id)
require.Nil(t, err)
assert.Equal(t, RepairRunStateRunning, started.State)
err = client.AbortRepairRun(context.Background(), run.Id)
require.Nil(t, err)
aborted, err := client.GetRepairRun(context.Background(), run.Id)
require.Nil(t, err)
assert.Equal(t, RepairRunStateAborted, aborted.State)
}

func testGetRepairRunSegments(t *testing.T, client Client) {
run := createRepairRun(t, client, "cluster-1")
defer deleteRepairRun(t, client, run)
Expand Down

0 comments on commit 4249ab6

Please sign in to comment.