carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "context"
5 "fmt"
6 "strconv"
7
8 "github.com/carlosframework/platform/internal/hostbox"
9 "github.com/carlosframework/platform/internal/hostclaim"
10 execlease "github.com/carlosframework/platform/internal/hostexec"
11)
12
13func (h ClaimRootHTTP) retainedExecutionSource(ctx context.Context, q execlease.ExecutionRequest, actor hostbox.Actor, c *hostclaim.Claim, a execlease.ExecutionAuthority) (execlease.ExecutionAuthority, error) {
14 source := c.Op.Intent["source"]
15 if c.Op.Kind == hostclaim.KindRelocating {
16 source = c.Op.Intent["source_box"]
17 }
18 if (!claimMovesKind(c.Op.Kind) && c.Op.Kind != hostclaim.KindRelocating) || source != actor.Box || c.Op.Intent["source_enrollment"] != actor.Enrollment {
19 return a, execlease.ErrLost
20 }
21 guard := h.Stop.Coordinator.Guard
22 prior, err := guard.Capture(q.Host)
23 if err != nil {
24 return a, err
25 }
26 if prior.Incarnation != q.Incarnation || prior.Stamp >= q.Stamp {
27 return a, execlease.ErrLost
28 }
29 if stamp := c.Op.Journal[hostclaim.JournalSourceStamp]; stamp != "" && stamp != strconv.FormatUint(prior.Stamp, 10) {
30 return a, execlease.ErrLost
31 }
32 view, err := guard.Root.View(ctx, q.Host, prior)
33 if err != nil {
34 return a, err
35 }
36 in := view.Installation
37 if view.Barrier != nil || in.Host != q.Host || in.Incarnation != q.Incarnation || in.Stamp != prior.Stamp || in.Account != a.Account || in.App != a.App || in.Record != c.Holder.Key || in.Box != actor.Box || in.Enrollment != actor.Enrollment || in.Migration == 0 || in.InventoryRevision == 0 {
38 return a, execlease.ErrLost
39 }
40 inventory, revision, err := h.Journals.Inventory.Snapshot(ctx, q.Host, prior)
41 if err != nil {
42 return a, err
43 }
44 if revision != in.InventoryRevision || !inventory.Complete || inventory.Box != actor.Box || inventory.Enrollment != actor.Enrollment {
45 return a, execlease.ErrLost
46 }
47 a.ParticipationOnly = true
48 a.Migration = in.Migration
49 a.Installation = fmt.Sprintf("%s/%d/%s/%s", in.Incarnation, in.Stamp, in.Box, in.Enrollment)
50 return a, nil
51}
52