Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

#patch Update FromWorkflowModel API #617

Merged
merged 7 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/manager/impl/testutils/mock_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,7 @@ func GetWorkflowRequestInterfaceBytes() []byte {
bytes, _ := proto.Marshal(GetWorkflowRequest().Spec.Template.Interface)
return bytes
}

func GetWorkflowRequestInterface() *core.TypedInterface {
return GetWorkflowRequest().Spec.Template.Interface
}
7 changes: 7 additions & 0 deletions pkg/manager/impl/workflow_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ func TestListWorkflows(t *testing.T) {
assert.Equal(t, fmt.Sprintf("version %v", idx), workflow.Id.Version)
assert.True(t, proto.Equal(&admin.WorkflowClosure{
CreatedAt: testutils.MockCreatedAtProto,
CompiledWorkflow: &core.CompiledWorkflowClosure{
Primary: &core.CompiledWorkflow{
Template: &core.WorkflowTemplate{
Interface: &core.TypedInterface{},
},
},
},
}, workflow.Closure))
}
assert.Empty(t, workflowList.Token)
Expand Down
17 changes: 17 additions & 0 deletions pkg/repositories/transformers/workflow.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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"
Expand Down Expand Up @@ -47,11 +49,26 @@
return admin.Workflow{}, errors.NewFlyteAdminErrorf(codes.Internal, "failed to read created at timestamp")
}

var workflowInterface core.TypedInterface
if 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 interface. Error message: %v", workflowModel.ID, err.Error()))
}

Check warning on line 57 in pkg/repositories/transformers/workflow.go

View check run for this annotation

Codecov / codecov/patch

pkg/repositories/transformers/workflow.go#L56-L57

Added lines #L56 - L57 were not covered by tests
}

// 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
Expand Down
30 changes: 30 additions & 0 deletions pkg/repositories/transformers/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,20 @@ func TestFromWorkflowModel(t *testing.T) {
Name: "name",
Version: "version",
}, workflow.Id))

var workflowInterface core.TypedInterface
squiishyy marked this conversation as resolved.
Show resolved Hide resolved
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))
}

Expand Down Expand Up @@ -122,8 +134,18 @@ func TestFromWorkflowModels(t *testing.T) {
Version: "version a",
}, workflowList[0].Id))

workflowInterface := testutils.GetWorkflowRequestInterface()
assert.NoError(t, err)

assert.True(t, proto.Equal(&admin.WorkflowClosure{
CreatedAt: createdAtAProto,
CompiledWorkflow: &core.CompiledWorkflowClosure{
Primary: &core.CompiledWorkflow{
Template: &core.WorkflowTemplate{
Interface: workflowInterface,
},
},
},
}, workflowList[0].Closure))

assert.True(t, proto.Equal(&core.Identifier{
Expand All @@ -133,7 +155,15 @@ func TestFromWorkflowModels(t *testing.T) {
Name: "name b",
Version: "version b",
}, workflowList[1].Id))

assert.True(t, proto.Equal(&admin.WorkflowClosure{
CreatedAt: createdAtBProto,
CompiledWorkflow: &core.CompiledWorkflowClosure{
Primary: &core.CompiledWorkflow{
Template: &core.WorkflowTemplate{
Interface: &core.TypedInterface{},
},
},
},
}, workflowList[1].Closure))
}
Loading