~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/resources.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        // service to the provided values.
48
48
        SetCharmStoreResources(serviceID string, info []charmresource.Resource, lastPolled time.Time) error
49
49
 
 
50
        // TODO(ericsnow) Move this down to ResourcesPersistence.
 
51
 
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)
53
55
}
54
56
 
55
 
var newResources func(Persistence) Resources
 
57
var newResources func(Persistence, *State) Resources
56
58
 
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) {
60
62
        newResources = fn
61
63
}
62
64
 
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")
67
69
        }
68
70
 
69
71
        persist := st.newPersistence()
70
 
        resources := newResources(persist)
 
72
        resources := newResources(persist, st)
71
73
        return resources, nil
72
74
}
 
75
 
 
76
// ResourcesPersistence exposes the resources persistence functionality
 
77
// needed by state.
 
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)
 
82
 
 
83
        // NewRemoveResourcesOps returns mgo transaction operations that
 
84
        // remove all the service's resources from state.
 
85
        NewRemoveResourcesOps(serviceID string) ([]txn.Op, error)
 
86
}
 
87
 
 
88
var newResourcesPersistence func(Persistence) ResourcesPersistence
 
89
 
 
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
 
94
}
 
95
 
 
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")
 
101
        }
 
102
 
 
103
        base := st.newPersistence()
 
104
        persist := newResourcesPersistence(base)
 
105
        return persist, nil
 
106
}