Skip to content

Commit b66b5c2

Browse files
authored
refactor: remove redundant SnapshotType enum and use protobuf oneof d… (#370)
refactor: remove redundant SnapshotType enum and use protobuf oneof d…
1 parent 069ba08 commit b66b5c2

9 files changed

Lines changed: 130 additions & 205 deletions

File tree

cmd/ateapi/internal/controlapi/functional_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,6 @@ func TestSuspendActor(t *testing.T) {
15561556
ActorTemplateName: "tmpl1",
15571557
Status: ateapipb.Actor_STATUS_SUSPENDED,
15581558
LatestSnapshotInfo: &ateapipb.SnapshotInfo{
1559-
Type: ateapipb.SnapshotType_SNAPSHOT_TYPE_EXTERNAL,
15601559
Data: &ateapipb.SnapshotInfo_External{
15611560
External: &ateapipb.ExternalSnapshotInfo{
15621561
SnapshotUriPrefix: fmt.Sprintf("gs://fake-fake-fake/%s/", id),
@@ -1641,7 +1640,6 @@ func TestPauseActor(t *testing.T) {
16411640
ActorTemplateName: "tmpl1",
16421641
Status: ateapipb.Actor_STATUS_PAUSED,
16431642
LatestSnapshotInfo: &ateapipb.SnapshotInfo{
1644-
Type: ateapipb.SnapshotType_SNAPSHOT_TYPE_LOCAL,
16451643
Data: &ateapipb.SnapshotInfo_Local{
16461644
Local: &ateapipb.LocalSnapshotInfo{
16471645
SnapshotPrefix: "id1",

cmd/ateapi/internal/controlapi/syncer_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ func TestSyncer_DeleteBoundWorker_ClearsActor(t *testing.T) {
195195
AteomPodNamespace: ns, AteomPodName: pod, AteomPodIp: ip,
196196
InProgressSnapshot: "gs://snapshots/partial",
197197
LatestSnapshotInfo: &ateapipb.SnapshotInfo{
198-
Type: ateapipb.SnapshotType_SNAPSHOT_TYPE_EXTERNAL,
199198
Data: &ateapipb.SnapshotInfo_External{
200199
External: &ateapipb.ExternalSnapshotInfo{
201200
SnapshotUriPrefix: "gs://snapshots/last",

cmd/ateapi/internal/controlapi/workflow_pause.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ func (s *FinalizePausedStep) Execute(ctx context.Context, input *PauseInput, sta
204204
// TODO(dberkov) - what if InProgressSnapshot is empty? That shouldn't be possible.
205205
if latestActor.InProgressSnapshot != "" {
206206
latestActor.LatestSnapshotInfo = &ateapipb.SnapshotInfo{
207-
Type: ateapipb.SnapshotType_SNAPSHOT_TYPE_LOCAL,
208207
Data: &ateapipb.SnapshotInfo_Local{
209208
Local: &ateapipb.LocalSnapshotInfo{
210209
SnapshotPrefix: latestActor.InProgressSnapshot,

cmd/ateapi/internal/controlapi/workflow_resume.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (s *CallAteletRestoreStep) Execute(ctx context.Context, input *ResumeInput,
267267
return err
268268
}
269269

270-
if state.Actor.GetLatestSnapshotInfo().GetType() != ateapipb.SnapshotType_SNAPSHOT_TYPE_UNSPECIFIED {
270+
if data := state.Actor.GetLatestSnapshotInfo().GetData(); data != nil {
271271
slog.InfoContext(ctx, "Actor has snapshot; Restoring from snapshot")
272272

273273
req := &ateletpb.RestoreRequest{
@@ -278,25 +278,25 @@ func (s *CallAteletRestoreStep) Execute(ctx context.Context, input *ResumeInput,
278278
ActorTemplateName: state.Actor.GetActorTemplateName(),
279279
Spec: workloadSpec,
280280
}
281-
switch state.Actor.GetLatestSnapshotInfo().GetType() {
282-
case ateapipb.SnapshotType_SNAPSHOT_TYPE_LOCAL:
281+
switch d := data.(type) {
282+
case *ateapipb.SnapshotInfo_Local:
283283
req.Type = ateletpb.CheckpointType_CHECKPOINT_TYPE_LOCAL
284284
req.Config = &ateletpb.RestoreRequest_LocalConfig{
285285
LocalConfig: &ateletpb.LocalCheckpointConfiguration{
286-
SnapshotPrefix: state.Actor.GetLatestSnapshotInfo().GetLocal().SnapshotPrefix,
286+
SnapshotPrefix: d.Local.GetSnapshotPrefix(),
287287
},
288288
}
289289
req.Scope = toAteletSnapshotScope(state.ActorTemplate.Spec.SnapshotsConfig.OnPause)
290-
case ateapipb.SnapshotType_SNAPSHOT_TYPE_EXTERNAL:
290+
case *ateapipb.SnapshotInfo_External:
291291
req.Type = ateletpb.CheckpointType_CHECKPOINT_TYPE_EXTERNAL
292292
req.Config = &ateletpb.RestoreRequest_ExternalConfig{
293293
ExternalConfig: &ateletpb.ExternalCheckpointConfiguration{
294-
SnapshotUriPrefix: state.Actor.GetLatestSnapshotInfo().GetExternal().SnapshotUriPrefix,
294+
SnapshotUriPrefix: d.External.GetSnapshotUriPrefix(),
295295
},
296296
}
297297
req.Scope = toAteletSnapshotScope(state.ActorTemplate.Spec.SnapshotsConfig.OnCommit)
298298
default:
299-
return fmt.Errorf("unsupported snapshot type: %v", state.Actor.GetLatestSnapshotInfo().GetType())
299+
return fmt.Errorf("unsupported snapshot type: %T", data)
300300
}
301301

302302
_, err = client.Restore(ctx, req)

cmd/ateapi/internal/controlapi/workflow_suspend.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ func (s *FinalizeSuspendedStep) Execute(ctx context.Context, input *SuspendInput
197197
latestActor.Status = ateapipb.Actor_STATUS_SUSPENDED
198198
if latestActor.InProgressSnapshot != "" {
199199
latestActor.LatestSnapshotInfo = &ateapipb.SnapshotInfo{
200-
Type: ateapipb.SnapshotType_SNAPSHOT_TYPE_EXTERNAL,
201200
Data: &ateapipb.SnapshotInfo_External{
202201
External: &ateapipb.ExternalSnapshotInfo{
203202
SnapshotUriPrefix: latestActor.InProgressSnapshot,

cmd/ateapi/internal/store/ateredis/ateredis_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ func TestListActors(t *testing.T) {
452452
ActorTemplateName: "tmpl1",
453453
Status: ateapipb.Actor_STATUS_SUSPENDED,
454454
LatestSnapshotInfo: &ateapipb.SnapshotInfo{
455-
Type: ateapipb.SnapshotType_SNAPSHOT_TYPE_EXTERNAL,
456455
Data: &ateapipb.SnapshotInfo_External{
457456
External: &ateapipb.ExternalSnapshotInfo{
458457
SnapshotUriPrefix: "gs://b1/f1",
@@ -466,7 +465,6 @@ func TestListActors(t *testing.T) {
466465
ActorTemplateName: "tmpl1",
467466
Status: ateapipb.Actor_STATUS_SUSPENDED,
468467
LatestSnapshotInfo: &ateapipb.SnapshotInfo{
469-
Type: ateapipb.SnapshotType_SNAPSHOT_TYPE_EXTERNAL,
470468
Data: &ateapipb.SnapshotInfo_External{
471469
External: &ateapipb.ExternalSnapshotInfo{
472470
SnapshotUriPrefix: "gs://b1/f2",

cmd/atecontroller/internal/controllers/actortemplate_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func (r *ActorTemplateReconciler) Reconcile(ctx context.Context, req ctrl.Reques
151151
return ctrl.Result{}, fmt.Errorf("while suspending golden actor: %w", err)
152152
}
153153

154-
if resp.GetActor().GetLatestSnapshotInfo().GetType() != ateapipb.SnapshotType_SNAPSHOT_TYPE_EXTERNAL {
155-
return ctrl.Result{}, fmt.Errorf("unexpected snapshot type for golden actor: %v", resp.GetActor().GetLatestSnapshotInfo().GetType())
154+
if resp.GetActor().GetLatestSnapshotInfo().GetExternal() == nil {
155+
return ctrl.Result{}, fmt.Errorf("unexpected snapshot type for golden actor: %T", resp.GetActor().GetLatestSnapshotInfo().GetData())
156156
}
157157

158158
// Transition to PhaseReady

0 commit comments

Comments
 (0)