| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "github.com/carlosframework/platform/internal/hostbox" |
| 7 | "github.com/carlosframework/platform/internal/hostguard" |
| 8 | "github.com/carlosframework/platform/internal/release" |
| 9 | "github.com/carlosframework/platform/internal/rootstate" |
| 10 | ) |
| 11 | |
| 12 | func recoverRootInventoryStartup(ctx context.Context, store release.Store, r ClaimRuntimeResources, owners ClaimOwnerBindings, actor hostbox.Actor, journals *hostbox.JournalService, launches *hostbox.LaunchJournal) error { |
| 13 | l, required, err := openRootMigrationParticipation() |
| 14 | if l.State != nil { |
| 15 | defer l.State.Close() |
| 16 | } |
| 17 | if err != nil || !required { |
| 18 | return err |
| 19 | } |
| 20 | c, err := l.RecoveryCensus() |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | state, err := openRootMigrationState() |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | defer state.Close() |
| 29 | if _, err := readRootMigrationState(state, l.State, rootMigrationIdentity{Deployment: actor.ControlBucket, Box: actor.Box, Enrollment: actor.Enrollment, Generation: c.Migration}); err != nil { |
| 30 | return err |
| 31 | } |
| 32 | fences, err := openClaimRootAuthority() |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | defer fences.Close() |
| 37 | authority := hostguard.NewRootAuthority(fences) |
| 38 | pending, err := authority.PendingInstallations() |
| 39 | if err != nil || len(pending) == 0 { |
| 40 | return err |
| 41 | } |
| 42 | roots := map[string]string{"data": r.DataDir, "opt": r.OptDir, "units": r.UnitsDir} |
| 43 | guard := hostguard.Guard{Root: authority, DataDir: r.DataDir, Claims: hostguard.StoreReader{Store: store}} |
| 44 | census := &hostbox.EmptyInstallationCensus{Inventory: journals.Inventory, Registry: r.Registry, Launches: launches, Box: actor.Box, Enrollment: actor.Enrollment, DirectoryRevision: actor.Binding, Roots: roots, SharedPaths: claimGlobalSharedPaths(r)} |
| 45 | h := ClaimRootHTTP{history: productionCreationHistory, inventoryIdentity: rootstate.ObjectIdentity, Journals: journals, Launches: launches, Roots: roots, |
| 46 | // Fresh authority (R2): the startup actor above pins only the census. |
| 47 | InventoryActor: owners.Identity.Verify, |
| 48 | startupBinding: actor.Binding, |
| 49 | Reconcile: hostbox.ReconcileAdapter{Registry: r.Registry, Inventory: journals.Inventory, Census: census, Box: actor.Box, Enrollment: actor.Enrollment}, |
| 50 | Stop: ClaimStopHTTP{Coordinator: ClaimStopCoordinator{Guard: guard, Evidence: store}}} |
| 51 | if err := h.recoverRootInventory(ctx); err != nil { |
| 52 | return err |
| 53 | } |
| 54 | pending, err = authority.PendingInstallations() |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | if len(pending) != 0 { |
| 59 | return errRootMigrationBusy |
| 60 | } |
| 61 | return nil |
| 62 | } |
| 63 | |