Ejemplo n.º 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
}
Ejemplo n.º 2
0
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

}
Ejemplo n.º 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
}
Ejemplo n.º 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
}
Ejemplo n.º 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
}
Ejemplo n.º 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
}
Ejemplo n.º 7
0
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
}