Documentation
¶
Index ¶
- type ResourceStoreGetter
- type Service
- func (s *Service) AddResourcesBeforeApplication(ctx context.Context, arg resource.AddResourcesBeforeApplicationArgs) ([]coreresource.UUID, error)
- func (s *Service) DeleteApplicationResources(ctx context.Context, applicationID coreapplication.ID) error
- func (s *Service) DeleteImportedResources(ctx context.Context, appNames []string) error
- func (s *Service) DeleteResourcesAddedBeforeApplication(ctx context.Context, resUUIDs []coreresource.UUID) error
- func (s *Service) DeleteUnitResources(ctx context.Context, uuid coreunit.UUID) error
- func (s *Service) GetApplicationResourceID(ctx context.Context, args resource.GetApplicationResourceIDArgs) (coreresource.UUID, error)
- func (s *Service) GetResource(ctx context.Context, resourceUUID coreresource.UUID) (coreresource.Resource, error)
- func (s *Service) GetResourceUUIDByApplicationAndResourceName(ctx context.Context, appName, resName string) (coreresource.UUID, error)
- func (s *Service) GetResourcesByApplicationID(ctx context.Context, applicationID coreapplication.ID) ([]coreresource.Resource, error)
- func (s *Service) ImportResources(ctx context.Context, args resource.ImportResourcesArgs) error
- func (s *Service) ListResources(ctx context.Context, applicationID coreapplication.ID) (coreresource.ApplicationResources, error)
- func (s *Service) OpenResource(ctx context.Context, resourceUUID coreresource.UUID) (coreresource.Resource, io.ReadCloser, error)
- func (s *Service) SetApplicationResource(ctx context.Context, resourceUUID coreresource.UUID) error
- func (s *Service) SetRepositoryResources(ctx context.Context, args resource.SetRepositoryResourcesArgs) error
- func (s *Service) SetUnitResource(ctx context.Context, resourceUUID coreresource.UUID, unitUUID coreunit.UUID) error
- func (s *Service) StoreResource(ctx context.Context, args resource.StoreResourceArgs) error
- func (s *Service) StoreResourceAndIncrementCharmModifiedVersion(ctx context.Context, args resource.StoreResourceArgs) error
- func (s *Service) UpdateResourceRevision(ctx context.Context, arg resource.UpdateResourceRevisionArgs) (coreresource.UUID, error)
- func (s *Service) UpdateUploadResource(ctx context.Context, resourceToUpdate coreresource.UUID) (coreresource.UUID, error)
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ResourceStoreGetter ¶
type ResourceStoreGetter interface { // GetResourceStore returns the appropriate ResourceStore for the // given resource type. GetResourceStore(context.Context, charmresource.Type) (coreresourcestore.ResourceStore, error) }
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides the API for working with resources.
func NewService ¶
func NewService( st State, resourceStoreGetter ResourceStoreGetter, logger logger.Logger, ) *Service
NewService returns a new service reference wrapping the input state.
func (*Service) AddResourcesBeforeApplication ¶
func (s *Service) AddResourcesBeforeApplication(ctx context.Context, arg resource.AddResourcesBeforeApplicationArgs) ([]coreresource.UUID, error)
AddResourcesBeforeApplication adds the details of which resource revision to use before the application exists in the model. The charm and resource metadata must exist. These resources are resolved when the application is created using the returned Resource UUIDs.
The following error types can be expected to be returned:
- resourceerrors.ArgumentNotValid is returned if the origin is store and the revision is empty; or the CharmLocator is zero.
- resourceerrors.ResourceNameNotValid is returned if resource name is empty.
- resourceerrors.ApplicationNameNotFound if the specified application does not exist.
func (*Service) DeleteApplicationResources ¶
func (s *Service) DeleteApplicationResources( ctx context.Context, applicationID coreapplication.ID, ) error
DeleteApplicationResources removes the resources of a specified application. It should be called after all resources have been unlinked from potential units by DeleteUnitResources and their associated data removed from store.
The following error types can be expected to be returned:
- resourceerrors.ApplicationIDNotValid is returned if the application ID is not valid.
- resourceerrors.CleanUpStateNotValid is returned is there is remaining units or stored resources which are still associated with application resources.
func (*Service) DeleteImportedResources ¶
DeleteImportedResources deletes all imported resource associated with the given applications during an import rollback.
func (*Service) DeleteResourcesAddedBeforeApplication ¶
func (s *Service) DeleteResourcesAddedBeforeApplication(ctx context.Context, resUUIDs []coreresource.UUID) error
DeleteResourcesAddedBeforeApplication removes all resources for the given resource UUIDs. These resource UUIDs must have been returned by AddResourcesBeforeApplication.
The following error types can be expected to be returned:
- resourceerrors.ResourceUUIDNotValid is returned if the Resource ID is not valid.
func (*Service) DeleteUnitResources ¶
DeleteUnitResources unlinks the resources associated to a unit by its UUID.
The following error types can be expected to be returned:
- resourceerrors.UnitUUIDNotValid is returned if the unit ID is not valid.
func (*Service) GetApplicationResourceID ¶
func (s *Service) 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.
The following error types can be expected to be returned:
- resourceerrors.ResourceNameNotValid if no resource name is provided in the args.
- [coreerrors.NotValid] is returned if the application ID is not valid.
- resourceerrors.ResourceNotFound if no resource with name exists for given application.
func (*Service) GetResource ¶
func (s *Service) GetResource( ctx context.Context, resourceUUID coreresource.UUID, ) (coreresource.Resource, error)
GetResource returns the identified application resource.
The following error types can be expected to be returned:
- resourceerrors.ApplicationNotFound if the specified application does not exist.
func (*Service) GetResourceUUIDByApplicationAndResourceName ¶
func (s *Service) GetResourceUUIDByApplicationAndResourceName( ctx context.Context, appName, resName string, ) (coreresource.UUID, error)
GetResourceUUIDByApplicationAndResourceName returns the ID of the application resource specified by natural key of application and resource name.
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.
- resourceerrors.ResourceNameNotValid if no resource name is provided in the args.
- resourceerrors.ApplicationNameNotValid if the application name is invalid.
func (*Service) GetResourcesByApplicationID ¶
func (s *Service) GetResourcesByApplicationID(ctx context.Context, applicationID coreapplication.ID) ([]coreresource.Resource, error)
GetResourcesByApplicationID retrieves resources associated with a specific application ID. Returns a slice of resources or an error if the operation fails.
The following error types can be expected to be returned:
- resourceerrors.ApplicationIDNotValid is returned if the application ID is not valid.
- resourceerrors.ApplicationNotFound is returned if the application ID is not an existing one.
If the application doesn't have any resources, no error are returned, the result just contain an empty list.
func (*Service) 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.
- resourceerrors.OriginNotValid if the resource origin is not valid.
func (*Service) ListResources ¶
func (s *Service) ListResources( ctx context.Context, applicationID coreapplication.ID, ) (coreresource.ApplicationResources, error)
ListResources returns the resource data for the given application including application, unit and repository resource data. Unit data is only included for machine units. Repository resource data is included if it exists.
The following error types can be expected to be returned:
- resourceerrors.ApplicationIDNotValid is returned if the application ID is not valid.
- resourceerrors.ApplicationNotFound when the specified application does not exist.
No error is returned if the provided application has no resource.
func (*Service) OpenResource ¶
func (s *Service) OpenResource( ctx context.Context, resourceUUID coreresource.UUID, ) (coreresource.Resource, io.ReadCloser, error)
OpenResource returns the details of and a reader for the resource.
The following error types can be expected to be returned:
- resourceerrors.ResourceNotFound if the specified resource does not exist.
- resourceerrors.StoredResourceNotFound if the specified resource is not in the resource store.
func (*Service) SetApplicationResource ¶
func (s *Service) SetApplicationResource( ctx context.Context, resourceUUID coreresource.UUID, ) error
SetApplicationResource marks an existing resource as in use by a CAAS application.
The following error types can be expected to be returned:
- resourceerrors.ResourceNotFound if the resource UUID cannot be found.
func (*Service) SetRepositoryResources ¶
func (s *Service) SetRepositoryResources( ctx context.Context, args resource.SetRepositoryResourcesArgs, ) error
SetRepositoryResources updates the last available revision of resources from charm repository for a specific application.
The following error types can be expected to be returned:
- resourceerrors.ApplicationIDNotValid is returned if the Application ID is not valid.
- resourceerrors.CharmIDNotValid is returned if the charm ID is not valid.
- resourceerrors.ArgumentNotValid is returned if LastPolled is zero, if the length of Info is zero or if any info are invalid.
- resourceerrors.ApplicationNotFound if the specified application does not exist.
func (*Service) SetUnitResource ¶
func (s *Service) SetUnitResource( ctx context.Context, resourceUUID coreresource.UUID, unitUUID coreunit.UUID, ) error
SetUnitResource sets the unit as using the resource.
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 (*Service) StoreResource ¶
StoreResource adds the application resource to blob storage and updates the metadata. It also sets the retrieval information for the resource.
The Size and Fingerprint should be validated against the resource blob before the resource is passed in.
If storing a blob for a resource that already has a blob stored, the old blob will be replaced and removed from the store.
The following error types can be expected to be returned:
- resourceerrors.ResourceNotFound if the resource UUID cannot be found.
- resourceerrors.RetrievedByTypeNotValid if the retrieved by type is invalid.
func (*Service) StoreResourceAndIncrementCharmModifiedVersion ¶
func (s *Service) StoreResourceAndIncrementCharmModifiedVersion( ctx context.Context, args resource.StoreResourceArgs, ) error
StoreResourceAndIncrementCharmModifiedVersion adds the application resource to blob storage and updates the metadata. It sets the retrival information for the resource and also increments the charm modified version for the resources' application.
The Size and Fingerprint should be validated against the resource blob before the resource is passed in.
If storing a blob for a resource that already has a blob stored, the old blob will be replaced and removed from the store.
The following error types can be expected to be returned:
- resourceerrors.ResourceNotFound if the resource UUID cannot be found.
- resourceerrors.RetrievedByTypeNotValid if the retrieved by type is invalid.
func (*Service) UpdateResourceRevision ¶
func (s *Service) UpdateResourceRevision( ctx context.Context, arg resource.UpdateResourceRevisionArgs, ) (coreresource.UUID, error)
UpdateResourceRevision updates the revision of a store resource to a new version. Increments charm modified version for the application to trigger use of the new resource revision by the application. To allow for a resource upgrade, the current resource blob is removed.
The following error types can be expected to be returned:
- resourceerrors.ResourceUUIDNotValid is returned if the Resource ID is not valid.
- resourceerrors.ArgumentNotValid is returned if the Revision is less than 0.
func (*Service) UpdateUploadResource ¶
func (s *Service) UpdateUploadResource( ctx context.Context, resourceToUpdate coreresource.UUID, ) (coreresource.UUID, error)
UpdateUploadResource adds a new entry for an uploaded blob in the resource table with the desired parameters and sets it on the application. Any previous resource blob is removed. The new resource UUID is returned.
The following error types can be expected to be returned:
- resourceerrors.ResourceUUIDNotValid is returned if the Resource ID is not valid.
type State ¶
type State interface { // AddResourcesBeforeApplication adds the details of which resource // revision to use before the application exists in the model. The // charm and resource metadata must exist. AddResourcesBeforeApplication(ctx context.Context, arg resource.AddResourcesBeforeApplicationArgs) ([]coreresource.UUID, error) // DeleteApplicationResources removes all associated resources of a given // application identified by applicationID. DeleteApplicationResources(ctx context.Context, applicationID coreapplication.ID) error // DeleteResourcesAddedBeforeApplication removes all resources for the // given resource UUIDs. These resource UUIDs must have been returned // by AddResourcesBeforeApplication. DeleteResourcesAddedBeforeApplication(ctx context.Context, resUUIDs []coreresource.UUID) error // DeleteUnitResources deletes the association of resources with a specific // unit. DeleteUnitResources(ctx context.Context, uuid coreunit.UUID) error // GetApplicationResourceID returns the ID of the application resource // specified by natural key of application and resource name. GetApplicationResourceID(ctx context.Context, args resource.GetApplicationResourceIDArgs) (coreresource.UUID, error) // GetResourceUUIDByApplicationAndResourceName returns the UUID of the // application resource specified by natural key of application and resource // name. // // 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. GetResourceUUIDByApplicationAndResourceName(ctx context.Context, appName, resName string) (coreresource.UUID, error) // ListResources returns the list of resource for the given application. ListResources(ctx context.Context, applicationID coreapplication.ID) (coreresource.ApplicationResources, error) // GetResource returns the identified resource. GetResource(ctx context.Context, resourceUUID coreresource.UUID) (coreresource.Resource, error) // GetResourcesByApplicationID returns the list of resource for the given application. // // 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. GetResourcesByApplicationID(ctx context.Context, applicationID coreapplication.ID) ([]coreresource.Resource, 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. GetResourceType(ctx context.Context, resourceUUID coreresource.UUID) (charmresource.Type, 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. RecordStoredResource(ctx context.Context, args resource.RecordStoredResourceArgs) (droppedHash string, err error) // SetUnitResource sets the resource metadata for a specific 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. SetUnitResource(ctx context.Context, resourceUUID coreresource.UUID, unitUUID coreunit.UUID) error // SetApplicationResource marks an existing resource as in use by a CAAS // application. // // The following error types can be expected to be returned: // - [resourceerrors.ResourceNotFound] if the resource id doesn't belong // to an existing resource. SetApplicationResource(ctx context.Context, resourceUUID coreresource.UUID) error // SetRepositoryResources sets the "polled" resource for the // application to the provided values. The current data for this // application/resource combination will be overwritten. SetRepositoryResources(ctx context.Context, config resource.SetRepositoryResourcesArgs) 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. UpdateResourceRevisionAndDeletePriorVersion( ctx context.Context, arg resource.UpdateResourceRevisionArgs, resType charmresource.Type, ) (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 which indicates the resource will be updated. Next, it sets it on the // application_resource table, removing the old resource for this charm // resource. UpdateUploadResourceAndDeletePriorVersion( ctx context.Context, arg resource.StateUpdateUploadResourceArgs, ) (string, coreresource.UUID, 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: // - [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. // - [resourceerrors.OriginNotValid] if the resource origin is not valid. ImportResources(ctx context.Context, args resource.ImportResourcesArgs) error // DeleteImportedResources deletes all imported resource associated with the // given applications during an import rollback. // // The following error types can be expected to be returned: // - [resourceerrors.ApplicationNotFound] is returned if the application is // not found. DeleteImportedResources(ctx context.Context, appNames []string) error }
State describes retrieval and persistence methods for resource.