This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathresource.go
68 lines (62 loc) · 2.36 KB
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package transformers
import (
"github.com/golang/protobuf/proto"
"github.com/lyft/flyteadmin/pkg/errors"
"github.com/lyft/flyteadmin/pkg/repositories/models"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin"
"google.golang.org/grpc/codes"
)
func WorkflowAttributesToResourceModel(attributes admin.WorkflowAttributes, resource admin.MatchableResource) (models.Resource, error) {
attributeBytes, err := proto.Marshal(attributes.MatchingAttributes)
if err != nil {
return models.Resource{}, err
}
return models.Resource{
Project: attributes.Project,
Domain: attributes.Domain,
Workflow: attributes.Workflow,
ResourceType: resource.String(),
Priority: models.ResourcePriorityWorkflowLevel,
Attributes: attributeBytes,
}, nil
}
func FromResourceModelToWorkflowAttributes(model models.Resource) (admin.WorkflowAttributes, error) {
var attributes admin.MatchingAttributes
err := proto.Unmarshal(model.Attributes, &attributes)
if err != nil {
return admin.WorkflowAttributes{}, errors.NewFlyteAdminErrorf(
codes.Internal, "Failed to decode project domain resource projectDomainAttributes with err: %v", err)
}
return admin.WorkflowAttributes{
Project: model.Project,
Domain: model.Domain,
Workflow: model.Workflow,
MatchingAttributes: &attributes,
}, nil
}
func ProjectDomainAttributesToResourceModel(attributes admin.ProjectDomainAttributes, resource admin.MatchableResource) (models.Resource, error) {
attributeBytes, err := proto.Marshal(attributes.MatchingAttributes)
if err != nil {
return models.Resource{}, err
}
return models.Resource{
Project: attributes.Project,
Domain: attributes.Domain,
ResourceType: resource.String(),
Priority: models.ResourcePriorityProjectDomainLevel,
Attributes: attributeBytes,
}, nil
}
func FromResourceModelToProjectDomainAttributes(model models.Resource) (admin.ProjectDomainAttributes, error) {
var attributes admin.MatchingAttributes
err := proto.Unmarshal(model.Attributes, &attributes)
if err != nil {
return admin.ProjectDomainAttributes{}, errors.NewFlyteAdminErrorf(
codes.Internal, "Failed to decode project domain resource projectDomainAttributes with err: %v", err)
}
return admin.ProjectDomainAttributes{
Project: model.Project,
Domain: model.Domain,
MatchingAttributes: &attributes,
}, nil
}