From ed9e9d37efe50d8bdcbd0a22d1a17a13b9e5f8df Mon Sep 17 00:00:00 2001 From: Joe Eschen Date: Fri, 22 Sep 2023 14:24:47 -0700 Subject: [PATCH] update FromWorkflowModel call to include typed interface in response object. updated tests Signed-off-by: Guest Account --- pkg/repositories/transformers/workflow.go | 16 +++++++++ .../transformers/workflow_test.go | 36 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/pkg/repositories/transformers/workflow.go b/pkg/repositories/transformers/workflow.go index ce9b75e00..c45bdc501 100644 --- a/pkg/repositories/transformers/workflow.go +++ b/pkg/repositories/transformers/workflow.go @@ -1,6 +1,7 @@ package transformers import ( + "fmt" "github.com/flyteorg/flyteadmin/pkg/errors" "github.com/flyteorg/flyteadmin/pkg/repositories/models" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" @@ -47,11 +48,26 @@ func FromWorkflowModel(workflowModel models.Workflow) (admin.Workflow, error) { return admin.Workflow{}, errors.NewFlyteAdminErrorf(codes.Internal, "failed to read created at timestamp") } + var workflowInterface core.TypedInterface + if workflowModel.TypedInterface != nil && len(workflowModel.TypedInterface) > 0 { + err = proto.Unmarshal(workflowModel.TypedInterface, &workflowInterface) + if err != nil { + return admin.Workflow{}, errors.NewFlyteAdminErrorf(codes.Internal, fmt.Sprintf("failed to unmarshal workflow %v inputs", workflowModel.ID)) + } + } + // Because the spec if offloaded, it is not populated in the model returned here. return admin.Workflow{ Id: &id, Closure: &admin.WorkflowClosure{ CreatedAt: createdAt, + CompiledWorkflow: &core.CompiledWorkflowClosure{ + Primary: &core.CompiledWorkflow{ + Template: &core.WorkflowTemplate{ + Interface: &workflowInterface, + }, + }, + }, }, ShortDescription: workflowModel.ShortDescription, }, nil diff --git a/pkg/repositories/transformers/workflow_test.go b/pkg/repositories/transformers/workflow_test.go index 282bd6c7a..916a01763 100644 --- a/pkg/repositories/transformers/workflow_test.go +++ b/pkg/repositories/transformers/workflow_test.go @@ -72,8 +72,20 @@ func TestFromWorkflowModel(t *testing.T) { Name: "name", Version: "version", }, workflow.Id)) + + var workflowInterface core.TypedInterface + err = proto.Unmarshal(workflowModel.TypedInterface, &workflowInterface) + assert.NoError(t, err) + assert.True(t, proto.Equal(&admin.WorkflowClosure{ CreatedAt: createdAtProto, + CompiledWorkflow: &core.CompiledWorkflowClosure{ + Primary: &core.CompiledWorkflow{ + Template: &core.WorkflowTemplate{ + Interface: &workflowInterface, + }, + }, + }, }, workflow.Closure)) } @@ -122,8 +134,19 @@ func TestFromWorkflowModels(t *testing.T) { Version: "version a", }, workflowList[0].Id)) + var workflowInterface0 core.TypedInterface + err = proto.Unmarshal(workflowModels[0].TypedInterface, &workflowInterface0) + assert.NoError(t, err) + assert.True(t, proto.Equal(&admin.WorkflowClosure{ CreatedAt: createdAtAProto, + CompiledWorkflow: &core.CompiledWorkflowClosure{ + Primary: &core.CompiledWorkflow{ + Template: &core.WorkflowTemplate{ + Interface: &workflowInterface0, + }, + }, + }, }, workflowList[0].Closure)) assert.True(t, proto.Equal(&core.Identifier{ @@ -133,7 +156,20 @@ func TestFromWorkflowModels(t *testing.T) { Name: "name b", Version: "version b", }, workflowList[1].Id)) + + // Expected to be nil + var workflowInterface1 core.TypedInterface + err = proto.Unmarshal(workflowModels[1].TypedInterface, &workflowInterface1) + assert.NoError(t, err) + assert.True(t, proto.Equal(&admin.WorkflowClosure{ CreatedAt: createdAtBProto, + CompiledWorkflow: &core.CompiledWorkflowClosure{ + Primary: &core.CompiledWorkflow{ + Template: &core.WorkflowTemplate{ + Interface: &workflowInterface1, + }, + }, + }, }, workflowList[1].Closure)) }