From 50125cf0a18ac8b6d81acb98746d091349e34baa Mon Sep 17 00:00:00 2001 From: Max Claus Nunes Date: Fri, 11 Nov 2016 16:57:35 -0200 Subject: [PATCH] Add support to enable debug --- .gitignore | 2 +- main.go | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5dc6ce6..6c9116d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -server-spark-submit +server-spark-submit* diff --git a/main.go b/main.go index 91bc3e6..93c94fa 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,13 @@ import ( // version is definded during the build var version string +var debug bool + +func logDebug(msg interface{}) { + if debug { + log.Print(msg) + } +} func getServiceAddress() string { if env := os.Getenv("VIRTUAL_PORT"); env != "" { @@ -34,6 +41,8 @@ func handleSubmit(w http.ResponseWriter, r *http.Request, defaults []string) { } err := json.NewDecoder(r.Body).Decode(&d) + logDebug(d) + if err != nil { http.Error(w, err.Error(), 400) return @@ -47,13 +56,18 @@ func handleSubmit(w http.ResponseWriter, r *http.Request, defaults []string) { args := append(defaults, d.Args...) out, err := exec.Command("spark-submit", args...).CombinedOutput() + logDebug(string(out)) + + if out != nil { + http.Error(w, string(out), 400) + return + } + if err != nil { http.Error(w, err.Error(), 400) return } - log.Println(out) - w.WriteHeader(200) } @@ -63,6 +77,10 @@ func main() { return } + if len(os.Args) > 1 && os.Args[1] == "debug" { + debug = true + } + defaults := strings.Split(os.Getenv("SPARK_SUBMIT_DEFAULT_ARGS"), " ") http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {