Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Fixed: CLI breaks with multiple spaces in submit args (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto authored and susanxhuynh committed Oct 24, 2017
1 parent e686c93 commit 17e2483
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cli/bin/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export GOPATH=$(pwd)/vendor:$GOPATH

# this may be omitted in 1.6+, left here for compatibility with 1.5:
export GO15VENDOREXPERIMENT=1

go test
# available GOOS/GOARCH permutations are listed at:
# https://golang.org/doc/install/source#environment

Expand Down
39 changes: 39 additions & 0 deletions cli/dcos-spark/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import "testing"

// test spaces
func TestCleanUpSubmitArgs(t *testing.T) {
_, args := sparkSubmitArgSetup()
inputArgs := "--conf spark.app.name=kerberosStreaming --conf spark.cores.max=8"
submitArgs, _ := cleanUpSubmitArgs(inputArgs, args.boolVals)
if "--conf=spark.app.name=kerberosStreaming" != submitArgs[0] {
t.Errorf("Failed to reduce spaces while cleaning submit args.")
}

if "--conf=spark.cores.max=8" != submitArgs[1] {
t.Errorf("Failed to reduce spaces while cleaning submit args.")
}
}

// test scopts pattern for app args when have full submit args
func TestScoptAppArgs(t *testing.T) {
_, args := sparkSubmitArgSetup()
inputArgs := `--driver-cores 1 --conf spark.cores.max=1 --driver-memory 512M
--class org.apache.spark.examples.SparkPi http://spark-example.jar --input1 value1 --input2 value2`
submitArgs, appFlags := cleanUpSubmitArgs(inputArgs, args.boolVals)

if "--input1" != appFlags[0] {
t.Errorf("Failed to parse app args.")
}
if "value1" != appFlags[1] {
t.Errorf("Failed to parse app args.")
}

if "--driver-memory=512M" != submitArgs[2] {
t.Errorf("Failed to parse submit args..")
}
if "http://spark-example.jar" != submitArgs[4] {
t.Errorf("Failed to parse submit args..")
}
}
6 changes: 5 additions & 1 deletion cli/dcos-spark/submit_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

var keyWhitespaceValPattern = regexp.MustCompile("(.+)\\s+(.+)")
var backslashNewlinePattern = regexp.MustCompile("\\s*\\\\s*\\n\\s+")
var collapseSpacesPattern = regexp.MustCompile(`[\s\p{Zs}]{2,}`)

type sparkVal struct {
flagName string
Expand Down Expand Up @@ -298,8 +299,11 @@ func parseApplicationFile(args *sparkArgs) error {
}

func cleanUpSubmitArgs(argsStr string, boolVals []*sparkVal) ([]string, []string) {

// collapse two or more spaces to one.
argsCompacted := collapseSpacesPattern.ReplaceAllString(argsStr, " ")
// clean up any instances of shell-style escaped newlines: "arg1\\narg2" => "arg1 arg2"
argsCleaned := strings.TrimSpace(backslashNewlinePattern.ReplaceAllLiteralString(argsStr, " "))
argsCleaned := strings.TrimSpace(backslashNewlinePattern.ReplaceAllLiteralString(argsCompacted, " "))
// HACK: spark-submit uses '--arg val' by convention, while kingpin only supports '--arg=val'.
// translate the former into the latter for kingpin to parse.
args := strings.Split(argsCleaned, " ")
Expand Down

0 comments on commit 17e2483

Please sign in to comment.