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
/
launch_plan.go
154 lines (139 loc) · 5.66 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
package adminservice
import (
"context"
"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)
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)
})
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)
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.Infof(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)
})
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)
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)
})
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)
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.Infof(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)
})
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)
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)
})
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)
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)
})
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)
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)
})
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.launchPlanEndpointMetrics.listIds)
}
m.Metrics.launchPlanEndpointMetrics.listIds.Success()
return response, nil
}