summaryrefslogtreecommitdiff
path: root/event.go
blob: 61de3c926186d00a8046222a875dd96718f589bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main

import (
	"fmt"
	"time"

	"go.wit.com/lib/gui/shell"
	"go.wit.com/lib/protobuf/virtpb"
	"go.wit.com/log"
)

// restarts the virtigod daemon on a hypervisor via http
func (h *HyperT) RestartVirtigod() {
	url := "http://" + h.pb.Hostname + ":2520/kill"
	s := shell.Wget(url)
	log.Info("EVENT RestartVirtigod", url, s)
	h.lastpoll = time.Now()
	h.killcount += 1

	dur := time.Since(h.lastpoll) // Calculate the elapsed time
	log.Info("KILLED DAEMON", h.pb.Hostname, shell.FormatDuration(dur), "curl", url)
	me.killcount += 1

	// mark the cluster as unstable so droplet starts can be throttled
	me.unstable = time.Now()
}

// this must be bool in string because accumulated output is sometimes
// written to STDOUT, sometimes to http
func (h *HyperT) start(d *virtpb.Droplet) (bool, string) {
	ready, result := me.cluster.DropletReady(d)
	if !ready {
		return false, result
	}

	url := "http://" + h.pb.Hostname + ":2520/start?start=" + d.Hostname
	var msg string
	var data []byte
	msg = d.FormatJSON()
	data = []byte(msg) // Convert the string to []byte
	req, err := httpPost(url, data)
	if err != nil {
		return false, fmt.Sprintln("error:", err)
	}
	log.Info("http post url:", url)
	log.Info("http post data:", msg)

	result = "EVENT start droplet url: " + url + "\n"
	result += "EVENT start droplet response: " + string(req)

	// increment the counter for a start attempt working
	d.Current.StartAttempts += 1

	// mark the cluster as unstable so droplet starts can be throttled
	me.unstable = time.Now()

	return true, result
}