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
/
execution.go
193 lines (182 loc) · 6.74 KB
/
execution.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package adminservice
import (
"context"
"time"
"github.com/lyft/flyteadmin/pkg/audit"
"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) CreateExecution(
ctx context.Context, request *admin.ExecutionCreateRequest) (*admin.ExecutionCreateResponse, 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.ExecutionCreateResponse
var err error
m.Metrics.executionEndpointMetrics.create.Time(func() {
response, err = m.ExecutionManager.CreateExecution(ctx, *request, requestedAt)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ExecutionCreateRequest",
map[string]string{
audit.Project: request.Project,
audit.Domain: request.Domain,
audit.Name: request.Name,
},
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.executionEndpointMetrics.create)
}
m.Metrics.executionEndpointMetrics.create.Success()
return response, nil
}
func (m *AdminService) RelaunchExecution(
ctx context.Context, request *admin.ExecutionRelaunchRequest) (*admin.ExecutionCreateResponse, 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.ExecutionCreateResponse
var err error
m.Metrics.executionEndpointMetrics.relaunch.Time(func() {
response, err = m.ExecutionManager.RelaunchExecution(ctx, *request, requestedAt)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ExecutionCreateRequest",
audit.ParametersFromExecutionIdentifier(request.Id),
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.executionEndpointMetrics.relaunch)
}
m.Metrics.executionEndpointMetrics.relaunch.Success()
return response, nil
}
func (m *AdminService) CreateWorkflowEvent(
ctx context.Context, request *admin.WorkflowExecutionEventRequest) (*admin.WorkflowExecutionEventResponse, 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.WorkflowExecutionEventResponse
var err error
m.Metrics.executionEndpointMetrics.createEvent.Time(func() {
response, err = m.ExecutionManager.CreateWorkflowEvent(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"CreateWorkflowEvent",
audit.ParametersFromExecutionIdentifier(request.Event.ExecutionId),
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.executionEndpointMetrics.createEvent)
}
m.Metrics.executionEndpointMetrics.createEvent.Success()
return response, nil
}
func (m *AdminService) GetExecution(
ctx context.Context, request *admin.WorkflowExecutionGetRequest) (*admin.Execution, 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.Execution
var err error
m.Metrics.executionEndpointMetrics.get.Time(func() {
response, err = m.ExecutionManager.GetExecution(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"GetExecution",
audit.ParametersFromExecutionIdentifier(request.Id),
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.executionEndpointMetrics.get)
}
m.Metrics.executionEndpointMetrics.get.Success()
return response, nil
}
func (m *AdminService) GetExecutionData(
ctx context.Context, request *admin.WorkflowExecutionGetDataRequest) (*admin.WorkflowExecutionGetDataResponse, 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.WorkflowExecutionGetDataResponse
var err error
m.Metrics.executionEndpointMetrics.get.Time(func() {
response, err = m.ExecutionManager.GetExecutionData(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"GetExecutionData",
audit.ParametersFromExecutionIdentifier(request.Id),
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.executionEndpointMetrics.getData)
}
m.Metrics.executionEndpointMetrics.getData.Success()
return response, nil
}
func (m *AdminService) ListExecutions(
ctx context.Context, request *admin.ResourceListRequest) (*admin.ExecutionList, 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.ExecutionList
var err error
m.Metrics.executionEndpointMetrics.list.Time(func() {
response, err = m.ExecutionManager.ListExecutions(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ListExecutions",
audit.ParametersFromNamedEntityIdentifier(request.Id),
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.executionEndpointMetrics.list)
}
m.Metrics.executionEndpointMetrics.list.Success()
return response, nil
}
func (m *AdminService) TerminateExecution(
ctx context.Context, request *admin.ExecutionTerminateRequest) (*admin.ExecutionTerminateResponse, 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.ExecutionTerminateResponse
var err error
m.Metrics.executionEndpointMetrics.terminate.Time(func() {
response, err = m.ExecutionManager.TerminateExecution(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"TerminateExecution",
audit.ParametersFromExecutionIdentifier(request.Id),
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.executionEndpointMetrics.terminate)
}
m.Metrics.executionEndpointMetrics.terminate.Success()
return response, nil
}