func (s *DeployHelperSuite) TestResolveDepValues(c *C) {
	datamodel.Zk.RecursiveDelete(helper.GetBaseEnvPath())
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPath(true))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPath(false))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPortsPath(true))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPortsPath(false))
	datamodel.CreateEnvPath()
	datamodel.CreateRouterPaths()
	datamodel.Router(true, "dev", "somehost", "1.2.3.4").Save()
	zkEnv := datamodel.Env("root")
	err := zkEnv.Save()
	c.Assert(err, IsNil)
	deps, err := ResolveDepValues("app", zkEnv, []string{"hello-go"}, false, &Task{})
	c.Assert(err, Not(IsNil))
	_, err = datamodel.CreateInstance("hello-go", "1234567890", "root", "myhost")
	c.Assert(err, IsNil)
	_, err = datamodel.CreateOrUpdateApp(false, false, "app", "ssh://github.com/ooyala/apo", "/", "*****@*****.**")
	c.Assert(err, IsNil)
	zkApp, err := datamodel.CreateOrUpdateApp(false, true, "hello-go", "ssh://github.com/ooyala/hello-go", "/", "*****@*****.**")
	c.Assert(err, IsNil)
	c.Assert(zkApp.AddDependerAppData(&DependerAppData{Name: "app", DependerEnvData: map[string]*DependerEnvData{"root": &DependerEnvData{Name: "root"}}}), IsNil)
	deps, err = ResolveDepValues("app", zkEnv, []string{"hello-go"}, false, &Task{})
	c.Assert(err, IsNil)
	c.Assert(deps["dev1"]["hello-go"].DataMap["address"], Equals, fmt.Sprintf("internal-router.1.%s.suffix.com:%d", Region, datamodel.MinRouterPort))
	deps, err = ResolveDepValues("app", zkEnv, []string{"hello-go"}, true, &Task{})
	c.Assert(err, IsNil)
	c.Assert(deps["dev1"]["hello-go"].EncryptedData, Not(Equals), "")
	c.Assert(deps["dev1"]["hello-go"].DataMap, IsNil)
	scrypto.DecryptAppDep(deps["dev1"]["hello-go"])
	c.Assert(deps["dev1"]["hello-go"].DataMap, Not(IsNil))
	c.Assert(deps["dev1"]["hello-go"].DataMap["address"], Equals, fmt.Sprintf("internal-router.1.%s.suffix.com:%d", Region, datamodel.MinRouterPort))
}
示例#2
0
func (s *DatamodelSuite) TestRouterModel(c *C) {
	Zk.RecursiveDelete(helper.GetBaseRouterPath(true))
	Zk.RecursiveDelete(helper.GetBaseRouterPath(false))
	CreateRouterPaths()
	routers, err := ListRouters(true)
	c.Assert(err, IsNil)
	for _, routersInZone := range routers {
		c.Assert(len(routersInZone), Equals, 0)
	}
	zkRouter := Router(true, Region, "host", "2.2.2.2")
	err = zkRouter.Save()
	c.Assert(err, IsNil)
	fetchedRouter, err := GetRouter(true, Region, "host")
	c.Assert(err, IsNil)
	c.Assert(zkRouter, DeepEquals, fetchedRouter)
	zkRouter.CName = "mycname"
	zkRouter.RecordIDs = []string{"rid1", "rid2"}
	zkRouter.Save()
	fetchedRouter, err = GetRouter(true, Region, "host")
	c.Assert(err, IsNil)
	c.Assert(zkRouter, DeepEquals, fetchedRouter)
	routers, err = ListRouters(true)
	c.Assert(len(routers[Region]), Equals, 1)
	err = zkRouter.Delete()
	c.Assert(err, IsNil)
	routers, err = ListRouters(true)
	c.Assert(len(routers[Region]), Equals, 0)
}
示例#3
0
func CreateRouterPaths() {
	helper.SetRouterRoot(true)
	for _, path := range routerzk.ZkPaths {
		Zk.Touch(path)
	}
	helper.SetRouterRoot(false)
	for _, path := range routerzk.ZkPaths {
		Zk.Touch(path)
	}
	for _, zone := range AvailableZones {
		Zk.Touch(helper.GetBaseRouterPath(true, zone))
		Zk.Touch(helper.GetBaseRouterPath(false, zone))
	}
}
示例#4
0
func ListRoutersInZone(internal bool, zone string) (routers []string, err error) {
	basePath := helper.GetBaseRouterPath(internal, zone)
	routers, _, err = Zk.Children(basePath)
	if err != nil {
		log.Printf("Error getting list of routers for zone %s. Error: %s.", zone, err.Error())
	}
	if routers == nil {
		log.Printf("No routers found in zone %s", zone)
		routers = []string{}
	}
	return
}
示例#5
0
func ListRouterZones(internal bool) (zones []string, err error) {
	basePath := helper.GetBaseRouterPath(internal)
	zones, _, err = Zk.Children(basePath)
	if err != nil {
		log.Printf("Error getting list of zones. Error: %s.", err.Error())
	}
	if zones == nil {
		log.Println("No zones found. Returning empty list.")
		zones = []string{}
	}
	return
}
示例#6
0
func ListRouterIPsInZone(internal bool, zone string) (ips []string, err error) {
	basePath := helper.GetBaseRouterPath(internal, zone)
	routers, _, err := Zk.Children(basePath)
	if err != nil {
		log.Printf("Error getting list of routers for zone %s. Error: %s.", zone, err.Error())
		return []string{}, err
	}
	if routers == nil {
		log.Printf("No routers found in zone %s", zone)
		return []string{}, err
	}
	ips = make([]string, len(routers))
	for i, routerName := range routers {
		router, err := GetRouter(internal, zone, routerName)
		if err != nil {
			return []string{}, err
		}
		ips[i] = router.IP
	}
	return
}
示例#7
0
func (r *ZkRouter) path() string {
	return helper.GetBaseRouterPath(r.Internal, r.Zone, r.Host)
}
示例#8
0
func GetRouter(internal bool, zone, value string) (zr *ZkRouter, err error) {
	zr = &ZkRouter{}
	err = getJson(helper.GetBaseRouterPath(internal, zone, value), zr)
	return
}