Documentation
¶
Index ¶
- type State
- func (st *State) AddResourcesBeforeApplication(ctx context.Context, args resource.AddResourcesBeforeApplicationArgs) ([]coreresource.UUID, error)
- func (st *State) DeleteApplicationResources(ctx context.Context, applicationID application.ID) error
- func (st *State) DeleteImportedResources(ctx context.Context, appNames []string) error
- func (st *State) DeleteResourcesAddedBeforeApplication(ctx context.Context, resources []coreresource.UUID) error
- func (st *State) DeleteUnitResources(ctx context.Context, uuid coreunit.UUID) error
- func (st *State) GetApplicationResourceID(ctx context.Context, args resource.GetApplicationResourceIDArgs) (coreresource.UUID, error)
- func (st *State) GetResource(ctx context.Context, resourceUUID coreresource.UUID) (coreresource.Resource, error)
- func (st *State) GetResourceType(ctx context.Context, resourceUUID coreresource.UUID) (charmresource.Type, error)
- func (st *State) GetResourceUUIDByApplicationAndResourceName(ctx context.Context, appName string, resName string) (coreresource.UUID, error)
- func (st *State) GetResourcesByApplicationID(ctx context.Context, applicationID application.ID) ([]coreresource.Resource, error)
- func (st *State) ImportResources(ctx context.Context, args resource.ImportResourcesArgs) error
- func (st *State) ListResources(ctx context.Context, applicationID application.ID) (coreresource.ApplicationResources, error)
- func (st *State) RecordStoredResource(ctx context.Context, args resource.RecordStoredResourceArgs) (droppedHash string, err error)
- func (st *State) SetApplicationResource(ctx context.Context, resourceUUID coreresource.UUID) error
- func (st *State) SetRepositoryResources(ctx context.Context, config resource.SetRepositoryResourcesArgs) error
- func (st *State) SetUnitResource(ctx context.Context, resourceUUID coreresource.UUID, unitUUID coreunit.UUID) error
- func (st *State) UpdateResourceRevisionAndDeletePriorVersion(ctx context.Context, args resource.UpdateResourceRevisionArgs, ...) (string, coreresource.UUID, error)
- func (st *State) UpdateUploadResourceAndDeletePriorVersion(ctx context.Context, args resource.StateUpdateUploadResourceArgs) (string, coreresource.UUID, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type State ¶
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:
- resourceerrors.CharmResourceNotFound if the charm or charm resource do not exist.
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 ¶
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 ¶
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:
- resourceerrors.ResourceNotFound if no such resource exists.
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:
- resourceerrors.ResourceNotFound if the resource UUID cannot be found.
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:
- resourceerrors.ApplicationNotFound is returned if the application is not found.
- resourceerrors.ResourceNotFound if no resource with name exists for given application.
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:
- resourceerrors.ApplicationNotFound if the application ID is not an existing one.
If the application exists but doesn't have any resources, no error are returned, the result just contains an empty list.
func (*State) ImportResources ¶
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:
- resourceerrors.ResourceNotFound if the resource metadata cannot be found on the charm.
- resourceerrors.ApplicationNotFound if the application name of an application resource cannot be found in the database.
- resourceerrors.UnitNotFound if the unit name of a unit resource cannot be found in the database.
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:
- resourceerrors.StoredResourceNotFound if the stored resource at the storageID cannot be found.
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:
- resourceerrors.ResourceNotFound is returned if the resource cannot be found.
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:
- resourceerrors.ApplicationNotFound if the application id doesn't belong to a valid application.
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:
- resourceerrors.UnitNotFound if the unit id doesn't belong to an existing unit.
- resourceerrors.ResourceNotFound if the resource id doesn't belong to an existing resource.
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:
- resourceerrors.ResourceNotFound is returned if the resource cannot be found.
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:
- resourceerrors.ResourceNotFound is returned if the resource cannot be found.