state

package
v0.0.0-...-1f8c1e5 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: AGPL-3.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// ExpirationDelay is the maximum time a metadata can live in the cache before being removed.
	ExpirationDelay = 5 * time.Minute
)

Variables

This section is empty.

Functions

func InsertMetadata

func InsertMetadata(ctx context.Context, db domain.TxnRunner, metadata []cloudimagemetadata.Metadata, createdAt time.Time) error

InsertMetadata inserts or updates metadata for cloud images in the database.

Types

type State

type State struct {
	*domain.StateBase
	// contains filtered or unexported fields
}

State encapsulates the state management, logging, and architecture data.

func NewState

func NewState(factory database.TxnRunnerFactory, clock clock.Clock, logger logger.Logger) *State

NewState creates a new State instance using the provided database transaction factory and logger.

func (*State) AllCloudImageMetadata

func (s *State) AllCloudImageMetadata(ctx context.Context) ([]cloudimagemetadata.Metadata, error)

AllCloudImageMetadata retrieves all cloud image metadata from the database without applying any filter criteria. Returns a slice of cloudimagemetadata.Metadata and any error encountered during the retrieval process.

func (*State) DeleteMetadataWithImageID

func (s *State) DeleteMetadataWithImageID(ctx context.Context, imageID string) error

DeleteMetadataWithImageID deletes all metadata associated with the given image ID from the database.

func (*State) FindMetadata

FindMetadata retrieves cloud image metadata from the database based on specified filter criteria. It constructs a dynamic SQL query using the supplied criteria and executes it to fetch matching records. Returns cloudmetadataerrors.NotFound if none are found with this criteria.

func (*State) SaveMetadata

func (s *State) SaveMetadata(ctx context.Context, metadata []cloudimagemetadata.Metadata) error

SaveMetadata stores the provided list of cloud image metadata into the database.

Returns any errors occurred during db transaction.

It also fires a cleanup for old images, if any.

cloudimagemetadata.Metadata are considered unique among a signature, composed of these fields:

  • Stream
  • Region
  • Version
  • Arch
  • VirtType
  • RootStorageType
  • Source

Above behaviors applies for duplicated inserted metadata:

  • If a metadata has the same signature than an existing one in the database, the imageID will be updated with the new value in the existing metadata
  • If a several metadata have the same signature in the list, it will cause a unique constraint error from the database. It is likely a programmatic error.

func (*State) SupportedArchitectures

func (s *State) SupportedArchitectures(context.Context) set.Strings

SupportedArchitectures retrieves the set of supported architecture names.

Jump to

Keyboard shortcuts

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