Skip to content

Commit

Permalink
move name (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
IronPan authored and k8s-ci-robot committed Dec 8, 2018
1 parent ee8c38f commit 9eee2bb
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 97 deletions.
117 changes: 59 additions & 58 deletions backend/api/go_client/pipeline.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions backend/api/go_client/pipeline.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions backend/api/go_http_client/pipeline_model/api_pipeline.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions backend/api/pipeline.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ service PipelineService {
rpc CreatePipeline(CreatePipelineRequest) returns (Pipeline) {
option (google.api.http) = {
post: "/apis/v1beta1/pipelines"
body: "url"
body: "pipeline"
};
}

Expand Down Expand Up @@ -97,8 +97,7 @@ message Url{
// and optionally a pipeline name. If name is not provided, file name is used as
// pipeline name by default. Maximum size of 32MB is supported.
message CreatePipelineRequest{
Url url = 1;
string name = 2;
Pipeline pipeline = 1;
}

message GetPipelineRequest {
Expand Down Expand Up @@ -136,6 +135,7 @@ message Pipeline{
string name = 3;
string description = 4;
repeated Parameter parameters = 5;
Url url = 7;

// In case any error happens retrieving a pipeline field, only pipeline ID
// and the error message is returned. Client has the flexibility of choosing
Expand Down
5 changes: 4 additions & 1 deletion backend/api/swagger/pipeline.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/apiUrl"
"$ref": "#/definitions/apiPipeline"
}
}
],
Expand Down Expand Up @@ -234,6 +234,9 @@
"$ref": "#/definitions/apiParameter"
}
},
"url": {
"$ref": "#/definitions/apiUrl"
},
"error": {
"type": "string",
"description": "In case any error happens retrieving a pipeline field, only pipeline ID\nand the error message is returned. Client has the flexibility of choosing\nhow to handle error. This is especially useful during listing call."
Expand Down
16 changes: 9 additions & 7 deletions backend/src/apiserver/server/pipeline_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ func (s *PipelineServer) CreatePipeline(ctx context.Context, request *api.Create
return nil, err
}

resp, err := s.httpClient.Get(request.Url.PipelineUrl)
pipelineUrl := request.Pipeline.Url.PipelineUrl
resp, err := s.httpClient.Get(pipelineUrl)
if err != nil || resp.StatusCode != http.StatusOK {
return nil, util.NewInternalServerError(err, "Failed to download the pipeline from %v "+
"Please double check the URL is valid and can be accessed by the pipeline system.", request.Url.PipelineUrl)
"Please double check the URL is valid and can be accessed by the pipeline system.", pipelineUrl)
}
pipelineFileName := path.Base(request.Url.PipelineUrl)
pipelineFileName := path.Base(pipelineUrl)
pipelineFile, err := ReadPipelineFile(pipelineFileName, resp.Body, MaxFileLength)
if err != nil {
return nil, util.Wrap(err, "The URL is valid but pipeline system failed to read the file.")
}

pipelineName, err := GetPipelineName(request.Name, pipelineFileName)
pipelineName, err := GetPipelineName(request.Pipeline.Name, pipelineFileName)
if err != nil {
return nil, util.Wrap(err, "Invalid pipeline name.")
}
Expand Down Expand Up @@ -103,12 +104,13 @@ func (s *PipelineServer) GetTemplate(ctx context.Context, request *api.GetTempla
}

func ValidateCreatePipelineRequest(request *api.CreatePipelineRequest) error {
if request.Url == nil || request.Url.PipelineUrl == "" {
if request.Pipeline.Url == nil || request.Pipeline.Url.PipelineUrl == "" {
return util.NewInvalidInputError("Pipeline URL is empty. Please specify a valid URL.")
}

if _, err := url.ParseRequestURI(request.Url.PipelineUrl); err != nil {
return util.NewInvalidInputError("Invalid Pipeline URL %v. Please specify a valid URL", request.Url.PipelineUrl)
if _, err := url.ParseRequestURI(request.Pipeline.Url.PipelineUrl); err != nil {
return util.NewInvalidInputError(
"Invalid Pipeline URL %v. Please specify a valid URL", request.Pipeline.Url.PipelineUrl)
}
return nil
}
Expand Down
21 changes: 16 additions & 5 deletions backend/src/apiserver/server/pipeline_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ func TestCreatePipeline_YAML(t *testing.T) {

pipelineServer := PipelineServer{resourceManager: resourceManager, httpClient: httpServer.Client()}
pipeline, err := pipelineServer.CreatePipeline(context.Background(), &api.CreatePipelineRequest{
Url: &api.Url{PipelineUrl: httpServer.URL + "/arguments-parameters.yaml"}, Name: "argument-parameters"})
Pipeline: &api.Pipeline{
Url:&api.Url{PipelineUrl: httpServer.URL + "/arguments-parameters.yaml"},
Name:"argument-parameters",
}})

assert.Nil(t, err)
assert.NotNil(t, pipeline)
Expand All @@ -50,7 +53,10 @@ func TestCreatePipeline_Tarball(t *testing.T) {

pipelineServer := PipelineServer{resourceManager: resourceManager, httpClient: httpServer.Client()}
pipeline, err := pipelineServer.CreatePipeline(context.Background(), &api.CreatePipelineRequest{
Url: &api.Url{PipelineUrl: httpServer.URL + "/arguments_tarball/arguments.tar.gz"}, Name: "argument-parameters"})
Pipeline: &api.Pipeline{
Url:&api.Url{PipelineUrl: httpServer.URL + "/arguments_tarball/arguments.tar.gz"},
Name:"argument-parameters",
}})

assert.Nil(t, err)
assert.NotNil(t, pipeline)
Expand All @@ -74,7 +80,10 @@ func TestCreatePipeline_InvalidYAML(t *testing.T) {

pipelineServer := PipelineServer{resourceManager: resourceManager, httpClient: httpServer.Client()}
_, err := pipelineServer.CreatePipeline(context.Background(), &api.CreatePipelineRequest{
Url: &api.Url{PipelineUrl: httpServer.URL + "/invalid-workflow.yaml"}, Name: "argument-parameters"})
Pipeline: &api.Pipeline{
Url:&api.Url{PipelineUrl: httpServer.URL + "/invalid-workflow.yaml"},
Name:"argument-parameters",
}})

assert.NotNil(t, err)
assert.Equal(t, codes.InvalidArgument, err.(*util.UserError).ExternalStatusCode())
Expand All @@ -91,8 +100,10 @@ func TestCreatePipeline_InvalidURL(t *testing.T) {

pipelineServer := PipelineServer{resourceManager: resourceManager, httpClient: httpServer.Client()}
_, err := pipelineServer.CreatePipeline(context.Background(), &api.CreatePipelineRequest{
Url: &api.Url{PipelineUrl: httpServer.URL + "/invalid-workflow.yaml"}, Name: "argument-parameters"})

Pipeline: &api.Pipeline{
Url:&api.Url{PipelineUrl: httpServer.URL + "/invalid-workflow.yaml"},
Name:"argument-parameters",
}})
assert.Equal(t, codes.Internal, err.(*util.UserError).ExternalStatusCode())
}

Expand Down
Loading

0 comments on commit 9eee2bb

Please sign in to comment.