| 1 | package extension |
| 2 | |
| 3 | import "time" |
| 4 | |
| 5 | // ComponentStatus is the diagnostic view of one lifecycle component. |
| 6 | type ComponentStatus struct { |
| 7 | ID ComponentID `json:"id"` |
| 8 | State ComponentState `json:"state"` |
| 9 | Generation uint64 `json:"generation"` |
| 10 | Epoch string `json:"epoch,omitempty"` |
| 11 | Error string `json:"error,omitempty"` |
| 12 | Diagnostics []string `json:"diagnostics,omitempty"` |
| 13 | UpdatedAt time.Time `json:"updatedAt"` |
| 14 | } |
| 15 | |
| 16 | // RuntimeStatus is the host-facing runtime component status document for |
| 17 | // /doctor and UI diagnostics. |
| 18 | type RuntimeStatus struct { |
| 19 | PublishedGeneration uint64 `json:"publishedGeneration"` |
| 20 | Components []ComponentStatus `json:"components"` |
| 21 | Plan *RuntimePlanView `json:"plan,omitempty"` |
| 22 | Receipts []EffectReceipt `json:"receipts,omitempty"` |
| 23 | } |
| 24 | |
| 25 | // RuntimePlanView is a JSON-friendly projection of RuntimePlan without the |
| 26 | // live graph pointer. |
| 27 | type RuntimePlanView struct { |
| 28 | FromGeneration uint64 `json:"fromGeneration"` |
| 29 | ToGeneration uint64 `json:"toGeneration"` |
| 30 | Added []ComponentID `json:"added,omitempty"` |
| 31 | Removed []ComponentID `json:"removed,omitempty"` |
| 32 | Reloaded []ComponentID `json:"reloaded,omitempty"` |
| 33 | Unchanged []ComponentID `json:"unchanged,omitempty"` |
| 34 | PrefixChanged bool `json:"prefixChanged"` |
| 35 | ProviderChanged bool `json:"providerChanged"` |
| 36 | } |
| 37 | |
| 38 | // PlanView projects a plan for diagnostics APIs. |
| 39 | func PlanView(p *RuntimePlan) *RuntimePlanView { |
| 40 | if p == nil { |
| 41 | return nil |
| 42 | } |
| 43 | return &RuntimePlanView{ |
| 44 | FromGeneration: p.FromGeneration, |
| 45 | ToGeneration: p.ToGeneration, |
| 46 | Added: append([]ComponentID(nil), p.Added...), |
| 47 | Removed: append([]ComponentID(nil), p.Removed...), |
| 48 | Reloaded: append([]ComponentID(nil), p.Reloaded...), |
| 49 | Unchanged: append([]ComponentID(nil), p.Unchanged...), |
| 50 | PrefixChanged: p.PrefixChanged, |
| 51 | ProviderChanged: p.ProviderChanged, |
| 52 | } |
| 53 | } |
| 54 |