Download this file
| 1 | package hostexec |
| 2 | |
| 3 | import ( |
| 4 | "github.com/carlosframework/platform/internal/hostclaim" |
| 5 | "slices" |
| 6 | ) |
| 7 | |
| 8 | func PreinstallationParticipant(c *hostclaim.Claim, box, enrollment string) error { |
| 9 | if c == nil || c.Holder == nil || c.Validate() != nil || box == "" || enrollment == "" || slices.Contains(c.Lost, box) { |
| 10 | return ErrInactive |
| 11 | } |
| 12 | if c.Op.Kind == hostclaim.KindServing { |
| 13 | if c.Op.Exec != box || (c.Holder.WriterBox != box && (c.Holder.WriterBox != "" || c.Holder.Session != 0)) { |
| 14 | return ErrInactive |
| 15 | } |
| 16 | return nil |
| 17 | } |
| 18 | if c.Op.Kind == hostclaim.KindCreating { |
| 19 | if c.Op.Phase != "" || c.Op.ID == "" || c.Op.Exec != "" || c.Holder.Stamp != 0 || c.Holder.Session != 0 || c.Holder.WriterBox != "" || len(c.Op.Participants) != 1 || c.Op.Participants[0] != box || c.Op.Intent["selected_executor"] != box || c.Op.Intent["executor_enrollment"] != enrollment { |
| 20 | return ErrInactive |
| 21 | } |
| 22 | return nil |
| 23 | } |
| 24 | if !slices.Contains(c.Op.Participants, box) || c.Op.ID == "" || c.Holder.Family != "instance" { |
| 25 | return ErrInactive |
| 26 | } |
| 27 | target := c.Op.Intent["target"] |
| 28 | if c.Op.Kind == hostclaim.KindRelocating { |
| 29 | target = c.Op.Intent["target_box"] |
| 30 | } |
| 31 | if target != box || (c.Op.Intent["target_enrollment"] != "" && c.Op.Intent["target_enrollment"] != enrollment) { |
| 32 | return ErrInactive |
| 33 | } |
| 34 | switch c.Op.Kind { |
| 35 | case hostclaim.KindRelocating: |
| 36 | switch c.Op.Phase { |
| 37 | case hostclaim.PhaseStarting, hostclaim.PhaseReleasing, hostclaim.PhasePinning: |
| 38 | return nil |
| 39 | case hostclaim.PhaseInstalling, hostclaim.PhaseInstalled: |
| 40 | if c.Op.Exec == box && c.Op.Journal["local_install"] == "" { |
| 41 | return nil |
| 42 | } |
| 43 | } |
| 44 | case hostclaim.KindMoving: |
| 45 | if c.Op.Phase == hostclaim.PhaseMoving || c.Op.Phase == hostclaim.PhaseSealed { |
| 46 | return nil |
| 47 | } |
| 48 | case hostclaim.KindLanding: |
| 49 | if c.Op.Phase == "checking" && c.Op.Exec == box { |
| 50 | return nil |
| 51 | } |
| 52 | } |
| 53 | return ErrInactive |
| 54 | } |
| 55 | |