Ejemplo n.º 1
0
func updateCommand(cmd Command) {
	log.Debugln("Updating ", cmd.Target)
	switch cmd.Target {
	case "all":
		cluster := cmd.Object.(string)
		updateAll(cluster)
	case "agent":
		cluster := cmd.Object.(string)
		updateAgent(cluster)
	case "services":
		cluster := cmd.Object.(string)
		updateServices(cluster)
	case "policy":
		cluster := cmd.Object.(string)
		updatePolicy(cluster)
	case "node-base-services":
		data := cmd.Object.([]interface{})
		upd := []string{}
		for _, item := range data {
			upd = append(upd, item.(string))
		}
		constraints := cfg.GetNodeConstraints()
		constraints.BaseServices = upd
		cfg.WriteNodeConstraints(cfg.GetNodeConfig().Remote, *constraints)
	case "node-cpumin":
		upd := cmd.Object.(float64)
		constraints := cfg.GetNodeConstraints()
		constraints.CpuMin = upd
		cfg.WriteNodeConstraints(cfg.GetNodeConfig().Remote, *constraints)
	case "node-cpumax":
		upd := cmd.Object.(float64)
		constraints := cfg.GetNodeConstraints()
		constraints.CpuMax = upd
		cfg.WriteNodeConstraints(cfg.GetNodeConfig().Remote, *constraints)
	case "service-constraints":
		name := cmd.Object.(string)
		srv, _ := service.GetServiceByName(name)
		upd := cfg.ReadService(srv.Remote)
		srv.Constraints = upd.Constraints
	default:
		log.WithField("target", cmd.Target).Errorln("Unrecognized target for command update")
	}
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
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
}