summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-26 20:09:59 -0500
committerJeff Carr <[email protected]>2024-10-26 20:09:59 -0500
commit3c1efcba0e6d5757aea38b0c2067fdbb26be8105 (patch)
treefbc91a529cbee31a72ffc303fc1cf9da2fc36449
parent7837182d532dcc022ca2ffafa9289640ac942195 (diff)
start worked by sending protobuf
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--event.go18
-rw-r--r--http.go4
-rw-r--r--main.go1
-rw-r--r--post.go49
-rw-r--r--structs.go1
5 files changed, 68 insertions, 5 deletions
diff --git a/event.go b/event.go
index 261c48b..0705595 100644
--- a/event.go
+++ b/event.go
@@ -51,6 +51,8 @@ func dropletReady(d *pb.Droplet) (bool, string) {
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) {
ready, result := clusterReady()
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
- 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 response: " + s.String()
+ result += "EVENT start droplet response: " + string(req)
// increment the counter for a start attempt working
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?
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"
return false, result
}
diff --git a/http.go b/http.go
index cb3f35a..684c9a8 100644
--- a/http.go
+++ b/http.go
@@ -5,9 +5,9 @@ import (
"net/http"
"strings"
+ pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/lib/virtigoxml"
"go.wit.com/log"
- pb "go.wit.com/lib/protobuf/virtbuf"
)
// remove '?' part and trailing '/'
@@ -104,7 +104,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
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
diff --git a/main.go b/main.go
index c484e8a..db6449c 100644
--- a/main.go
+++ b/main.go
@@ -43,6 +43,7 @@ func main() {
me.changed = false
// me.dmap = make(map[*pb.Droplet]*DropletT)
me.hmap = make(map[*pb.Hypervisor]*HyperT)
+ me.unstableTimeout = 17 * time.Second
// read in the config file
me.cluster = new(pb.Cluster)
diff --git a/post.go b/post.go
new file mode 100644
index 0000000..9537bc8
--- /dev/null
+++ b/post.go
@@ -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
+}
diff --git a/structs.go b/structs.go
index a19c2ba..d2dd8cb 100644
--- a/structs.go
+++ b/structs.go
@@ -31,6 +31,7 @@ type virtigoT struct {
killcount int
unstable time.Time // the last time the cluster was incorrect
changed bool
+ unstableTimeout time.Duration
// dirs []string // all the paths too search for a qcow image
}