-
Notifications
You must be signed in to change notification settings - Fork 127
/
readiness.go
99 lines (83 loc) · 3.2 KB
/
readiness.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
/*
Copyright 2017 The go-marathon Authors All rights reserved.
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 marathon
import "time"
// ReadinessCheck represents a readiness check.
type ReadinessCheck struct {
Name *string `json:"name,omitempty"`
Protocol string `json:"protocol,omitempty"`
Path string `json:"path,omitempty"`
PortName string `json:"portName,omitempty"`
IntervalSeconds int `json:"intervalSeconds,omitempty"`
TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
HTTPStatusCodesForReady *[]int `json:"httpStatusCodesForReady,omitempty"`
PreserveLastResponse *bool `json:"preserveLastResponse,omitempty"`
}
// SetName sets the name on the readiness check.
func (rc *ReadinessCheck) SetName(name string) *ReadinessCheck {
rc.Name = &name
return rc
}
// SetProtocol sets the protocol on the readiness check.
func (rc *ReadinessCheck) SetProtocol(proto string) *ReadinessCheck {
rc.Protocol = proto
return rc
}
// SetPath sets the path on the readiness check.
func (rc *ReadinessCheck) SetPath(p string) *ReadinessCheck {
rc.Path = p
return rc
}
// SetPortName sets the port name on the readiness check.
func (rc *ReadinessCheck) SetPortName(name string) *ReadinessCheck {
rc.PortName = name
return rc
}
// SetInterval sets the interval on the readiness check.
func (rc *ReadinessCheck) SetInterval(interval time.Duration) *ReadinessCheck {
secs := int(interval.Seconds())
rc.IntervalSeconds = secs
return rc
}
// SetTimeout sets the timeout on the readiness check.
func (rc *ReadinessCheck) SetTimeout(timeout time.Duration) *ReadinessCheck {
secs := int(timeout.Seconds())
rc.TimeoutSeconds = secs
return rc
}
// SetHTTPStatusCodesForReady sets the HTTP status codes for ready on the
// readiness check.
func (rc *ReadinessCheck) SetHTTPStatusCodesForReady(codes []int) *ReadinessCheck {
rc.HTTPStatusCodesForReady = &codes
return rc
}
// SetPreserveLastResponse sets the preserve last response flag on the
// readiness check.
func (rc *ReadinessCheck) SetPreserveLastResponse(preserve bool) *ReadinessCheck {
rc.PreserveLastResponse = &preserve
return rc
}
// ReadinessLastResponse holds the result of the last response embedded in a
// readiness check result.
type ReadinessLastResponse struct {
Body string `json:"body"`
ContentType string `json:"contentType"`
Status int `json:"status"`
}
// ReadinessCheckResult is the result of a readiness check.
type ReadinessCheckResult struct {
Name string `json:"name"`
TaskID string `json:"taskId"`
Ready bool `json:"ready"`
LastResponse ReadinessLastResponse `json:"lastResponse,omitempty"`
}