Documentation
¶
Index ¶
- Constants
- Variables
- func ComponentFilterEqual(a, b json.RawMessage) (bool, error)
- func CountWaitingTasksForRack(ctx context.Context, idb bun.IDB, rackID uuid.UUID) (int, error)
- func DeleteLegacyUnscopedDrifts(ctx context.Context, idb bun.IDB) error
- func GetRackOperationStatusCounts(ctx context.Context, idb bun.IDB, rackIDs []uuid.UUID) (map[uuid.UUID]types.TrayStatusCountsByType, error)
- func ListRacksWithWaitingTasks(ctx context.Context, idb bun.IDB) ([]uuid.UUID, error)
- func MarshalComponentFilter(cf *ComponentFilter) (json.RawMessage, error)
- func ReplaceDriftsByComponentType(ctx context.Context, idb bun.IDB, componentType string, ...) error
- type BMC
- type Component
- func GetAllComponents(ctx context.Context, idb bun.IDB) (ret []Component, err error)
- func GetComponentByBMCMAC(ctx context.Context, idb bun.IDB, macAddress string) (*Component, error)
- func GetComponentsByType(ctx context.Context, idb bun.IDB, componentType devicetypes.ComponentType) (ret []Component, err error)
- func GetListOfComponents(ctx context.Context, idb bun.IDB, info dbquery.StringQueryInfo, ...) ([]Component, int32, error)
- func (cd *Component) BuildColumnPatch(cur *Component) *ComponentPatch
- func (cd *Component) BuildPatch(cur *Component) *Component
- func (cd *Component) Create(ctx context.Context, idb bun.IDB) error
- func (cd *Component) Delete(ctx context.Context, idb bun.IDB) error
- func (cd *Component) ForceDelete(ctx context.Context, idb bun.IDB) error
- func (cd *Component) Get(ctx context.Context, idb bun.IDB) (*Component, error)
- func (cd *Component) GetIncludingDeleted(ctx context.Context, idb bun.IDB) (*Component, error)
- func (cd *Component) InvalidType() bool
- func (cd *Component) Patch(ctx context.Context, idb bun.IDB) error
- func (cd *Component) SerialInfo() deviceinfo.SerialInfo
- func (cd *Component) SetFirmwareVersionByComponentID(ctx context.Context, idb bun.IDB) error
- func (cd *Component) SetHealthByComponentID(ctx context.Context, idb bun.IDB) error
- func (cd *Component) SetLeakStatusByComponentID(ctx context.Context, idb bun.IDB) error
- func (cd *Component) SetPowerStateByComponentID(ctx context.Context, idb bun.IDB) error
- func (cd *Component) SetStatusByComponentID(ctx context.Context, idb bun.IDB) error
- type ComponentDrift
- type ComponentFilter
- type ComponentFilterKind
- type ComponentPatch
- type DriftType
- type Event
- type EventActionExecution
- type EventRule
- type EventRuleBinding
- type FieldDiff
- type NVLDomain
- type OperationRule
- type OperationRun
- type OperationRunTarget
- type OverlapPolicy
- type Rack
- func GetAllRacks(ctx context.Context, idb bun.IDB) (ret []Rack, err error)
- func GetListOfRacks(ctx context.Context, idb bun.IDB, info dbquery.StringQueryInfo, ...) ([]Rack, int32, error)
- func GetRacksByIDs(ctx context.Context, idb bun.IDB, ids []uuid.UUID, withComponents bool) ([]Rack, error)
- func GetRacksByIDsIncludingDeleted(ctx context.Context, idb bun.IDB, ids []uuid.UUID, withComponents bool) ([]Rack, error)
- func GetRacksForNVLDomain(ctx context.Context, idb bun.IDB, nvlDomainID uuid.UUID, withComponents bool) ([]Rack, error)
- func (rd *Rack) BuildColumnPatch(cur *Rack) *RackPatch
- func (rd *Rack) BuildPatch(cur *Rack) *Rack
- func (rd *Rack) Create(ctx context.Context, idb bun.IDB) error
- func (rd *Rack) Delete(ctx context.Context, idb bun.IDB) error
- func (rd *Rack) ForceDelete(ctx context.Context, idb bun.IDB) error
- func (rd *Rack) Get(ctx context.Context, idb bun.IDB, withComponents bool) (*Rack, error)
- func (rd *Rack) GetIncludingDeleted(ctx context.Context, idb bun.IDB) (*Rack, error)
- func (rd *Rack) Patch(ctx context.Context, idb bun.IDB) error
- func (rd *Rack) SerialInfo() deviceinfo.SerialInfo
- func (rd *Rack) SetHealthByExternalID(ctx context.Context, idb bun.IDB) error
- type RackPatch
- type RackRuleAssociation
- type RackStatus
- type SpecType
- type Task
- func GetTask(ctx context.Context, idb bun.IDB, id uuid.UUID) (*Task, error)
- func GetTaskByIdempotencyKey(ctx context.Context, idb bun.IDB, key string) (*Task, error)
- func ListFirmwareTasksForRack(ctx context.Context, idb bun.IDB, rackID uuid.UUID) ([]Task, error)
- func ListPowerTasksForRack(ctx context.Context, idb bun.IDB, rackID uuid.UUID) ([]Task, error)
- func ListTaskContextForRack(ctx context.Context, idb bun.IDB, rackID uuid.UUID) ([]Task, error)
- func ListTasks(ctx context.Context, idb bun.IDB, options *taskcommon.TaskListOptions, ...) ([]Task, int32, error)
- func ListTasksForRackByStatus(ctx context.Context, idb bun.IDB, rackID uuid.UUID, ...) ([]Task, error)
- func ListTasksForRacksByStatus(ctx context.Context, idb bun.IDB, rackIDs []uuid.UUID, ...) ([]Task, error)
- func (t *Task) Create(ctx context.Context, idb bun.IDB) error
- func (t *Task) CreateOrGetByIdempotencyKey(ctx context.Context, idb bun.IDB) (*Task, bool, error)
- func (t *Task) HasIdempotencyKey() bool
- func (t *Task) UpdateScheduledTask(ctx context.Context, idb bun.IDB) error
- func (t *Task) UpdateTaskReport(ctx context.Context, idb bun.IDB, report json.RawMessage) error
- func (t *Task) UpdateTaskStatus(ctx context.Context, idb bun.IDB, status taskcommon.TaskStatus, message string, ...) error
- type TaskSchedule
- type TaskScheduleScope
Constants ¶
const ( // ComponentFilterKindTypes filters by component type (e.g. COMPUTE, POWERSHELF). ComponentFilterKindTypes = operation.ComponentFilterKindTypes // ComponentFilterKindComponents targets specific components by their UUIDs. ComponentFilterKindComponents = operation.ComponentFilterKindComponents )
Variables ¶
var ErrAmbiguousBMCMAC = errors.New("BMC MAC address matches multiple components")
ErrAmbiguousBMCMAC indicates that case variants of a BMC MAC belong to different components.
Functions ¶
func ComponentFilterEqual ¶
func ComponentFilterEqual(a, b json.RawMessage) (bool, error)
ComponentFilterEqual reports whether two component_filter JSONB values are semantically equivalent. nil, empty, and the JSON null literal are all treated as equivalent (they all mean "all components"). For type-based filters, element order is ignored.
func CountWaitingTasksForRack ¶
CountWaitingTasksForRack returns the count of waiting tasks for a rack.
func DeleteLegacyUnscopedDrifts ¶
DeleteLegacyUnscopedDrifts removes rows written without a component type. Callers may invoke this only after every supported type was synchronized and persisted successfully, because unlinked rows cannot otherwise be assigned to a safe replacement boundary.
func GetRackOperationStatusCounts ¶
func GetRackOperationStatusCounts( ctx context.Context, idb bun.IDB, rackIDs []uuid.UUID, ) (map[uuid.UUID]types.TrayStatusCountsByType, error)
GetRackOperationStatusCounts counts each requested rack's operability phases from its active Compute, NVSwitch, and PowerShelf components. Empty membership produces zero counts; missing or unrecognized status increments Unknown.
func ListRacksWithWaitingTasks ¶
ListRacksWithWaitingTasks returns the distinct rack IDs that have at least one task in the waiting state.
func MarshalComponentFilter ¶
func MarshalComponentFilter(cf *ComponentFilter) (json.RawMessage, error)
MarshalComponentFilter marshals a ComponentFilter to JSON for JSONB storage.
func ReplaceDriftsByComponentType ¶
func ReplaceDriftsByComponentType( ctx context.Context, idb bun.IDB, componentType string, drifts []ComponentDrift, ) error
ReplaceDriftsByComponentType atomically replaces one component type's drift rows. Legacy linked rows can be classified through component.type and are removed with that type. Unlinked legacy rows cannot be classified safely and remain until a complete successful inventory cycle removes them.
Types ¶
type BMC ¶
type BMC struct {
bun.BaseModel `bun:"table:bmc,alias:b"`
MacAddress string `bun:"mac_address,pk"`
Type string `bun:"type,type:varchar(16),default:'Unknown'"`
ComponentID uuid.UUID `bun:"component_id,type:uuid,notnull"`
IPAddress *string `bun:"ip_address"`
User *string `bun:"user"`
Password *string `bun:"password"`
Component *Component `bun:"rel:belongs-to,join:component_id=id"`
}
func (*BMC) BuildPatch ¶
BuildPatch builds a patched BMC from the current BMC and the input BMC. It goes through the patchable fields and builds the patched BMC. If there is no change on patchable fields, it returns nil.
func (*BMC) InvalidType ¶
InvalidType returns true if the BMC type is unknown.
type Component ¶
type Component struct {
bun.BaseModel `bun:"table:component,alias:c"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
Name string `bun:"name"`
Type string `bun:"type,type:varchar(16),default:'Compute'"`
// Manufacturer and SerialNumber are descriptive labels, not identity: a
// mirrored component is identified by its host BMC's MAC address. nullzero
// maps the empty string to SQL NULL, so a component missing either half
// occupies no slot in component_manufacturer_serial_idx.
Manufacturer string `bun:"manufacturer,nullzero,unique:component_manufacturer_serial_idx"`
Model string `bun:"model"`
SerialNumber string `bun:"serial_number,nullzero,unique:component_manufacturer_serial_idx"`
Description map[string]any `bun:"description,type:jsonb,json_use_number"`
FirmwareVersion string `bun:"firmware_version,nullzero"`
// RackID is uuid.Nil when the component has been ingested but is not yet
// assigned to a rack. Stored as NULL in the database thanks to nullzero.
RackID uuid.UUID `bun:"rack_id,type:uuid,nullzero"`
SlotID int `bun:"slot_id"`
TrayIndex int `bun:"tray_index"`
HostID int `bun:"host_id"`
IngestedAt *time.Time `bun:"ingested_at"`
UpdatedAt time.Time `bun:"updated_at,nullzero,notnull,default:current_timestamp"`
DeletedAt *time.Time `bun:"deleted_at,soft_delete"`
Rack *Rack `bun:"rel:belongs-to,join:rack_id=id"`
BMCs []BMC `bun:"rel:has-many,join:id=component_id"`
ComponentID *string `bun:"external_id"`
PowerState *nicoapi.PowerState `bun:"power_state"`
Status *types.ComponentOperationStatus `bun:"status,type:jsonb,nullzero"`
Health *types.HealthReport `bun:"health,type:jsonb,nullzero"`
// LeakStatus is owned by the leak-detection loop. nullzero so an
// insert that leaves it empty falls back to the DB default 'UNKNOWN'
// rather than writing an empty string.
LeakStatus types.LeakStatus `bun:"leak_status,type:varchar(16),nullzero,notnull,default:'UNKNOWN'"`
}
func GetAllComponents ¶
func GetComponentByBMCMAC ¶
func GetComponentByBMCMAC( ctx context.Context, idb bun.IDB, macAddress string, ) (*Component, error)
GetComponentByBMCMAC retrieves a unique component by its case-insensitive BMC MAC address. Returns the component with all its associated BMCs (needed for powershelf manager queries).
func GetComponentsByType ¶
func GetComponentsByType(ctx context.Context, idb bun.IDB, componentType devicetypes.ComponentType) (ret []Component, err error)
GetComponentsByType returns all components of the given type, with each component's BMCs relation preloaded (callers rely on this for BMC-MAC-based linking).
func GetListOfComponents ¶
func GetListOfComponents( ctx context.Context, idb bun.IDB, info dbquery.StringQueryInfo, manufacturerFilter *dbquery.StringQueryInfo, modelFilter *dbquery.StringQueryInfo, componentTypes []devicetypes.ComponentType, pagination *dbquery.Pagination, orderBy *dbquery.OrderBy, ) ([]Component, int32, error)
GetListOfComponents returns a list of components matching the given criteria.
func (*Component) BuildColumnPatch ¶
func (cd *Component) BuildColumnPatch(cur *Component) *ComponentPatch
BuildColumnPatch returns only patchable component fields whose supplied values differ from the current row. The result is safe to pass to Patch without rewriting state owned by reconciliation loops.
func (*Component) BuildPatch ¶
BuildPatch builds a patched component from the current component and the input component. It goes through the patchable fields and builds the patched component. If there is no change on patchable fields, it returns nil.
func (*Component) ForceDelete ¶
ForceDelete permanently removes the component row from the database.
func (*Component) Get ¶
Get looks the component up by ID, or by (manufacturer, serial_number) when no ID is set. Both label columns are nullable, so a component stored without one of them is only reachable by the first form.
func (*Component) GetIncludingDeleted ¶
GetIncludingDeleted retrieves a component by ID regardless of soft-delete status.
func (*Component) InvalidType ¶
InvalidType returns true if the component type is unknown.
func (*Component) SerialInfo ¶
func (cd *Component) SerialInfo() deviceinfo.SerialInfo
SerialInfo returns the serial number information of the component.
func (*Component) SetFirmwareVersionByComponentID ¶
func (*Component) SetHealthByComponentID ¶
SetHealthByComponentID writes the latest aggregate health snapshot for the row identified by external_id.
func (*Component) SetLeakStatusByComponentID ¶
SetLeakStatusByComponentID writes LeakStatus for the row identified by external_id. Used by the leak-detection loop, which keys off the component external IDs core reports leak alerts for.
func (*Component) SetPowerStateByComponentID ¶
type ComponentDrift ¶
type ComponentDrift struct {
bun.BaseModel `bun:"table:component_drift,alias:cd"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
ComponentID *uuid.UUID `bun:"component_id,type:uuid"` // NULL for missing_in_expected
ExternalID *string `bun:"external_id"` // Component ID from the component manager service; NULL for missing_in_actual
ComponentType *string `bun:"component_type"` // Internal replacement boundary; NULL only for rows written by a predecessor
DriftType DriftType `bun:"drift_type,type:varchar(32),notnull"`
Diffs []FieldDiff `bun:"diffs,type:jsonb,notnull,default:'[]'"`
CheckedAt time.Time `bun:"checked_at,notnull,default:current_timestamp"`
}
ComponentDrift stores validation drift detected by the inventory loop. Each row represents one drift record between expected (component table) and actual (source system) data.
func GetAllDrifts ¶
GetAllDrifts retrieves all drift records.
func GetDriftsByComponentIDs ¶
func GetDriftsByComponentIDs(ctx context.Context, idb bun.IDB, componentIDs []uuid.UUID) ([]ComponentDrift, error)
GetDriftsByComponentIDs retrieves drift records for the given component UUIDs.
type ComponentFilter ¶
type ComponentFilter = operation.ComponentFilter
ComponentFilter aliases the shared operation target filter shape.
func UnmarshalComponentFilter ¶
func UnmarshalComponentFilter(raw json.RawMessage) (*ComponentFilter, error)
UnmarshalComponentFilter parses a JSONB value into a ComponentFilter. Returns nil if raw is nil, empty, or the JSON null literal — all three representations mean "no filter" (target all components in the rack). The JSON null case arises when bun's AppendJSONValue serialises a nil json.RawMessage for a jsonb-typed column without the nullzero tag.
type ComponentFilterKind ¶
type ComponentFilterKind = operation.ComponentFilterKind
ComponentFilterKind aliases the shared operation target filter kind.
type ComponentPatch ¶
type ComponentPatch struct {
ID uuid.UUID
FirmwareVersion *string
Description *map[string]any
RackID *uuid.UUID
SlotID *int
TrayIndex *int
HostID *int
}
ComponentPatch contains values explicitly supplied by a component patch. Nil fields are omitted from the UPDATE.
type DriftType ¶
type DriftType string
DriftType represents the type of drift detected for a component.
const ( // DriftTypeMissingInExpected means the component exists in the source system // but is NOT in the local DB (component table). DriftTypeMissingInExpected DriftType = "missing_in_expected" // DriftTypeMissingInActual means the component exists in the local DB // but was NOT found in the source system. DriftTypeMissingInActual DriftType = "missing_in_actual" // DriftTypeMismatch means the component exists in both the local DB // and the source system, but some validation fields have different values. DriftTypeMismatch DriftType = "mismatch" )
type Event ¶
type Event struct {
bun.BaseModel `bun:"table:events,alias:e"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
SourceName string `bun:"source_name,notnull"`
SourceKey string `bun:"source_key,notnull"`
EventType string `bun:"event_type,notnull"`
ResourceID uuid.UUID `bun:"resource_id,type:uuid,notnull"`
ResourceKind string `bun:"resource_kind,notnull"`
AppliedRuleID uuid.UUID `bun:"applied_rule_id,type:uuid,notnull"`
EffectivePolicy json.RawMessage `bun:"effective_policy,type:jsonb,notnull"`
Summary string `bun:"summary,notnull"`
Observations int `bun:"observations,notnull"`
CreatedAt time.Time `bun:"created_at,notnull"`
LastObservedAt time.Time `bun:"last_observed_at,notnull"`
}
Event is the bun model for the durable events table.
type EventActionExecution ¶
type EventActionExecution struct {
bun.BaseModel `bun:"table:event_action_executions,alias:eae"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
EventID uuid.UUID `bun:"event_id,type:uuid,notnull"`
ActionName string `bun:"action_name,notnull"`
ActionType string `bun:"action_type,notnull"`
Plan json.RawMessage `bun:"plan,type:jsonb,notnull"`
Status string `bun:"status,notnull"`
Reason *string `bun:"reason"`
Attempts int `bun:"attempts,notnull"`
ClaimToken *uuid.UUID `bun:"claim_token,type:uuid"`
ClaimOwner *string `bun:"claim_owner"`
ClaimExpiresAt *time.Time `bun:"claim_expires_at"`
StatusMessage *string `bun:"status_message"`
CreatedAt time.Time `bun:"created_at,notnull"`
UpdatedAt time.Time `bun:"updated_at,notnull"`
NextAttemptAt *time.Time `bun:"next_attempt_at"`
}
EventActionExecution is the persistence model for one immutable event action plan and its mutable dispatch state.
type EventRule ¶
type EventRule struct {
bun.BaseModel `bun:"table:event_rules,alias:er"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
Name string `bun:"name,notnull"`
Description string `bun:"description,notnull"`
Enabled bool `bun:"enabled,notnull"`
EventType string `bun:"event_type,notnull"`
Policy json.RawMessage `bun:"policy,type:jsonb,notnull"`
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp"`
}
EventRule is the bun model for the event_rules table.
type EventRuleBinding ¶
type EventRuleBinding struct {
bun.BaseModel `bun:"table:event_rule_bindings,alias:erb"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
RuleID uuid.UUID `bun:"rule_id,type:uuid,notnull"`
EventType string `bun:"event_type,notnull"`
ScopeType string `bun:"scope_type,notnull"`
ScopeID *uuid.UUID `bun:"scope_id,type:uuid"`
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp"`
}
EventRuleBinding is the bun model for the event_rule_bindings table.
type FieldDiff ¶
type FieldDiff struct {
FieldName string `json:"field_name"`
ExpectedValue string `json:"expected_value"`
ActualValue string `json:"actual_value"`
}
FieldDiff represents a single field difference between expected and actual values.
type NVLDomain ¶
type NVLDomain struct {
bun.BaseModel `bun:"table:nvldomain,alias:n"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
Name string `bun:"name,nullzero,unique:nvldomain_name_idx"`
ExternalID *string `bun:"external_id,unique:nvldomain_external_id_idx"`
NMXCClusterID *uuid.UUID `bun:"nmxc_cluster_id,type:uuid"`
CreatedAt time.Time `bun:"created_at,nullzero,notnull,default:current_timestamp"`
DeletedAt *time.Time `bun:"deleted_at,soft_delete"`
Racks []Rack `bun:"rel:has-many,join:id=nvldomain_id"`
}
func GetListOfNVLDomains ¶
func GetListOfNVLDomains( ctx context.Context, idb bun.IDB, info dbquery.StringQueryInfo, pagination *dbquery.Pagination, options ...nvldomain.ListOptions, ) ([]NVLDomain, int32, error)
type OperationRule ¶
type OperationRule struct {
bun.BaseModel `bun:"table:operation_rules,alias:or"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
Name string `bun:"name,notnull"`
Description sql.NullString `bun:"description"`
OperationType string `bun:"operation_type,notnull"`
OperationCode string `bun:"operation_code,notnull"`
RuleDefinition json.RawMessage `bun:"rule_definition,type:jsonb,notnull"`
IsDefault bool `bun:"is_default,notnull,default:false"`
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp"`
}
OperationRule models the persisted operation rule metadata. Rules are templates that define how operations should be performed.
func GetOperationRule ¶
GetOperationRule retrieves an operation rule by its UUID.
func ListOperationRules ¶
func ListOperationRules( ctx context.Context, idb bun.IDB, options *taskcommon.OperationRuleListOptions, pagination *dbquery.Pagination, ) ([]OperationRule, int32, error)
OperationRuleListOptions defines filter options for listing operation rules. ListOperationRules returns all operation rules matching the given criteria with pagination.
type OperationRun ¶
type OperationRun struct {
bun.BaseModel `bun:"table:operation_run,alias:orun"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
Name string `bun:"name,notnull"`
Description string `bun:"description,nullzero"`
Status operationrun.OperationRunStatus `bun:"status,type:varchar(32),notnull"` //nolint:lll
StatusReason operationrun.OperationRunStatusReason `bun:"status_reason,type:varchar(64),notnull"` //nolint:lll
StatusMessage string `bun:"status_message,nullzero"`
CurrentPhaseIndex int32 `bun:"current_phase_index,notnull"`
TotalPhases int32 `bun:"total_phases,notnull"`
Selector json.RawMessage `bun:"selector,type:jsonb,notnull"`
Options json.RawMessage `bun:"options,type:jsonb,notnull"`
OperationTemplate json.RawMessage `bun:"operation_template,type:jsonb,notnull"`
OperationType taskcommon.TaskType `bun:"operation_type,type:varchar(64),notnull"`
OperationCode string `bun:"operation_code,type:varchar(64),notnull"`
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp"`
StartedAt *time.Time `bun:"started_at"`
FinishedAt *time.Time `bun:"finished_at"`
}
OperationRun is the bun model for the operation_run table.
type OperationRunTarget ¶
type OperationRunTarget struct {
bun.BaseModel `bun:"table:operation_run_target,alias:ort"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
OperationRunID uuid.UUID `bun:"operation_run_id,type:uuid,notnull"`
RackID uuid.UUID `bun:"rack_id,type:uuid,notnull"`
SequenceIndex int32 `bun:"sequence_index,notnull"`
PhaseIndex int32 `bun:"phase_index,notnull"`
ComponentsByType operation.ComponentsByType `bun:"components_by_type,type:jsonb,notnull"`
TaskID *uuid.UUID `bun:"task_id,type:uuid"`
Status operationrun.OperationRunTargetStatus `bun:"status,type:varchar(32),notnull"` //nolint:lll
Message string `bun:"message,nullzero"`
RetryAfter *time.Time `bun:"retry_after"`
RetryState json.RawMessage `bun:"retry_state,type:jsonb,nullzero"`
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp"`
}
OperationRunTarget is the bun model for one rack execution target in an operation run. ComponentsByType is the concrete component set resolved by the planner, not the caller-facing target filter expression.
type OverlapPolicy ¶
type OverlapPolicy string
OverlapPolicy controls what happens when a schedule fires but the previous execution is still active.
const ( OverlapPolicySkip OverlapPolicy = "skip" OverlapPolicyQueue OverlapPolicy = "queue" )
type Rack ¶
type Rack struct {
bun.BaseModel `bun:"table:rack,alias:r"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
Name string `bun:"name,notnull"`
// Manufacturer and SerialNumber are descriptive chassis labels, not
// identity: a mirrored rack is identified by ExternalID. nullzero maps the
// empty string to SQL NULL, so a rack missing either half occupies no slot
// in rack_manufacturer_serial_idx.
Manufacturer string `bun:"manufacturer,nullzero,unique:rack_manufacturer_serial_idx"`
SerialNumber string `bun:"serial_number,nullzero,unique:rack_manufacturer_serial_idx"`
Description map[string]any `bun:"description,type:jsonb,json_use_number"`
Location map[string]any `bun:"location,type:jsonb"`
NVLDomainID uuid.UUID `bun:"nvldomain_id,type:uuid"`
// ExternalID is Core's operator-supplied stable rack identifier
// (ExpectedRack.rack_id, e.g. "a12") populated by the expected-inventory
// mirror. NULL on racks that the mirror has never adopted (e.g. legacy
// ingestion-gRPC rows on first run).
ExternalID *string `bun:"external_id"`
RackProfileID *string `bun:"rack_profile_id"`
RackGroupID *string `bun:"rack_group_id"`
Status RackStatus `bun:"status,type:varchar(16),default:'new'"`
Health *types.HealthReport `bun:"health,type:jsonb,nullzero"`
CreatedAt time.Time `bun:"created_at,nullzero,notnull,default:current_timestamp"`
UpdatedAt time.Time `bun:"updated_at,nullzero,notnull,default:current_timestamp"`
IngestedAt *time.Time `bun:"ingested_at"`
DeletedAt *time.Time `bun:"deleted_at,soft_delete"`
Components []Component `bun:"rel:has-many,join:id=rack_id"`
NVLDomain *NVLDomain `bun:"rel:belongs-to,join:nvldomain_id=id"`
}
func GetAllRacks ¶
GetAllRacks returns every non-deleted rack without relations.
func GetListOfRacks ¶
func GetListOfRacks( ctx context.Context, idb bun.IDB, info dbquery.StringQueryInfo, manufacturerFilter *dbquery.StringQueryInfo, modelFilter *dbquery.StringQueryInfo, pagination *dbquery.Pagination, orderBy *dbquery.OrderBy, withComponents bool, withExternalIDOnly bool, ) ([]Rack, int32, error)
func GetRacksByIDs ¶
func GetRacksByIDs( ctx context.Context, idb bun.IDB, ids []uuid.UUID, withComponents bool, ) ([]Rack, error)
GetRacksByIDs retrieves multiple racks by their UUIDs
func GetRacksByIDsIncludingDeleted ¶
func GetRacksByIDsIncludingDeleted( ctx context.Context, idb bun.IDB, ids []uuid.UUID, withComponents bool, ) ([]Rack, error)
GetRacksByIDsIncludingDeleted retrieves multiple racks by UUID, including soft-deleted rows.
func GetRacksForNVLDomain ¶
func (*Rack) BuildColumnPatch ¶
BuildColumnPatch returns only patchable rack metadata whose supplied values differ from the current row.
func (*Rack) BuildPatch ¶
BuildPatch builds a patched rack from the current rack and the input rack. It goes through the patchable fields and builds the patched rack. If there is no change on patchable fields, it returns nil.
func (*Rack) ForceDelete ¶
ForceDelete permanently removes the rack row from the database. The rack must already be soft-deleted.
func (*Rack) Get ¶
Get looks the rack up by ID, or by (manufacturer, serial_number) when no ID is set. Both chassis columns are nullable, so a rack stored without one of them is only reachable by the first form.
func (*Rack) GetIncludingDeleted ¶
GetIncludingDeleted retrieves a rack by ID regardless of soft-delete status.
func (*Rack) SerialInfo ¶
func (rd *Rack) SerialInfo() deviceinfo.SerialInfo
SerialInfo returns the serial number information of the rack.
type RackPatch ¶
type RackPatch struct {
ID uuid.UUID
Name *string
Description *map[string]any
Location *map[string]any
}
RackPatch contains rack metadata fields selected by a patch operation. Nil fields are omitted from the UPDATE.
type RackRuleAssociation ¶
type RackRuleAssociation struct {
bun.BaseModel `bun:"table:rack_rule_associations,alias:rra"`
RackID uuid.UUID `bun:"rack_id,pk,type:uuid,notnull"`
OperationType string `bun:"operation_type,pk,type:varchar(64),notnull"`
OperationCode string `bun:"operation_code,pk,type:varchar(64),notnull"`
RuleID uuid.UUID `bun:"rule_id,type:uuid,notnull"`
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp"`
}
RackRuleAssociation models the association between a rack and an operation rule. It defines which specific rule a rack should use for a given operation type.
func GetRackRuleAssociation ¶
func GetRackRuleAssociation( ctx context.Context, idb bun.IDB, rackID uuid.UUID, opType taskcommon.TaskType, operationCode string, ) (*RackRuleAssociation, error)
GetRackRuleAssociation retrieves the rule association for a rack, operation type, and operation code.
func ListRackRuleAssociations ¶
func ListRackRuleAssociations( ctx context.Context, idb bun.IDB, rackID uuid.UUID, ) ([]RackRuleAssociation, error)
ListRackRuleAssociations retrieves all rule associations for a rack.
type RackStatus ¶
type RackStatus string
const ( RackStatusNew RackStatus = "new" RackStatusIngesting RackStatus = "ingesting" RackStatusIngested RackStatus = "ingested" )
type SpecType ¶
type SpecType string
SpecType identifies the scheduling mechanism for a task schedule.
type Task ¶
type Task struct {
bun.BaseModel `bun:"table:task,alias:t"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
Type taskcommon.TaskType `bun:"type,type:varchar(64),notnull"`
ExecutorType taskcommon.ExecutorType `bun:"executor_type,type:varchar(64),nullzero"`
Information json.RawMessage `bun:"information,type:jsonb,json_use_number"`
Description string `bun:"description,nullzero"`
RackID uuid.UUID `bun:"rack_id,type:uuid,notnull"` // The rack this task operates on
Attributes taskcommon.TaskAttributes `bun:"attributes,type:jsonb"`
ExecutionID string `bun:"execution_id,notnull"`
Status taskcommon.TaskStatus `bun:"status,type:varchar(32),notnull"`
Message string `bun:"message,nullzero"`
Report json.RawMessage `bun:"report,type:jsonb"`
AppliedRuleID *uuid.UUID `bun:"applied_rule_id,type:uuid"` // Which operation rule was applied
CreatedAt time.Time `bun:"created_at,nullzero,notnull,default:current_timestamp"`
UpdatedAt time.Time `bun:"updated_at,nullzero,notnull,default:current_timestamp"`
StartedAt *time.Time `bun:"started_at"`
FinishedAt *time.Time `bun:"finished_at"`
// QueueExpiresAt is set for pre-execution waits. After this time, the
// Promoter or task manager terminates the task instead of executing it.
QueueExpiresAt *time.Time `bun:"queue_expires_at"`
IdempotencyKey string `bun:"idempotency_key,nullzero"`
TriggerType string `bun:"trigger_type,nullzero"`
TriggerID *uuid.UUID `bun:"trigger_id,type:uuid"`
}
Task models the persisted task metadata managed by Flow.
func GetTaskByIdempotencyKey ¶
GetTaskByIdempotencyKey retrieves one task by its stable submission key.
func ListFirmwareTasksForRack ¶
ListFirmwareTasksForRack returns Waiting, Pending, and Running firmware tasks for one rack, ordered by creation time then UUID, ascending. Recorded target membership survives inventory removal. Only projection fields are loaded; reports and free-form descriptions/messages are excluded. More than MaxFirmwareTasksPerRack records returns *taskcommon.FirmwareTaskLimitError without a partial list. The bound limits rows, not stored JSON bytes.
func ListPowerTasksForRack ¶
ListPowerTasksForRack returns every Waiting, Pending, or Running power task for the rack, ordered by creation time and then UUID, both ascending. Only fields used by power details are loaded. More than MaxPowerTasksPerRack records returns PowerTaskLimitError and no tasks, so an incomplete list cannot look like the complete queue.
func ListTaskContextForRack ¶
ListTaskContextForRack loads nonterminal metadata in creation/UUID order. No operation payloads or reports are read. Overflow returns no partial list.
func ListTasks ¶
func ListTasks( ctx context.Context, idb bun.IDB, options *taskcommon.TaskListOptions, pagination *dbquery.Pagination, ) ([]Task, int32, error)
ListTasks returns all tasks that match the given criteria.
func ListTasksForRackByStatus ¶
func ListTasksForRackByStatus( ctx context.Context, idb bun.IDB, rackID uuid.UUID, statuses []taskcommon.TaskStatus, ) ([]Task, error)
ListTasksForRackByStatus returns tasks for a rack matching any of the given statuses, ordered oldest-first.
func ListTasksForRacksByStatus ¶
func ListTasksForRacksByStatus( ctx context.Context, idb bun.IDB, rackIDs []uuid.UUID, statuses []taskcommon.TaskStatus, ) ([]Task, error)
ListTasksForRacksByStatus returns tasks for the requested racks matching any of the given statuses.
func (*Task) CreateOrGetByIdempotencyKey ¶
func (t *Task) CreateOrGetByIdempotencyKey( ctx context.Context, idb bun.IDB, ) (*Task, bool, error)
CreateOrGetByIdempotencyKey inserts the task or returns the existing task carrying the same idempotency key.
func (*Task) HasIdempotencyKey ¶
func (*Task) UpdateScheduledTask ¶
UpdateScheduledTask updates the scheduled task information.
func (*Task) UpdateTaskReport ¶
UpdateTaskReport updates the structured report without changing status or message.
func (*Task) UpdateTaskStatus ¶
func (t *Task) UpdateTaskStatus( ctx context.Context, idb bun.IDB, status taskcommon.TaskStatus, message string, report json.RawMessage, queueExpiresAt *time.Time, ) error
UpdateTaskStatus updates the status of the task. Non-nil report and queueExpiresAt values replace their corresponding stored columns. Finished statuses clear queueExpiresAt because the deadline applies only while waiting.
type TaskSchedule ¶
type TaskSchedule struct {
bun.BaseModel `bun:"table:task_schedule,alias:ts"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
Name string `bun:"name,notnull"`
SpecType SpecType `bun:"spec_type,type:varchar(16),notnull"`
Spec string `bun:"spec,notnull"`
Timezone string `bun:"timezone,notnull"`
OperationTemplate json.RawMessage `bun:"operation_template,type:jsonb,notnull"`
OverlapPolicy OverlapPolicy `bun:"overlap_policy,type:varchar(16),notnull"`
Enabled bool `bun:"enabled,notnull"`
NextRunAt *time.Time `bun:"next_run_at"`
LastRunAt *time.Time `bun:"last_run_at"`
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp"`
}
TaskSchedule is the bun model for the task_schedule table.
type TaskScheduleScope ¶
type TaskScheduleScope struct {
bun.BaseModel `bun:"table:task_schedule_scope,alias:tss"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:gen_random_uuid()"`
ScheduleID uuid.UUID `bun:"schedule_id,type:uuid,notnull"`
RackID uuid.UUID `bun:"rack_id,type:uuid,notnull"`
ComponentFilter json.RawMessage `bun:"component_filter,type:jsonb,nullzero"`
LastTaskID *uuid.UUID `bun:"last_task_id,type:uuid"`
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp"`
}
TaskScheduleScope is the bun model for the task_schedule_scope table. Each row represents one rack target in a schedule's scope. LastTaskID tracks the task produced for this rack by the most recent firing, used by the overlap check to determine whether the previous execution is still active.
Invariant: when ComponentFilter has kind "components", every UUID listed in that filter must belong to RackID. This is enforced by the API write path (resolveComponentScope groups components by rack before persisting). At fire time the dispatcher sets RequiredRackID on the SubmitTask request, so any violation caused by a direct DB modification (e.g. a component moved to a different rack) is detected before any task is created, and the scope is skipped with an error.