Skip to content

Commit

Permalink
fix list run (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
IronPan authored and k8s-ci-robot committed Dec 21, 2018
1 parent e182e37 commit 66d238d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
12 changes: 6 additions & 6 deletions backend/src/apiserver/resource/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,16 +754,16 @@ func TestReportWorkflowResource_ScheduledWorkflowIDNotEmpty_Success(t *testing.T
{
ResourceUUID: "WORKFLOW_1",
ResourceType: common.Run,
ReferenceUUID: DefaultFakeUUID,
ReferenceType: common.Experiment,
Relationship: common.Owner,
ReferenceUUID: job.UUID,
ReferenceType: common.Job,
Relationship: common.Creator,
},
{
ResourceUUID: "WORKFLOW_1",
ResourceType: common.Run,
ReferenceUUID: job.UUID,
ReferenceType: common.Job,
Relationship: common.Creator,
ReferenceUUID: DefaultFakeUUID,
ReferenceType: common.Experiment,
Relationship: common.Owner,
},
},
},
Expand Down
50 changes: 49 additions & 1 deletion backend/src/apiserver/server/run_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/golang/protobuf/ptypes/timestamp"
api "github.com/kubeflow/pipelines/backend/api/go_client"
"github.com/kubeflow/pipelines/backend/api/go_client"
"github.com/kubeflow/pipelines/backend/src/common/util"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -55,6 +55,54 @@ func TestCreateRun(t *testing.T) {
assert.Equal(t, expectedRunDetail, *runDetail)
}

func TestListRun(t *testing.T) {
clients, manager, experiment := initWithExperiment(t)
defer clients.Close()
server := NewRunServer(manager)
run := &api.Run{
Name: "123",
ResourceReferences: validReference,
PipelineSpec: &api.PipelineSpec{
WorkflowManifest: testWorkflow.ToStringForStore(),
Parameters: []*api.Parameter{{Name: "param1", Value: "world"}},
},
}
_, err := server.CreateRun(nil, &api.CreateRunRequest{Run: run})
assert.Nil(t, err)

expectedRun := &api.Run{
Id: "workflow1",
Name: "123",
StorageState: api.Run_STORAGESTATE_AVAILABLE,
CreatedAt: &timestamp.Timestamp{Seconds: 2},
ScheduledAt: &timestamp.Timestamp{},
PipelineSpec: &api.PipelineSpec{
WorkflowManifest: testWorkflow.ToStringForStore(),
Parameters: []*api.Parameter{{Name: "param1", Value: "world"}},
},
ResourceReferences: []*api.ResourceReference{
{
Key: &api.ResourceKey{Type: api.ResourceType_EXPERIMENT, Id: experiment.UUID},
Relationship: api.Relationship_OWNER,
},
},
}
listRunsResponse, err := server.ListRuns(nil, &api.ListRunsRequest{})
assert.Equal(t, expectedRun, listRunsResponse.Runs[0])

run2 := &api.Run{
Name: "456",
PipelineSpec: &api.PipelineSpec{
WorkflowManifest: testWorkflow2.ToStringForStore(),
Parameters: []*api.Parameter{{Name: "param1", Value: "world"}},
},
}
_, err = server.CreateRun(nil, &api.CreateRunRequest{Run: run2})
assert.Nil(t, err)
listRunsResponse, err = server.ListRuns(nil, &api.ListRunsRequest{})
assert.Equal(t, 2, len(listRunsResponse.Runs))
}

func TestValidateCreateRunRequest(t *testing.T) {
clients, manager, _ := initWithExperiment(t)
defer clients.Close()
Expand Down
6 changes: 6 additions & 0 deletions backend/src/apiserver/server/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ var testWorkflow = util.NewWorkflow(&v1alpha1.Workflow{
Spec: v1alpha1.WorkflowSpec{Arguments: v1alpha1.Arguments{Parameters: []v1alpha1.Parameter{{Name: "param1"}}}},
})

var testWorkflow2 = util.NewWorkflow(&v1alpha1.Workflow{
TypeMeta: v1.TypeMeta{APIVersion: "argoproj.io/v1alpha1", Kind: "Workflow"},
ObjectMeta: v1.ObjectMeta{Name: "workflow-name", UID: "workflow2"},
Spec: v1alpha1.WorkflowSpec{Arguments: v1alpha1.Arguments{Parameters: []v1alpha1.Parameter{{Name: "param1"}}}},
})

var validReference = []*api.ResourceReference{
{
Key: &api.ResourceKey{
Expand Down
4 changes: 2 additions & 2 deletions backend/src/apiserver/storage/job_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (s *JobStore) selectJob() sq.SelectBuilder {
Select("jobs.*", resourceRefConcatQuery+" AS refs").
From("jobs").
// Append all the resource references for the run as a json column
LeftJoin("resource_references AS r ON jobs.UUID=r.ResourceUUID").
Where(sq.Eq{"r.ResourceType": common.Job}).GroupBy("jobs.UUID")
LeftJoin("(select * from resource_references where ResourceType='Job') AS r ON jobs.UUID=r.ResourceUUID").
GroupBy("jobs.UUID")
}

func (s *JobStore) scanRows(r *sql.Rows) ([]*model.Job, error) {
Expand Down
3 changes: 1 addition & 2 deletions backend/src/apiserver/storage/run_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ func (s *RunStore) selectRunDetails() sq.SelectBuilder {
Select("subq.*", resourceRefConcatQuery+" AS refs").
FromSelect(subQ, "subq").
// Append all the resource references for the run as a json column
LeftJoin("resource_references AS r ON subq.UUID=r.ResourceUUID").
Where(sq.Eq{"r.ResourceType": common.Run}).
LeftJoin("(select * from resource_references where ResourceType='Run') AS r ON subq.UUID=r.ResourceUUID").
GroupBy("subq.UUID")
}

Expand Down

0 comments on commit 66d238d

Please sign in to comment.