-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 331df14
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
; Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
indent_size = 2 | ||
end_of_line = lf | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
; Golang | ||
[*.go] | ||
indent_style = tab | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
server-spark-submit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
server-spark-submit | ||
================ | ||
|
||
This server expose an API to create spark jobs with `spark-submit` command. Due that this server must run in a environment where that command is available. | ||
|
||
Checkout the `example-submit.sh` to understand how to call this API. | ||
|
||
### Running the server with default args | ||
|
||
``` | ||
SPARK_SUBMIT_DEFAULT_ARGS="--deploy-mode client --packages com.databricks:spark-csv_2.11:1.4.0,com.datastax.spark:spark-cassandra-connector_2.10:1.6.0 --conf spark.cassandra.connection.host=cassandra.production-cassandra.svc.cluster.local --master spark://10.2.93.2:7077 --verbose" server-spark-submit | ||
``` | ||
|
||
### Building | ||
|
||
``` | ||
go build -ldflags "-X main.version=1" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
curl -H "Content-Type: application/json" \ | ||
-X POST \ | ||
-d '{ | ||
"args" : [ | ||
"arg1", | ||
"arg2", | ||
"arg3", | ||
"arg4" | ||
] | ||
}' \ | ||
http://localhost:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
// version is definded during the build | ||
var version string | ||
|
||
func handleSubmit(w http.ResponseWriter, r *http.Request, defaults []string) { | ||
var d struct{ Args []string } | ||
|
||
if r.Body == nil { | ||
http.Error(w, "Please send a request body", 400) | ||
return | ||
} | ||
|
||
err := json.NewDecoder(r.Body).Decode(&d) | ||
if err != nil { | ||
http.Error(w, err.Error(), 400) | ||
return | ||
} | ||
|
||
if len(d.Args) == 0 { | ||
http.Error(w, "Missing submit args", 400) | ||
return | ||
} | ||
|
||
args := append(defaults, d.Args...) | ||
|
||
out, err := exec.Command("spark-submit", args...).CombinedOutput() | ||
if err != nil { | ||
http.Error(w, err.Error(), 400) | ||
return | ||
} | ||
|
||
log.Println(out) | ||
|
||
w.WriteHeader(200) | ||
} | ||
|
||
func main() { | ||
if len(os.Args) > 1 && os.Args[1] == "version" { | ||
fmt.Println("server-spark-submit version " + version) | ||
return | ||
} | ||
|
||
defaults := strings.Split(os.Getenv("SPARK_SUBMIT_DEFAULT_ARGS"), " ") | ||
|
||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method == "POST" { | ||
handleSubmit(w, r, defaults) | ||
return | ||
} | ||
|
||
http.NotFound(w, r) | ||
}) | ||
|
||
log.Println("Starting server") | ||
log.Fatal(http.ListenAndServe(":8080", nil)) | ||
} |