DEMO: add temporary task runner
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Wed, 13 Dec 2017 18:15:32 +0000 (19:15 +0100)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Fri, 5 Jan 2018 14:23:57 +0000 (15:23 +0100)
Change-Id: I61573aa78e0c4c424efc8f26114633061692840d

Makefile [new file with mode: 0644]
cmd/main.go [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..24c1e4f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,20 @@
+BORUTA=localhost:8080
+WELES=localhost:5010
+
+.PHONY: build run watch minitest clean
+
+build:
+       mkdir -p /tmp/weles/
+       go build cmd/main.go
+
+run:
+       ./main -borutaAddress http://${BORUTA}
+
+watch:
+       watch -n1 "tree /tmp/weles"
+
+minitest:
+       curl -L ${WELES}/api/v1/jobs/ -F "uploadfile=@demo/mini.yml;type=application/octet-stream" -vvv
+
+clean:
+       rm -r /tmp/weles
diff --git a/cmd/main.go b/cmd/main.go
new file mode 100644 (file)
index 0000000..a3661c3
--- /dev/null
@@ -0,0 +1,59 @@
+package main
+
+import (
+       "flag"
+       "log"
+       "net/http"
+       "os"
+       "os/signal"
+       "time"
+
+       "git.tizen.org/tools/boruta/http/client"
+       "git.tizen.org/tools/weles/artifacts"
+       "git.tizen.org/tools/weles/controller"
+       "git.tizen.org/tools/weles/manager"
+       "git.tizen.org/tools/weles/parser"
+       "git.tizen.org/tools/weles/server/api/v1"
+       "github.com/dimfeld/httptreemux"
+)
+
+var (
+       address             string
+       borutaAddress       string
+       borutaRefreshPeriod time.Duration
+)
+
+func setFlags() {
+       flag.StringVar(&address, "address", ":5010", "address to listen on")
+       flag.StringVar(&borutaAddress, "borutaAddress", ":7175", "Boruta address")
+       flag.DurationVar(&borutaRefreshPeriod, "borutaRefreshPeriod", 2*time.Second, "Boruta refresh period")
+}
+
+func exitOnErr(ctx string, err error) {
+       if err != nil {
+               log.Fatal(ctx, err)
+       }
+}
+
+func main() {
+       setFlags()
+       flag.Parse()
+
+       var yap parser.Parser
+
+       am, err := artifacts.NewArtifactManager()
+       exitOnErr("failed to initialize ArtifactManager", err)
+
+       bor := client.NewBorutaClient(borutaAddress)
+       djm := manager.NewDryadJobManager()
+       jm := controller.NewJobManager(am, &yap, bor, borutaRefreshPeriod, djm)
+       router := httptreemux.New()
+       _ = v1.NewAPI(router, jm, am)
+
+       log.Fatal(http.ListenAndServe(address, router))
+
+       // Wait for interrupt.
+       c := make(chan os.Signal, 1)
+       signal.Notify(c, os.Interrupt)
+       <-c
+}