start worked by sending protobuf
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
7837182d53
commit
3c1efcba0e
18
event.go
18
event.go
|
@ -51,6 +51,8 @@ func dropletReady(d *pb.Droplet) (bool, string) {
|
||||||
return true, ""
|
return true, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this must be bool in string because accumulated output is sometimes
|
||||||
|
// written to STDOUT, sometimes to http
|
||||||
func (h *HyperT) start(d *pb.Droplet) (bool, string) {
|
func (h *HyperT) start(d *pb.Droplet) (bool, string) {
|
||||||
ready, result := clusterReady()
|
ready, result := clusterReady()
|
||||||
if !ready {
|
if !ready {
|
||||||
|
@ -62,9 +64,19 @@ func (h *HyperT) start(d *pb.Droplet) (bool, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
url := "http://" + h.pb.Hostname + ":2520/start?start=" + d.Hostname
|
url := "http://" + h.pb.Hostname + ":2520/start?start=" + d.Hostname
|
||||||
s := shell.Wget(url)
|
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 url: " + url + "\n"
|
||||||
result += "EVENT start droplet response: " + s.String()
|
result += "EVENT start droplet response: " + string(req)
|
||||||
|
|
||||||
// increment the counter for a start attempt working
|
// increment the counter for a start attempt working
|
||||||
d.Starts += 1
|
d.Starts += 1
|
||||||
|
@ -99,7 +111,7 @@ func Start(name string) (bool, string) {
|
||||||
|
|
||||||
dur := time.Since(me.unstable) // how long has the cluster been stable?
|
dur := time.Since(me.unstable) // how long has the cluster been stable?
|
||||||
result = fmt.Sprintln("should start droplet", name, "here. grid stable for:", shell.FormatDuration(dur))
|
result = fmt.Sprintln("should start droplet", name, "here. grid stable for:", shell.FormatDuration(dur))
|
||||||
if dur < 17*time.Second {
|
if dur < me.unstableTimeout {
|
||||||
result += "grid is still too unstable"
|
result += "grid is still too unstable"
|
||||||
return false, result
|
return false, result
|
||||||
}
|
}
|
||||||
|
|
4
http.go
4
http.go
|
@ -5,9 +5,9 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
"go.wit.com/lib/virtigoxml"
|
"go.wit.com/lib/virtigoxml"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// remove '?' part and trailing '/'
|
// remove '?' part and trailing '/'
|
||||||
|
@ -104,7 +104,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Warn("BAD URL =", tmp)
|
log.Warn("BAD URL =", tmp)
|
||||||
fmt.Fprintln(w, "BAD URL", tmp)
|
fmt.Fprintln(w, "BAD URL tmp =", tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// write a file out to the http socket
|
// write a file out to the http socket
|
||||||
|
|
1
main.go
1
main.go
|
@ -43,6 +43,7 @@ func main() {
|
||||||
me.changed = false
|
me.changed = false
|
||||||
// me.dmap = make(map[*pb.Droplet]*DropletT)
|
// me.dmap = make(map[*pb.Droplet]*DropletT)
|
||||||
me.hmap = make(map[*pb.Hypervisor]*HyperT)
|
me.hmap = make(map[*pb.Hypervisor]*HyperT)
|
||||||
|
me.unstableTimeout = 17 * time.Second
|
||||||
|
|
||||||
// read in the config file
|
// read in the config file
|
||||||
me.cluster = new(pb.Cluster)
|
me.cluster = new(pb.Cluster)
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func httpPost(url string, data []byte) ([]byte, error) {
|
||||||
|
var err error
|
||||||
|
var req *http.Request
|
||||||
|
|
||||||
|
// data := []byte("some junk")
|
||||||
|
// url := "https://go.wit.com/register/"
|
||||||
|
|
||||||
|
req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data))
|
||||||
|
|
||||||
|
usr, _ := user.Current()
|
||||||
|
req.Header.Set("author", usr.Username)
|
||||||
|
hostname, _ := os.Hostname()
|
||||||
|
req.Header.Set("hostname", hostname)
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return body, err
|
||||||
|
}
|
||||||
|
|
||||||
|
test := strings.TrimSpace(string(body))
|
||||||
|
log.Info("go.wit.com returned body:", test)
|
||||||
|
if test == "OK" {
|
||||||
|
return body, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return body, nil
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ type virtigoT struct {
|
||||||
killcount int
|
killcount int
|
||||||
unstable time.Time // the last time the cluster was incorrect
|
unstable time.Time // the last time the cluster was incorrect
|
||||||
changed bool
|
changed bool
|
||||||
|
unstableTimeout time.Duration
|
||||||
// dirs []string // all the paths too search for a qcow image
|
// dirs []string // all the paths too search for a qcow image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue