Compare commits
No commits in common. "master" and "v0.0.67" have entirely different histories.
6
argv.go
6
argv.go
|
@ -79,8 +79,8 @@ func (args) doBashHelp() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (args) DoAutoComplete(argv []string) {
|
func (args) doBashAuto() {
|
||||||
switch argv[0] {
|
switch argv.BashAuto[0] {
|
||||||
case "list":
|
case "list":
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
case "verify":
|
case "verify":
|
||||||
|
@ -88,7 +88,7 @@ func (args) DoAutoComplete(argv []string) {
|
||||||
case "upgrade":
|
case "upgrade":
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
default:
|
default:
|
||||||
if argv[0] == ARGNAME {
|
if argv.BashAuto[0] == ARGNAME {
|
||||||
// list the subcommands here
|
// list the subcommands here
|
||||||
fmt.Println("help list")
|
fmt.Println("help list")
|
||||||
}
|
}
|
||||||
|
|
24
doGui.go
24
doGui.go
|
@ -7,7 +7,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/gui"
|
||||||
|
"go.wit.com/lib/fhelp"
|
||||||
"go.wit.com/lib/gadgets"
|
"go.wit.com/lib/gadgets"
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -35,6 +38,21 @@ func refresh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func doGui() {
|
func doGui() {
|
||||||
|
me.myGui = gui.New()
|
||||||
|
me.myGui.SetAppDefaultPlugin("gocui") // sets the default GUI plugin to use
|
||||||
|
if pname, err := me.myGui.Default(); err != nil {
|
||||||
|
if !fhelp.BuildPlugin("gocui") {
|
||||||
|
log.Info("You can't run the forge GUI since the plugins did not build", pname)
|
||||||
|
okExit("")
|
||||||
|
} else {
|
||||||
|
if err := me.myGui.LoadToolkitNew("gocui"); err != nil {
|
||||||
|
log.Info("The plugins built, but still failed to load", pname)
|
||||||
|
badExit(err)
|
||||||
|
}
|
||||||
|
log.Info("The plugins built and loaded!", pname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
win := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
|
win := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
|
||||||
win.Make()
|
win.Make()
|
||||||
win.Show()
|
win.Show()
|
||||||
|
@ -66,6 +84,12 @@ func doGui() {
|
||||||
grid.NewButton("ConfigSave()", func() {
|
grid.NewButton("ConfigSave()", func() {
|
||||||
saveMachineState()
|
saveMachineState()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// sit here forever refreshing the GUI
|
||||||
|
for {
|
||||||
|
refresh()
|
||||||
|
time.Sleep(90 * time.Second)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveMachineState() {
|
func saveMachineState() {
|
||||||
|
|
113
http.go
113
http.go
|
@ -5,90 +5,81 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/httppb"
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
// remove '?' part and trailing '/'
|
||||||
if strings.HasPrefix(route, "/repos/") {
|
func cleanURL(url string) string {
|
||||||
pb := gitpb.NewRepos()
|
url = "/" + strings.Trim(url, "/")
|
||||||
if err := pb.Unmarshal(reqPB.ClientData); err == nil {
|
return url
|
||||||
reqPB.Log("Repos Unmarshal() len=%d", pb.Len())
|
}
|
||||||
} else {
|
|
||||||
reqPB.Logf("Repos Unmarshal() err=%v", err)
|
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
// log.Info("Got URL Path: ", r.URL.Path)
|
||||||
result := gitpb.NewRepos()
|
route := cleanURL(r.URL.Path)
|
||||||
switch route {
|
|
||||||
case "/repos/check":
|
hostname := r.URL.Query().Get("hostname")
|
||||||
result = addRequest(pb, reqPB)
|
// flag := r.URL.Query().Get("flag")
|
||||||
reqPB.Logf("repos check result.Len()=%d pb.Len()=%d\n", result.Len(), pb.Len())
|
|
||||||
case "/repos/pull":
|
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
|
||||||
result = pullRequest(pb, reqPB)
|
if err != nil {
|
||||||
case "/repos/add":
|
log.Info("ReadAll() error =", err)
|
||||||
result = addRequest(pb, reqPB)
|
|
||||||
default:
|
|
||||||
reqPB.Logf("repos check result.Len()=%d pb.Len()=%d\n", result.Len(), pb.Len())
|
|
||||||
log.Info("repos", route, "unknown")
|
|
||||||
}
|
|
||||||
if err := result.SendReply(w, reqPB); err != nil {
|
|
||||||
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
|
|
||||||
}
|
|
||||||
// todo: logReq(reqPB)
|
|
||||||
logReqPB(reqPB)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
reqPB, err := httppb.ReqToPB(r)
|
|
||||||
reqPB.Logf("START: Got %d bytes from the client", len(reqPB.ClientData))
|
|
||||||
if err != nil {
|
|
||||||
reqPB.Logf("httppb err %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
route := reqPB.Route
|
|
||||||
|
|
||||||
if route == "/" {
|
if route == "/" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/machine" {
|
if route == "/machine" {
|
||||||
handleMachine(w, reqPB)
|
handleMachine(r, w, hostname, msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/uptime" {
|
if route == "/uptime" {
|
||||||
doUptime(w)
|
if me.zood == nil {
|
||||||
|
fmt.Fprintf(w, "BAD zood == nil\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var count int
|
||||||
|
var bad int
|
||||||
|
for m := range me.machines.IterAll() {
|
||||||
|
count += 1
|
||||||
|
if m.FindVersion("zood") != me.zood.version {
|
||||||
|
if m.SinceLastUpdate() > 10*time.Minute {
|
||||||
|
// skip machines that have not been updated in the last 10 minutes
|
||||||
|
log.Info("ignoring old machine", m.Hostname)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
bad += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if bad == 0 {
|
||||||
|
fmt.Fprintf(w, "GOOD machine count=(%d) all machines are version %s\n", count, me.zood.version)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "BAD machine count=(%d) upgrade=(%d) to %s\n", count, bad, me.zood.version)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Warn("BAD URL =", route)
|
log.Warn("BAD URL =", route)
|
||||||
}
|
}
|
||||||
|
|
||||||
func doUptime(w io.Writer) {
|
// starts and sits waiting for HTTP requests
|
||||||
if me.zood == nil {
|
func startHTTP() {
|
||||||
fmt.Fprintf(w, "BAD zood == nil\n")
|
http.HandleFunc("/", okHandler)
|
||||||
return
|
|
||||||
}
|
p := fmt.Sprintf(":%d", argv.Port)
|
||||||
var count int
|
log.Println("zookeeper main startHTTP() Running on port", p)
|
||||||
var bad int
|
|
||||||
for m := range me.machines.IterAll() {
|
err := http.ListenAndServe(p, nil)
|
||||||
count += 1
|
if err != nil {
|
||||||
if m.FindVersion("zood") != me.zood.version {
|
log.Println("Error starting server:", err)
|
||||||
if m.SinceLastUpdate() > 10*time.Minute {
|
badExit(err)
|
||||||
// skip machines that have not been updated in the last 10 minutes
|
|
||||||
log.Info("ignoring old machine", m.Hostname)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
bad += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if bad == 0 {
|
|
||||||
fmt.Fprintf(w, "GOOD machine count=(%d) all machines are version %s\n", count, me.zood.version)
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(w, "BAD machine count=(%d) upgrade=(%d) to %s\n", count, bad, me.zood.version)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dumpRemoteAddr(r *http.Request) string {
|
||||||
|
return r.RemoteAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
func dumpUserAgent(r *http.Request) string {
|
||||||
|
var all string
|
||||||
|
for param, values := range r.URL.Query() {
|
||||||
|
for _, value := range values {
|
||||||
|
all += fmt.Sprint(" Query:", param, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// hostname := r.URL.Query().Get("hostname")
|
||||||
|
return r.UserAgent() + all
|
||||||
|
}
|
||||||
|
|
||||||
|
func dumpClient(r *http.Request) {
|
||||||
|
/*
|
||||||
|
var host, url, proto, addr, agent string
|
||||||
|
|
||||||
|
host = r.Host
|
||||||
|
url = r.URL.String()
|
||||||
|
proto = r.Proto
|
||||||
|
addr = r.RemoteAddr
|
||||||
|
agent = r.UserAgent()
|
||||||
|
|
||||||
|
log.Warn(host, proto, addr, url, agent)
|
||||||
|
|
||||||
|
fmt.Fprintln(accessf, time.Now(), host, proto, addr, url, agent)
|
||||||
|
// return
|
||||||
|
|
||||||
|
fmt.Fprintln(clientf)
|
||||||
|
fmt.Fprintln(clientf, time.Now())
|
||||||
|
// Basic request information
|
||||||
|
fmt.Fprintln(clientf, "Method:", r.Method)
|
||||||
|
fmt.Fprintln(clientf, "URL:", r.URL)
|
||||||
|
fmt.Fprintln(clientf, "Protocol:", r.Proto)
|
||||||
|
fmt.Fprintln(clientf, "Host:", r.Host)
|
||||||
|
fmt.Fprintln(clientf, "Remote Address:", r.RemoteAddr)
|
||||||
|
|
||||||
|
// Headers
|
||||||
|
fmt.Fprintln(clientf, "Headers:")
|
||||||
|
for name, values := range r.Header {
|
||||||
|
for _, value := range values {
|
||||||
|
fmt.Fprintln(clientf, "Headers:", name, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query parameters
|
||||||
|
fmt.Fprintln(clientf, "Query Parameters:")
|
||||||
|
for param, values := range r.URL.Query() {
|
||||||
|
for _, value := range values {
|
||||||
|
fmt.Fprintln(clientf, "Query:", param, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// User-Agent
|
||||||
|
fmt.Fprintln(clientf, "User-Agent:", r.UserAgent())
|
||||||
|
|
||||||
|
// Content Length
|
||||||
|
fmt.Fprintln(clientf, "Content Length:", r.ContentLength)
|
||||||
|
|
||||||
|
// Cookies
|
||||||
|
fmt.Fprintln(clientf, "Cookies:")
|
||||||
|
for _, cookie := range r.Cookies() {
|
||||||
|
fmt.Fprintln(clientf, cookie.Name, cookie.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request Body (if applicable)
|
||||||
|
if r.Body != nil {
|
||||||
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Fprintln(clientf, "Body:", string(body))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
38
machine.go
38
machine.go
|
@ -6,9 +6,9 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/httppb"
|
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
@ -20,27 +20,25 @@ func rawGetHostname(data []byte) *zoopb.Machine {
|
||||||
return newm
|
return newm
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMachine(w http.ResponseWriter, reqPB *httppb.HttpRequest) {
|
func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data []byte) {
|
||||||
// hostname := strings.TrimSpace(reqPB.Hostname)
|
hostname = strings.TrimSpace(hostname)
|
||||||
newm := rawGetHostname(reqPB.ClientData)
|
newm := rawGetHostname(data)
|
||||||
if newm == nil {
|
if newm == nil {
|
||||||
log.Info("unmarshal failed on data len =", len(reqPB.ClientData))
|
log.Info("unmarshal failed on data len =", len(data))
|
||||||
|
}
|
||||||
|
if hostname != newm.Hostname {
|
||||||
|
// log.Info("hostname mismatch", hostname, "vs", newm.Hostname)
|
||||||
|
hostname = newm.Hostname
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if reqPB.Hostname != newm.Hostname {
|
|
||||||
// log.Info("hostname mismatch", hostname, "vs", newm.Hostname)
|
|
||||||
hostname = newm.Hostname
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if reqPB.Hostname == "" {
|
if hostname == "" {
|
||||||
ua := reqPB.DumpUserAgent()
|
ua := dumpUserAgent(r)
|
||||||
ra := reqPB.DumpRemoteAddr()
|
ra := dumpRemoteAddr(r)
|
||||||
log.Info("hostname is blank even after unmarshal. data len =", len(reqPB.ClientData), ra, ua, newm.Cpus, newm.Hostname)
|
log.Info("hostname is blank even after unmarshal. data len =", len(data), ra, ua, newm.Cpus, newm.Hostname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// log.Info("lookoing for", hostname)
|
// log.Info("lookoing for", hostname)
|
||||||
m := me.machines.FindByHostname(reqPB.Hostname)
|
m := me.machines.FindByHostname(hostname)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
am := new(zoopb.Machine)
|
am := new(zoopb.Machine)
|
||||||
am.Hostname = newm.Hostname
|
am.Hostname = newm.Hostname
|
||||||
|
@ -49,10 +47,10 @@ func handleMachine(w http.ResponseWriter, reqPB *httppb.HttpRequest) {
|
||||||
log.Info("new machine", am.Hostname, am.Memory)
|
log.Info("new machine", am.Hostname, am.Memory)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ua := reqPB.DumpUserAgent()
|
ua := dumpUserAgent(r)
|
||||||
ra := reqPB.DumpRemoteAddr()
|
ra := dumpRemoteAddr(r)
|
||||||
if m.UserAgent != ua {
|
if m.UserAgent != ua {
|
||||||
log.Info("hostname ua changed len =", len(reqPB.ClientData), ra, reqPB.Hostname, ua)
|
log.Info("hostname ua changed len =", len(data), ra, hostname, ua)
|
||||||
m.UserAgent = ua
|
m.UserAgent = ua
|
||||||
}
|
}
|
||||||
if m.Upgrade {
|
if m.Upgrade {
|
||||||
|
@ -67,7 +65,7 @@ func handleMachine(w http.ResponseWriter, reqPB *httppb.HttpRequest) {
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(w, "good")
|
fmt.Fprintln(w, "good")
|
||||||
}
|
}
|
||||||
// log.Info("update machine protobuf", reqPB.hostname)
|
// log.Info("update machine protobuf", hostname)
|
||||||
updateMachine(newm)
|
updateMachine(newm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
main.go
39
main.go
|
@ -8,8 +8,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/lib/gui/prep"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/protobuf/httppb"
|
"go.wit.com/lib/fhelp"
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
@ -21,10 +21,29 @@ var ARGNAME string = "zookeeper"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
me = new(mainType)
|
me = new(mainType)
|
||||||
prep.Bash(ARGNAME, argv.DoAutoComplete) // this line should be: prep.Bash(argv)
|
gui.InitArg()
|
||||||
me.myGui = prep.Gui() // prepares the GUI package for go-args
|
|
||||||
me.pp = arg.MustParse(&argv)
|
me.pp = arg.MustParse(&argv)
|
||||||
|
|
||||||
|
if argv.Bash {
|
||||||
|
fhelp.DoBash(ARGNAME)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
if len(argv.BashAuto) != 0 {
|
||||||
|
argv.doBashAuto()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if the binary is being called to test
|
||||||
|
// if the plugin can actually loaded. This is a hack
|
||||||
|
// around needing a Test() plugin load function in GO
|
||||||
|
if gui.IsGoPluginTestHack() {
|
||||||
|
argv.NoPort = true
|
||||||
|
gui.CheckPlugin()
|
||||||
|
os.Exit(0)
|
||||||
|
// if argv.GuiCheck != "" {
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
if argv.Daemon {
|
if argv.Daemon {
|
||||||
// turn off timestamps for STDOUT (systemd adds them)
|
// turn off timestamps for STDOUT (systemd adds them)
|
||||||
log.DaemonMode(true)
|
log.DaemonMode(true)
|
||||||
|
@ -44,15 +63,7 @@ func main() {
|
||||||
|
|
||||||
go NewWatchdog()
|
go NewWatchdog()
|
||||||
if !argv.NoPort {
|
if !argv.NoPort {
|
||||||
go httppb.StartHTTP(okHandler, argv.Port)
|
go startHTTP()
|
||||||
}
|
|
||||||
|
|
||||||
me.myGui.Start() // loads the GUI toolkit
|
|
||||||
doGui() // start making our forge GUI
|
|
||||||
|
|
||||||
// sit here forever refreshing the GUI
|
|
||||||
for {
|
|
||||||
refresh()
|
|
||||||
time.Sleep(90 * time.Second)
|
|
||||||
}
|
}
|
||||||
|
doGui()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/gadgets"
|
"go.wit.com/lib/gadgets"
|
||||||
"go.wit.com/lib/gui/prep"
|
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ type mainType struct {
|
||||||
machines *zoopb.Machines // every machine that has reported itself to the zookeeper
|
machines *zoopb.Machines // every machine that has reported itself to the zookeeper
|
||||||
targets map[string]string // what versions the machines should be running
|
targets map[string]string // what versions the machines should be running
|
||||||
upgrade map[string]bool // use this to trigger builds
|
upgrade map[string]bool // use this to trigger builds
|
||||||
myGui *prep.GuiPrep // the gui toolkit handle
|
myGui *gui.Node // the gui toolkit handle
|
||||||
machinesWin *gadgets.GenericWindow // the machines gui window
|
machinesWin *gadgets.GenericWindow // the machines gui window
|
||||||
machinesBox *gui.Node // the machines gui parent box widget
|
machinesBox *gui.Node // the machines gui parent box widget
|
||||||
machinesTB *zoopb.MachinesTable // the machines gui table buffer
|
machinesTB *zoopb.MachinesTable // the machines gui table buffer
|
||||||
|
|
Loading…
Reference in New Issue