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

Commit af81751

Browse files
authored
#patch Update FromWorkflowModel API (#617)
1 parent dc8cc9d commit af81751

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

pkg/manager/impl/testutils/mock_requests.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,7 @@ func GetWorkflowRequestInterfaceBytes() []byte {
300300
bytes, _ := proto.Marshal(GetWorkflowRequest().Spec.Template.Interface)
301301
return bytes
302302
}
303+
304+
func GetWorkflowRequestInterface() *core.TypedInterface {
305+
return GetWorkflowRequest().Spec.Template.Interface
306+
}

pkg/manager/impl/workflow_manager_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ func TestListWorkflows(t *testing.T) {
454454
assert.Equal(t, fmt.Sprintf("version %v", idx), workflow.Id.Version)
455455
assert.True(t, proto.Equal(&admin.WorkflowClosure{
456456
CreatedAt: testutils.MockCreatedAtProto,
457+
CompiledWorkflow: &core.CompiledWorkflowClosure{
458+
Primary: &core.CompiledWorkflow{
459+
Template: &core.WorkflowTemplate{
460+
Interface: &core.TypedInterface{},
461+
},
462+
},
463+
},
457464
}, workflow.Closure))
458465
}
459466
assert.Empty(t, workflowList.Token)

pkg/repositories/transformers/workflow.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package transformers
22

33
import (
4+
"fmt"
5+
46
"github.com/flyteorg/flyteadmin/pkg/errors"
57
"github.com/flyteorg/flyteadmin/pkg/repositories/models"
68
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
@@ -47,11 +49,26 @@ func FromWorkflowModel(workflowModel models.Workflow) (admin.Workflow, error) {
4749
return admin.Workflow{}, errors.NewFlyteAdminErrorf(codes.Internal, "failed to read created at timestamp")
4850
}
4951

52+
var workflowInterface core.TypedInterface
53+
if len(workflowModel.TypedInterface) > 0 {
54+
err = proto.Unmarshal(workflowModel.TypedInterface, &workflowInterface)
55+
if err != nil {
56+
return admin.Workflow{}, errors.NewFlyteAdminErrorf(codes.Internal, fmt.Sprintf("failed to unmarshal workflow %v interface. Error message: %v", workflowModel.ID, err.Error()))
57+
}
58+
}
59+
5060
// Because the spec if offloaded, it is not populated in the model returned here.
5161
return admin.Workflow{
5262
Id: &id,
5363
Closure: &admin.WorkflowClosure{
5464
CreatedAt: createdAt,
65+
CompiledWorkflow: &core.CompiledWorkflowClosure{
66+
Primary: &core.CompiledWorkflow{
67+
Template: &core.WorkflowTemplate{
68+
Interface: &workflowInterface,
69+
},
70+
},
71+
},
5572
},
5673
ShortDescription: workflowModel.ShortDescription,
5774
}, nil

pkg/repositories/transformers/workflow_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,20 @@ func TestFromWorkflowModel(t *testing.T) {
7272
Name: "name",
7373
Version: "version",
7474
}, workflow.Id))
75+
76+
var workflowInterface core.TypedInterface
77+
err = proto.Unmarshal(workflowModel.TypedInterface, &workflowInterface)
78+
assert.NoError(t, err)
79+
7580
assert.True(t, proto.Equal(&admin.WorkflowClosure{
7681
CreatedAt: createdAtProto,
82+
CompiledWorkflow: &core.CompiledWorkflowClosure{
83+
Primary: &core.CompiledWorkflow{
84+
Template: &core.WorkflowTemplate{
85+
Interface: &workflowInterface,
86+
},
87+
},
88+
},
7789
}, workflow.Closure))
7890
}
7991

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

137+
workflowInterface := testutils.GetWorkflowRequestInterface()
138+
assert.NoError(t, err)
139+
125140
assert.True(t, proto.Equal(&admin.WorkflowClosure{
126141
CreatedAt: createdAtAProto,
142+
CompiledWorkflow: &core.CompiledWorkflowClosure{
143+
Primary: &core.CompiledWorkflow{
144+
Template: &core.WorkflowTemplate{
145+
Interface: workflowInterface,
146+
},
147+
},
148+
},
127149
}, workflowList[0].Closure))
128150

129151
assert.True(t, proto.Equal(&core.Identifier{
@@ -133,7 +155,15 @@ func TestFromWorkflowModels(t *testing.T) {
133155
Name: "name b",
134156
Version: "version b",
135157
}, workflowList[1].Id))
158+
136159
assert.True(t, proto.Equal(&admin.WorkflowClosure{
137160
CreatedAt: createdAtBProto,
161+
CompiledWorkflow: &core.CompiledWorkflowClosure{
162+
Primary: &core.CompiledWorkflow{
163+
Template: &core.WorkflowTemplate{
164+
Interface: &core.TypedInterface{},
165+
},
166+
},
167+
},
138168
}, workflowList[1].Closure))
139169
}

0 commit comments

Comments
 (0)