示例#1
0
func readData(remote string, dest interface{}) error {
	var err error
	resp, err := discovery.Get(remote, discovery.Options{})
	if err != nil {
		return err
	}
	data := resp[remote]
	err = json.Unmarshal([]byte(data), dest)
	if err != nil {
		return err
	}

	return nil
}
示例#2
0
文件: cluster.go 项目: elleFlorio/gru
func ListClusters() map[string]string {
	resp, err := discovery.Get(c_GRU_REMOTE, discovery.Options{})
	if err != nil {
		log.WithField("err", err).Errorln("Error listing clusters")
		return map[string]string{}
	}
	clusters := []string{}
	for k, _ := range resp {
		tokens := strings.Split(k, "/")
		clusters = append(clusters, tokens[2])
	}

	clustersUuid := make(map[string]string, len(clusters))
	for _, name := range clusters {
		resp, err := discovery.Get(c_GRU_REMOTE+name+"/uuid", discovery.Options{})
		if err != nil {
			log.Error("Error getting UUID of cluster ", name)
		}
		clustersUuid[name] = resp[c_GRU_REMOTE+name+"/uuid"]
	}

	return clustersUuid

}
示例#3
0
func ReadAnalytics(remote string) map[string]AnalyticExpr {
	expressions := make(map[string]AnalyticExpr)
	resp, err := discovery.Get(remote, discovery.Options{})
	if err != nil {
		log.WithField("err", err).Errorln("Error reading analytics from ", remote)
		return expressions
	}

	for exprPath, _ := range resp {
		expr := ReadAnalytic(exprPath)
		expressions[expr.Name] = expr
	}

	return expressions
}
示例#4
0
func ReadServices(remote string) []Service {
	resp, err := discovery.Get(remote, discovery.Options{})
	if err != nil {
		log.WithField("err", err).Errorln("Error reading services from ", remote)
		return []Service{}
	}

	services := []Service{}
	for servicePath, _ := range resp {
		srv := ReadService(servicePath)
		services = append(services, srv)
	}

	return services
}
示例#5
0
func ReadNodeActive(remote string) bool {
	activePath := remote + "/active"
	resp, err := discovery.Get(activePath, discovery.Options{})
	if err != nil {
		log.WithField("err", err).Errorln("Error reading node active")
		return false
	}
	active, err := strconv.ParseBool(resp[activePath])
	if err != nil {
		log.WithField("err", err).Errorln("Error parsing node active")
		return false
	}

	return active
}
示例#6
0
func ReadNodes(remote string) []Node {
	log.WithField("remote", remote).Debugln("Reading nodes from remote")
	resp, err := discovery.Get(remote, discovery.Options{})
	if err != nil {
		log.WithField("err", err).Errorln("Error reading nodes from ", remote)
		return []Node{}
	}

	nodes := []Node{}
	for nodePath, _ := range resp {
		n := ReadNode(nodePath)
		nodes = append(nodes, n)
	}

	return nodes
}
示例#7
0
文件: cluster.go 项目: elleFlorio/gru
func JoinCluster(name string) error {
	key := c_GRU_REMOTE + name + "/uuid"
	data, err := discovery.Get(key, discovery.Options{})
	if err != nil {
		log.WithField("err", err).Errorln("Error getting cluster uuid")
		return err
	}

	if id, ok := data[key]; ok {
		initMyCluster(name, id, c_GRU_REMOTE+name)

		err := createNodeFolder()
		if err != nil {
			return err
		}

		go keepAlive(c_TTL)

	} else {
		return ErrNoClusterId
	}

	return nil
}