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

Commit

Permalink
#patch Update FromWorkflowModel API (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
squiishyy authored Sep 26, 2023
1 parent dc8cc9d commit af81751
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
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 @@ 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 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()))
}
}

// 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
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))
}

0 comments on commit af81751

Please sign in to comment.