package host import ( "context" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/moves" "github.com/carlosframework/platform/internal/park" "github.com/carlosframework/platform/internal/provision" ) // CommittedLandingRecords is hostclaim.CommittedLandingGuard over the // authoritative instance record: the move named by the claim's op has // committed for this incarnation (provision.MoveCommitted, no rollback), // and the regions and park scopes are the commit's (moves.CommitScopes), // the regions as engine regions. type CommittedLandingRecords struct{ Records MovesRecordReader } var _ hostclaim.CommittedLandingGuard = CommittedLandingRecords{} func (g CommittedLandingRecords) CheckLandingCommitted(ctx context.Context, o hostclaim.Observed, opID string) (hostclaim.CommittedLanding, error) { c := o.Claim if g.Records == nil || c == nil || c.Holder == nil || c.Op.ID != opID { return hostclaim.CommittedLanding{}, hostclaim.ErrWrongState } rec, err := g.Records(ctx, c.Holder.Account, c.Holder.App, o.Host) if err != nil { return hostclaim.CommittedLanding{}, err } if rec == nil || rec.Move == nil { return hostclaim.CommittedLanding{}, hostclaim.ErrWrongState } m := rec.Move if m.ID != opID || m.Incarnation != c.Holder.Incarnation || m.State != provision.MoveCommitted || m.Rollback != nil || m.CommittedAt == nil { return hostclaim.CommittedLanding{}, hostclaim.ErrWrongState } source, staging, err := moves.CommitScopes(c, m.FlippedAt) if err != nil { return hostclaim.CommittedLanding{}, err } // The record's From and To are placement codes. The commit's parks are // queued in engine regions, as moves' commitClaim queues them // (park.PlacementRegion, so the home is park.HomeRegion, never ""); a // code that is no placement refuses. from, to := park.PlacementRegion(m.From), park.PlacementRegion(m.To) if from == "" || to == "" { return hostclaim.CommittedLanding{}, hostclaim.ErrWrongState } return hostclaim.CommittedLanding{FromRegion: from, ToRegion: to, SourceScope: source, StagingScope: staging}, nil }