コード例 #1
0
ファイル: com-manager.go プロジェクト: elleFlorio/gru
func getAllPeers() map[string]string {
	myCluster, err := cluster.GetMyCluster()
	if err != nil {
		log.WithField("err", err).Errorln("Error getting my cluster")
		return map[string]string{}
	}
	peers := cluster.ListNodes(myCluster.Name, true)
	delete(peers, cfg.GetNodeConfig().Name)
	return peers
}
コード例 #2
0
ファイル: handlers-commands.go プロジェクト: elleFlorio/gru
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")
	}
}
コード例 #3
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
}
コード例 #4
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
}
コード例 #5
0
ファイル: handlers-commands.go プロジェクト: elleFlorio/gru
func deactivateNode() {
	log.Debugln("Deactivating node")
	cfg.ToggleActiveNode()
	cfg.WriteNodeActive(cfg.GetNodeConfig().Remote, false)
}
コード例 #6
0
ファイル: handlers-commands.go プロジェクト: elleFlorio/gru
func activateNode() {
	log.Debugln("Activating node")
	cfg.ToggleActiveNode()
	cfg.WriteNodeActive(cfg.GetNodeConfig().Remote, true)
}
コード例 #7
0
ファイル: metric-manager.go プロジェクト: elleFlorio/gru
func updateMetrics() {
	var err error
	metrics = newMetrics()
	metrics.Node.UUID = cfg.GetNodeConfig().UUID
	metrics.Node.Name = cfg.GetNodeConfig().Name
	metrics.Node.Resources.CPU.Total = res.GetResources().CPU.Total
	metrics.Node.Resources.CPU.Availabe = res.GetResources().CPU.Total - res.GetResources().CPU.Used
	localShared, err := data.GetSharedLocal()
	if err != nil {
		log.WithField("err", err).Warnln("Cannot update node active metric")
	} else {
		metrics.Node.ActiveServices = len(localShared.System.ActiveServices)
	}

	for _, name := range service.List() {
		srv, _ := service.GetServiceByName(name)
		srv_metrics := metrics.Service[name]
		srv_metrics.Name = name
		srv_metrics.Image = srv.Image
		srv_metrics.Type = srv.Type

		srv_metrics.Instances.All = len(srv.Instances.All)
		srv_metrics.Instances.Pending = len(srv.Instances.Pending)
		srv_metrics.Instances.Running = len(srv.Instances.Running)
		srv_metrics.Instances.Paused = len(srv.Instances.Paused)
		srv_metrics.Instances.Stopped = len(srv.Instances.Stopped)

		stats, err := data.GetStats()
		if err != nil {
			log.WithFields(log.Fields{
				"err":     err,
				"service": name,
			}).Warnln("Cannot update stats metrics")
		} else {
			if srv_stats, ok := stats.Metrics.Service[name]; ok {
				srv_metrics.Stats = srv_stats
			} else {
				log.Warnln("Cannot find stats metrics for service ", name)
			}

			metrics.Node.Stats = stats.Metrics.System
		}

		analytics, err := data.GetAnalytics()
		if err != nil {
			log.WithFields(log.Fields{
				"err":     err,
				"service": name,
			}).Warnln("Cannot update analytics metrics")
		} else {
			if srv_analytisc, ok := analytics.Service[name]; ok {
				srv_metrics.Analytics = srv_analytisc
			} else {
				log.Debugln("Cannot find analytics metrics for service ", name)
			}
		}

		shared, err := data.GetSharedCluster()
		if err != nil {
			log.WithFields(log.Fields{
				"err":     err,
				"service": name,
			}).Warnln("Cannot update shared data metrics")
		} else {
			if srv_shared, ok := shared.Service[name]; ok {
				srv_metrics.Shared = srv_shared.Data
			}
		}

		metrics.Service[name] = srv_metrics
	}

	plc, err := data.GetPolicy()
	if err != nil {
		log.WithField("err", err).Warnln("Cannot update plans metrics")
	} else {
		metrics.Policy.Name = plc.Name
		metrics.Policy.Weight = plc.Weight
	}

}