Пример #1
0
func GetPool(name string) (cfg.Pool, error) {
	if name == "" {
		return cfg.Pool{}, errors.New("Please specify a name")
	}

	return routerzk.GetPool(zkConn.Conn, name)
}
Пример #2
0
func (e *GetPoolExecutor) Execute(t *Task) (err error) {
	if e.arg.Name == "" {
		return errors.New("Please specify a name")
	}
	helper.SetRouterRoot(e.arg.Internal)
	e.reply.Pool, err = routerzk.GetPool(datamodel.Zk.Conn, e.arg.Name)
	if err != nil {
		e.reply.Status = StatusError
	} else {
		e.reply.Status = StatusOk
	}
	return err
}
Пример #3
0
func ParsePool(name string) (Pool, error) {
	var res Pool
	data, err := zk.GetPool(Zk, name)
	if err != nil {
		return res, err
	}
	numHosts := len(data.Hosts)
	hosts := make([]string, numHosts)
	count := 0
	for _, v := range data.Hosts {
		hosts[count] = v.Address
		count++
	}
	return Pool{data.Config.HealthzEvery, "N/A", "N/A",
		data.Config.HealthzTimeout, data.Config.RequestTimeout, hosts}, nil

}
Пример #4
0
func (s *DatamodelSuite) TestRouterExternalPool(c *C) {
	Zk.RecursiveDelete("/atlantis/router")
	Zk.RecursiveDelete("/atlantis/apps")
	Zk.RecursiveDelete(helper.GetBaseInstancePath())
	CreateRouterPaths()
	CreateAppPath()
	// fake register app
	CreateOrUpdateApp(false, false, app, "ssh://[email protected]/app", "/", "*****@*****.**")
	CreateOrUpdateApp(false, false, "app2", "ssh://[email protected]/app", "/", "*****@*****.**")
	// do tests
	instance, err := CreateInstance(app, sha, env, host+"-1")
	c.Assert(err, IsNil)
	instance.SetPort(uint16(1337))
	instance2, err := CreateInstance(app, sha, env, host+"-2")
	c.Assert(err, IsNil)
	instance2.SetPort(uint16(1338))
	c.Assert(AddToPool([]string{instance.ID, instance2.ID}), IsNil)
	theName := helper.CreatePoolName(app, sha, env)
	helper.SetRouterRoot(false)
	thePool, err := routerzk.GetPool(Zk.Conn, theName)
	c.Assert(err, IsNil)
	c.Assert(thePool.Name, Equals, theName)
	c.Assert(thePool.Config.HealthzEvery, Not(Equals), "")
	c.Assert(thePool.Config.HealthzTimeout, Not(Equals), "")
	c.Assert(thePool.Config.RequestTimeout, Not(Equals), "")
	c.Assert(thePool.Hosts, DeepEquals, map[string]config.Host{host + "-1:1337": config.Host{Address: host + "-1:1337"}, host + "-2:1338": config.Host{Address: host + "-2:1338"}})
	newInstance, err := CreateInstance("app2", "sha1", "env1", host+"-1")
	c.Assert(err, IsNil)
	newInstance.SetPort(uint16(1339))
	newInstance2, err := CreateInstance(app, sha, env, host+"-3")
	c.Assert(err, IsNil)
	newInstance2.SetPort(uint16(1340))
	c.Assert(DeleteFromPool([]string{instance2.ID}), IsNil)
	instance2.Delete()
	c.Assert(AddToPool([]string{newInstance.ID, newInstance2.ID}), IsNil)
	helper.SetRouterRoot(false)
	thePool, err = routerzk.GetPool(Zk.Conn, theName)
	c.Assert(err, IsNil)
	c.Assert(thePool.Name, Equals, theName)
	c.Assert(thePool.Config.HealthzEvery, Not(Equals), "")
	c.Assert(thePool.Config.HealthzTimeout, Not(Equals), "")
	c.Assert(thePool.Config.RequestTimeout, Not(Equals), "")
	c.Assert(thePool.Hosts, DeepEquals, map[string]config.Host{host + "-1:1337": config.Host{Address: host + "-1:1337"}, host + "-3:1340": config.Host{Address: host + "-3:1340"}})
	helper.SetRouterRoot(false)
	thePool2, err := routerzk.GetPool(Zk.Conn, helper.CreatePoolName("app2", "sha1", "env1"))
	c.Assert(err, IsNil)
	c.Assert(thePool2.Name, Equals, helper.CreatePoolName("app2", "sha1", "env1"))
	c.Assert(thePool2.Config.HealthzEvery, Not(Equals), "")
	c.Assert(thePool2.Config.HealthzTimeout, Not(Equals), "")
	c.Assert(thePool2.Config.RequestTimeout, Not(Equals), "")
	c.Assert(thePool2.Hosts, DeepEquals, map[string]config.Host{host + "-1:1339": config.Host{Address: host + "-1:1339"}})
	helper.SetRouterRoot(false)
	pools, err := routerzk.ListPools(Zk.Conn)
	c.Assert(err, IsNil)
	sort.Strings(pools)
	c.Assert(pools, DeepEquals, []string{thePool2.Name, thePool.Name})
	c.Assert(DeleteFromPool([]string{instance.ID, newInstance.ID, newInstance2.ID}), IsNil)
	instance.Delete()
	newInstance.Delete()
	newInstance2.Delete()
	helper.SetRouterRoot(false)
	thePool, err = routerzk.GetPool(Zk.Conn, theName)
	c.Assert(err, Not(IsNil))
}