func (e *ListPoolsExecutor) Execute(t *Task) (err error) { helper.SetRouterRoot(e.arg.Internal) e.reply.Pools, err = routerzk.ListPools(datamodel.Zk.Conn) if err != nil { e.reply.Status = StatusError } else { sort.Strings(e.reply.Pools) e.reply.Status = StatusOk } return err }
func ListPools() ([]string, error) { return routerzk.ListPools(zkConn.Conn) }
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)) }