/
mdb_io.go
362 lines (298 loc) · 9.47 KB
/
mdb_io.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
package remote
import (
"time"
"github.com/deciduosity/jasper"
"github.com/deciduosity/jasper/options"
"github.com/deciduosity/jasper/scripting"
"github.com/tychoish/birch/mrpc/shell"
)
// infoRequest represents a request for runtime information regarding the
// process given by ID.
type infoRequest struct {
ID string `bson:"info"`
}
// infoResponse represents a response indicating runtime information for a
// process.
type infoResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
Info jasper.ProcessInfo `bson:"info"`
}
func makeInfoResponse(info jasper.ProcessInfo) infoResponse {
return infoResponse{Info: info, ErrorResponse: shell.MakeSuccessResponse()}
}
// runningRequest represents a request for the running state of the process
// given by ID.
type runningRequest struct {
ID string `bson:"running"`
}
// runningResponse represents a response indicating the running state of a
// process.
type runningResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
Running bool `bson:"running"`
}
func makeRunningResponse(running bool) runningResponse {
return runningResponse{Running: running, ErrorResponse: shell.MakeSuccessResponse()}
}
// completeRequest represents a request for the completion status of the process
// given by ID.
type completeRequest struct {
ID string `bson:"complete"`
}
// completeResponse represents a response indicating the completion status of a
// process.
type completeResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
Complete bool `bson:"complete"`
}
func makeCompleteResponse(complete bool) completeResponse {
return completeResponse{Complete: complete, ErrorResponse: shell.MakeSuccessResponse()}
}
// waitRequest represents a request for the wait status of the process given by
// ID.
type waitRequest struct {
ID string `bson:"wait"`
}
// waitResponse represents a response indicating the exit code and error of
// a waited process.
type waitResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
ExitCode int `bson:"exit_code"`
}
func makeWaitResponse(exitCode int, err error) waitResponse {
return waitResponse{ExitCode: exitCode, ErrorResponse: shell.MakeErrorResponse(true, err)}
}
// respawnRequest represents a request to respawn the process given by ID.
type respawnRequest struct {
ID string `bson:"respawn"`
}
// signalRequest represents a request to send a signal to the process given by
// ID.
type signalRequest struct {
Params struct {
ID string `bson:"id"`
Signal int `bson:"signal"`
} `bson:"signal"`
}
// registerSignalTriggerIDRequest represents a request to register the signal
// trigger ID on the process given by ID.
type registerSignalTriggerIDRequest struct {
Params struct {
ID string `bson:"id"`
SignalTriggerID jasper.SignalTriggerID `bson:"signal_trigger_id"`
} `bson:"register_signal_trigger_id"`
}
// tagRequest represents a request to associate the process given by ID with the
// tag.
type tagRequest struct {
Params struct {
ID string `bson:"id"`
Tag string `bson:"tag"`
} `bson:"add_tag"`
}
// getTagsRequest represents a request to get all the tags for the process given
// by ID.
type getTagsRequest struct {
ID string `bson:"get_tags"`
}
// getTagsResponse represents a response indicating the tags of a process.
type getTagsResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
Tags []string `bson:"tags"`
}
func makeGetTagsResponse(tags []string) getTagsResponse {
return getTagsResponse{Tags: tags, ErrorResponse: shell.MakeSuccessResponse()}
}
// resetTagsRequest represents a request to clear all the tags for the process
// given by ID.
type resetTagsRequest struct {
ID string `bson:"reset_tags"`
}
// idRequest represents a request to get the ID associated with the service
// manager.
type idRequest struct {
ID int `bson:"id"`
}
// idResponse requests a response indicating the service manager's ID.
type idResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
ID string `bson:"id"`
}
func makeIDResponse(id string) idResponse {
return idResponse{ID: id, ErrorResponse: shell.MakeSuccessResponse()}
}
// createProcessRequest represents a request to create a process with the given
// options.
type createProcessRequest struct {
Options options.Create `bson:"create_process"`
}
// listRequest represents a request to get information regarding the processes
// matching the given filter.
type listRequest struct {
Filter options.Filter `bson:"list"`
}
// groupRequest represents a request to get information regarding the processes
// matching the given tag.
type groupRequest struct {
Tag string `bson:"group"`
}
// getProcessRequest represents a request to get information regarding the
// process given by ID.
type getProcessRequest struct {
ID string `bson:"get_process"`
}
// infosResponse represents a response indicating the runtime information for
// multiple processes.
type infosResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
Infos []jasper.ProcessInfo `bson:"infos"`
}
func makeInfosResponse(infos []jasper.ProcessInfo) infosResponse {
return infosResponse{Infos: infos, ErrorResponse: shell.MakeSuccessResponse()}
}
// clearRequest represents a request to clear the current processes that have
// completed.
type clearRequest struct {
Clear int `bson:"clear"`
}
// closeRequest represents a request to terminate all processes.
type closeRequest struct {
Close int `bson:"close"`
}
type writeFileRequest struct {
Options options.WriteFile `bson:"write_file"`
}
type downloadFileRequest struct {
Options options.Download `bson:"download_file"`
}
type getLogStreamRequest struct {
Params struct {
ID string `bson:"id"`
Count int `bson:"count"`
} `bson:"get_log_stream"`
}
type getLogStreamResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
LogStream jasper.LogStream `bson:"log_stream"`
}
func makeGetLogStreamResponse(logs []string, done bool) getLogStreamResponse {
return getLogStreamResponse{
LogStream: jasper.LogStream{Logs: logs, Done: done},
ErrorResponse: shell.MakeSuccessResponse(),
}
}
type signalEventRequest struct {
Name string `bson:"signal_event"`
}
type loggingCacheSizeResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
Size int `bson:"size"`
}
type loggingCacheCreateRequest struct {
Params struct {
ID string `bson:"id"`
Options *options.Output `bson:"options"`
} `bson:"create_logging_cache"`
}
type loggingCacheGetRequest struct {
ID string `bson:"get_logging_cache"`
}
type loggingCacheDeleteRequest struct {
ID string `bson:"delete_logging_cache"`
}
type loggingCacheCloseAndRemoveRequest struct {
ID string `bson:"logging_cache_close_and_remove"`
}
type loggingCacheClearRequest struct {
Clear int `bson:"logging_cache_clear"`
}
type loggingCacheCreateAndGetResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
CachedLogger *options.CachedLogger `bson:"cached_logger"`
}
func makeLoggingCacheCreateAndGetResponse(l *options.CachedLogger) *loggingCacheCreateAndGetResponse {
return &loggingCacheCreateAndGetResponse{
ErrorResponse: shell.MakeSuccessResponse(),
CachedLogger: l,
}
}
type loggingCachePruneRequest struct {
LastAccessed time.Time `bson:"logging_cache_prune"`
}
type loggingCacheLenRequest struct {
Len bool `bson:"logging_cache_size"`
}
type loggingSendMessagesRequest struct {
Payload options.LoggingPayload `bson:"send_messages"`
}
type scriptingCreateRequest struct {
Params struct {
Type string `bson:"type"`
Options []byte `bson:"options"`
} `bson:"create_scripting"`
}
type scriptingCreateResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
ID string `bson:"id"`
}
func makeScriptingCreateResponse(id string) *scriptingCreateResponse {
return &scriptingCreateResponse{
ErrorResponse: shell.MakeSuccessResponse(),
ID: id,
}
}
type scriptingGetRequest struct {
ID string `bson:"get_scripting"`
}
type scriptingSetupRequest struct {
ID string `bson:"setup_scripting"`
}
type scriptingCleanupRequest struct {
ID string `bson:"cleanup_scripting"`
}
type scriptingRunRequest struct {
Params struct {
ID string `bson:"id"`
Args []string `bson:"args"`
} `bson:"run_scripting"`
}
type scriptingRunScriptRequest struct {
Params struct {
ID string `bson:"id"`
Script string `bson:"script"`
} `bson:"run_script_scripting"`
}
type scriptingBuildRequest struct {
Params struct {
ID string `bson:"id"`
Dir string `bson:"dir"`
Args []string `bson:"args"`
} `bson:"build_scripting"`
}
type scriptingBuildResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
Path string `bson:"path"`
}
func makeScriptingBuildResponse(path string) *scriptingBuildResponse {
return &scriptingBuildResponse{
ErrorResponse: shell.MakeSuccessResponse(),
Path: path,
}
}
type scriptingTestRequest struct {
Params struct {
ID string `bson:"id"`
Dir string `bson:"dir"`
Options []scripting.TestOptions `bson:"options"`
} `bson:"test_scripting"`
}
type scriptingTestResponse struct {
shell.ErrorResponse `bson:"error_response,inline"`
Results []scripting.TestResult
}
func makeScriptingTestResponse(results []scripting.TestResult) *scriptingTestResponse {
return &scriptingTestResponse{
ErrorResponse: shell.MakeSuccessResponse(),
Results: results,
}
}