[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC 01/59] Initial controller framework



From: George Dunlap <george.dunlap@xxxxxxxxxx>

Go code to execute a worker and parse its output.

The go json marshaller needs capitalized structure elements; make the
output match.

Also add fflush()-es to make sure that output actually gets to the controller
in a timely manner.

Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>
---
 Makefile | 12 ++++++++++
 main.go  | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 Makefile
 create mode 100644 main.go

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..736d959
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,12 @@
+BIN = controller
+BINALL = $(BIN)
+
+.PHONY: all
+all: $(BIN)
+
+controller: main.go
+       go build -o $@ $<
+
+.PHONY: clean
+clean:
+       rm -f $(BINALL)
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..6e90754
--- /dev/null
+++ b/main.go
@@ -0,0 +1,78 @@
+package main
+
+import (
+       "fmt"
+       "os/exec"
+       "encoding/json"
+       "bufio"
+       "io"
+)
+
+type Worker struct {
+       c *exec.Cmd
+
+       stdout io.ReadCloser
+       
+       jsonStarted bool
+}
+
+type WorkerReport struct {
+       Now int
+       Mops int
+       MaxDelta int
+}
+
+func (w *Worker) Start() (err error) {
+       w.c = exec.Command("../worker/worker-proc", "burnwait", "20", 
"20000000")
+       
+
+       w.stdout, err = w.c.StdoutPipe()
+       if err != nil {
+               fmt.Print("Conneting to stdout: ", err)
+               return
+       }
+
+       w.c.Start()
+
+       b, err := json.Marshal(WorkerReport{5,6,7})
+       fmt.Print("Example json: ", string(b))
+       
+       return
+}
+
+func (w *Worker) Wait() {
+       w.c.Wait()
+}
+
+func (w *Worker) Process() {
+       scanner := bufio.NewScanner(w.stdout)
+
+       for scanner.Scan() {
+               s := scanner.Text()
+               
+               fmt.Println("Got these bytes: ", s);
+
+               if w.jsonStarted {
+                       var r WorkerReport
+                       
+                       json.Unmarshal([]byte(s), &r)
+                       fmt.Println(r)
+               } else {
+                       if s == "START JSON" {
+                               fmt.Println("Got token to start parsing json")
+                               w.jsonStarted = true
+                       }
+               }
+       }
+}
+
+func main() {
+
+       w:=Worker{}
+       
+       w.Start()
+
+       w.Process()
+
+       w.Wait()
+}
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.