Skip to content

Commit

Permalink
Rename ResourceAllocator -> ResourceManager
Browse files Browse the repository at this point in the history
  • Loading branch information
mapuri committed Apr 2, 2015
1 parent eff0e16 commit 3af1f04
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 59 deletions.
4 changes: 2 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ type Resource interface {
Deallocate(interface{}) error
}

type ResourceAllocator interface {
// A resource allocator provides mechanism to manage (define/undefine,
type ResourceManager interface {
// A resource manager provides mechanism to manage (define/undefine,
// allocate/deallocate) resources. Example, it may provide management in
// logically centralized manner in a distributed system
Init() error
Expand Down
14 changes: 7 additions & 7 deletions gstate/gstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (gc *Cfg) initVxlanBitset(vxlans string) (*resources.AutoVxlanCfgResource,
return vxlanRsrcCfg, freeVxlansStart, nil
}

func (gc *Cfg) AllocVxlan(ra core.ResourceAllocator) (vxlan uint,
func (gc *Cfg) AllocVxlan(ra core.ResourceManager) (vxlan uint,
localVlan uint, err error) {

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

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

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

func (gc *Cfg) FreeVlan(ra core.ResourceAllocator, vlan uint) error {
func (gc *Cfg) FreeVlan(ra core.ResourceManager, vlan uint) error {
return ra.DeallocateResourceVal(gc.Tenant, resources.AUTO_VLAN_RSRC, vlan)
}

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

func (gc *Cfg) FreeSubnet(ra core.ResourceAllocator, subnetIp string) error {
func (gc *Cfg) FreeSubnet(ra core.ResourceManager, subnetIp string) error {
return ra.DeallocateResourceVal(gc.Tenant, resources.AUTO_SUBNET_RSRC,
resources.SubnetIpLenPair{
Ip: net.ParseIP(subnetIp),
Len: gc.Auto.AllocSubnetLen})
}

func (gc *Cfg) Process(ra core.ResourceAllocator) error {
func (gc *Cfg) Process(ra core.ResourceManager) error {
var err error

if gc.Version != VersionBeta1 {
Expand Down
2 changes: 1 addition & 1 deletion gstate/gstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/contiv/netplugin/resources"
)

var gstateTestRA = &resources.EtcdResourceAllocator{Etcd: gstateSD}
var gstateTestRA = &resources.EtcdResourceManager{Etcd: gstateSD}

type ValueData struct {
value []byte
Expand Down
18 changes: 9 additions & 9 deletions netmaster/netmaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ func CreateTenant(stateDriver core.StateDriver, tenant *ConfigTenant) error {
}

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

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

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

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

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

if nwCfg.PktTagType == "vlan" {
err = gCfg.FreeVlan(ra, uint(nwCfg.PktTag))
Expand Down
20 changes: 10 additions & 10 deletions resources/etcdresourceallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/contiv/netplugin/core"
)

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

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

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

func (ra *EtcdResourceAllocator) Init() error {
func (ra *EtcdResourceManager) Init() error {
return nil
}

func (ra *EtcdResourceAllocator) Deinit() {
func (ra *EtcdResourceManager) Deinit() {
}

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

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

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

}

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

func (ra *EtcdResourceAllocator) DeallocateResourceVal(id, desc string,
func (ra *EtcdResourceManager) DeallocateResourceVal(id, desc string,
value interface{}) error {
// XXX: need to take care of distibuted updates, locks etc here
rsrc, alreadyExists, err := ra.findResource(id, desc)
Expand Down
44 changes: 22 additions & 22 deletions resources/etcdresourceallocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (r *TestResource) Deallocate(value interface{}) error {
return nil
}

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

Expand All @@ -106,8 +106,8 @@ func TestEtcdResourceAllocatorDefineResource(t *testing.T) {
}
}

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

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

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

Expand All @@ -137,8 +137,8 @@ func TestEtcdResourceAllocatorUndefineResource(t *testing.T) {
}
}

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

gReadCtr = 0
err := ra.UndefineResource(testResourceId, testResourceDesc)
Expand All @@ -151,8 +151,8 @@ func TestEtcdResourceAllocatorUndefineInvalidResource(t *testing.T) {
}
}

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

Expand All @@ -167,8 +167,8 @@ func TestEtcdResourceAllocatorUndefineNonexistentResource(t *testing.T) {
}
}

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

Expand All @@ -184,8 +184,8 @@ func TestEtcdResourceAllocatorAllocateResource(t *testing.T) {
}
}

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

gReadCtr = 0
_, err := ra.AllocateResourceVal(testResourceId, testResourceDesc)
Expand All @@ -198,8 +198,8 @@ func TestEtcdResourceAllocatorAllocateInvalidResource(t *testing.T) {
}
}

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

Expand All @@ -214,8 +214,8 @@ func TestEtcdResourceAllocatorAllocateiNonexistentResource(t *testing.T) {
}
}

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

Expand All @@ -236,8 +236,8 @@ func TestEtcdResourceAllocatorDeallocateResource(t *testing.T) {
}
}

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

gReadCtr = 0
err := ra.DeallocateResourceVal(testResourceId, testResourceDesc, 0)
Expand All @@ -250,8 +250,8 @@ func TestEtcdResourceAllocatorDeallocateInvalidResource(t *testing.T) {
}
}

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

Expand Down
16 changes: 8 additions & 8 deletions systemtests/twohosts/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,12 @@ func TestTwoHostsMultipleVxlansNetsLateContainerBindings_regress(t *testing.T) {
// Start server containers: Container1 and Container2
utils.StartServer(t, node1, "myContainer1")
defer func() {
utils.DockerCleanup(node1, "myContainer1")
utils.DockerCleanup(t, node1, "myContainer1")
}()
// Container2 and Container4 are on purple network
utils.StartServer(t, node1, "myContainer2")
defer func() {
utils.DockerCleanup(node1, "myContainer2")
utils.DockerCleanup(t, node1, "myContainer2")
}()

// apply uuid base config on started containers
Expand All @@ -424,12 +424,12 @@ func TestTwoHostsMultipleVxlansNetsLateContainerBindings_regress(t *testing.T) {
ipAddress := utils.GetIpAddress(t, node2, "orange-myContainer1")
utils.StartClient(t, node2, "myContainer3", ipAddress)
defer func() {
utils.DockerCleanup(node2, "myContainer3")
utils.DockerCleanup(t, node2, "myContainer3")
}()
ipAddress = utils.GetIpAddress(t, node2, "purple-myContainer2")
utils.StartClient(t, node2, "myContainer4", ipAddress)
defer func() {
utils.DockerCleanup(node2, "myContainer4")
utils.DockerCleanup(t, node2, "myContainer4")
}()
}

Expand All @@ -450,12 +450,12 @@ func TestTwoHostsMultipleVxlansNetsInfraContainerBindings_regress(t *testing.T)
// Start server containers: Container1 and Container2
utils.StartServer(t, node1, "myContainer1")
defer func() {
utils.DockerCleanup(node1, "myContainer1")
utils.DockerCleanup(t, node1, "myContainer1")
}()
// Container2 and Container4 are on purple network
utils.StartServer(t, node1, "myContainer2")
defer func() {
utils.DockerCleanup(node1, "myContainer2")
utils.DockerCleanup(t, node1, "myContainer2")
}()

// read host bindings and infra container mappings
Expand All @@ -478,11 +478,11 @@ func TestTwoHostsMultipleVxlansNetsInfraContainerBindings_regress(t *testing.T)
ipAddress := utils.GetIpAddress(t, node2, "orange-myPod1")
utils.StartClient(t, node2, "myContainer3", ipAddress)
defer func() {
utils.DockerCleanup(node2, "myContainer3")
utils.DockerCleanup(t, node2, "myContainer3")
}()
ipAddress = utils.GetIpAddress(t, node2, "purple-myPod2")
utils.StartClient(t, node2, "myContainer4", ipAddress)
defer func() {
utils.DockerCleanup(node2, "myContainer4")
utils.DockerCleanup(t, node2, "myContainer4")
}()
}

0 comments on commit 3af1f04

Please sign in to comment.