| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "github.com/carlosframework/platform/internal/activator" |
| 7 | "github.com/carlosframework/platform/internal/hostbox" |
| 8 | "github.com/carlosframework/platform/internal/hostclaim" |
| 9 | "github.com/carlosframework/platform/internal/hostfiles" |
| 10 | "github.com/carlosframework/platform/internal/registry" |
| 11 | ) |
| 12 | |
| 13 | func settleFilesSeedRerun(ctx context.Context, rt registry.Route, files *movesFiles, retries activator.ServingRetries, expected hostclaim.Observed, exclusion *activator.SeedExclusion) (hostclaim.Observed, error) { |
| 14 | if err := exclusion.Check(rt.Host); err != nil { |
| 15 | return hostclaim.Observed{}, err |
| 16 | } |
| 17 | if expected.Host != rt.Host || expected.Claim == nil || expected.Claim.Holder == nil { |
| 18 | return hostclaim.Observed{}, hostbox.ErrChanged |
| 19 | } |
| 20 | if _, err := checkFilesSeedLayout(files, rt, claimEmptyBootstrap(expected.Claim.Holder)); err != nil { |
| 21 | return hostclaim.Observed{}, err |
| 22 | } |
| 23 | fresh, err := retries.SettleAbandoned(ctx, expected) |
| 24 | if err != nil { |
| 25 | return hostclaim.Observed{}, err |
| 26 | } |
| 27 | if err := exclusion.Check(rt.Host); err != nil { |
| 28 | return hostclaim.Observed{}, err |
| 29 | } |
| 30 | return fresh, nil |
| 31 | } |
| 32 | |
| 33 | func (s *filesSeedOperation) prerequisites(exclusion *activator.SeedExclusion) func(context.Context, registry.Route, hostclaim.Observed) error { |
| 34 | return func(ctx context.Context, rt registry.Route, o hostclaim.Observed) error { |
| 35 | if err := exclusion.Check(rt.Host); err != nil { |
| 36 | return err |
| 37 | } |
| 38 | if s == nil || s.ctx == nil || s.ctx.Err() != nil || s.selected.State != "eligible" || o.Host != s.selected.Observation.Host || o.ETag != s.selected.Observation.ETag || s.bound != (servingArtifactIdentity{}) { |
| 39 | return hostbox.ErrChanged |
| 40 | } |
| 41 | if err := s.files.checkServingFilesEvidence(ctx, o, rt); !errors.Is(err, hostfiles.ErrNoEvidence) { |
| 42 | if err == nil { |
| 43 | return hostfiles.ErrManifestExists |
| 44 | } |
| 45 | return err |
| 46 | } |
| 47 | selected, err := inspectFilesSeed(ctx, s.claims, s.files, o, s.actor, &rt) |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | if selected.State != "eligible" { |
| 52 | return hostbox.ErrChanged |
| 53 | } |
| 54 | return nil |
| 55 | } |
| 56 | } |
| 57 | |