예제 #1
0
파일: discovery.go 프로젝트: elleFlorio/gru
func keepAlive(name string, id string) {
	var err error
	discoveryConf := cfg.GetAgentDiscovery()
	ticker := time.NewTicker(time.Duration(discoveryConf.TTL-1) * time.Second)
	opt := discovery.Options{
		"TTL": time.Duration(discoveryConf.TTL) * time.Second,
	}

	ch_stop := ch.CreateInstanceChannel(id)

	isntanceKey := discoveryConf.AppRoot + "/" + name + "/" + id
	instanceValue := addressMap[id]

	for {
		select {
		case <-ticker.C:
			err = discovery.Set(isntanceKey, instanceValue, opt)
			if err != nil {
				log.WithFields(log.Fields{
					"service":  name,
					"instance": id,
					"address":  instanceValue,
					"err":      err,
				}).Errorln("Error keeping instance alive")
			}
		case <-ch_stop:
			log.Debugln("Stopping keep alive routine")
			return
		}
	}
}
예제 #2
0
파일: cluster.go 프로젝트: elleFlorio/gru
func RegisterCluster(name string, id string) {
	var err error
	err = discovery.Register(c_GRU_REMOTE+name+"/uuid", id)
	if err != nil {
		log.Errorln("Error registering cluster")
	}
	log.Debugln("Created cluster forder: ", name)

	opt := discovery.Options{"Dir": true}
	err = discovery.Set(c_GRU_REMOTE+name+"/"+c_NODES_REMOTE, "", opt)
	if err != nil {
		log.Errorln("Error creating nodes folder")
	}
	log.Debugln("Created nodes folder")

	err = discovery.Set(c_GRU_REMOTE+name+"/"+c_SERVICES_REMOTE, "", opt)
	if err != nil {
		log.Errorln("Error creating services folder")
	}
	log.Debugln("Created services folder")

	err = discovery.Set(c_GRU_REMOTE+name+"/"+c_CONFIG_REMOTE, "empty", discovery.Options{})
	if err != nil {
		log.Errorln("Error creating config key")
	}
	log.Debugln("Created config key")

	err = discovery.Set(c_GRU_REMOTE+name+"/"+c_POLICY_REMOTE, "empty", discovery.Options{})
	if err != nil {
		log.Errorln("Error creating policy key")
	}
	log.Debugln("Created policy key")

	err = discovery.Set(c_GRU_REMOTE+name+"/"+c_ANALYTIC_REMOTE, "", opt)
	if err != nil {
		log.Errorln("Error creating analytics folder")
	}
	log.Debugln("Created analytics folder")
}
예제 #3
0
func writeData(remote string, src interface{}) error {
	var err error
	data, err := json.Marshal(src)
	if err != nil {
		return err
	}

	err = discovery.Set(remote, string(data), discovery.Options{})
	if err != nil {
		return err
	}

	return nil
}
예제 #4
0
func WriteNodeActive(remote string, active bool) {
	activePath := remote + "/active"
	var value string
	if active {
		value = "true"
	} else {
		value = "false"
	}
	err := discovery.Set(activePath, value, discovery.Options{})
	if err != nil {
		log.WithField("err", err).Errorln("Error writing node active")
	}

}
예제 #5
0
파일: cluster.go 프로젝트: elleFlorio/gru
func updateNodeFolder(ttl int) error {
	opt := discovery.Options{
		"TTL":       time.Second * time.Duration(ttl),
		"Dir":       true,
		"PrevExist": true,
	}
	remote := cfg.GetNodeConfig().Remote
	err := discovery.Set(remote, "", opt)
	cfg.WriteNodeConfig(remote, cfg.GetNode().Configuration)
	cfg.WriteNodeConstraints(remote, cfg.GetNode().Constraints)
	cfg.WriteNodeResources(remote, cfg.GetNode().Resources)
	cfg.WriteNodeActive(remote, cfg.GetNode().Active)
	if err != nil {
		log.WithField("err", err).Errorln("Error updating node folder")
		return err
	}

	return nil
}
예제 #6
0
파일: discovery.go 프로젝트: elleFlorio/gru
func RegisterServiceInstanceId(name string, id string) {
	var err error
	discoveryConf := cfg.GetAgentDiscovery()
	opt := discovery.Options{
		"TTL": time.Duration(discoveryConf.TTL) * time.Second,
	}

	isntanceKey := discoveryConf.AppRoot + "/" + name + "/" + id
	instanceValue := addressMap[id]

	err = discovery.Set(isntanceKey, instanceValue, opt)
	if err != nil {
		log.WithFields(log.Fields{
			"service":  name,
			"instance": id,
			"address":  instanceValue,
			"err":      err,
		}).Errorln("Error registering service instance to discovery service")
	}
}
예제 #7
0
파일: cluster.go 프로젝트: elleFlorio/gru
func createNodeFolder() error {
	var err error
	opt := discovery.Options{
		"TTL": time.Second * time.Duration(c_TTL+1),
		"Dir": true,
	}

	config := cfg.GetNodeConfig()
	config.Cluster = myCluster.Name
	remote := c_GRU_REMOTE + myCluster.Name + "/" + c_NODES_REMOTE + config.Name
	config.Remote = remote

	err = discovery.Set(remote, "", opt)
	cfg.WriteNodeConfig(remote, cfg.GetNode().Configuration)
	cfg.WriteNodeConstraints(remote, cfg.GetNode().Constraints)
	cfg.WriteNodeResources(remote, cfg.GetNode().Resources)
	cfg.WriteNodeActive(remote, cfg.GetNode().Active)
	if err != nil {
		log.WithField("err", err).Errorln("Error creating node folder")
		return err
	}

	return nil
}