service

package
v0.0.0-...-f88c608 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: 14 Imported by: 2

Documentation

Index

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:

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:

func (*Service) DeleteImportedResources

func (s *Service) DeleteImportedResources(
	ctx context.Context,
	appNames []string,
) error

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:

func (*Service) DeleteUnitResources

func (s *Service) DeleteUnitResources(
	ctx context.Context,
	uuid coreunit.UUID,
) error

DeleteUnitResources unlinks the resources associated to a unit by its UUID.

The following error types can be expected to be returned:

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:

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:

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:

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:

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

func (*Service) ImportResources

func (s *Service) 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 (*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:

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:

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:

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:

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:

func (*Service) StoreResource

func (s *Service) StoreResource(
	ctx context.Context,
	args resource.StoreResourceArgs,
) error

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:

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:

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:

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:

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.

Jump to

Keyboard shortcuts

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