-
Notifications
You must be signed in to change notification settings - Fork 0
/
thermos_types.go
165 lines (145 loc) · 6.04 KB
/
thermos_types.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
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package handler
import "go.uber.org/thriftrw/ptr"
// ExecutorData is the main data structure used by Thermos executor,
// represents a single thermos job.
type ExecutorData struct {
Role *string `json:"role,omitempty"`
Environment *string `json:"environment,omitempty"`
Name *string `json:"name,omitempty"`
Priority *int32 `json:"priority,omitempty"`
MaxTaskFailures *int32 `json:"max_task_failures,omitempty"`
Production *bool `json:"production,omitempty"`
Tier *string `json:"tier,omitempty"`
HealthCheckConfig *HealthCheckConfig `json:"health_check_config,omitempty"`
CronCollisionPolicy *string `json:"cron_collision_policy,omitempty"`
EnableHooks *bool `json:"enable_hooks,omitempty"`
Cluster *string `json:"cluster,omitempty"`
Task *Task `json:"task,omitempty"`
}
// NewExecutorData initializes a new instance of ExecutorData.
func NewExecutorData() *ExecutorData {
return &ExecutorData{}
}
// HealthCheckConfig defines the health check rules for a Thermos job.
type HealthCheckConfig struct {
HealthChecker *HealthCheckerConfig `json:"health_checker,omitempty"`
InitialIntervalSecs *float64 `json:"initial_interval_secs,omitempty"`
IntervalSecs *float64 `json:"interval_secs,omitempty"`
MaxConsecutiveFailures *int32 `json:"max_consecutive_failures,omitempty"`
MinConsecutiveSuccesses *int32 `json:"min_consecutive_successes,omitempty"`
TimeoutSecs *float64 `json:"timeout_secs,omitempty"`
}
// NewHealthCheckConfig initializes a new instance of HealthCheckConfig
// along with defaults values.
func NewHealthCheckConfig() *HealthCheckConfig {
return &HealthCheckConfig{
InitialIntervalSecs: ptr.Float64(15.0),
IntervalSecs: ptr.Float64(10.0),
MaxConsecutiveFailures: ptr.Int32(3),
MinConsecutiveSuccesses: ptr.Int32(1),
TimeoutSecs: ptr.Float64(20.0),
}
}
// HealthCheckerConfig defines the actual health check implementation
// (http or shell) to be used inside a HealthCheckConfig.
type HealthCheckerConfig struct {
Http *HttpHealthChecker `json:"http,omitempty"`
Shell *ShellHealthChecker `json:"shell,omitempty"`
}
// NewHealthCheckerConfig initializes a new instance of HealthCheckerConfig.
func NewHealthCheckerConfig() *HealthCheckerConfig {
return &HealthCheckerConfig{}
}
// HttpHealthChecker defines the health checker for testing against an HTTP
// endpoint.
type HttpHealthChecker struct {
Endpoint *string `json:"endpoint,omitempty"`
ExpectedResponse *string `json:"expected_response,omitempty"`
ExpectedResponseCode *int32 `json:"expected_response_code,omitempty"`
}
// NewHttpHealthChecker initializes a new instance of HttpHealthChecker
// along with default values.
func NewHttpHealthChecker() *HttpHealthChecker {
return &HttpHealthChecker{
ExpectedResponseCode: ptr.Int32(200),
}
}
// ShellHealthChecker defines the health checker for running a shell command.
type ShellHealthChecker struct {
ShellCommand *string `json:"shell_command,omitempty"`
}
// NewShellHealthChecker initializes a new instance of ShellHealthChecker.
func NewShellHealthChecker() *ShellHealthChecker {
return &ShellHealthChecker{}
}
// Task represents the task to be run inside a Thermos job.
type Task struct {
Name *string `json:"name,omitempty"`
FinalizationWait *int32 `json:"finalization_wait,omitempty"`
MaxFailures *int32 `json:"max_failures,omitempty"`
MaxConcurrency *int32 `json:"max_concurrency,omitempty"`
Resources *Resources `json:"resources,omitempty"`
Processes []*Process `json:"processes,omitempty"`
Constraints []*Constraint `json:"constraints,omitempty"`
}
// NewTask initializes a new instance of Task along with default values.
func NewTask() *Task {
return &Task{
FinalizationWait: ptr.Int32(30),
MaxFailures: ptr.Int32(1),
MaxConcurrency: ptr.Int32(0),
}
}
// Resources represents the task resources.
type Resources struct {
Cpu *float64 `json:"cpu,omitempty"`
RamBytes *int64 `json:"ram,omitempty"`
DiskBytes *int64 `json:"disk,omitempty"`
Gpu *int32 `json:"gpu,omitempty"`
}
// NewResources initializes a new instance of Resources.
func NewResources() *Resources {
return &Resources{}
}
// Process represents the single process inside a Thermos task.
type Process struct {
Cmdline *string `json:"cmdline,omitempty"`
Name *string `json:"name,omitempty"`
MaxFailures *int32 `json:"max_failures,omitempty"`
Daemon *bool `json:"daemon,omitempty"`
Ephemeral *bool `json:"ephemeral,omitempty"`
MinDuration *int32 `json:"min_duration,omitempty"`
Final *bool `json:"final,omitempty"`
}
// NewProcess initializes a new instance of Process along with default values.
func NewProcess() *Process {
return &Process{
Daemon: ptr.Bool(false),
Ephemeral: ptr.Bool(false),
Final: ptr.Bool(false),
MaxFailures: ptr.Int32(1),
MinDuration: ptr.Int32(5),
}
}
// Constraint represents launching constraints for processes defined in
// a Thermos task.
type Constraint struct {
Order []*string `json:"order,omitempty"`
}
// NewConstraint initializes a new instance of Constraint.
func NewConstraint() *Constraint {
return &Constraint{}
}