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
/
workflow.go
127 lines (116 loc) · 4.24 KB
/
workflow.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package adminservice
import (
"context"
"time"
"github.com/lyft/flyteadmin/pkg/audit"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core"
"github.com/lyft/flytestdlib/logger"
"github.com/lyft/flyteadmin/pkg/rpc/adminservice/util"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (m *AdminService) CreateWorkflow(
ctx context.Context,
request *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error) {
defer m.interceptPanic(ctx, request)
requestedAt := time.Now()
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.WorkflowCreateResponse
var err error
m.Metrics.workflowEndpointMetrics.create.Time(func() {
response, err = m.WorkflowManager.CreateWorkflow(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"CreateWorkflow",
audit.ParametersFromIdentifier(request.Id),
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.workflowEndpointMetrics.create)
}
m.Metrics.workflowEndpointMetrics.create.Success()
return response, nil
}
func (m *AdminService) GetWorkflow(ctx context.Context, request *admin.ObjectGetRequest) (*admin.Workflow, error) {
defer m.interceptPanic(ctx, request)
requestedAt := time.Now()
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
// NOTE: When the Get HTTP endpoint is called the resource type is implicit (from the URL) so we must add it
// to the request.
if request.Id != nil && request.Id.ResourceType == core.ResourceType_UNSPECIFIED {
logger.Info(ctx, "Adding resource type for unspecified value in request: [%+v]", request)
request.Id.ResourceType = core.ResourceType_WORKFLOW
}
var response *admin.Workflow
var err error
m.Metrics.workflowEndpointMetrics.get.Time(func() {
response, err = m.WorkflowManager.GetWorkflow(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"GetWorkflow",
audit.ParametersFromIdentifier(request.Id),
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.workflowEndpointMetrics.get)
}
m.Metrics.workflowEndpointMetrics.get.Success()
return response, nil
}
func (m *AdminService) ListWorkflowIds(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) (
*admin.NamedEntityIdentifierList, error) {
defer m.interceptPanic(ctx, request)
requestedAt := time.Now()
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.NamedEntityIdentifierList
var err error
m.Metrics.workflowEndpointMetrics.listIds.Time(func() {
response, err = m.WorkflowManager.ListWorkflowIdentifiers(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ListWorkflowIds",
map[string]string{
audit.Project: request.Project,
audit.Domain: request.Domain,
},
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.workflowEndpointMetrics.listIds)
}
m.Metrics.workflowEndpointMetrics.listIds.Success()
return response, nil
}
func (m *AdminService) ListWorkflows(ctx context.Context, request *admin.ResourceListRequest) (*admin.WorkflowList, error) {
defer m.interceptPanic(ctx, request)
requestedAt := time.Now()
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.WorkflowList
var err error
m.Metrics.workflowEndpointMetrics.list.Time(func() {
response, err = m.WorkflowManager.ListWorkflows(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ListWorkflows",
audit.ParametersFromNamedEntityIdentifier(request.Id),
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.workflowEndpointMetrics.list)
}
m.Metrics.workflowEndpointMetrics.list.Success()
return response, nil
}