From 618eb9ec0378e2f6fc309ac0af9d177edf2f0972 Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Tue, 31 May 2022 12:21:58 +0100 Subject: [PATCH] swarm --> sprinkle --- Makefile | 11 +- README.md | 18 +- .../swarm.proto => sprinkle/sprinkle.proto} | 4 +- cmd/run/main.go | 4 +- cmd/ui/index.html | 164 ++++++++++-------- cmd/ui/main.go | 20 +-- cmd/worker/main.go | 10 +- cmd/worker/server.go | 4 +- go.mod | 2 +- internal/worker.go | 2 +- 10 files changed, 125 insertions(+), 114 deletions(-) rename api/{swarm/swarm.proto => sprinkle/sprinkle.proto} (93%) diff --git a/Makefile b/Makefile index e65b945..0537cac 100644 --- a/Makefile +++ b/Makefile @@ -15,20 +15,19 @@ ui: $(OUT)/ui .PHONY: clean clean: @rm $(OUT)/* - @rm api/swarm/*.pb.go + @rm api/sprinkle/*.pb.go -# go generate ./api/swarm -api/swarm/*.pb.go: ./api/swarm/swarm.proto +api/sprinkle/*.pb.go: ./api/sprinkle/sprinkle.proto protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative $< -$(OUT)/worker: internal/*.go api/swarm/*.pb.go cmd/worker/*.go +$(OUT)/worker: internal/*.go api/sprinkle/*.pb.go cmd/worker/*.go mkdir -p $(OUT) go build -o $@ ./cmd/worker -$(OUT)/run: internal/*.go api/swarm/*.pb.go cmd/run/*.go +$(OUT)/run: internal/*.go api/sprinkle/*.pb.go cmd/run/*.go mkdir -p $(OUT) go build -o $@ ./cmd/run -$(OUT)/ui: internal/*.go api/swarm/*.pb.go cmd/ui/*.go cmd/ui/*.html +$(OUT)/ui: internal/*.go api/sprinkle/*.pb.go cmd/ui/*.go cmd/ui/*.html mkdir -p $(OUT) go build -o $@ ./cmd/ui diff --git a/README.md b/README.md index 100b266..859d0df 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Swarm +# Sprinkle Run jobs on distributed machines easily. No master negotiation or consensus in sight: All parts take an `addr` command line argument that refers to a UDP multicast address on which workers can be discovered. @@ -6,30 +6,30 @@ multicast address on which workers can be discovered. ## Commands ### Worker Responsible for doing work. Exposes a gRPC service definition defined in -api/proto/swarm.proto. +api/proto/sprinkle.proto. -### Swarm -User-facing command line for running work on a swarm. +### Run +User-facing command line for running work on the most appropriate worker. ### UI -Simple HTTP server to monitor the swarm. +Simple HTTP server to monitor the workers and running jobs. ## Example command lines Start the UI ``` -$ ./bin/ui --logtostderr --addr="225.0.0.1:9999" +$ ./bin/ui --logtostderr" ``` Start a worker ``` -$ ./bin/worker --logtostderr --addr="225.0.0.1:9999" +$ ./bin/worker --logtostderr" ``` Run a command ``` -$ ./bin/swarm --cmd="echo hello" --logtostderr --addr=225.0.0.1:9999 +$ ./bin/run --cmd="sleep 10 && echo hello" --logtostderr ... -I0103 10:13:41.607985 14308 swarm.go:224] hello +hello ``` ## TODO diff --git a/api/swarm/swarm.proto b/api/sprinkle/sprinkle.proto similarity index 93% rename from api/swarm/swarm.proto rename to api/sprinkle/sprinkle.proto index 3b965d3..0275df6 100644 --- a/api/swarm/swarm.proto +++ b/api/sprinkle/sprinkle.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -option go_package = "github.com/dominichamon/swarm/api/swarm"; +option go_package = "github.com/dominichamon/sprinkle/api/sprinkle"; -package swarm; +package sprinkle; message StatusRequest {} diff --git a/cmd/run/main.go b/cmd/run/main.go index 7c6e408..c20103d 100644 --- a/cmd/run/main.go +++ b/cmd/run/main.go @@ -11,11 +11,11 @@ import ( "strconv" "time" - "github.com/dominichamon/swarm/internal" + "github.com/dominichamon/sprinkle/internal" "github.com/golang/glog" "golang.org/x/net/context" - pb "github.com/dominichamon/swarm/api/swarm" + pb "github.com/dominichamon/sprinkle/api/sprinkle" ) var ( diff --git a/cmd/ui/index.html b/cmd/ui/index.html index 06e5a5f..b9bf72b 100644 --- a/cmd/ui/index.html +++ b/cmd/ui/index.html @@ -1,90 +1,102 @@ - - - swarm - + - tbody td { - text-align: center; - } + +

sprinkle

+

status

+ + + + + + + + + {{range $id, $status := .Status}} + + + + + + + + {{end}} +
IdIPHostTotal RAM (GB)Free RAM (GB)
{{$id}}{{$status.Ip}}{{$status.Hostname}}{{toGB $status.TotalRam}}{{toGB $status.FreeRam}}
- th { - border-bottom: 1px solid; - } - - - -

swarm

-

status

- - - {{range $id, $status := .Status}} - - - - - - - - {{end}} -
IdIPHostTotal RAM (GB)Free RAM (GB)
{{$id}}{{$status.Ip}}{{$status.Hostname}}{{toGB $status.TotalRam}}{{toGB $status.FreeRam}}
+

jobs

+ + + + + + + + {{range $id, $jobs := .Jobs}} + {{range $_, $job := $jobs}} + + + + + + + {{end}} + {{end}} +
IdStart timeExitedSuccess
{{$id}}{{$job.StartTime}}{{$job.Exited}}{{$job.Success}}
+ -

jobs

- - - {{range $id, $jobs := .Jobs}} - {{range $_, $job := $jobs}} - - - - - - - {{end}} - {{end}} -
IdStart timeExitedSuccess
{{$id}}{{$job.StartTime}}{{$job.Exited}}{{$job.Success}}
- - + \ No newline at end of file diff --git a/cmd/ui/main.go b/cmd/ui/main.go index 12c2662..2e5df28 100644 --- a/cmd/ui/main.go +++ b/cmd/ui/main.go @@ -1,4 +1,4 @@ -// Package ui defines a UI for visualizing a swarm. +// Package ui defines a UI for visualizing a set of workers and the jobs running on them. package main import ( @@ -13,19 +13,19 @@ import ( "sync" "time" - "github.com/dominichamon/swarm/internal" + "github.com/dominichamon/sprinkle/internal" "github.com/golang/glog" "golang.org/x/net/context" - pb "github.com/dominichamon/swarm/api/swarm" + pb "github.com/dominichamon/sprinkle/api/sprinkle" ) var ( - port = flag.Int("port", 1248, "The port on which to listen for HTTP") - poll = flag.Duration("poll", 1*time.Minute, "The time to wait between discovery attempts") + port = flag.Int("port", 1248, "The port on which to listen for HTTP") + poll = flag.Duration("poll", 1*time.Minute, "The time to wait between discovery attempts") statusPoll = flag.Duration("status_poll", 10*time.Second, "The time to wait between status updates") - addr = flag.String("addr", "239.192.0.1:9999", "The multicast address to use for discovery") + addr = flag.String("addr", "239.192.0.1:9999", "The multicast address to use for discovery") dport = flag.Int("dport", 9997, "The port on which to listen for discovery") worker workerMap @@ -33,12 +33,12 @@ var ( jobs jobsMap //go:embed index.html - embedFS embed.FS + embedFS embed.FS indexTmpl *template.Template - funcMap = template.FuncMap { - "toGB": func (bytes uint64) string { - return fmt.Sprintf("%.3f", float64(bytes) / (1000*1000*1000)) + funcMap = template.FuncMap{ + "toGB": func(bytes uint64) string { + return fmt.Sprintf("%.3f", float64(bytes)/(1000*1000*1000)) }, } ) diff --git a/cmd/worker/main.go b/cmd/worker/main.go index 9d26ab6..ae762f1 100644 --- a/cmd/worker/main.go +++ b/cmd/worker/main.go @@ -7,16 +7,16 @@ import ( "fmt" "net" - "github.com/dominichamon/swarm/internal" + "github.com/dominichamon/sprinkle/internal" "github.com/golang/glog" "google.golang.org/grpc" - pb "github.com/dominichamon/swarm/api/swarm" + pb "github.com/dominichamon/sprinkle/api/sprinkle" ) var ( - port = flag.Int("port", 5432, "The port on which to listen for RPC requests") - addr = flag.String("addr", "239.192.0.1:9999", "The multicast address to use for discovery") + port = flag.Int("port", 5432, "The port on which to listen for RPC requests") + addr = flag.String("addr", "239.192.0.1:9999", "The multicast address to use for discovery") iface = flag.String("iface", "", "The interface on which to listen for pings. Defaults to first that supports multicast if unset") ) @@ -26,7 +26,7 @@ func multicastInterface() (*net.Interface, error) { if err != nil { return nil, err } - if ifi.Flags & net.FlagMulticast == 0 { + if ifi.Flags&net.FlagMulticast == 0 { return nil, fmt.Errorf("iface %q does not support multicast", *iface) } return ifi, nil diff --git a/cmd/worker/server.go b/cmd/worker/server.go index 0024722..ceef4f9 100644 --- a/cmd/worker/server.go +++ b/cmd/worker/server.go @@ -11,13 +11,13 @@ import ( "syscall" "time" - "github.com/dominichamon/swarm/internal" + "github.com/dominichamon/sprinkle/internal" "github.com/golang/glog" "github.com/mackerelio/go-osstat/loadavg" "github.com/mackerelio/go-osstat/memory" "golang.org/x/net/context" - pb "github.com/dominichamon/swarm/api/swarm" + pb "github.com/dominichamon/sprinkle/api/sprinkle" ) var ( diff --git a/go.mod b/go.mod index de3821d..1459c5e 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/dominichamon/swarm +module github.com/dominichamon/sprinkle go 1.18 diff --git a/internal/worker.go b/internal/worker.go index 691d5f8..5ea9170 100644 --- a/internal/worker.go +++ b/internal/worker.go @@ -6,7 +6,7 @@ import ( "google.golang.org/grpc" - pb "github.com/dominichamon/swarm/api/swarm" + pb "github.com/dominichamon/sprinkle/api/sprinkle" ) type Worker struct {