Esempio n. 1
0
func keepAlive(ttl int) {
	ticker := time.NewTicker(time.Second * time.Duration(ttl))
	for {
		select {
		case <-ticker.C:
			err := updateNodeFolder(ttl + 1)
			if err != nil {
				log.Errorln("Error keeping the node alive")
			}
		}
	}
}
Esempio n. 2
0
func (db *influxdb) StoreMetrics(metrics GruMetric) error {
	points, err := createInfluxMetrics(metrics)
	if err != nil {
		log.Errorln("Error storing Influx metrics")
		return err
	}

	for _, point := range points {
		db.batch.AddPoint(point)
	}

	return db.influx.Write(db.batch)
}
Esempio n. 3
0
func clearFriendsData() error {
	allData, err := storage.GetAllData(enum.SHARED)
	if err != nil {
		log.Errorln("Error cleaning up friends data")
		return err
	}

	for key, _ := range allData {
		if key != enum.CLUSTER.ToString() && key != enum.LOCAL.ToString() {
			log.WithField("friend", key).Debugln("cleared friend data")
			storage.DeleteData(key, enum.SHARED)
		}
	}

	return nil
}
Esempio n. 4
0
func executeCommand(cmd Command) {
	switch cmd.Name {
	case "start":
		startCommand(cmd)
	case "stop":
		stopCommand(cmd)
	case "update":
		updateCommand(cmd)
	default:
		log.Errorln("Unrecognized command name: ", cmd.Name)
	}

	log.WithFields(log.Fields{
		"cmd":    cmd.Name,
		"target": cmd.Target,
	}).Debugln("Executed command")
}
Esempio n. 5
0
func createPortBindings(name string) map[string][]dockerclient.PortBinding {
	portBindings_dckr := make(map[string][]dockerclient.PortBinding)

	assigned, err := res.RequestPortsForService(name)
	if err != nil {
		log.Errorln("Error creating port bindings")
		return portBindings_dckr
	}
	for guest, host := range assigned {
		portTcp := guest + "/tcp"
		pBindings := []dockerclient.PortBinding{}
		pBinding := dockerclient.PortBinding{
			HostIp:   "0.0.0.0",
			HostPort: host,
		}
		pBindings = append(pBindings, pBinding)
		portBindings_dckr[portTcp] = pBindings
	}

	return portBindings_dckr
}
Esempio n. 6
0
func FreeInstanceCores(id string) {
	defer runtime.Gosched()
	if cores, ok := instanceCores[id]; ok {
		toFree, _ := getCoresNumber(cores)
		mutex_cpu.Lock()
		for _, core := range toFree {
			resources.CPU.Cores[core] = true
		}
		mutex_cpu.Unlock()

		mutex_instance.Lock()
		delete(instanceCores, id)
		mutex_instance.Unlock()

		log.WithFields(log.Fields{
			"id":    id,
			"cores": cores,
		}).Debugln("Released cores of instance")

	} else {
		log.Errorln("Error freeing cores: unrecognized instance ", id)
	}

}
Esempio n. 7
0
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")
}