state

package
v0.0.0-...-491b0ec Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: AGPL-3.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type State

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

func NewState

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

NewState returns a new state reference.

func (*State) AddResourcesBeforeApplication

func (st *State) AddResourcesBeforeApplication(
	ctx context.Context,
	args resource.AddResourcesBeforeApplicationArgs,
) ([]coreresource.UUID, error)

AddResourcesBeforeApplication adds the details of which resource revisions to use before the application exists in the model. The charm and resource metadata must exist.

The following error types can be expected to be returned:

func (*State) DeleteApplicationResources

func (st *State) DeleteApplicationResources(
	ctx context.Context,
	applicationID application.ID,
) error

DeleteApplicationResources deletes all resources associated with a given application ID. It checks that resources are not linked to a file store, image store, or unit before deletion. The method uses several SQL statements to prepare and execute the deletion process within a transaction. If related records are found in any store, deletion is halted and an error is returned, preventing any deletion which can led to inconsistent state due to foreign key constraints.

func (*State) DeleteImportedResources

func (st *State) DeleteImportedResources(
	ctx context.Context,
	appNames []string,
) error

DeleteImportedResources deletes all imported resource associated with the given applications during an import rollback.

func (*State) DeleteResourcesAddedBeforeApplication

func (st *State) DeleteResourcesAddedBeforeApplication(ctx context.Context, resources []coreresource.UUID) error

DeleteResourcesAddedBeforeApplication removes all resources for the given resource UUIDs. These resource UUIDs must have been returned by AddResourcesBeforeApplication.

func (*State) DeleteUnitResources

func (st *State) DeleteUnitResources(
	ctx context.Context,
	uuid coreunit.UUID,
) error

DeleteUnitResources removes the association of a unit, identified by UUID, with any of its' application's resources. It initiates a transaction and executes an SQL statement to delete rows from the unit_resource table. Returns an error if the operation fails at any point in the process.

func (*State) GetApplicationResourceID

func (st *State) GetApplicationResourceID(
	ctx context.Context,
	args resource.GetApplicationResourceIDArgs,
) (coreresource.UUID, error)

GetApplicationResourceID returns the ID of the application resource specified by natural key of application and resource name. Only resources with state available will be returned, not state potential.

func (*State) GetResource

func (st *State) GetResource(ctx context.Context,
	resourceUUID coreresource.UUID) (coreresource.Resource, error)

GetResource returns the identified resource.

The following error types can be expected to be returned:

func (*State) GetResourceType

func (st *State) GetResourceType(
	ctx context.Context,
	resourceUUID coreresource.UUID,
) (charmresource.Type, error)

GetResourceType finds the type of the given resource from the resource table.

The following error types can be expected to be returned:

func (*State) GetResourceUUIDByApplicationAndResourceName

func (st *State) GetResourceUUIDByApplicationAndResourceName(
	ctx context.Context,
	appName string,
	resName string,
) (coreresource.UUID, error)

GetResourceUUIDByApplicationAndResourceName returns the ID of the application resource specified by natural key of application and resource name. Only resources with state available will be returned, not state potential.

The following error types can be expected to be returned:

func (*State) GetResourcesByApplicationID

func (st *State) GetResourcesByApplicationID(
	ctx context.Context,
	applicationID application.ID,
) ([]coreresource.Resource, error)

GetResourcesByApplicationID returns the list of resource for the given application. Returns an error if the operation fails at any point in the process.

The following error types can be expected to be returned:

If the application exists but doesn't have any resources, no error are returned, the result just contains an empty list.

func (*State) ImportResources

func (st *State) ImportResources(ctx context.Context, args resource.ImportResourcesArgs) error

ImportResources sets resources imported in migration. It first builds all the resources to insert from the arguments, then inserts them at the end so as to wait as long as possible before turning into a write transaction.

The following error types can be expected to be returned:

func (*State) ListResources

func (st *State) ListResources(
	ctx context.Context,
	applicationID application.ID,
) (coreresource.ApplicationResources, error)

ListResources returns the list of resource for the given application.

func (*State) RecordStoredResource

func (st *State) RecordStoredResource(
	ctx context.Context,
	args resource.RecordStoredResourceArgs,
) (droppedHash string, err error)

RecordStoredResource records a stored resource along with who retrieved it.

If recording a stored blob for a resource that already has a blob associated with it, this association is removed and the hash of this blob returned in droppedHash. If there was no blob associated, droppedHash is empty.

The following error types can be expected to be returned:

func (*State) SetApplicationResource

func (st *State) SetApplicationResource(
	ctx context.Context,
	resourceUUID coreresource.UUID,
) error

SetApplicationResource marks an existing resource as in use by a kubernetes application.

Existing links between the application and resources with the same charm uuid and resource name as the resource being set are left in the table to be removed later on resource cleanup.

The following error types can be expected to be returned:

func (*State) SetRepositoryResources

func (st *State) SetRepositoryResources(
	ctx context.Context,
	config resource.SetRepositoryResourcesArgs,
) error

SetRepositoryResources updates the "potential" resources as the last revision from charm repository. The current data for this application/resource combination with "potential" state will be overwritten. If the resource doesn't exist, a log is generated.

"Potential" resources should be created at the creation of the application for repository charm, with undefined `revision` and `last_polled` fields.

The following error types can be expected to be returned:

func (*State) SetUnitResource

func (st *State) SetUnitResource(
	ctx context.Context,
	resourceUUID coreresource.UUID,
	unitUUID coreunit.UUID,
) error

SetUnitResource links a unit and a resource. If the unit is already linked to a resource with the same charm uuid and resource name as the resource being set, this resource is unset from the unit.

The following error types can be expected to be returned:

func (*State) UpdateResourceRevisionAndDeletePriorVersion

func (st *State) UpdateResourceRevisionAndDeletePriorVersion(
	ctx context.Context,
	args resource.UpdateResourceRevisionArgs,
	resourceType charmresource.Type,
) (string, coreresource.UUID, error)

UpdateResourceRevisionAndDeletePriorVersion deletes a reference to the old stored blob, saving the hash to return. Adds a new row in the resource table with a Store origin and new revision which indicates the resource will be updated. Next, it sets it on the application_resource table, removing the old resource for this charm resource. Lastly the charm modified version is updated to enable the resource upgrade.

The following error types can be expected to be returned:

func (*State) UpdateUploadResourceAndDeletePriorVersion

func (st *State) UpdateUploadResourceAndDeletePriorVersion(
	ctx context.Context,
	args resource.StateUpdateUploadResourceArgs,
) (string, coreresource.UUID, error)

UpdateUploadResourceAndDeletePriorVersion deletes a reference to the old stored blob, saving the hash to return. Adds a new row in the resource table with an Upload origin and nil revision, which indicates the resource will be updated via an uploaded blob. Next, it sets it on the application_resource table, removing the old resource for this charm resource.

The following error types can be expected to be returned:

Jump to

Keyboard shortcuts

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