store

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package store provides the storage layer for inventory management. It defines the InventoryStore interface for persisting and retrieving inventory data (racks, components, NVL domains).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComponentDrift

type ComponentDrift struct {
	ID          uuid.UUID
	ComponentID *uuid.UUID  // NULL for missing_in_expected
	ExternalID  *string     // Component ID from the component manager service; NULL for missing_in_actual
	DriftType   string      // "missing_in_expected", "missing_in_actual", "mismatch"
	Diffs       []FieldDiff // Field-level differences (for mismatch type)
	CheckedAt   time.Time
}

ComponentDrift represents a drift detected between expected (local DB) and actual (source system) data.

type FieldDiff

type FieldDiff struct {
	FieldName     string
	ExpectedValue string
	ActualValue   string
}

FieldDiff represents a single field difference between expected and actual values.

type PostgresStore

type PostgresStore struct {
	// contains filtered or unexported fields
}

PostgresStore implements the Store interface using PostgreSQL.

func NewPostgres

func NewPostgres(pg *cdb.Session) *PostgresStore

NewPostgres creates a new PostgreSQL-backed inventory store.

func (*PostgresStore) AddComponent

func (s *PostgresStore) AddComponent(ctx context.Context, comp *component.Component) (uuid.UUID, error)

AddComponent creates a single component (with BMCs) in the database and returns its UUID.

func (*PostgresStore) AttachRacksToNVLDomain

func (s *PostgresStore) AttachRacksToNVLDomain(
	ctx context.Context,
	nvlDomainID identifier.Identifier,
	rackIDs []identifier.Identifier,
) error

AttachRacksToNVLDomain attaches racks to an NVL domain.

func (*PostgresStore) CreateExpectedRack

func (s *PostgresStore) CreateExpectedRack(
	ctx context.Context,
	rack *rack.Rack,
) (uuid.UUID, error)

CreateExpectedRack creates an expected rack in the database and returns its UUID.

func (*PostgresStore) CreateNVLDomain

func (s *PostgresStore) CreateNVLDomain(
	ctx context.Context,
	nvlDomain *nvldomain.NVLDomain,
) (uuid.UUID, error)

CreateNVLDomain creates a new NVL domain.

func (*PostgresStore) DeleteComponent

func (s *PostgresStore) DeleteComponent(ctx context.Context, id uuid.UUID) error

DeleteComponent soft-deletes a component by UUID.

func (*PostgresStore) DeleteRack

func (s *PostgresStore) DeleteRack(ctx context.Context, id uuid.UUID) error

DeleteRack soft-deletes a rack and all its components in a single transaction.

func (*PostgresStore) DetachRacksFromNVLDomain

func (s *PostgresStore) DetachRacksFromNVLDomain(
	ctx context.Context,
	rackIDs []identifier.Identifier,
) error

DetachRacksFromNVLDomain detaches racks from their NVL domain.

func (*PostgresStore) GetAllDrifts

func (s *PostgresStore) GetAllDrifts(ctx context.Context) ([]ComponentDrift, error)

GetAllDrifts retrieves all drift records.

func (*PostgresStore) GetComponentByBMCMAC

func (s *PostgresStore) GetComponentByBMCMAC(
	ctx context.Context,
	macAddress string,
) (*component.Component, error)

GetComponentByBMCMAC retrieves a component by its BMC MAC address.

func (*PostgresStore) GetComponentByID

func (s *PostgresStore) GetComponentByID(
	ctx context.Context,
	id uuid.UUID,
) (*component.Component, error)

GetComponentByID retrieves a component by its UUID.

func (*PostgresStore) GetComponentBySerial

func (s *PostgresStore) GetComponentBySerial(
	ctx context.Context,
	manufacturer string,
	serialNumber string,
	withRack bool,
) (*component.Component, error)

GetComponentBySerial retrieves a component by its serial number and manufacturer.

func (*PostgresStore) GetComponentsByExternalIDs

func (s *PostgresStore) GetComponentsByExternalIDs(
	ctx context.Context,
	externalIDs []string,
) ([]*component.Component, error)

GetComponentsByExternalIDs retrieves components by their external IDs.

func (*PostgresStore) GetDriftsByComponentIDs

func (s *PostgresStore) GetDriftsByComponentIDs(ctx context.Context, componentIDs []uuid.UUID) ([]ComponentDrift, error)

GetDriftsByComponentIDs retrieves drift records for the given component UUIDs.

func (*PostgresStore) GetListOfComponents

func (s *PostgresStore) GetListOfComponents(
	ctx context.Context,
	info dbquery.StringQueryInfo,
	manufacturerFilter *dbquery.StringQueryInfo,
	modelFilter *dbquery.StringQueryInfo,
	componentTypes []devicetypes.ComponentType,
	pagination *dbquery.Pagination,
	orderBy *dbquery.OrderBy,
) ([]*component.Component, int32, error)

GetListOfComponents lists components matching the given criteria.

func (*PostgresStore) GetListOfNVLDomains

func (s *PostgresStore) GetListOfNVLDomains(
	ctx context.Context,
	info dbquery.StringQueryInfo,
	pagination *dbquery.Pagination,
) ([]*nvldomain.NVLDomain, int32, error)

GetListOfNVLDomains lists NVL domains matching the given criteria.

func (*PostgresStore) GetListOfRacks

func (s *PostgresStore) GetListOfRacks(
	ctx context.Context,
	info dbquery.StringQueryInfo,
	manufacturerFilter *dbquery.StringQueryInfo,
	modelFilter *dbquery.StringQueryInfo,
	pagination *dbquery.Pagination,
	orderBy *dbquery.OrderBy,
	withComponents bool,
) ([]*rack.Rack, int32, error)

GetListOfRacks lists racks matching the given criteria.

func (*PostgresStore) GetRackByID

func (s *PostgresStore) GetRackByID(
	ctx context.Context,
	id uuid.UUID,
	withComponents bool,
) (*rack.Rack, error)

GetRackByID retrieves a rack by its UUID, optionally with its components.

func (*PostgresStore) GetRackByIdentifier

func (s *PostgresStore) GetRackByIdentifier(
	ctx context.Context,
	identifier identifier.Identifier,
	withComponents bool,
) (*rack.Rack, error)

GetRackByIdentifier retrieves a rack by its identifier (ID or name).

func (*PostgresStore) GetRackBySerial

func (s *PostgresStore) GetRackBySerial(
	ctx context.Context,
	manufacturer string,
	serialNumber string,
	withComponents bool,
) (*rack.Rack, error)

GetRackBySerial retrieves a rack by its serial number and manufacturer.

func (*PostgresStore) GetRacksByIDs

func (s *PostgresStore) GetRacksByIDs(
	ctx context.Context,
	ids []uuid.UUID,
	withComponents bool,
) ([]*rack.Rack, error)

GetRacksByIDs retrieves multiple racks by their UUIDs, optionally with their components.

func (*PostgresStore) GetRacksForNVLDomain

func (s *PostgresStore) GetRacksForNVLDomain(
	ctx context.Context,
	nvlDomainID identifier.Identifier,
) ([]*rack.Rack, error)

GetRacksForNVLDomain retrieves all racks belonging to an NVL domain.

func (*PostgresStore) PatchComponent

func (s *PostgresStore) PatchComponent(ctx context.Context, comp *component.Component) error

PatchComponent updates a single component's fields and reconciles BMCs in the database.

func (*PostgresStore) PatchRack

func (s *PostgresStore) PatchRack(
	ctx context.Context,
	r *rack.Rack,
) (string, error)

PatchRack updates an existing rack.

func (*PostgresStore) PurgeComponent

func (s *PostgresStore) PurgeComponent(ctx context.Context, id uuid.UUID) error

PurgeComponent permanently removes a soft-deleted component.

func (*PostgresStore) PurgeRack

func (s *PostgresStore) PurgeRack(ctx context.Context, id uuid.UUID) error

PurgeRack permanently removes a soft-deleted rack and its components.

func (*PostgresStore) Start

func (s *PostgresStore) Start(ctx context.Context) error

Start starts the PostgresStore instance. Currently, it is no-op.

func (*PostgresStore) Stop

func (s *PostgresStore) Stop(ctx context.Context) error

Stop stops the PostgresStore instance by closing the PostgreSQL connection.

type Store

type Store interface {
	// Lifecycle
	Start(ctx context.Context) error
	Stop(ctx context.Context) error

	// Rack operations
	CreateExpectedRack(ctx context.Context, rack *rack.Rack) (uuid.UUID, error)
	GetRackByID(ctx context.Context, id uuid.UUID, withComponents bool) (*rack.Rack, error)
	GetRacksByIDs(ctx context.Context, ids []uuid.UUID, withComponents bool) ([]*rack.Rack, error)
	GetRackBySerial(ctx context.Context, manufacturer string, serial string, withComponents bool) (*rack.Rack, error)
	GetRackByIdentifier(ctx context.Context, identifier identifier.Identifier, withComponents bool) (*rack.Rack, error)
	PatchRack(ctx context.Context, rack *rack.Rack) (string, error)
	DeleteRack(ctx context.Context, id uuid.UUID) error
	PurgeRack(ctx context.Context, id uuid.UUID) error
	GetListOfRacks(ctx context.Context, info dbquery.StringQueryInfo, manufacturerFilter *dbquery.StringQueryInfo, modelFilter *dbquery.StringQueryInfo, pagination *dbquery.Pagination, orderBy *dbquery.OrderBy, withComponents bool) ([]*rack.Rack, int32, error)

	// Component operations
	GetComponentByID(ctx context.Context, id uuid.UUID) (*component.Component, error)
	GetComponentBySerial(ctx context.Context, manufacturer string, serial string, withRack bool) (*component.Component, error)
	GetComponentByBMCMAC(ctx context.Context, macAddress string) (*component.Component, error)
	GetComponentsByExternalIDs(ctx context.Context, externalIDs []string) ([]*component.Component, error)
	GetListOfComponents(ctx context.Context, info dbquery.StringQueryInfo, manufacturerFilter *dbquery.StringQueryInfo, modelFilter *dbquery.StringQueryInfo, componentTypes []devicetypes.ComponentType, pagination *dbquery.Pagination, orderBy *dbquery.OrderBy) ([]*component.Component, int32, error)
	AddComponent(ctx context.Context, comp *component.Component) (uuid.UUID, error)
	PatchComponent(ctx context.Context, comp *component.Component) error
	DeleteComponent(ctx context.Context, id uuid.UUID) error
	PurgeComponent(ctx context.Context, id uuid.UUID) error

	// Component drift operations
	GetDriftsByComponentIDs(ctx context.Context, componentIDs []uuid.UUID) ([]ComponentDrift, error)
	GetAllDrifts(ctx context.Context) ([]ComponentDrift, error)

	// NVL Domain operations
	CreateNVLDomain(ctx context.Context, nvlDomain *nvldomain.NVLDomain) (uuid.UUID, error)
	AttachRacksToNVLDomain(ctx context.Context, nvlDomainID identifier.Identifier, rackIDs []identifier.Identifier) error
	DetachRacksFromNVLDomain(ctx context.Context, rackIDs []identifier.Identifier) error
	GetListOfNVLDomains(ctx context.Context, info dbquery.StringQueryInfo, pagination *dbquery.Pagination) ([]*nvldomain.NVLDomain, int32, error)
	GetRacksForNVLDomain(ctx context.Context, nvlDomainID identifier.Identifier) ([]*rack.Rack, error)
}

Store defines the interface for inventory data persistence. It provides operations for managing racks (with components) and NVL domains.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL