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 62
/
launch_plan.go
212 lines (196 loc) · 7.42 KB
/
launch_plan.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package adminservice
import (
"context"
"time"
"github.com/flyteorg/flyteadmin/pkg/audit"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flytestdlib/logger"
"github.com/flyteorg/flyteadmin/pkg/rpc/adminservice/util"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (m *AdminService) CreateLaunchPlan(
ctx context.Context, request *admin.LaunchPlanCreateRequest) (*admin.LaunchPlanCreateResponse, 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.LaunchPlanCreateResponse
var err error
m.Metrics.launchPlanEndpointMetrics.create.Time(func() {
response, err = m.LaunchPlanManager.CreateLaunchPlan(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"CreateLaunchPlan",
audit.ParametersFromIdentifier(request.Id),
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.launchPlanEndpointMetrics.create)
}
m.Metrics.launchPlanEndpointMetrics.create.Success()
return response, nil
}
func (m *AdminService) GetLaunchPlan(ctx context.Context, request *admin.ObjectGetRequest) (*admin.LaunchPlan, 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_LAUNCH_PLAN
}
var response *admin.LaunchPlan
var err error
m.Metrics.launchPlanEndpointMetrics.get.Time(func() {
response, err = m.LaunchPlanManager.GetLaunchPlan(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"GetLaunchPlan",
audit.ParametersFromIdentifier(request.Id),
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.launchPlanEndpointMetrics.get)
}
m.Metrics.launchPlanEndpointMetrics.get.Success()
return response, nil
}
func (m *AdminService) GetActiveLaunchPlan(ctx context.Context, request *admin.ActiveLaunchPlanRequest) (*admin.LaunchPlan, 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.LaunchPlan
var err error
m.Metrics.launchPlanEndpointMetrics.getActive.Time(func() {
response, err = m.LaunchPlanManager.GetActiveLaunchPlan(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"GetActiveLaunchPlan",
audit.ParametersFromNamedEntityIdentifier(request.Id),
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.launchPlanEndpointMetrics.getActive)
}
m.Metrics.launchPlanEndpointMetrics.getActive.Success()
return response, nil
}
func (m *AdminService) UpdateLaunchPlan(ctx context.Context, request *admin.LaunchPlanUpdateRequest) (
*admin.LaunchPlanUpdateResponse, 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_LAUNCH_PLAN
}
var response *admin.LaunchPlanUpdateResponse
var err error
m.Metrics.launchPlanEndpointMetrics.update.Time(func() {
response, err = m.LaunchPlanManager.UpdateLaunchPlan(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"UpdateLaunchPlan",
audit.ParametersFromIdentifier(request.Id),
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.launchPlanEndpointMetrics.update)
}
m.Metrics.launchPlanEndpointMetrics.update.Success()
return response, nil
}
func (m *AdminService) ListLaunchPlans(ctx context.Context, request *admin.ResourceListRequest) (
*admin.LaunchPlanList, error) {
defer m.interceptPanic(ctx, request)
requestedAt := time.Now()
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Empty request. Please rephrase.")
}
var response *admin.LaunchPlanList
var err error
m.Metrics.launchPlanEndpointMetrics.list.Time(func() {
response, err = m.LaunchPlanManager.ListLaunchPlans(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ListLaunchPlans",
audit.ParametersFromNamedEntityIdentifier(request.Id),
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.launchPlanEndpointMetrics.list)
}
m.Metrics.launchPlanEndpointMetrics.list.Success()
return response, nil
}
func (m *AdminService) ListActiveLaunchPlans(ctx context.Context, request *admin.ActiveLaunchPlanListRequest) (
*admin.LaunchPlanList, error) {
defer m.interceptPanic(ctx, request)
requestedAt := time.Now()
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Empty request. Please rephrase.")
}
var response *admin.LaunchPlanList
var err error
m.Metrics.launchPlanEndpointMetrics.listActive.Time(func() {
response, err = m.LaunchPlanManager.ListActiveLaunchPlans(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ListActiveLaunchPlans",
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.launchPlanEndpointMetrics.listActive)
}
m.Metrics.launchPlanEndpointMetrics.listActive.Success()
return response, nil
}
func (m *AdminService) ListLaunchPlanIds(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, "Empty request. Please rephrase.")
}
var response *admin.NamedEntityIdentifierList
var err error
m.Metrics.launchPlanEndpointMetrics.listIds.Time(func() {
response, err = m.LaunchPlanManager.ListLaunchPlanIds(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ListLaunchPlanIds",
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.launchPlanEndpointMetrics.listIds)
}
m.Metrics.launchPlanEndpointMetrics.listIds.Success()
return response, nil
}