示例#1
0
func ListAllInstances() (instances []string, err error) {
	instances, _, err = Zk.VisibleChildren(helper.GetBaseInstanceDataPath())
	if err != nil {
		log.Printf("Error getting list of all instances. Error: %s.", err.Error())
	}
	if instances == nil {
		log.Println("No instances found. Returning empty list.")
		instances = []string{}
	}
	return
}
示例#2
0
func GetInstance(id string) (zi *ZkInstance, err error) {
	zi = &ZkInstance{}
	err = getJson(helper.GetBaseInstanceDataPath(id), zi)
	if err != nil {
		/* NOTE(edanaher): The default error message here is typically from zookeeper, which is not very user
		 * friendly.  And at Ooyala, we've had a number of users run into this because they're looking at the wrong
		 * region.  So as long as that is the dominant source of this error, it makes sense to suggest this as the
		 * cause, much like compilers will attempt to guess at missing semicolons. */
		err = errors.New(err.Error() + "\nContainer " + id + " not found; is this the right region?")
	}
	return
}
示例#3
0
func CreateInstancePaths() {
	Zk.Touch(helper.GetBaseInstancePath())
	Zk.Touch(helper.GetBaseInstanceDataPath())
}
示例#4
0
func InstanceExists(id string) bool {
	if stat, err := Zk.Exists(helper.GetBaseInstanceDataPath(id)); err == nil && stat != nil {
		return true
	}
	return false
}
示例#5
0
func (zi *ZkInstance) dataPath() string {
	return helper.GetBaseInstanceDataPath(zi.ID)
}