Skip to content

Commit ae3560b

Browse files
committed
Rename ResourceAllocator -> ResourceManager
1 parent ba7e0c0 commit ae3560b

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

core/core.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ type Resource interface {
124124
Deallocate(interface{}) error
125125
}
126126

127-
type ResourceAllocator interface {
128-
// A resource allocator provides mechanism to manage (define/undefine,
127+
type ResourceManager interface {
128+
// A resource manager provides mechanism to manage (define/undefine,
129129
// allocate/deallocate) resources. Example, it may provide management in
130130
// logically centralized manner in a distributed system
131131
Init() error

gstate/gstate.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (gc *Cfg) initVxlanBitset(vxlans string) (*resources.AutoVxlanCfgResource,
218218
return vxlanRsrcCfg, freeVxlansStart, nil
219219
}
220220

221-
func (gc *Cfg) AllocVxlan(ra core.ResourceAllocator) (vxlan uint,
221+
func (gc *Cfg) AllocVxlan(ra core.ResourceManager) (vxlan uint,
222222
localVlan uint, err error) {
223223

224224
pair, err1 := ra.AllocateResourceVal(gc.Tenant, resources.AUTO_VXLAN_RSRC)
@@ -238,7 +238,7 @@ func (gc *Cfg) AllocVxlan(ra core.ResourceAllocator) (vxlan uint,
238238
return
239239
}
240240

241-
func (gc *Cfg) FreeVxlan(ra core.ResourceAllocator, vxlan uint, localVlan uint) error {
241+
func (gc *Cfg) FreeVxlan(ra core.ResourceManager, vxlan uint, localVlan uint) error {
242242
g := Oper{StateDriver: gc.StateDriver}
243243
err := g.Read(gc.Tenant)
244244
if err != nil {
@@ -275,7 +275,7 @@ func (gc *Cfg) initVlanBitset(vlans string) (*bitset.BitSet, error) {
275275
return vlanBitset, nil
276276
}
277277

278-
func (gc *Cfg) AllocVlan(ra core.ResourceAllocator) (uint, error) {
278+
func (gc *Cfg) AllocVlan(ra core.ResourceManager) (uint, error) {
279279
vlan, err := ra.AllocateResourceVal(gc.Tenant, resources.AUTO_VLAN_RSRC)
280280
if err != nil {
281281
log.Printf("alloc vlan failed: %q", err)
@@ -285,11 +285,11 @@ func (gc *Cfg) AllocVlan(ra core.ResourceAllocator) (uint, error) {
285285
return vlan.(uint), err
286286
}
287287

288-
func (gc *Cfg) FreeVlan(ra core.ResourceAllocator, vlan uint) error {
288+
func (gc *Cfg) FreeVlan(ra core.ResourceManager, vlan uint) error {
289289
return ra.DeallocateResourceVal(gc.Tenant, resources.AUTO_VLAN_RSRC, vlan)
290290
}
291291

292-
func (gc *Cfg) AllocSubnet(ra core.ResourceAllocator) (string, error) {
292+
func (gc *Cfg) AllocSubnet(ra core.ResourceManager) (string, error) {
293293
pair, err := ra.AllocateResourceVal(gc.Tenant, resources.AUTO_SUBNET_RSRC)
294294
if err != nil {
295295
return "", err
@@ -298,14 +298,14 @@ func (gc *Cfg) AllocSubnet(ra core.ResourceAllocator) (string, error) {
298298
return pair.(resources.SubnetIpLenPair).Ip.String(), err
299299
}
300300

301-
func (gc *Cfg) FreeSubnet(ra core.ResourceAllocator, subnetIp string) error {
301+
func (gc *Cfg) FreeSubnet(ra core.ResourceManager, subnetIp string) error {
302302
return ra.DeallocateResourceVal(gc.Tenant, resources.AUTO_SUBNET_RSRC,
303303
resources.SubnetIpLenPair{
304304
Ip: net.ParseIP(subnetIp),
305305
Len: gc.Auto.AllocSubnetLen})
306306
}
307307

308-
func (gc *Cfg) Process(ra core.ResourceAllocator) error {
308+
func (gc *Cfg) Process(ra core.ResourceManager) error {
309309
var err error
310310

311311
if gc.Version != VersionBeta1 {

gstate/gstate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/contiv/netplugin/resources"
2525
)
2626

27-
var gstateTestRA = &resources.EtcdResourceAllocator{Etcd: gstateSD}
27+
var gstateTestRA = &resources.EtcdResourceManager{Etcd: gstateSD}
2828

2929
type ValueData struct {
3030
value []byte

netmaster/netmaster.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ func CreateTenant(stateDriver core.StateDriver, tenant *ConfigTenant) error {
124124
}
125125

126126
// XXX: instead of initing resource-manager always, just init and
127-
// store it once. Also the type of resource-allocator should be picked up
127+
// store it once. Also the type of resource-manager should be picked up
128128
// based on configuration.
129-
ra := &resources.EtcdResourceAllocator{Etcd: stateDriver}
129+
ra := &resources.EtcdResourceManager{Etcd: stateDriver}
130130
err = ra.Init()
131131
if err != nil {
132132
return err
133133
}
134134

135-
err = gCfg.Process(core.ResourceAllocator(ra))
135+
err = gCfg.Process(core.ResourceManager(ra))
136136
if err != nil {
137137
log.Printf("Error '%s' updating the config %v \n", err, gCfg)
138138
return err
@@ -437,14 +437,14 @@ func CreateNetworks(stateDriver core.StateDriver, tenant *ConfigTenant) error {
437437
}
438438

439439
// XXX: instead of initing resource-manager always, just init and
440-
// store it once. Also the type of resource-allocator should be picked up
440+
// store it once. Also the type of resource-manager should be picked up
441441
// based on configuration.
442-
tempRa := &resources.EtcdResourceAllocator{Etcd: stateDriver}
442+
tempRa := &resources.EtcdResourceManager{Etcd: stateDriver}
443443
err = tempRa.Init()
444444
if err != nil {
445445
return err
446446
}
447-
ra := core.ResourceAllocator(tempRa)
447+
ra := core.ResourceManager(tempRa)
448448

449449
err = validateNetworkConfig(tenant)
450450
if err != nil {
@@ -551,14 +551,14 @@ func freeNetworkResources(stateDriver core.StateDriver, nwMasterCfg *MasterNwCon
551551
nwCfg *drivers.OvsCfgNetworkState, gCfg *gstate.Cfg) (err error) {
552552

553553
// XXX: instead of initing resource-manager always, just init and
554-
// store it once. Also the type of resource-allocator should be picked up
554+
// store it once. Also the type of resource-manager should be picked up
555555
// based on configuration.
556-
tempRa := &resources.EtcdResourceAllocator{Etcd: stateDriver}
556+
tempRa := &resources.EtcdResourceManager{Etcd: stateDriver}
557557
err = tempRa.Init()
558558
if err != nil {
559559
return err
560560
}
561-
ra := core.ResourceAllocator(tempRa)
561+
ra := core.ResourceManager(tempRa)
562562

563563
if nwCfg.PktTagType == "vlan" {
564564
err = gCfg.FreeVlan(ra, uint(nwCfg.PktTag))

resources/etcdresourceallocator.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/contiv/netplugin/core"
2424
)
2525

26-
// Etcd resource allocator implements the core.ResourceAllocator interface.
26+
// Etcd resource manager implements the core.ResourceManager interface.
2727
// It manages the resource in a logically centralized manner using serialized
2828
// writes to a etcd based datastore.
2929

@@ -33,22 +33,22 @@ var ResourceRegistry = map[string]reflect.Type{
3333
AUTO_SUBNET_RSRC: reflect.TypeOf(AutoSubnetCfgResource{}),
3434
}
3535

36-
type EtcdResourceAllocator struct {
36+
type EtcdResourceManager struct {
3737
//XXX: should be '*drivers.EtcdStateDriver', but leaving is
3838
//core.StateDriver to get tests going and until the netmaster
39-
//is changed to pickup the resource-allocator from config
39+
//is changed to pickup the resource-manager from config
4040
Etcd core.StateDriver
4141
}
4242

43-
func (ra *EtcdResourceAllocator) Init() error {
43+
func (ra *EtcdResourceManager) Init() error {
4444
return nil
4545
}
4646

47-
func (ra *EtcdResourceAllocator) Deinit() {
47+
func (ra *EtcdResourceManager) Deinit() {
4848
}
4949

5050
// XXX: It might be better to keep cache of resources and avoid frequent etcd reads
51-
func (ra *EtcdResourceAllocator) findResource(id, desc string) (core.Resource, bool, error) {
51+
func (ra *EtcdResourceManager) findResource(id, desc string) (core.Resource, bool, error) {
5252
alreadyExists := false
5353
rsrcType, ok := ResourceRegistry[desc]
5454
if !ok {
@@ -80,7 +80,7 @@ func (ra *EtcdResourceAllocator) findResource(id, desc string) (core.Resource, b
8080
return rsrc, alreadyExists, nil
8181
}
8282

83-
func (ra *EtcdResourceAllocator) DefineResource(id, desc string,
83+
func (ra *EtcdResourceManager) DefineResource(id, desc string,
8484
rsrcCfg interface{}) error {
8585
// XXX: need to take care of distibuted updates, locks etc here
8686
rsrc, alreadyExists, err := ra.findResource(id, desc)
@@ -101,7 +101,7 @@ func (ra *EtcdResourceAllocator) DefineResource(id, desc string,
101101
return nil
102102
}
103103

104-
func (ra *EtcdResourceAllocator) UndefineResource(id, desc string) error {
104+
func (ra *EtcdResourceManager) UndefineResource(id, desc string) error {
105105
// XXX: need to take care of distibuted updates, locks etc here
106106
rsrc, alreadyExists, err := ra.findResource(id, desc)
107107
if err != nil {
@@ -118,7 +118,7 @@ func (ra *EtcdResourceAllocator) UndefineResource(id, desc string) error {
118118

119119
}
120120

121-
func (ra *EtcdResourceAllocator) AllocateResourceVal(id, desc string) (interface{},
121+
func (ra *EtcdResourceManager) AllocateResourceVal(id, desc string) (interface{},
122122
error) {
123123
// XXX: need to take care of distibuted updates, locks etc here
124124
rsrc, alreadyExists, err := ra.findResource(id, desc)
@@ -134,7 +134,7 @@ func (ra *EtcdResourceAllocator) AllocateResourceVal(id, desc string) (interface
134134
return rsrc.Allocate()
135135
}
136136

137-
func (ra *EtcdResourceAllocator) DeallocateResourceVal(id, desc string,
137+
func (ra *EtcdResourceManager) DeallocateResourceVal(id, desc string,
138138
value interface{}) error {
139139
// XXX: need to take care of distibuted updates, locks etc here
140140
rsrc, alreadyExists, err := ra.findResource(id, desc)

resources/etcdresourceallocator_test.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func (r *TestResource) Deallocate(value interface{}) error {
9494
return nil
9595
}
9696

97-
func TestEtcdResourceAllocatorDefineResource(t *testing.T) {
98-
ra := &EtcdResourceAllocator{Etcd: nil}
97+
func TestEtcdResourceManagerDefineResource(t *testing.T) {
98+
ra := &EtcdResourceManager{Etcd: nil}
9999
ResourceRegistry[testResourceDesc] = reflect.TypeOf(TestResource{})
100100
defer func() { delete(ResourceRegistry, testResourceDesc) }()
101101

@@ -106,8 +106,8 @@ func TestEtcdResourceAllocatorDefineResource(t *testing.T) {
106106
}
107107
}
108108

109-
func TestEtcdResourceAllocatorDefineInvalidResource(t *testing.T) {
110-
ra := &EtcdResourceAllocator{Etcd: nil}
109+
func TestEtcdResourceManagerDefineInvalidResource(t *testing.T) {
110+
ra := &EtcdResourceManager{Etcd: nil}
111111

112112
gReadCtr = 0
113113
err := ra.DefineResource(testResourceId, testResourceDesc, &TestResource{})
@@ -120,8 +120,8 @@ func TestEtcdResourceAllocatorDefineInvalidResource(t *testing.T) {
120120
}
121121
}
122122

123-
func TestEtcdResourceAllocatorUndefineResource(t *testing.T) {
124-
ra := &EtcdResourceAllocator{Etcd: nil}
123+
func TestEtcdResourceManagerUndefineResource(t *testing.T) {
124+
ra := &EtcdResourceManager{Etcd: nil}
125125
ResourceRegistry[testResourceDesc] = reflect.TypeOf(TestResource{})
126126
defer func() { delete(ResourceRegistry, testResourceDesc) }()
127127

@@ -137,8 +137,8 @@ func TestEtcdResourceAllocatorUndefineResource(t *testing.T) {
137137
}
138138
}
139139

140-
func TestEtcdResourceAllocatorUndefineInvalidResource(t *testing.T) {
141-
ra := &EtcdResourceAllocator{Etcd: nil}
140+
func TestEtcdResourceManagerUndefineInvalidResource(t *testing.T) {
141+
ra := &EtcdResourceManager{Etcd: nil}
142142

143143
gReadCtr = 0
144144
err := ra.UndefineResource(testResourceId, testResourceDesc)
@@ -151,8 +151,8 @@ func TestEtcdResourceAllocatorUndefineInvalidResource(t *testing.T) {
151151
}
152152
}
153153

154-
func TestEtcdResourceAllocatorUndefineNonexistentResource(t *testing.T) {
155-
ra := &EtcdResourceAllocator{Etcd: nil}
154+
func TestEtcdResourceManagerUndefineNonexistentResource(t *testing.T) {
155+
ra := &EtcdResourceManager{Etcd: nil}
156156
ResourceRegistry[testResourceDesc] = reflect.TypeOf(TestResource{})
157157
defer func() { delete(ResourceRegistry, testResourceDesc) }()
158158

@@ -167,8 +167,8 @@ func TestEtcdResourceAllocatorUndefineNonexistentResource(t *testing.T) {
167167
}
168168
}
169169

170-
func TestEtcdResourceAllocatorAllocateResource(t *testing.T) {
171-
ra := &EtcdResourceAllocator{Etcd: nil}
170+
func TestEtcdResourceManagerAllocateResource(t *testing.T) {
171+
ra := &EtcdResourceManager{Etcd: nil}
172172
ResourceRegistry[testResourceDesc] = reflect.TypeOf(TestResource{})
173173
defer func() { delete(ResourceRegistry, testResourceDesc) }()
174174

@@ -184,8 +184,8 @@ func TestEtcdResourceAllocatorAllocateResource(t *testing.T) {
184184
}
185185
}
186186

187-
func TestEtcdResourceAllocatorAllocateInvalidResource(t *testing.T) {
188-
ra := &EtcdResourceAllocator{Etcd: nil}
187+
func TestEtcdResourceManagerAllocateInvalidResource(t *testing.T) {
188+
ra := &EtcdResourceManager{Etcd: nil}
189189

190190
gReadCtr = 0
191191
_, err := ra.AllocateResourceVal(testResourceId, testResourceDesc)
@@ -198,8 +198,8 @@ func TestEtcdResourceAllocatorAllocateInvalidResource(t *testing.T) {
198198
}
199199
}
200200

201-
func TestEtcdResourceAllocatorAllocateiNonexistentResource(t *testing.T) {
202-
ra := &EtcdResourceAllocator{Etcd: nil}
201+
func TestEtcdResourceManagerAllocateiNonexistentResource(t *testing.T) {
202+
ra := &EtcdResourceManager{Etcd: nil}
203203
ResourceRegistry[testResourceDesc] = reflect.TypeOf(TestResource{})
204204
defer func() { delete(ResourceRegistry, testResourceDesc) }()
205205

@@ -214,8 +214,8 @@ func TestEtcdResourceAllocatorAllocateiNonexistentResource(t *testing.T) {
214214
}
215215
}
216216

217-
func TestEtcdResourceAllocatorDeallocateResource(t *testing.T) {
218-
ra := &EtcdResourceAllocator{Etcd: nil}
217+
func TestEtcdResourceManagerDeallocateResource(t *testing.T) {
218+
ra := &EtcdResourceManager{Etcd: nil}
219219
ResourceRegistry[testResourceDesc] = reflect.TypeOf(TestResource{})
220220
defer func() { delete(ResourceRegistry, testResourceDesc) }()
221221

@@ -236,8 +236,8 @@ func TestEtcdResourceAllocatorDeallocateResource(t *testing.T) {
236236
}
237237
}
238238

239-
func TestEtcdResourceAllocatorDeallocateInvalidResource(t *testing.T) {
240-
ra := &EtcdResourceAllocator{Etcd: nil}
239+
func TestEtcdResourceManagerDeallocateInvalidResource(t *testing.T) {
240+
ra := &EtcdResourceManager{Etcd: nil}
241241

242242
gReadCtr = 0
243243
err := ra.DeallocateResourceVal(testResourceId, testResourceDesc, 0)
@@ -250,8 +250,8 @@ func TestEtcdResourceAllocatorDeallocateInvalidResource(t *testing.T) {
250250
}
251251
}
252252

253-
func TestEtcdResourceAllocatorDeallocateiNonexistentResource(t *testing.T) {
254-
ra := &EtcdResourceAllocator{Etcd: nil}
253+
func TestEtcdResourceManagerDeallocateiNonexistentResource(t *testing.T) {
254+
ra := &EtcdResourceManager{Etcd: nil}
255255
ResourceRegistry[testResourceDesc] = reflect.TypeOf(TestResource{})
256256
defer func() { delete(ResourceRegistry, testResourceDesc) }()
257257

0 commit comments

Comments
 (0)