-
Notifications
You must be signed in to change notification settings - Fork 453
/
types.go
287 lines (223 loc) · 10.9 KB
/
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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package node
import (
"time"
"github.com/m3db/m3/src/cluster/placement"
"github.com/m3db/m3/src/m3em/build"
hb "github.com/m3db/m3/src/m3em/generated/proto/heartbeat"
"github.com/m3db/m3/src/m3em/generated/proto/m3em"
xclock "github.com/m3db/m3/src/x/clock"
"github.com/m3db/m3/src/x/instrument"
xretry "github.com/m3db/m3/src/x/retry"
"google.golang.org/grpc"
)
// Status indicates the different states a ServiceNode can be in. The
// state diagram below describes the transitions between the various states:
//
// ┌──────────────────┐
// │ │
// ┌Teardown()─────│ Error │
// │ │ │
// │ └──────────────────┘
// │
// ▼
// ┌──────────────────┐ ┌───────────────-──┐
// │ │ Setup() │ │
// │ Uninitialized ├────────────────────────▶│ Setup │◀─┐
// │ │◀───────────┐ │ │ │
// └──────────────────┘ Teardown()└────────────└──────────────────┘ │
// ▲ │ │
// │ │ │
// │ │ │
// │ Start() │ │
// │ ┌─────────────┘ │
// │ │ │
// │ │ │
// │ │ │
// │ ▼ │
// │ ┌──────────────────┐ │
// │Teardown() │ │ |
// └────────────────────│ Running │────────────Stop()
// │ │
// └──────────────────┘
type Status int
const (
// StatusUninitialized refers to the state of an un-initialized node.
StatusUninitialized Status = iota
// StatusSetup is the state of a node which has been Setup()
StatusSetup
// StatusRunning is the state of a node which has been Start()-ed
StatusRunning
// StatusError is the state of a node which is in an Error state
StatusError
)
// RemoteOutputType describes the various outputs available on the remote agents
type RemoteOutputType int
const (
// RemoteProcessStdout refers to the remote process stdout
RemoteProcessStdout RemoteOutputType = iota
// RemoteProcessStderr refers to the remote process stderr
RemoteProcessStderr
// TODO(prateek): capture agent remote logs
)
// ServiceNode represents an executable service node. This object controls both the service
// and resources on the host running the service (e.g. fs, processes, etc.)
type ServiceNode interface {
placement.Instance
// Setup initializes the directories, config file, and binary for the process being tested.
// It does not Start the process on the ServiceNode.
Setup(
build build.ServiceBuild,
config build.ServiceConfiguration,
token string,
force bool,
) error
// Start starts the service process for this ServiceNode.
Start() error
// Stop stops the service process for this ServiceNode.
Stop() error
// Status returns the ServiceNode status.
Status() Status
// Teardown releases any remote resources used for testing.
Teardown() error
// Close releases any locally held resources
Close() error
// RegisterListener registers an event listener
RegisterListener(Listener) ListenerID
// DeregisterListener un-registers an event listener
DeregisterListener(ListenerID)
// TransferLocalFile transfers a local file to the specified destination paths
// NB: destPaths are not allowed to use relative path specifiers, i.e. '..' is illegal;
// the eventual destination path on remote hosts is relative to the working directory
// of the remote agent.
// e.g. if the remote agent has working directory /var/m3em-agent, and we make the call:
// svcNode.TransferLocalFile("some/local/file/path/id", []string{"path/id", "another/path/id"})
//
// upon success, there will be two new files under the remote agent working directory:
// /var/m3em-agent/
// /var/m3em-agent/path/id <-- same contents as "some/local/file/path/id"
// /var/m3em-agent/another/path/id <-- same contents as "some/local/file/path/id"
TransferLocalFile(localSrc string, destPaths []string, overwrite bool) error
// GetRemoteOutput transfers the specified remote file to the specified path
GetRemoteOutput(t RemoteOutputType, localDest string) (truncated bool, err error)
}
// ServiceNodeFn performs an operation on a given ServiceNode
type ServiceNodeFn func(ServiceNode) error
// ConcurrentExecutor executes functions on a collection of service
// nodes concurrently
type ConcurrentExecutor interface {
// Run runs the provide ServiceNodeFn concurrently
Run() error
}
// HeartbeatRouter routes heartbeats based on registered servers
type HeartbeatRouter interface {
hb.HeartbeaterServer
// Endpoint returns the router endpoint
Endpoint() string
// Register registers the specified server under the given id
Register(string, hb.HeartbeaterServer) error
// Deregister un-registers any server registered under the given id
Deregister(string) error
}
// ListenerID is a unique identifier for a registered listener
type ListenerID int
// Listener provides callbacks invoked upon remote process state transitions
type Listener interface {
// OnProcessTerminate is invoked when the remote process being run terminates
OnProcessTerminate(node ServiceNode, desc string)
// OnHeartbeatTimeout is invoked upon remote heartbeats having timed-out
OnHeartbeatTimeout(node ServiceNode, lastHeartbeatTs time.Time)
// OnOverwrite is invoked if remote agent control is overwritten by another
// coordinator
OnOverwrite(node ServiceNode, desc string)
}
// ServiceNodes is a collection of ServiceNode(s)
type ServiceNodes []ServiceNode
// Options are the various knobs to control Node behavior
type Options interface {
// Validate validates the NodeOptions
Validate() error
// SetInstrumentOptions sets the instrumentation options
SetInstrumentOptions(instrument.Options) Options
// InstrumentOptions returns the instrumentation options
InstrumentOptions() instrument.Options
// SetOperationTimeout returns the timeout for node operations
SetOperationTimeout(time.Duration) Options
// OperationTimeout returns the timeout for node operations
OperationTimeout() time.Duration
// SetRetrier sets the retrier for node operations
SetRetrier(xretry.Retrier) Options
// OperationRetrier returns the retrier for node operations
Retrier() xretry.Retrier
// SetTransferBufferSize sets the bytes buffer size used during file transfer
SetTransferBufferSize(int) Options
// TransferBufferSize returns the bytes buffer size used during file transfer
TransferBufferSize() int
// SetMaxPullSize sets the max bytes retrieved from remote agents when
// fetching output files
SetMaxPullSize(int64) Options
// MaxPullSize returns the max bytes retrieved from remote agents when
// fetching output files
MaxPullSize() int64
// SetHeartbeatOptions sets the HeartbeatOptions
SetHeartbeatOptions(HeartbeatOptions) Options
// HeartbeatOptions returns the HeartbeatOptions
HeartbeatOptions() HeartbeatOptions
// SetOperatorClientFn sets the OperatorClientFn
SetOperatorClientFn(OperatorClientFn) Options
// OperatorClientFn returns the OperatorClientFn
OperatorClientFn() OperatorClientFn
}
// OperatorClientFn returns a function able to construct connections to remote Operators
type OperatorClientFn func() (*grpc.ClientConn, m3em.OperatorClient, error)
// HeartbeatOptions are the knobs to control heartbeating behavior
type HeartbeatOptions interface {
// Validate validates the HeartbeatOptions
Validate() error
// SetEnabled sets whether the Heartbeating is enabled
SetEnabled(bool) HeartbeatOptions
// Enabled returns whether the Heartbeating is enabled
Enabled() bool
// SetNowFn sets the NowFn
SetNowFn(xclock.NowFn) HeartbeatOptions
// NowFn returns the NowFn
NowFn() xclock.NowFn
// SetInterval sets the heartbeating interval
SetInterval(time.Duration) HeartbeatOptions
// Interval returns the heartbeating interval
Interval() time.Duration
// SetCheckInterval sets the frequency with which heartbeating timeouts
// are checked
SetCheckInterval(time.Duration) HeartbeatOptions
// CheckInterval returns the frequency with which heartbeating timeouts
// are checked
CheckInterval() time.Duration
// SetTimeout sets the heartbeat timeout duration, i.e. the window of
// time after which missing heartbeats are considered errorneous
SetTimeout(time.Duration) HeartbeatOptions
// Timeout returns the heartbeat timeout duration, i.e. the window of
// time after which missing heartbeats are considered errorneous
Timeout() time.Duration
// SetHeartbeatRouter sets the heartbeat router to be used
SetHeartbeatRouter(HeartbeatRouter) HeartbeatOptions
// HeartbeatRouter returns the heartbeat router in use
HeartbeatRouter() HeartbeatRouter
}