Ejemplo n.º 1
0
func GetManager(region, value string) (zm *ZkManager, err error) {
	zm = &ZkManager{}
	err = getJson(helper.GetBaseManagerPath(region, value), zm)
	if err == nil && zm.Roles == nil {
		err = zm.Save()
	}
	return
}
Ejemplo n.º 2
0
func (s *DatamodelSuite) TestManagerTouchAndDelete(c *C) {
	Zk.RecursiveDelete(helper.GetBaseManagerPath())
	CreateManagerPath()
	opt := Manager("dev", "2.1.1.1")
	err := opt.Delete()
	c.Assert(err, Not(IsNil))
	c.Assert(opt.Save(), IsNil)
	err = opt.Delete()
	c.Assert(err, IsNil)
}
Ejemplo n.º 3
0
func ListManagersInRegion(region string) (managers []string, err error) {
	basePath := helper.GetBaseManagerPath(region)
	managers, _, err = Zk.Children(basePath)
	if err != nil {
		log.Printf("Error getting list of managers for region %s. Error: %s.", region, err.Error())
	}
	if managers == nil {
		log.Printf("No managers found in region %s", region)
		managers = []string{}
	}
	return
}
Ejemplo n.º 4
0
func ListRegions() (regions []string, err error) {
	basePath := helper.GetBaseManagerPath()
	regions, _, err = Zk.Children(basePath)
	if err != nil {
		log.Printf("Error getting list of regions. Error: %s.", err.Error())
	}
	if regions == nil {
		log.Println("No regions found. Returning empty list.")
		regions = []string{}
	}
	return
}
Ejemplo n.º 5
0
// Delete the manager node and all children (don't realy need DelDir here but there isn't much overhead)
func (m *ZkManager) Delete() error {
	if err := Zk.RecursiveDelete(m.path()); err != nil {
		return err
	}
	managers, err := ListManagersInRegion(m.Region)
	if err == nil && managers != nil && len(managers) == 0 {
		Zk.RecursiveDelete(helper.GetBaseManagerPath(m.Region))
	} else if err != nil {
		log.Printf("Warning: clean up fail during managers delete: %s", err)
		// this is extra, no need to return the error if we couldn't get them
	}
	return nil
}
Ejemplo n.º 6
0
func (s *DatamodelSuite) TestManagerRoles(c *C) {
	Zk.RecursiveDelete(helper.GetBaseManagerPath())
	CreateManagerPath()
	opt := Manager("dev", "2.1.1.1")
	c.Assert(opt.Save(), IsNil)
	c.Assert(opt.HasRole("deploy", "write"), Equals, false)
	c.Assert(opt.HasRole("permissions", "read"), Equals, false)
	c.Assert(opt.HasRole("permissions", "write"), Equals, false)
	ok, err := ManagerHasRole("dev", "2.1.1.1", "permissions", "write")
	c.Assert(err, IsNil)
	c.Assert(ok, Equals, false)

	c.Assert(opt.AddRole("deploy", "write"), IsNil)
	c.Assert(opt.HasRole("deploy", "write"), Equals, true)
	c.Assert(opt.HasRole("permissions", "read"), Equals, false)
	c.Assert(opt.HasRole("permissions", "write"), Equals, false)

	c.Assert(opt.AddRole("permissions", "read"), IsNil)
	c.Assert(opt.HasRole("deploy", "write"), Equals, true)
	c.Assert(opt.HasRole("permissions", "read"), Equals, true)
	c.Assert(opt.HasRole("permissions", "write"), Equals, false)

	c.Assert(opt.AddRole("permissions", "write"), IsNil)
	c.Assert(opt.HasRole("deploy", "write"), Equals, true)
	c.Assert(opt.HasRole("permissions", "read"), Equals, true)
	c.Assert(opt.HasRole("permissions", "write"), Equals, true)
	ok, err = ManagerHasRole("dev", "2.1.1.1", "permissions", "write")
	c.Assert(err, IsNil)
	c.Assert(ok, Equals, true)

	c.Assert(opt.RemoveRole("deploy", "write"), IsNil)
	c.Assert(opt.HasRole("deploy", "write"), Equals, false)
	c.Assert(opt.HasRole("permissions", "read"), Equals, true)
	c.Assert(opt.HasRole("permissions", "write"), Equals, true)

	c.Assert(opt.RemoveRole("permissions", "write"), IsNil)
	c.Assert(opt.HasRole("deploy", "write"), Equals, false)
	c.Assert(opt.HasRole("permissions", "read"), Equals, true)
	c.Assert(opt.HasRole("permissions", "write"), Equals, false)

	c.Assert(opt.RemoveRole("permissions", "read"), IsNil)
	c.Assert(opt.HasRole("deploy", "write"), Equals, false)
	c.Assert(opt.HasRole("permissions", "read"), Equals, false)
	c.Assert(opt.HasRole("permissions", "write"), Equals, false)
	c.Assert(opt.Delete(), IsNil)
}
Ejemplo n.º 7
0
func (s *DatamodelSuite) TestManagerListers(c *C) {
	Zk.RecursiveDelete(helper.GetBaseManagerPath())
	CreateManagerPath()
	regions, err := ListRegions()
	c.Assert(err, IsNil)
	c.Assert(regions, DeepEquals, []string{})
	regionManagers, err := ListManagersInRegion("dev")
	c.Assert(err, Not(IsNil))
	c.Assert(regionManagers, DeepEquals, []string{})
	managers, err := ListManagers()
	c.Assert(err, IsNil)
	c.Assert(managers, DeepEquals, map[string][]string{})
	devOpt := Manager("dev", "2.1.1.1")
	c.Assert(devOpt.Save(), IsNil)
	devOtherOpt := Manager("dev", "2.1.1.2")
	c.Assert(devOtherOpt.Save(), IsNil)
	omgOpt := Manager("omg", "2.1.1.3")
	c.Assert(omgOpt.Save(), IsNil)
	bbqOpt := Manager("bbq", "2.1.1.4")
	c.Assert(bbqOpt.Save(), IsNil)
	regions, err = ListRegions()
	c.Assert(err, IsNil)
	sort.Strings(regions)
	c.Assert(regions, DeepEquals, []string{"bbq", "dev", "omg"})
	devManagers, err := ListManagersInRegion("dev")
	c.Assert(err, IsNil)
	sort.Strings(devManagers)
	c.Assert(devManagers, DeepEquals, []string{"2.1.1.1", "2.1.1.2"})
	managers, err = ListManagers()
	c.Assert(err, IsNil)
	for _, regionManagers := range managers {
		sort.Strings(regionManagers)
	}
	c.Assert(managers, DeepEquals, map[string][]string{"bbq": []string{"2.1.1.4"},
		"dev": []string{"2.1.1.1", "2.1.1.2"}, "omg": []string{"2.1.1.3"}})
}
Ejemplo n.º 8
0
func (s *DatamodelSuite) TestManagerPath(c *C) {
	Zk.RecursiveDelete(helper.GetBaseManagerPath())
	CreateManagerPath()
	opt := Manager("dev", "2.1.1.1")
	c.Assert(opt.path(), Equals, helper.GetBaseManagerPath("dev", "2.1.1.1"))
}
Ejemplo n.º 9
0
func CreateManagerPath() {
	Zk.Touch(helper.GetBaseManagerPath())
}
Ejemplo n.º 10
0
func (m *ZkManager) path() string {
	return helper.GetBaseManagerPath(m.Region, m.Host)
}