migration

package
v0.0.0-pre.3 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("Not found")

	ErrConstraintViolation = errors.New("Constraint violation")

	ErrOperationNotPermitted = errors.New("Operation not permitted")
)

Functions

func NewBatchService

func NewBatchService(repo BatchRepo, instance InstanceService, source SourceService) batchService

func NewInstanceService

func NewInstanceService(repo InstanceRepo, source SourceService, opts ...InstanceServiceOption) instanceService

func NewNetworkService

func NewNetworkService(repo NetworkRepo) networkService

func NewQueueService

func NewQueueService(batch BatchService, instance InstanceService, source SourceService) queueService

func NewSourceService

func NewSourceService(repo SourceRepo) sourceService

func NewTargetService

func NewTargetService(repo TargetRepo) targetService

func NewValidationErrf

func NewValidationErrf(format string, a ...any) error

Types

type Batch

type Batch struct {
	ID                   int64
	Name                 string `db:"primary=yes"`
	Target               string `db:"join=targets.name"`
	TargetProject        string
	Status               api.BatchStatusType
	StatusMessage        string
	StoragePool          string
	IncludeExpression    string
	MigrationWindowStart time.Time
	MigrationWindowEnd   time.Time
}

func (Batch) CanBeModified

func (b Batch) CanBeModified() bool

func (Batch) CompileIncludeExpression

func (b Batch) CompileIncludeExpression(i InstanceFilterable) (*vm.Program, error)

func (Batch) InstanceMatchesCriteria

func (b Batch) InstanceMatchesCriteria(instance Instance, source Source) (bool, error)

func (Batch) ToAPI

func (b Batch) ToAPI() api.Batch

ToAPI returns the API representation of a batch.

func (Batch) Validate

func (b Batch) Validate() error

type BatchRepo

type BatchRepo interface {
	Create(ctx context.Context, batch Batch) (int64, error)
	GetAll(ctx context.Context) (Batches, error)
	GetAllByState(ctx context.Context, status api.BatchStatusType) (Batches, error)
	GetAllNames(ctx context.Context) ([]string, error)
	GetAllNamesByState(ctx context.Context, status api.BatchStatusType) ([]string, error)
	GetByName(ctx context.Context, name string) (*Batch, error)
	Update(ctx context.Context, name string, batch Batch) error
	Rename(ctx context.Context, oldName string, newName string) error
	DeleteByName(ctx context.Context, name string) error
}

type BatchService

type BatchService interface {
	Create(ctx context.Context, batch Batch) (Batch, error)
	GetAll(ctx context.Context) (Batches, error)
	GetAllByState(ctx context.Context, status api.BatchStatusType) (Batches, error)
	GetAllNames(ctx context.Context) ([]string, error)
	GetAllNamesByState(ctx context.Context, status api.BatchStatusType) ([]string, error)
	GetByName(ctx context.Context, name string) (*Batch, error)
	Update(ctx context.Context, name string, batch *Batch) error
	UpdateInstancesAssignedToBatch(ctx context.Context, batch Batch) error
	UpdateStatusByName(ctx context.Context, name string, status api.BatchStatusType, statusMessage string) (*Batch, error)
	Rename(ctx context.Context, oldName string, newName string) error
	DeleteByName(ctx context.Context, name string) error
	StartBatchByName(ctx context.Context, name string) error
	StopBatchByName(ctx context.Context, name string) error
}

type Batches

type Batches []Batch

type ErrValidation

type ErrValidation string

func (ErrValidation) Error

func (e ErrValidation) Error() string

type Instance

type Instance struct {
	ID   int64
	UUID uuid.UUID `db:"primary=yes"`

	MigrationStatus        api.MigrationStatusType
	MigrationStatusMessage string
	LastUpdateFromSource   time.Time
	LastUpdateFromWorker   time.Time

	Source string  `db:"join=sources.name"`
	Batch  *string `db:"leftjoin=batches.name"`

	NeedsDiskImport bool
	SecretToken     uuid.UUID

	Overrides *InstanceOverride `db:"ignore"`

	Properties api.InstanceProperties `db:"marshal=json"`
}

func (Instance) CanBeModified

func (i Instance) CanBeModified() bool

func (Instance) GetName

func (i Instance) GetName() string

GetName returns the name of the instance, which may not be unique among all instances for a given source. If a unique, human-readable identifier is needed, use the Location property.

func (Instance) IsMigrating

func (i Instance) IsMigrating() bool

func (Instance) ToAPI

func (i Instance) ToAPI() api.Instance

func (Instance) ToFilterable

func (i Instance) ToFilterable(s Source) InstanceFilterable

func (Instance) Validate

func (i Instance) Validate() error

type InstanceFilterable

type InstanceFilterable struct {
	api.InstanceProperties

	MigrationStatus        api.MigrationStatusType
	MigrationStatusMessage string
	LastUpdateFromSource   time.Time

	Source     string
	SourceType api.SourceType
}

type InstanceOverride

type InstanceOverride struct {
	Properties api.InstancePropertiesConfigurable `db:"marshal=json"`

	ID               int64
	UUID             uuid.UUID `db:"primary=yes"`
	LastUpdate       time.Time
	Comment          string
	DisableMigration bool
}

func (InstanceOverride) ToAPI

func (InstanceOverride) Validate

func (o InstanceOverride) Validate() error

type InstanceRepo

type InstanceRepo interface {
	Create(ctx context.Context, instance Instance) (int64, error)
	GetAll(ctx context.Context) (Instances, error)
	GetAllByState(ctx context.Context, status ...api.MigrationStatusType) (Instances, error)
	GetAllByBatch(ctx context.Context, batch string) (Instances, error)
	GetAllByBatchAndState(ctx context.Context, batch string, status api.MigrationStatusType) (Instances, error)
	GetAllBySource(ctx context.Context, source string) (Instances, error)
	GetAllUUIDs(ctx context.Context) ([]uuid.UUID, error)
	GetAllUnassigned(ctx context.Context) (Instances, error)
	GetByUUID(ctx context.Context, id uuid.UUID) (*Instance, error)
	Update(ctx context.Context, instance Instance) error
	DeleteByUUID(ctx context.Context, id uuid.UUID) error

	// Overrides
	CreateOverrides(ctx context.Context, overrides InstanceOverride) (int64, error)
	GetOverridesByUUID(ctx context.Context, id uuid.UUID) (*InstanceOverride, error)
	DeleteOverridesByUUID(ctx context.Context, id uuid.UUID) error
	UpdateOverrides(ctx context.Context, overrides InstanceOverride) error
}

type InstanceService

type InstanceService interface {
	Create(ctx context.Context, instance Instance) (Instance, error)
	GetAll(ctx context.Context, withOverrides bool) (Instances, error)
	GetAllByState(ctx context.Context, withOverrides bool, statuses ...api.MigrationStatusType) (Instances, error)
	GetAllByBatch(ctx context.Context, batch string, withOverrides bool) (Instances, error)
	GetAllByBatchAndState(ctx context.Context, batch string, status api.MigrationStatusType, withOverrides bool) (Instances, error)
	GetAllBySource(ctx context.Context, source string, withOverrides bool) (Instances, error)
	GetAllUUIDs(ctx context.Context) ([]uuid.UUID, error)
	GetAllUnassigned(ctx context.Context, withOverrides bool) (Instances, error)
	GetByUUID(ctx context.Context, id uuid.UUID, withOverrides bool) (*Instance, error)

	UnassignFromBatch(ctx context.Context, id uuid.UUID) error
	Update(ctx context.Context, instance *Instance) error
	UpdateStatusByUUID(ctx context.Context, i uuid.UUID, status api.MigrationStatusType, statusMessage string, needsDiskImport bool, workerUpdate bool) (*Instance, error)
	ProcessWorkerUpdate(ctx context.Context, id uuid.UUID, workerResponseTypeArg api.WorkerResponseType, statusMessage string) (Instance, error)
	DeleteByUUID(ctx context.Context, id uuid.UUID) error

	// Overrride
	CreateOverrides(ctx context.Context, overrides InstanceOverride) (InstanceOverride, error)
	GetOverridesByUUID(ctx context.Context, id uuid.UUID) (*InstanceOverride, error)
	DeleteOverridesByUUID(ctx context.Context, id uuid.UUID) error
	UpdateOverrides(ctx context.Context, overrides *InstanceOverride) error
}

type InstanceServiceOption

type InstanceServiceOption func(s *instanceService)

type Instances

type Instances []Instance

type Network

type Network struct {
	ID   int64
	Name string `db:"primary=yes"`

	Config map[string]string `db:"marshal=json"`
}

func (Network) Validate

func (n Network) Validate() error

type NetworkRepo

type NetworkRepo interface {
	Create(ctx context.Context, network Network) (int64, error)
	GetAll(ctx context.Context) (Networks, error)
	GetAllNames(ctx context.Context) ([]string, error)
	GetByName(ctx context.Context, name string) (*Network, error)
	Update(ctx context.Context, network Network) error
	Rename(ctx context.Context, oldName string, newName string) error
	DeleteByName(ctx context.Context, name string) error
}

type NetworkService

type NetworkService interface {
	Create(ctx context.Context, network Network) (Network, error)
	GetAll(ctx context.Context) (Networks, error)
	GetAllNames(ctx context.Context) ([]string, error)
	GetByName(ctx context.Context, name string) (*Network, error)
	Update(ctx context.Context, network *Network) error
	DeleteByName(ctx context.Context, name string) error
}

type Networks

type Networks []Network

type QueueEntries

type QueueEntries []QueueEntry

type QueueEntry

type QueueEntry struct {
	InstanceUUID           uuid.UUID
	InstanceName           string
	MigrationStatus        api.MigrationStatusType
	MigrationStatusMessage string
	BatchName              string
}

type QueueService

type QueueService interface {
	GetAll(ctx context.Context) (QueueEntries, error)
	GetByInstanceID(ctx context.Context, id uuid.UUID) (QueueEntry, error)
	NewWorkerCommandByInstanceUUID(ctx context.Context, id uuid.UUID) (WorkerCommand, error)
}

type Source

type Source struct {
	ID         int64
	Name       string `db:"primary=yes"`
	SourceType api.SourceType

	Properties json.RawMessage

	EndpointFunc func(api.Source) (SourceEndpoint, error) `json:"-" db:"ignore"`
}

func (Source) GetExternalConnectivityStatus

func (s Source) GetExternalConnectivityStatus() api.ExternalConnectivityStatus

func (Source) GetServerCertificate

func (s Source) GetServerCertificate() *x509.Certificate

func (Source) GetTrustedServerCertificateFingerprint

func (s Source) GetTrustedServerCertificateFingerprint() string

func (*Source) SetExternalConnectivityStatus

func (s *Source) SetExternalConnectivityStatus(status api.ExternalConnectivityStatus)

func (*Source) SetServerCertificate

func (s *Source) SetServerCertificate(cert *x509.Certificate)

func (Source) ToAPI

func (s Source) ToAPI() api.Source

ToAPI returns the API representation of a source.

func (Source) Validate

func (s Source) Validate() error

type SourceEndpoint

type SourceEndpoint interface {
	Connect(ctx context.Context) error
	DoBasicConnectivityCheck() (api.ExternalConnectivityStatus, *x509.Certificate)
}

type SourceRepo

type SourceRepo interface {
	Create(ctx context.Context, source Source) (int64, error)
	GetAll(ctx context.Context) (Sources, error)
	GetAllNames(ctx context.Context) ([]string, error)
	GetByName(ctx context.Context, name string) (*Source, error)
	Update(ctx context.Context, name string, source Source) error
	Rename(ctx context.Context, oldName string, newName string) error
	DeleteByName(ctx context.Context, name string) error
}

type SourceService

type SourceService interface {
	Create(ctx context.Context, source Source) (Source, error)
	GetAll(ctx context.Context) (Sources, error)
	GetAllNames(ctx context.Context) ([]string, error)
	GetByName(ctx context.Context, name string) (*Source, error)
	Update(ctx context.Context, name string, source *Source, instanceService InstanceService) error
	DeleteByName(ctx context.Context, name string, instanceService InstanceService) error
}

type Sources

type Sources []Source

type Target

type Target struct {
	ID         int64
	Name       string `db:"primary=yes"`
	TargetType api.TargetType

	Properties json.RawMessage

	EndpointFunc func(api.Target) (TargetEndpoint, error) `json:"-" db:"ignore"`
}

func (Target) GetEndpoint

func (t Target) GetEndpoint() string

func (Target) GetExternalConnectivityStatus

func (t Target) GetExternalConnectivityStatus() api.ExternalConnectivityStatus

func (Target) GetServerCertificate

func (t Target) GetServerCertificate() *x509.Certificate

func (Target) GetTrustedServerCertificateFingerprint

func (t Target) GetTrustedServerCertificateFingerprint() string

func (*Target) SetExternalConnectivityStatus

func (t *Target) SetExternalConnectivityStatus(status api.ExternalConnectivityStatus)

func (*Target) SetOIDCTokens

func (t *Target) SetOIDCTokens(tokens *oidc.Tokens[*oidc.IDTokenClaims])

func (*Target) SetServerCertificate

func (t *Target) SetServerCertificate(cert *x509.Certificate)

func (Target) ToAPI

func (t Target) ToAPI() api.Target

ToAPI returns the API representation of a target.

func (Target) Validate

func (t Target) Validate() error

type TargetEndpoint

type TargetEndpoint interface {
	Connect(ctx context.Context) error
	DoBasicConnectivityCheck() (api.ExternalConnectivityStatus, *x509.Certificate)
	IsWaitingForOIDCTokens() bool
}

type TargetRepo

type TargetRepo interface {
	Create(ctx context.Context, target Target) (int64, error)
	GetAll(ctx context.Context) (Targets, error)
	GetAllNames(ctx context.Context) ([]string, error)
	GetByName(ctx context.Context, name string) (*Target, error)
	Update(ctx context.Context, name string, target Target) error
	Rename(ctx context.Context, oldName string, newName string) error
	DeleteByName(ctx context.Context, name string) error
}

type TargetService

type TargetService interface {
	Create(ctx context.Context, target Target) (Target, error)
	GetAll(ctx context.Context) (Targets, error)
	GetAllNames(ctx context.Context) ([]string, error)
	GetByName(ctx context.Context, name string) (*Target, error)
	Update(ctx context.Context, name string, target *Target) error
	DeleteByName(ctx context.Context, name string) error
}

type Targets

type Targets []Target

type WorkerCommand

type WorkerCommand struct {
	Command    api.WorkerCommandType
	Location   string
	SourceType api.SourceType
	Source     Source
	OS         string
	OSVersion  string
}

Directories

Path Synopsis
endpoint

Jump to

Keyboard shortcuts

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