From 8935a6842f902d1845301cd3baf3512c91a3963e Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Wed, 4 Dec 2019 21:36:16 +0800 Subject: [PATCH 01/21] workflow e2e test --- cmd/sqlflowserver/main_test.go | 76 ++++++++++++++++++++++++++++++ pkg/sql/codegen/couler/codegen.go | 16 +++++-- pkg/sql/codegen/couler/template.go | 5 +- pkg/sql/executor_ir.go | 14 ++++-- scripts/test_couler.sh | 24 ++++++++-- 5 files changed, 120 insertions(+), 15 deletions(-) diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index 4ed72e78af..8fb3568ae3 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -23,6 +23,7 @@ import ( "os" "os/exec" "path" + "strings" "testing" "time" @@ -44,6 +45,7 @@ var caseDB = "iris" var caseTrainTable = "train" var caseTestTable = "test" var casePredictTable = "predict" +var testDatasource = os.Getenv("SQLFLOW_TEST_DATASOURCE") const unitestPort = 50051 @@ -478,6 +480,80 @@ func TestEnd2EndMaxComputeElasticDL(t *testing.T) { t.Run("CaseTrainElasticDL", CaseTrainElasticDL) } +func TestEnd2EndMaxComputeWorkflow(t *testing.T) { + if testDatasource == "" { + t.Fatal("env SQLFLOW_TEST_DATASOURCE is required.") + } + driverName, _, err := sql.SplitDataSource(testDatasource) + if err != nil { + t.Fatalf("parse datasource failed, %v", err) + } + + if driverName != "maxcompute" || os.Getenv("SQLFLOW_ARGO_MODE") != "True" { + t.Skip("Skipping workflow test on maxcompute") + } + + modelDir := "" + tmpDir, caCrt, caKey, err := generateTempCA() + defer os.RemoveAll(tmpDir) + if err != nil { + t.Fatalf("failed to generate CA pair %v", err) + } + + go start(modelDir, caCrt, caKey, unitestPort, true) + waitPortReady(fmt.Sprintf("localhost:%d", unitestPort), 0) + if err != nil { + t.Fatalf("prepare test dataset failed: %v", err) + } + + t.Run("CaseSubmitSQLProgram", CaseSubmitSQLProgram) +} + +func CaseSubmitSQLProgram(t *testing.T) { + a := assert.New(t) + sqlProgram := fmt.Sprintf(` +SELECT * +FROM %s.%s +TO TRAIN DNNClassifier +WITH + model.n_classes = 3, + model.hidden_units = [10, 20] +COLUMN sepal_length, sepal_width, petal_length, petal_width +LABEL class +INTO sqlflow_models.my_dnn_model; + +SELECT * +FROM %s.%s +TO PREDICT %s.%s.class +USING sqlflow_models.my_dnn_model; + +SELECT * +FROM %s.%s LIMIT 5; + `, caseDB, caseTrainTable, + caseDB, caseTrainTable, caseDB, casePredictTable, caseDB, casePredictTable) + + conn, err := createRPCConn() + if err != nil { + a.Fail("Create gRPC client error: %v", err) + } + defer conn.Close() + cli := pb.NewSQLFlowClient(conn) + ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second) + defer cancel() + stream, err := cli.Run(ctx, &pb.Request{Sql: sqlProgram, Session: &pb.Session{DbConnStr: testDatasource}}) + for { + iter, err := stream.Recv() + if err == io.EOF { + break + } + if err != nil { + log.Fatalf("stream read err: %v", err) + } + a.True(strings.HasPrefix(iter.GetJob().GetId(), "sqlflow-couler")) + } + //TODO(yancey1989) implement Fetch interface to verify the workflow status +} + func CaseShowDatabases(t *testing.T) { a := assert.New(t) cmd := "show databases;" diff --git a/pkg/sql/codegen/couler/codegen.go b/pkg/sql/codegen/couler/codegen.go index 7cfdf8b6de..4cc6ba6523 100644 --- a/pkg/sql/codegen/couler/codegen.go +++ b/pkg/sql/codegen/couler/codegen.go @@ -15,17 +15,23 @@ package couler import ( "bytes" + "fmt" + pb "sqlflow.org/sqlflow/pkg/proto" "sqlflow.org/sqlflow/pkg/sql/ir" ) +var defaultDockerImage = "sqlflow/sqlflow" + // Run generates Couler program -func Run(programIR ir.SQLProgram) (string, error) { +func Run(programIR ir.SQLProgram, session *pb.Session) (string, error) { // TODO(yancey1989): fill session as env - r := &coulerFiller{} + r := &coulerFiller{ + DataSource: session.DbConnStr, + } for _, sqlIR := range programIR { ss := &sqlStatment{} - switch sqlIR.(type) { + switch i := sqlIR.(type) { case *ir.StandardSQL: ss.IsExtendedSQL = false ss.OriginalSQL = string(*sqlIR.(*ir.StandardSQL)) @@ -38,9 +44,11 @@ func Run(programIR ir.SQLProgram) (string, error) { case *ir.AnalyzeClause: ss.IsExtendedSQL = true ss.OriginalSQL = sqlIR.(*ir.AnalyzeClause).OriginalSQL + default: + return "", fmt.Errorf("uncognized IR type: %v", i) } // TODO(yancey1989): using the custom Docker image in model zoo - ss.DockerImage = "sqlflow/sqlflow" + ss.DockerImage = defaultDockerImage r.SQLStatements = append(r.SQLStatements, ss) } var program bytes.Buffer diff --git a/pkg/sql/codegen/couler/template.go b/pkg/sql/codegen/couler/template.go index 64b1ff3342..c0409cebe2 100644 --- a/pkg/sql/codegen/couler/template.go +++ b/pkg/sql/codegen/couler/template.go @@ -21,15 +21,16 @@ type sqlStatment struct { DockerImage string } type coulerFiller struct { - dataSource string + DataSource string SQLStatements []*sqlStatment } const coulerTemplateText = ` import couler.argo as couler +datasource = "{{ .DataSource }}" {{ range $ss := .SQLStatements }} {{if $ss.IsExtendedSQL }} -couler.run_container(command='''repl -e "{{ $ss.OriginalSQL }}"''', image="{{ $ss.DockerImage }}") +couler.run_container(command='''repl -e "{{ $ss.OriginalSQL }}" --datasource="%s"'''%datasource, image="{{ $ss.DockerImage }}") {{else}} # TODO(yancey1989): # using "repl -parse" to output IR and diff --git a/pkg/sql/executor_ir.go b/pkg/sql/executor_ir.go index a63a53d1f9..e90cd4c2a5 100644 --- a/pkg/sql/executor_ir.go +++ b/pkg/sql/executor_ir.go @@ -112,14 +112,18 @@ func SubmitWorkflow(sqlProgram string, db *DB, modelDir string, session *pb.Sess defer wr.Close() err := submitWorkflow(wr, sqlProgram, db, modelDir, session) if err != nil { - log.Errorf("submit Workflow error: %v", err) + if err != ErrClosedPipe { + if err := wr.Write(err); err != nil { + log.Errorf("submit workflow error(piping): %v", err) + } + } } }() return rd } -func writeCoulerFile(spIRs ir.SQLProgram) (string, error) { - program, err := couler.Run(spIRs) +func writeCoulerFile(spIRs ir.SQLProgram, session *pb.Session) (string, error) { + program, err := couler.Run(spIRs, session) if err != nil { return "", fmt.Errorf("generate couler program error: %v", err) } @@ -188,7 +192,7 @@ func submitWorkflow(wr *PipeWriter, sqlProgram string, db *DB, modelDir string, } // 1. call codegen_couler.go to genearte Couler program. - coulerFileName, err := writeCoulerFile(spIRs) + coulerFileName, err := writeCoulerFile(spIRs, session) if err != nil { return err } @@ -203,7 +207,7 @@ func submitWorkflow(wr *PipeWriter, sqlProgram string, db *DB, modelDir string, cmd := exec.Command("kubectl", "create", "-f", argoFile) output, err := cmd.CombinedOutput() if err != nil { - return fmt.Errorf("submit Argo YAML error: %v", err) + return fmt.Errorf("submit Argo YAML error: %v, output: %s", err, string(output)) } reWorkflow := regexp.MustCompile(`.+/(.+) .+`) wf := reWorkflow.FindStringSubmatch(string(output)) diff --git a/scripts/test_couler.sh b/scripts/test_couler.sh index ac447ac025..3f6f6bc939 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_couler.sh @@ -65,8 +65,24 @@ if [[ "$ret" != "0" ]]; then fi ############# Run SQLFLow test with Argo Mode ############# -service mysql start -go generate ./... -go install ./... -SQLFLOW_ARGO_MODE=True go test ./pkg/sql/. -run TestSubmitWorkflow -v +# start a SQLFlow MySQL Pod with testdata +kubectl run mysql --port 3306 --env="SQLFLOW_MYSQL_HOST=0.0.0.0" --env="SQLFLOW_MYSQL_PORT=3306" --image=sqlflow/sqlflow --command -- bash /start.sh mysql +MYSQL_POD_NAME=$(kubectl get pod -l run=mysql -o jsonpath="{.items[0].metadata.name}") +for i in {1...30}; do + POD_STATUS=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.phase}') + if [[ "POD_STATUS" == "Running" ]]; then + echo "SQLFlow MySQL Pod running." + go generate ./... + go install ./... + SQLFLOW_ARGO_MODE=True go test ./pkg/sql/. -run TestSubmitWorkflow -v + go test ./cmd/... -run TestEnd2EndMySQLArgoMode -v + exit 0 + else + echo "Wait SQLFlow MySQL Pod ${MYSQL_POD_NAME}" + sleep 3 + fi +done + +echo "Start SQLFlow MySQL Pod failed." +exit 1 \ No newline at end of file From b69c256780bed64347d8535646f303158a8820e8 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 00:30:47 +0800 Subject: [PATCH 02/21] merge bug fix --- cmd/sqlflowserver/main_test.go | 26 +++++++++++++++++++++----- pkg/sql/codegen/couler/codegen.go | 10 ++++++++-- pkg/sql/codegen/couler/template.go | 4 ++-- pkg/sql/executor_ir.go | 6 ++++-- pkg/sql/executor_ir_test.go | 23 ----------------------- scripts/test_couler.sh | 11 +++++++---- 6 files changed, 42 insertions(+), 38 deletions(-) diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index 8fb3568ae3..a5ffc95dfb 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -480,7 +480,7 @@ func TestEnd2EndMaxComputeElasticDL(t *testing.T) { t.Run("CaseTrainElasticDL", CaseTrainElasticDL) } -func TestEnd2EndMaxComputeWorkflow(t *testing.T) { +func TestEnd2EndMySQLWorkflow(t *testing.T) { if testDatasource == "" { t.Fatal("env SQLFLOW_TEST_DATASOURCE is required.") } @@ -489,8 +489,8 @@ func TestEnd2EndMaxComputeWorkflow(t *testing.T) { t.Fatalf("parse datasource failed, %v", err) } - if driverName != "maxcompute" || os.Getenv("SQLFLOW_ARGO_MODE") != "True" { - t.Skip("Skipping workflow test on maxcompute") + if driverName != "mysql" || os.Getenv("SQLFLOW_ARGO_MODE") != "True" { + t.Skip("Skipping workflow test on MySQL") } modelDir := "" @@ -541,6 +541,7 @@ FROM %s.%s LIMIT 5; ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second) defer cancel() stream, err := cli.Run(ctx, &pb.Request{Sql: sqlProgram, Session: &pb.Session{DbConnStr: testDatasource}}) + var workflowID string for { iter, err := stream.Recv() if err == io.EOF { @@ -549,9 +550,24 @@ FROM %s.%s LIMIT 5; if err != nil { log.Fatalf("stream read err: %v", err) } - a.True(strings.HasPrefix(iter.GetJob().GetId(), "sqlflow-couler")) + workflowID = iter.GetJob().GetId() + } + a.True(strings.HasPrefix(workflowID, "sqlflow-couler")) + cmd := exec.Command("kubectl", "get", "wf", workflowID, "-o", "jsonpath='{.status.phase}'") + // check the workflow status in 60 seconods + // TODO(yancey1989): using Fetch gRPC interface to check the workflow status + for i := 0; i < 20; i++ { + out, err := cmd.CombinedOutput() + if err != nil { + log.Fatalf("get workflow status error: %v", err) + } + if string(out) == "Succeeded" { + return + } + time.Sleep(3 * time.Second) } - //TODO(yancey1989) implement Fetch interface to verify the workflow status + // workflow times out + log.Fatalf("workflow: %s times out", workflowID) } func CaseShowDatabases(t *testing.T) { diff --git a/pkg/sql/codegen/couler/codegen.go b/pkg/sql/codegen/couler/codegen.go index 4cc6ba6523..66d9bd125f 100644 --- a/pkg/sql/codegen/couler/codegen.go +++ b/pkg/sql/codegen/couler/codegen.go @@ -16,6 +16,7 @@ package couler import ( "bytes" "fmt" + "os" pb "sqlflow.org/sqlflow/pkg/proto" "sqlflow.org/sqlflow/pkg/sql/ir" @@ -47,8 +48,13 @@ func Run(programIR ir.SQLProgram, session *pb.Session) (string, error) { default: return "", fmt.Errorf("uncognized IR type: %v", i) } - // TODO(yancey1989): using the custom Docker image in model zoo - ss.DockerImage = defaultDockerImage + // NOTE(yancey1989): does not use ModelImage here since the Predict statment + // does not contain the ModelImage field in the current implementation. + if os.Getenv("SQLFLOW_WORKFLOW_DOCKER_IMAGE") != "" { + ss.DockerImage = os.Getenv("SQLFLOW_WORKFLOW_DOCKER_IMAGE") + } else { + ss.DockerImage = defaultDockerImage + } r.SQLStatements = append(r.SQLStatements, ss) } var program bytes.Buffer diff --git a/pkg/sql/codegen/couler/template.go b/pkg/sql/codegen/couler/template.go index c0409cebe2..0969bc19ec 100644 --- a/pkg/sql/codegen/couler/template.go +++ b/pkg/sql/codegen/couler/template.go @@ -30,12 +30,12 @@ import couler.argo as couler datasource = "{{ .DataSource }}" {{ range $ss := .SQLStatements }} {{if $ss.IsExtendedSQL }} -couler.run_container(command='''repl -e "{{ $ss.OriginalSQL }}" --datasource="%s"'''%datasource, image="{{ $ss.DockerImage }}") +couler.run_container(command='''repl -e "{{ $ss.OriginalSQL }}" --datasource="%s"''' % datasource, image="{{ $ss.DockerImage }}") {{else}} # TODO(yancey1989): # using "repl -parse" to output IR and # feed to "sqlflow_submitter.{submitter}.train" to submite the job -couler.run_container(command='''repl -e "{{ $ss.OriginalSQL }}"''', image="{{ $ss.DockerImage }}") +couler.run_container(command='''repl -e "{{ $ss.OriginalSQL }}" --datasource="%s"''' % datasource, image="{{ $ss.DockerImage }}") {{end}} {{end}} ` diff --git a/pkg/sql/executor_ir.go b/pkg/sql/executor_ir.go index fffa174fe3..4799c1b4be 100644 --- a/pkg/sql/executor_ir.go +++ b/pkg/sql/executor_ir.go @@ -206,15 +206,17 @@ func submitWorkflow(wr *PipeWriter, sqlProgram string, modelDir string, session if err != nil { return err } + defer os.RemoveAll(coulerFileName) // 2. compile Couler program into Argo YAML. - argoFile, err := writeArgoFile(coulerFileName) + argoFileName, err := writeArgoFile(coulerFileName) if err != nil { return err } + defer os.RemoveAll(argoFileName) // 3. submit Argo YAML and fetch the workflow ID. - cmd := exec.Command("kubectl", "create", "-f", argoFile) + cmd := exec.Command("kubectl", "create", "-f", argoFileName) output, err := cmd.CombinedOutput() if err != nil { return fmt.Errorf("submit Argo YAML error: %v, output: %s", err, string(output)) diff --git a/pkg/sql/executor_ir_test.go b/pkg/sql/executor_ir_test.go index b32a1226d8..00edc88c16 100644 --- a/pkg/sql/executor_ir_test.go +++ b/pkg/sql/executor_ir_test.go @@ -17,7 +17,6 @@ import ( "fmt" "io/ioutil" "os" - "strings" "testing" "github.com/stretchr/testify/assert" @@ -279,25 +278,3 @@ func TestLogChanWriter_Write(t *testing.T) { _, more := <-c a.False(more) } - -func TestSubmitWorkflow(t *testing.T) { - if os.Getenv("SQLFLOW_ARGO_MODE") != "True" { - t.Skip("argo: skip Argo tests") - } - a := assert.New(t) - modelDir := "" - a.NotPanics(func() { - rd := SubmitWorkflow(testXGBoostTrainSelectIris, modelDir, getDefaultSession()) - for r := range rd.ReadAll() { - switch r.(type) { - case WorkflowJob: - job := r.(WorkflowJob) - a.True(strings.HasPrefix(job.JobID, "sqlflow-couler")) - // TODO(tony): wait to check if job succeeded. - // The workflow is currently failed since we haven't configure the data source. - default: - a.Fail("SubmitWorkflow should return JobID") - } - } - }) -} diff --git a/scripts/test_couler.sh b/scripts/test_couler.sh index 3f6f6bc939..01d661d2d5 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_couler.sh @@ -66,17 +66,20 @@ fi ############# Run SQLFLow test with Argo Mode ############# +if [[ "${TRAVIS}" == "true" ]]; then + export SQLFLOW_WORKFLOW_STEP_IMAGE="sqlflow" +fi # start a SQLFlow MySQL Pod with testdata kubectl run mysql --port 3306 --env="SQLFLOW_MYSQL_HOST=0.0.0.0" --env="SQLFLOW_MYSQL_PORT=3306" --image=sqlflow/sqlflow --command -- bash /start.sh mysql MYSQL_POD_NAME=$(kubectl get pod -l run=mysql -o jsonpath="{.items[0].metadata.name}") for i in {1...30}; do - POD_STATUS=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.phase}') - if [[ "POD_STATUS" == "Running" ]]; then + MYSQL_POD_STATUS=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.phase}') + if [[ "${MYSQL_POD_STATUS}" == "Running" ]]; then echo "SQLFlow MySQL Pod running." + MYSQL_POD_IP=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.podIP}') go generate ./... go install ./... - SQLFLOW_ARGO_MODE=True go test ./pkg/sql/. -run TestSubmitWorkflow -v - go test ./cmd/... -run TestEnd2EndMySQLArgoMode -v + SQLFLOW_TEST_DATASOURCE="mysql://root:root@tcp(${MYSQL_POD_IP}:3306)/?maxAllowedPacket=0" SQLFLOW_ARGO_MODE=True go test ./cmd/... -run TestEnd2EndMySQLWorkflow -v exit 0 else echo "Wait SQLFlow MySQL Pod ${MYSQL_POD_NAME}" From 0cd5a6d487c7a08715d07ce56bdca6fde690d4db Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 09:15:08 +0800 Subject: [PATCH 03/21] fix ci --- cmd/sqlflowserver/main_test.go | 8 +++----- pkg/sql/codegen/couler/codegen_test.go | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index a5ffc95dfb..49a5f62048 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -481,6 +481,9 @@ func TestEnd2EndMaxComputeElasticDL(t *testing.T) { } func TestEnd2EndMySQLWorkflow(t *testing.T) { + if driverName != "mysql" || os.Getenv("SQLFLOW_ARGO_MODE") != "True" { + t.Skip("Skipping workflow test on MySQL") + } if testDatasource == "" { t.Fatal("env SQLFLOW_TEST_DATASOURCE is required.") } @@ -488,11 +491,6 @@ func TestEnd2EndMySQLWorkflow(t *testing.T) { if err != nil { t.Fatalf("parse datasource failed, %v", err) } - - if driverName != "mysql" || os.Getenv("SQLFLOW_ARGO_MODE") != "True" { - t.Skip("Skipping workflow test on MySQL") - } - modelDir := "" tmpDir, caCrt, caKey, err := generateTempCA() defer os.RemoveAll(tmpDir) diff --git a/pkg/sql/codegen/couler/codegen_test.go b/pkg/sql/codegen/couler/codegen_test.go index dedc9338a5..d9d894584c 100644 --- a/pkg/sql/codegen/couler/codegen_test.go +++ b/pkg/sql/codegen/couler/codegen_test.go @@ -20,13 +20,14 @@ import ( "github.com/go-sql-driver/mysql" "github.com/stretchr/testify/assert" + pb "sqlflow.org/sqlflow/pkg/proto" "sqlflow.org/sqlflow/pkg/sql/ir" ) func TestCodegen(t *testing.T) { a := assert.New(t) sqlIR := mockSQLProgramIR() - code, err := Run(sqlIR) + code, err := Run(sqlIR, &pb.Session{}) a.NoError(err) r, _ := regexp.Compile(`repl -e "(.*);"`) From 22d291f6b06d1979a59ded836717831ed85eaf1d Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 13:09:40 +0800 Subject: [PATCH 04/21] fix ci --- cmd/sqlflowserver/main_test.go | 22 +++++++++++----------- scripts/test_couler.sh | 10 +++++++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index 49a5f62048..4fe58f8ef3 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -481,15 +481,15 @@ func TestEnd2EndMaxComputeElasticDL(t *testing.T) { } func TestEnd2EndMySQLWorkflow(t *testing.T) { - if driverName != "mysql" || os.Getenv("SQLFLOW_ARGO_MODE") != "True" { - t.Skip("Skipping workflow test on MySQL") - } - if testDatasource == "" { - t.Fatal("env SQLFLOW_TEST_DATASOURCE is required.") + a := assert.New(t) + if os.Getenv("SQLFLOW_TEST_DATASOURCE") == "" || os.Getenv("SQLFLOW_ARGO_MODE") != "True" { + t.Skip("Skipping workflow test.") } driverName, _, err := sql.SplitDataSource(testDatasource) - if err != nil { - t.Fatalf("parse datasource failed, %v", err) + a.NoError(err) + + if driverName != "mysql" { + t.Skip("Skipping workflow test.") } modelDir := "" tmpDir, caCrt, caKey, err := generateTempCA() @@ -551,10 +551,10 @@ FROM %s.%s LIMIT 5; workflowID = iter.GetJob().GetId() } a.True(strings.HasPrefix(workflowID, "sqlflow-couler")) - cmd := exec.Command("kubectl", "get", "wf", workflowID, "-o", "jsonpath='{.status.phase}'") - // check the workflow status in 60 seconods - // TODO(yancey1989): using Fetch gRPC interface to check the workflow status - for i := 0; i < 20; i++ { + // check the workflow status in 180 seconods + // TODO(yancey1989): using the Fetch gRPC interface to check the workflow status + for i := 0; i < 60; i++ { + cmd := exec.Command("kubectl", "get", "wf", workflowID, "-o", "jsonpath='{.status.phase}'") out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("get workflow status error: %v", err) diff --git a/scripts/test_couler.sh b/scripts/test_couler.sh index 01d661d2d5..0468e36f9e 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_couler.sh @@ -65,15 +65,18 @@ if [[ "$ret" != "0" ]]; then fi ############# Run SQLFLow test with Argo Mode ############# - +set -x +set -e if [[ "${TRAVIS}" == "true" ]]; then export SQLFLOW_WORKFLOW_STEP_IMAGE="sqlflow" fi # start a SQLFlow MySQL Pod with testdata kubectl run mysql --port 3306 --env="SQLFLOW_MYSQL_HOST=0.0.0.0" --env="SQLFLOW_MYSQL_PORT=3306" --image=sqlflow/sqlflow --command -- bash /start.sh mysql MYSQL_POD_NAME=$(kubectl get pod -l run=mysql -o jsonpath="{.items[0].metadata.name}") -for i in {1...30}; do +for i in {1..30} +do MYSQL_POD_STATUS=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.phase}') + echo ${MYSQL_POD_STATUS} if [[ "${MYSQL_POD_STATUS}" == "Running" ]]; then echo "SQLFlow MySQL Pod running." MYSQL_POD_IP=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.podIP}') @@ -83,7 +86,8 @@ for i in {1...30}; do exit 0 else echo "Wait SQLFlow MySQL Pod ${MYSQL_POD_NAME}" - sleep 3 + sleep ${CHECK_INTERVAL_SECS} + continue fi done From 719bbbd9947226a97461a2095231140da656ef05 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 15:22:47 +0800 Subject: [PATCH 05/21] fix ci --- pkg/sql/codegen/couler/codegen.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/sql/codegen/couler/codegen.go b/pkg/sql/codegen/couler/codegen.go index 66d9bd125f..6c30705ff1 100644 --- a/pkg/sql/codegen/couler/codegen.go +++ b/pkg/sql/codegen/couler/codegen.go @@ -50,8 +50,8 @@ func Run(programIR ir.SQLProgram, session *pb.Session) (string, error) { } // NOTE(yancey1989): does not use ModelImage here since the Predict statment // does not contain the ModelImage field in the current implementation. - if os.Getenv("SQLFLOW_WORKFLOW_DOCKER_IMAGE") != "" { - ss.DockerImage = os.Getenv("SQLFLOW_WORKFLOW_DOCKER_IMAGE") + if os.Getenv("SQLFLOW_WORKFLOW_STEP_IMAGE") != "" { + ss.DockerImage = os.Getenv("SQLFLOW_WORKFLOW_STEP_IMAGE") } else { ss.DockerImage = defaultDockerImage } From 86889ce8a6ee1aa5be1917303b331951de45ac74 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 15:42:54 +0800 Subject: [PATCH 06/21] print travis ci env --- scripts/test_couler.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test_couler.sh b/scripts/test_couler.sh index 0468e36f9e..d1f6860763 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_couler.sh @@ -67,6 +67,7 @@ fi ############# Run SQLFLow test with Argo Mode ############# set -x set -e +env if [[ "${TRAVIS}" == "true" ]]; then export SQLFLOW_WORKFLOW_STEP_IMAGE="sqlflow" fi @@ -81,7 +82,6 @@ do echo "SQLFlow MySQL Pod running." MYSQL_POD_IP=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.podIP}') go generate ./... - go install ./... SQLFLOW_TEST_DATASOURCE="mysql://root:root@tcp(${MYSQL_POD_IP}:3306)/?maxAllowedPacket=0" SQLFLOW_ARGO_MODE=True go test ./cmd/... -run TestEnd2EndMySQLWorkflow -v exit 0 else From 24795384dcbbfbea8495514f1d0a00c316b68415 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 16:15:13 +0800 Subject: [PATCH 07/21] use ci sqlflow image --- .travis.yml | 2 +- scripts/test_couler.sh | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 37e8467a47..bed1528b61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,7 +54,7 @@ jobs: script: - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - bash scripts/setup_k8s_env.sh - - docker run --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh + - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh - docker run --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_ipython.sh - docker run -e MAXCOMPUTE_AK=$MAXCOMPUTE_AK -e MAXCOMPUTE_SK=$MAXCOMPUTE_SK --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_maxcompute.sh - env: SQLFLOW_TEST=java diff --git a/scripts/test_couler.sh b/scripts/test_couler.sh index d1f6860763..9592d2a072 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_couler.sh @@ -67,10 +67,6 @@ fi ############# Run SQLFLow test with Argo Mode ############# set -x set -e -env -if [[ "${TRAVIS}" == "true" ]]; then - export SQLFLOW_WORKFLOW_STEP_IMAGE="sqlflow" -fi # start a SQLFlow MySQL Pod with testdata kubectl run mysql --port 3306 --env="SQLFLOW_MYSQL_HOST=0.0.0.0" --env="SQLFLOW_MYSQL_PORT=3306" --image=sqlflow/sqlflow --command -- bash /start.sh mysql MYSQL_POD_NAME=$(kubectl get pod -l run=mysql -o jsonpath="{.items[0].metadata.name}") @@ -87,7 +83,6 @@ do else echo "Wait SQLFlow MySQL Pod ${MYSQL_POD_NAME}" sleep ${CHECK_INTERVAL_SECS} - continue fi done From 1477f8f08f70d7ced4865a3a168ac2bd9414ee2f Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 16:41:04 +0800 Subject: [PATCH 08/21] debug on ci --- cmd/sqlflowserver/main_test.go | 4 ++++ scripts/test_couler.sh | 1 + 2 files changed, 5 insertions(+) diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index 4fe58f8ef3..ab1adda8b1 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -556,6 +556,7 @@ FROM %s.%s LIMIT 5; for i := 0; i < 60; i++ { cmd := exec.Command("kubectl", "get", "wf", workflowID, "-o", "jsonpath='{.status.phase}'") out, err := cmd.CombinedOutput() + fmt.Println(strnig(out)) if err != nil { log.Fatalf("get workflow status error: %v", err) } @@ -563,6 +564,9 @@ FROM %s.%s LIMIT 5; return } time.Sleep(3 * time.Second) + cmd := exec.Command("kubectl", "get", "wf", workflowID, "-o", "json") + out, err := cmd.CombinedOutput() + fmt.Println(strnig(out)) } // workflow times out log.Fatalf("workflow: %s times out", workflowID) diff --git a/scripts/test_couler.sh b/scripts/test_couler.sh index 9592d2a072..6ec9875ea1 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_couler.sh @@ -67,6 +67,7 @@ fi ############# Run SQLFLow test with Argo Mode ############# set -x set -e +env # start a SQLFlow MySQL Pod with testdata kubectl run mysql --port 3306 --env="SQLFLOW_MYSQL_HOST=0.0.0.0" --env="SQLFLOW_MYSQL_PORT=3306" --image=sqlflow/sqlflow --command -- bash /start.sh mysql MYSQL_POD_NAME=$(kubectl get pod -l run=mysql -o jsonpath="{.items[0].metadata.name}") From 77ecd80d675974de42feff8c6289ee307ded269d Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 17:13:24 +0800 Subject: [PATCH 09/21] debug timesout on ci --- cmd/sqlflowserver/main_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index ab1adda8b1..e7d1244edb 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -556,7 +556,7 @@ FROM %s.%s LIMIT 5; for i := 0; i < 60; i++ { cmd := exec.Command("kubectl", "get", "wf", workflowID, "-o", "jsonpath='{.status.phase}'") out, err := cmd.CombinedOutput() - fmt.Println(strnig(out)) + fmt.Println(string(out)) if err != nil { log.Fatalf("get workflow status error: %v", err) } @@ -564,9 +564,9 @@ FROM %s.%s LIMIT 5; return } time.Sleep(3 * time.Second) - cmd := exec.Command("kubectl", "get", "wf", workflowID, "-o", "json") - out, err := cmd.CombinedOutput() - fmt.Println(strnig(out)) + cmd = exec.Command("kubectl", "get", "wf", workflowID, "-o", "json") + out, err = cmd.CombinedOutput() + fmt.Println(string(out)) } // workflow times out log.Fatalf("workflow: %s times out", workflowID) From 78cc8daf53e18317c75d570d80bc867b574311ac Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 19:34:19 +0800 Subject: [PATCH 10/21] debug times out on ci --- .travis.yml | 11 ++++++++--- cmd/sqlflowserver/main_test.go | 2 +- scripts/test_couler.sh | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index bed1528b61..854a95dd70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,13 +54,18 @@ jobs: script: - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - bash scripts/setup_k8s_env.sh - - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh - docker run --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_ipython.sh - docker run -e MAXCOMPUTE_AK=$MAXCOMPUTE_AK -e MAXCOMPUTE_SK=$MAXCOMPUTE_SK --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_maxcompute.sh - env: SQLFLOW_TEST=java script: - - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_java.sh + - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . + - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_java.sh + - env: + - SQLFLOW_TEST_DB=mysql + - SQLFLOW_TEST_WORKFLOW=true + script: + - eval $(minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . + - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh - stage: deploy script: - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index e7d1244edb..496d849a41 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -482,7 +482,7 @@ func TestEnd2EndMaxComputeElasticDL(t *testing.T) { func TestEnd2EndMySQLWorkflow(t *testing.T) { a := assert.New(t) - if os.Getenv("SQLFLOW_TEST_DATASOURCE") == "" || os.Getenv("SQLFLOW_ARGO_MODE") != "True" { + if os.Getenv("SQLFLOW_TEST_DATASOURCE") == "" || strings.ToLower(os.Getenv("SQLFLOW_ARGO_MODE")) != "true" { t.Skip("Skipping workflow test.") } driverName, _, err := sql.SplitDataSource(testDatasource) diff --git a/scripts/test_couler.sh b/scripts/test_couler.sh index 6ec9875ea1..d0981750b5 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_couler.sh @@ -79,7 +79,7 @@ do echo "SQLFlow MySQL Pod running." MYSQL_POD_IP=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.podIP}') go generate ./... - SQLFLOW_TEST_DATASOURCE="mysql://root:root@tcp(${MYSQL_POD_IP}:3306)/?maxAllowedPacket=0" SQLFLOW_ARGO_MODE=True go test ./cmd/... -run TestEnd2EndMySQLWorkflow -v + SQLFLOW_TEST_DATASOURCE="mysql://root:root@tcp(${MYSQL_POD_IP}:3306)/?maxAllowedPacket=0" go test ./cmd/... -run TestEnd2EndMySQLWorkflow -v exit 0 else echo "Wait SQLFlow MySQL Pod ${MYSQL_POD_NAME}" From 8156be48561aea05875b336d7996c3995e669a4d Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 20:02:41 +0800 Subject: [PATCH 11/21] fix workflow ci --- .travis.yml | 6 ++---- scripts/test_couler.sh | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 854a95dd70..91e4a08a85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,11 +60,9 @@ jobs: script: - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_java.sh - - env: - - SQLFLOW_TEST_DB=mysql - - SQLFLOW_TEST_WORKFLOW=true + - env: SQLFLOW_TEST_WORKFLOW=true script: - - eval $(minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . + - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh - stage: deploy script: diff --git a/scripts/test_couler.sh b/scripts/test_couler.sh index d0981750b5..0b5b46cf09 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_couler.sh @@ -14,6 +14,8 @@ set -e +export SQLFLOW_TEST_DB=mysql +export SQLFLOW_TEST_WORKFLOW=true ############# Run Couler unit tests ############# pip install -r python/couler/requirements.txt From d0e94f3420dec892d0d71752cdb11b4ac28ad9a2 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 20:16:15 +0800 Subject: [PATCH 12/21] only run workflow test --- .travis.yml | 58 ++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index 91e4a08a85..539156b2e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,36 +38,40 @@ jobs: - docker run --rm -v $GOPATH/src:/root/go/src -w /root/go/src/sqlflow.org/sqlflow sqlflow/sqlflow:latest go generate ./... && go build ./... && python scripts/copyright.py pkg/sql/extended_syntax_parser.go - docker run --rm -v $GOPATH/src:/root/go/src -w /root/go/src/sqlflow.org/sqlflow sqlflow/sqlflow:latest pre-commit run -a - stage: Unitests - # env is just used for displaying the job type in travis web page - env: SQLFLOW_TEST_DB=mysql - script: - - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_units.sh - - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/upload_coveralls.sh - - # run more parallel tests in the same stage: - env: SQLFLOW_TEST_DB=hive - script: - - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - - docker pull sqlflow/gohive:dev && docker run -d --name=hive sqlflow/gohive:dev python3 -m http.server 8899 - - docker run --rm -v $GOPATH:/root/go --net=container:hive --entrypoint bash -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest scripts/test_hive.sh - - env: SQLFLOW_TEST_DB=maxcompute - script: - - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - - bash scripts/setup_k8s_env.sh - - docker run --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_ipython.sh - - docker run -e MAXCOMPUTE_AK=$MAXCOMPUTE_AK -e MAXCOMPUTE_SK=$MAXCOMPUTE_SK --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_maxcompute.sh - - env: SQLFLOW_TEST=java - script: - - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_java.sh - - env: SQLFLOW_TEST_WORKFLOW=true + env: SQLFLOW_TEST_WORKFLOW=true script: - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh - - stage: deploy - script: - - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - - bash scripts/deploy.sh + # env is just used for displaying the job type in travis web page +# env: SQLFLOW_TEST_DB=mysql +# script: +# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . +# - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_units.sh +# - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/upload_coveralls.sh +# - # run more parallel tests in the same stage: +# env: SQLFLOW_TEST_DB=hive +# script: +# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . +# - docker pull sqlflow/gohive:dev && docker run -d --name=hive sqlflow/gohive:dev python3 -m http.server 8899 +# - docker run --rm -v $GOPATH:/root/go --net=container:hive --entrypoint bash -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest scripts/test_hive.sh +# - env: SQLFLOW_TEST_DB=maxcompute +# script: +# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . +# - bash scripts/setup_k8s_env.sh +# - docker run --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_ipython.sh +# - docker run -e MAXCOMPUTE_AK=$MAXCOMPUTE_AK -e MAXCOMPUTE_SK=$MAXCOMPUTE_SK --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_maxcompute.sh +# - env: SQLFLOW_TEST=java +# script: +# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . +# - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_java.sh +# - env: SQLFLOW_TEST_WORKFLOW=true +# script: +# - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . +# - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh +# - stage: deploy +# script: +# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . +# - bash scripts/deploy.sh env: global: From e0ae7d466f53ecb087c4df0313ebec2270e86634 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 22:36:45 +0800 Subject: [PATCH 13/21] fix ci times out --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 539156b2e3..e8d64eaea4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,6 +41,7 @@ jobs: env: SQLFLOW_TEST_WORKFLOW=true script: - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . + - bash scripts/setup_k8s_env.sh - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh # env is just used for displaying the job type in travis web page # env: SQLFLOW_TEST_DB=mysql From 9649a60a9ceda8f7f0848662216fe53713c15197 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 23:04:37 +0800 Subject: [PATCH 14/21] fix ci... --- cmd/sqlflowserver/main_test.go | 2 +- scripts/test_couler.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index 496d849a41..e873e41fdb 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -482,7 +482,7 @@ func TestEnd2EndMaxComputeElasticDL(t *testing.T) { func TestEnd2EndMySQLWorkflow(t *testing.T) { a := assert.New(t) - if os.Getenv("SQLFLOW_TEST_DATASOURCE") == "" || strings.ToLower(os.Getenv("SQLFLOW_ARGO_MODE")) != "true" { + if os.Getenv("SQLFLOW_TEST_DATASOURCE") == "" || strings.ToLower(os.Getenv("SQLFLOW_TEST_WORKFLOW")) != "true" { t.Skip("Skipping workflow test.") } driverName, _, err := sql.SplitDataSource(testDatasource) diff --git a/scripts/test_couler.sh b/scripts/test_couler.sh index 0b5b46cf09..5029e6da5e 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_couler.sh @@ -14,7 +14,6 @@ set -e -export SQLFLOW_TEST_DB=mysql export SQLFLOW_TEST_WORKFLOW=true ############# Run Couler unit tests ############# pip install -r python/couler/requirements.txt From 8e4b28da0964e26888399405bd23b0c2297d1462 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Thu, 5 Dec 2019 23:27:49 +0800 Subject: [PATCH 15/21] fix ci --- pkg/sql/codegen/couler/codegen.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/sql/codegen/couler/codegen.go b/pkg/sql/codegen/couler/codegen.go index cc0dccb7e2..7a6e895117 100644 --- a/pkg/sql/codegen/couler/codegen.go +++ b/pkg/sql/codegen/couler/codegen.go @@ -44,7 +44,7 @@ func Run(programIR ir.SQLProgram, session *pb.Session) (string, error) { ss.OriginalSQL = sqlIR.(*ir.PredictStmt).OriginalSQL case *ir.AnalyzeStmt: ss.IsExtendedSQL = true - ss.OriginalSQL = sqlIR.(*ir.AnalyzeClause).OriginalSQL + ss.OriginalSQL = sqlIR.(*ir.AnalyzeStmt).OriginalSQL default: return "", fmt.Errorf("uncognized IR type: %v", i) } From 61e1a9dfa539891cb958cb1143e1f8c0ac279197 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Fri, 6 Dec 2019 00:34:58 +0800 Subject: [PATCH 16/21] setup k8s --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e8d64eaea4..a9d5795962 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,8 +40,8 @@ jobs: - stage: Unitests env: SQLFLOW_TEST_WORKFLOW=true script: - - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - bash scripts/setup_k8s_env.sh + - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh # env is just used for displaying the job type in travis web page # env: SQLFLOW_TEST_DB=mysql From 2399b331abe775cdfd91f90f060de5cd79c8d793 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Fri, 6 Dec 2019 00:58:53 +0800 Subject: [PATCH 17/21] fix ci --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a9d5795962..266b7dd431 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,8 +41,8 @@ jobs: env: SQLFLOW_TEST_WORKFLOW=true script: - bash scripts/setup_k8s_env.sh - - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh + - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . && docker tag sqlflow:latest sqlflow:submitter + - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow:submitter -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh # env is just used for displaying the job type in travis web page # env: SQLFLOW_TEST_DB=mysql # script: From 77466bd0a02575e07e1019a10406643009c53bd1 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Fri, 6 Dec 2019 01:28:46 +0800 Subject: [PATCH 18/21] fix workflow timesout on ci --- cmd/sqlflowserver/main_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index acb77edd02..6d98ccea89 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -561,10 +561,11 @@ FROM %s.%s LIMIT 5; for i := 0; i < 60; i++ { cmd := exec.Command("kubectl", "get", "wf", workflowID, "-o", "jsonpath='{.status.phase}'") out, err := cmd.CombinedOutput() - fmt.Println(string(out)) if err != nil { log.Fatalf("get workflow status error: %v", err) } + fmt.Println(string(out)) + fmt.Println(string(out) == "Succeeded") if string(out) == "Succeeded" { return } From 0ad7c8405789f4c17251551988cde4f2f98021b7 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Fri, 6 Dec 2019 09:01:48 +0800 Subject: [PATCH 19/21] fix ci timesout --- cmd/sqlflowserver/main_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index 6d98ccea89..a01b22489b 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -565,8 +565,8 @@ FROM %s.%s LIMIT 5; log.Fatalf("get workflow status error: %v", err) } fmt.Println(string(out)) - fmt.Println(string(out) == "Succeeded") - if string(out) == "Succeeded" { + fmt.Println(string(out) == "'Succeeded'") + if string(out) == "'Succeeded'" { return } time.Sleep(3 * time.Second) From e3a05fb22026422a625046499e84a94549a8aeaa Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Fri, 6 Dec 2019 13:48:52 +0800 Subject: [PATCH 20/21] polish code --- .travis.yml | 60 ++++++++--------- cmd/sqlflowserver/main_test.go | 5 -- scripts/{test_couler.sh => test_workflow.sh} | 71 ++++++++++---------- 3 files changed, 65 insertions(+), 71 deletions(-) rename scripts/{test_couler.sh => test_workflow.sh} (58%) diff --git a/.travis.yml b/.travis.yml index 266b7dd431..83bc28aa87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,41 +38,37 @@ jobs: - docker run --rm -v $GOPATH/src:/root/go/src -w /root/go/src/sqlflow.org/sqlflow sqlflow/sqlflow:latest go generate ./... && go build ./... && python scripts/copyright.py pkg/sql/extended_syntax_parser.go - docker run --rm -v $GOPATH/src:/root/go/src -w /root/go/src/sqlflow.org/sqlflow sqlflow/sqlflow:latest pre-commit run -a - stage: Unitests - env: SQLFLOW_TEST_WORKFLOW=true + # env is just used for displaying the job type in travis web page + env: SQLFLOW_TEST_DB=mysql + script: + - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . + - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_units.sh + - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/upload_coveralls.sh + - # run more parallel tests in the same stage: + env: SQLFLOW_TEST_DB=hive + script: + - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . + - docker pull sqlflow/gohive:dev && docker run -d --name=hive sqlflow/gohive:dev python3 -m http.server 8899 + - docker run --rm -v $GOPATH:/root/go --net=container:hive --entrypoint bash -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest scripts/test_hive.sh + - env: SQLFLOW_TEST_DB=maxcompute + script: + - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . + - bash scripts/setup_k8s_env.sh + - docker run --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_ipython.sh + - docker run -e MAXCOMPUTE_AK=$MAXCOMPUTE_AK -e MAXCOMPUTE_SK=$MAXCOMPUTE_SK --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_maxcompute.sh + - env: SQLFLOW_TEST=java + script: + - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . + - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_java.sh + - env: SQLFLOW_TEST_WORKFLOW=true script: - bash scripts/setup_k8s_env.sh - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . && docker tag sqlflow:latest sqlflow:submitter - - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow:submitter -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh - # env is just used for displaying the job type in travis web page -# env: SQLFLOW_TEST_DB=mysql -# script: -# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . -# - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_units.sh -# - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/upload_coveralls.sh -# - # run more parallel tests in the same stage: -# env: SQLFLOW_TEST_DB=hive -# script: -# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . -# - docker pull sqlflow/gohive:dev && docker run -d --name=hive sqlflow/gohive:dev python3 -m http.server 8899 -# - docker run --rm -v $GOPATH:/root/go --net=container:hive --entrypoint bash -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest scripts/test_hive.sh -# - env: SQLFLOW_TEST_DB=maxcompute -# script: -# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . -# - bash scripts/setup_k8s_env.sh -# - docker run --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_ipython.sh -# - docker run -e MAXCOMPUTE_AK=$MAXCOMPUTE_AK -e MAXCOMPUTE_SK=$MAXCOMPUTE_SK --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_maxcompute.sh -# - env: SQLFLOW_TEST=java -# script: -# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . -# - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_java.sh -# - env: SQLFLOW_TEST_WORKFLOW=true -# script: -# - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . -# - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_couler.sh -# - stage: deploy -# script: -# - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . -# - bash scripts/deploy.sh + - docker run --rm --net=host -e SQLFLOW_WORKFLOW_STEP_IMAGE=sqlflow:submitter -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kube:/root/.kube -v /home/$USER/.minikube/:/home/$USER/.minikube/ -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_workflow.sh + - stage: deploy + script: + - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . + - bash scripts/deploy.sh env: global: diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index a01b22489b..cbec30aba0 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -564,15 +564,10 @@ FROM %s.%s LIMIT 5; if err != nil { log.Fatalf("get workflow status error: %v", err) } - fmt.Println(string(out)) - fmt.Println(string(out) == "'Succeeded'") if string(out) == "'Succeeded'" { return } time.Sleep(3 * time.Second) - cmd = exec.Command("kubectl", "get", "wf", workflowID, "-o", "json") - out, err = cmd.CombinedOutput() - fmt.Println(string(out)) } // workflow times out log.Fatalf("workflow: %s times out", workflowID) diff --git a/scripts/test_couler.sh b/scripts/test_workflow.sh similarity index 58% rename from scripts/test_couler.sh rename to scripts/test_workflow.sh index 5029e6da5e..e1db244f89 100644 --- a/scripts/test_couler.sh +++ b/scripts/test_workflow.sh @@ -30,12 +30,9 @@ function test_couler() { import couler.argo as couler couler.run_container(image="docker/whalesay", command='echo "SQLFlow bridges AI and SQL engine."') EOF - - + couler run --mode argo --file /tmp/sqlflow_couler.py > /tmp/sqlflow_argo.yaml - MESSAGE=$(kubectl create -f /tmp/sqlflow_argo.yaml) - WORKFLOW_NAME=$(echo ${MESSAGE} | cut -d ' ' -f 1 | cut -d '/' -f 2) echo WORKFLOW_NAME ${WORKFLOW_NAME} @@ -56,37 +53,43 @@ EOF return 1 } -test_couler -ret=$? +function check_ret() { + ret=$1 + message=$2 + echo $ret $message + if [[ "$ret" != "0" ]]; then + echo $message + exit 1 + fi +} -if [[ "$ret" != "0" ]]; then - echo "Argo job timed out." - rm -rf /tmp/sqlflow* - exit 1 -fi +test_couler +check_ret $? "Test Couler failed" ############# Run SQLFLow test with Argo Mode ############# -set -x -set -e -env -# start a SQLFlow MySQL Pod with testdata -kubectl run mysql --port 3306 --env="SQLFLOW_MYSQL_HOST=0.0.0.0" --env="SQLFLOW_MYSQL_PORT=3306" --image=sqlflow/sqlflow --command -- bash /start.sh mysql -MYSQL_POD_NAME=$(kubectl get pod -l run=mysql -o jsonpath="{.items[0].metadata.name}") -for i in {1..30} -do - MYSQL_POD_STATUS=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.phase}') - echo ${MYSQL_POD_STATUS} - if [[ "${MYSQL_POD_STATUS}" == "Running" ]]; then - echo "SQLFlow MySQL Pod running." - MYSQL_POD_IP=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.podIP}') - go generate ./... - SQLFLOW_TEST_DATASOURCE="mysql://root:root@tcp(${MYSQL_POD_IP}:3306)/?maxAllowedPacket=0" go test ./cmd/... -run TestEnd2EndMySQLWorkflow -v - exit 0 - else - echo "Wait SQLFlow MySQL Pod ${MYSQL_POD_NAME}" - sleep ${CHECK_INTERVAL_SECS} - fi -done +function test_workflow() { + # start a SQLFlow MySQL Pod with testdata + kubectl run mysql --port 3306 --env="SQLFLOW_MYSQL_HOST=0.0.0.0" --env="SQLFLOW_MYSQL_PORT=3306" --image=sqlflow/sqlflow --command -- bash /start.sh mysql + MYSQL_POD_NAME=$(kubectl get pod -l run=mysql -o jsonpath="{.items[0].metadata.name}") + + for i in {1..30} + do + MYSQL_POD_STATUS=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.phase}') + echo ${MYSQL_POD_STATUS} + if [[ "${MYSQL_POD_STATUS}" == "Running" ]]; then + echo "SQLFlow MySQL Pod running." + MYSQL_POD_IP=$(kubectl get pod ${MYSQL_POD_NAME} -o jsonpath='{.status.podIP}') + go generate ./... + SQLFLOW_TEST_DATASOURCE="mysql://root:root@tcp(${MYSQL_POD_IP}:3306)/?maxAllowedPacket=0" go test ./cmd/... -run TestEnd2EndMySQLWorkflow -v + return 0 + else + echo "Wait SQLFlow MySQL Pod ${MYSQL_POD_NAME}" + sleep ${CHECK_INTERVAL_SECS} + fi + done + echo "Launch SQLFlow MySQL Pod times out" + return 1 +} -echo "Start SQLFlow MySQL Pod failed." -exit 1 \ No newline at end of file +test_workflow +check_ret $? "Test SQLFLow workflow failed" \ No newline at end of file From f116baa5bc3e008b61e0d40654bb94fbae9755a5 Mon Sep 17 00:00:00 2001 From: Yancey1989 Date: Fri, 6 Dec 2019 14:56:59 +0800 Subject: [PATCH 21/21] follow comment --- .travis.yml | 2 +- cmd/sqlflowserver/main_test.go | 2 +- pkg/sql/codegen/couler/codegen.go | 2 +- pkg/sql/database.go | 3 +++ pkg/sql/executor_ir.go | 2 +- scripts/test_workflow.sh | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 83bc28aa87..08852baf60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,7 +60,7 @@ jobs: script: - docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . - docker run --rm -v $GOPATH:/root/go -w /root/go/src/sqlflow.org/sqlflow sqlflow:latest bash scripts/test_java.sh - - env: SQLFLOW_TEST_WORKFLOW=true + - env: SQLFLOW_TEST=workflow script: - bash scripts/setup_k8s_env.sh - eval $(sudo minikube docker-env) && docker pull sqlflow/sqlflow:latest && docker build --cache-from sqlflow/sqlflow:latest -t sqlflow:latest -f Dockerfile . && docker tag sqlflow:latest sqlflow:submitter diff --git a/cmd/sqlflowserver/main_test.go b/cmd/sqlflowserver/main_test.go index cbec30aba0..5a9c7140dd 100644 --- a/cmd/sqlflowserver/main_test.go +++ b/cmd/sqlflowserver/main_test.go @@ -487,7 +487,7 @@ func TestEnd2EndMaxComputeElasticDL(t *testing.T) { func TestEnd2EndMySQLWorkflow(t *testing.T) { a := assert.New(t) - if os.Getenv("SQLFLOW_TEST_DATASOURCE") == "" || strings.ToLower(os.Getenv("SQLFLOW_TEST_WORKFLOW")) != "true" { + if os.Getenv("SQLFLOW_TEST_DATASOURCE") == "" || strings.ToLower(os.Getenv("SQLFLOW_TEST")) != "workflow" { t.Skip("Skipping workflow test.") } driverName, _, err := sql.SplitDataSource(testDatasource) diff --git a/pkg/sql/codegen/couler/codegen.go b/pkg/sql/codegen/couler/codegen.go index 7a6e895117..492badb48d 100644 --- a/pkg/sql/codegen/couler/codegen.go +++ b/pkg/sql/codegen/couler/codegen.go @@ -49,7 +49,7 @@ func Run(programIR ir.SQLProgram, session *pb.Session) (string, error) { return "", fmt.Errorf("uncognized IR type: %v", i) } // NOTE(yancey1989): does not use ModelImage here since the Predict statment - // does not contain the ModelImage field in the current implementation. + // does not contain the ModelImage field in SQL Program IR. if os.Getenv("SQLFLOW_WORKFLOW_STEP_IMAGE") != "" { ss.DockerImage = os.Getenv("SQLFLOW_WORKFLOW_STEP_IMAGE") } else { diff --git a/pkg/sql/database.go b/pkg/sql/database.go index 2dce78039d..b424d93bab 100644 --- a/pkg/sql/database.go +++ b/pkg/sql/database.go @@ -65,6 +65,9 @@ func openDB(db *DB) error { // SplitDataSource splits the datasource into drivername and datasource name func SplitDataSource(datasource string) (string, string, error) { + if datasource == "" { + return "", "", fmt.Errorf("datasource should not be an empty string") + } dses := strings.Split(datasource, "://") if len(dses) != 2 { return "", "", fmt.Errorf("Expecting but cannot find :// in datasource %v", datasource) diff --git a/pkg/sql/executor_ir.go b/pkg/sql/executor_ir.go index bae90b00ff..d8aa24443c 100644 --- a/pkg/sql/executor_ir.go +++ b/pkg/sql/executor_ir.go @@ -48,7 +48,7 @@ func RunSQLProgram(sqlProgram string, modelDir string, session *pb.Session) *Pip var db *DB var err error if db, err = NewDB(session.DbConnStr); err != nil { - wr.Write(fmt.Sprintf("create DB failed: %v", err)) + wr.Write(fmt.Errorf("create DB failed: %v", err)) log.Errorf("create DB failed: %v", err) } defer wr.Close() diff --git a/scripts/test_workflow.sh b/scripts/test_workflow.sh index e1db244f89..8117f07fbc 100644 --- a/scripts/test_workflow.sh +++ b/scripts/test_workflow.sh @@ -14,7 +14,7 @@ set -e -export SQLFLOW_TEST_WORKFLOW=true +export SQLFLOW_TEST=workflow ############# Run Couler unit tests ############# pip install -r python/couler/requirements.txt