47
47
// service to the provided values.
48
48
SetCharmStoreResources(serviceID string, info []charmresource.Resource, lastPolled time.Time) error
50
// TODO(ericsnow) Move this down to ResourcesPersistence.
50
52
// NewResolvePendingResourcesOps generates mongo transaction operations
51
53
// to set the identified resources as active.
52
54
NewResolvePendingResourcesOps(serviceID string, pendingIDs map[string]string) ([]txn.Op, error)
55
var newResources func(Persistence) Resources
57
var newResources func(Persistence, *State) Resources
57
59
// SetResourcesComponent registers the function that provide the state
58
60
// functionality related to resources.
59
func SetResourcesComponent(fn func(Persistence) Resources) {
61
func SetResourcesComponent(fn func(Persistence, *State) Resources) {
63
65
// Resources returns the resources functionality for the current state.
64
66
func (st *State) Resources() (Resources, error) {
65
67
if newResources == nil {
66
return nil, errors.Errorf("resources not supported")
68
return nil, errors.NotSupportedf("resources")
69
71
persist := st.newPersistence()
70
resources := newResources(persist)
72
resources := newResources(persist, st)
71
73
return resources, nil
76
// ResourcesPersistence exposes the resources persistence functionality
78
type ResourcesPersistence interface {
79
// NewRemoveUnitResourcesOps returns mgo transaction operations
80
// that remove resource information specific to the unit from state.
81
NewRemoveUnitResourcesOps(unitID string) ([]txn.Op, error)
83
// NewRemoveResourcesOps returns mgo transaction operations that
84
// remove all the service's resources from state.
85
NewRemoveResourcesOps(serviceID string) ([]txn.Op, error)
88
var newResourcesPersistence func(Persistence) ResourcesPersistence
90
// SetResourcesPersistence registers the function that provides the
91
// state persistence functionality related to resources.
92
func SetResourcesPersistence(fn func(Persistence) ResourcesPersistence) {
93
newResourcesPersistence = fn
96
// ResourcesPersistence returns the resources persistence functionality
97
// for the current state.
98
func (st *State) ResourcesPersistence() (ResourcesPersistence, error) {
99
if newResourcesPersistence == nil {
100
return nil, errors.NotSupportedf("resources")
103
base := st.newPersistence()
104
persist := newResourcesPersistence(base)