-
Notifications
You must be signed in to change notification settings - Fork 250
/
tcworkermanager.go
684 lines (644 loc) · 24.8 KB
/
tcworkermanager.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
// The following code is AUTO-GENERATED. Please DO NOT edit.
// To update this generated code, run `go generate` in the
// clients/client-go/codegenerator/model subdirectory of the
// taskcluster git repository.
// This package was generated from the reference schema of
// the WorkerManager service, which is also published here:
//
// * ${TASKCLUSTER_ROOT_URL}/references/worker-manager/v1/api.json
//
// where ${TASKCLUSTER_ROOT_URL} points to the root URL of
// your taskcluster deployment.
// This service manages workers, including provisioning for dynamic worker pools.
//
// Methods interacting with a provider may return a 503 response if that provider has
// not been able to start up, such as if the service to which it interfaces has an
// outage. Such requests can be retried as for any other 5xx response.
//
// See:
//
// # How to use this package
//
// First create a WorkerManager object:
//
// workerManager := tcworkermanager.New(nil)
//
// and then call one or more of workerManager's methods, e.g.:
//
// err := workerManager.Ping(.....)
//
// handling any errors...
//
// if err != nil {
// // handle error...
// }
//
// # Taskcluster Schema
//
// The source code of this go package was auto-generated from the API definition at
// <rootUrl>/references/worker-manager/v1/api.json together with the input and output schemas it references,
package tcworkermanager
import (
"net/url"
"time"
tcclient "github.com/taskcluster/taskcluster/v62/clients/client-go"
)
type WorkerManager tcclient.Client
// New returns a WorkerManager client, configured to run against production. Pass in
// nil credentials to create a client without authentication. The
// returned client is mutable, so returned settings can be altered.
//
// workerManager := tcworkermanager.New(
// nil, // client without authentication
// "http://localhost:1234/my/taskcluster", // taskcluster hosted at this root URL on local machine
// )
// err := workerManager.Ping(.....) // for example, call the Ping(.....) API endpoint (described further down)...
// if err != nil {
// // handle errors...
// }
func New(credentials *tcclient.Credentials, rootURL string) *WorkerManager {
return &WorkerManager{
Credentials: credentials,
RootURL: rootURL,
ServiceName: "worker-manager",
APIVersion: "v1",
Authenticate: credentials != nil,
}
}
// NewFromEnv returns a *WorkerManager configured from environment variables.
//
// The root URL is taken from TASKCLUSTER_PROXY_URL if set to a non-empty
// string, otherwise from TASKCLUSTER_ROOT_URL if set, otherwise the empty
// string.
//
// The credentials are taken from environment variables:
//
// TASKCLUSTER_CLIENT_ID
// TASKCLUSTER_ACCESS_TOKEN
// TASKCLUSTER_CERTIFICATE
//
// If TASKCLUSTER_CLIENT_ID is empty/unset, authentication will be
// disabled.
func NewFromEnv() *WorkerManager {
c := tcclient.CredentialsFromEnvVars()
rootURL := tcclient.RootURLFromEnvVars()
return &WorkerManager{
Credentials: c,
RootURL: rootURL,
ServiceName: "worker-manager",
APIVersion: "v1",
Authenticate: c.ClientID != "",
}
}
// Respond without doing anything.
// This endpoint is used to check that the service is up.
//
// See #ping
func (workerManager *WorkerManager) Ping() error {
cd := tcclient.Client(*workerManager)
_, _, err := (&cd).APICall(nil, "GET", "/ping", nil, nil)
return err
}
// Respond without doing anything.
// This endpoint is used to check that the service is up.
//
// See #lbheartbeat
func (workerManager *WorkerManager) Lbheartbeat() error {
cd := tcclient.Client(*workerManager)
_, _, err := (&cd).APICall(nil, "GET", "/__lbheartbeat__", nil, nil)
return err
}
// Respond with the JSON version object.
// https://github.com/mozilla-services/Dockerflow/blob/main/docs/version_object.md
//
// See #version
func (workerManager *WorkerManager) Version() error {
cd := tcclient.Client(*workerManager)
_, _, err := (&cd).APICall(nil, "GET", "/__version__", nil, nil)
return err
}
// Retrieve a list of providers that are available for worker pools.
//
// Required scopes:
//
// worker-manager:list-providers
//
// See #listProviders
func (workerManager *WorkerManager) ListProviders(continuationToken, limit string) (*ProviderList, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/providers", new(ProviderList), v)
return responseObject.(*ProviderList), err
}
// Returns a signed URL for ListProviders, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:list-providers
//
// See ListProviders for more details.
func (workerManager *WorkerManager) ListProviders_SignedURL(continuationToken, limit string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/providers", v, duration)
}
// Create a new worker pool. If the worker pool already exists, this will throw an error.
//
// Required scopes:
//
// All of:
// * worker-manager:manage-worker-pool:<workerPoolId>
// * worker-manager:provider:<providerId>
//
// See #createWorkerPool
func (workerManager *WorkerManager) CreateWorkerPool(workerPoolId string, payload *WorkerPoolDefinition) (*WorkerPoolFullDefinition, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(payload, "PUT", "/worker-pool/"+url.QueryEscape(workerPoolId), new(WorkerPoolFullDefinition), nil)
return responseObject.(*WorkerPoolFullDefinition), err
}
// Stability: *** EXPERIMENTAL ***
//
// Given an existing worker pool definition, this will modify it and return
// the new definition.
//
// To delete a worker pool, set its `providerId` to `"null-provider"`.
// After any existing workers have exited, a cleanup job will remove the
// worker pool. During that time, the worker pool can be updated again, such
// as to set its `providerId` to a real provider.
//
// Required scopes:
//
// All of:
// * worker-manager:manage-worker-pool:<workerPoolId>
// * worker-manager:provider:<providerId>
//
// See #updateWorkerPool
func (workerManager *WorkerManager) UpdateWorkerPool(workerPoolId string, payload *WorkerPoolDefinition1) (*WorkerPoolFullDefinition, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(payload, "POST", "/worker-pool/"+url.QueryEscape(workerPoolId), new(WorkerPoolFullDefinition), nil)
return responseObject.(*WorkerPoolFullDefinition), err
}
// Mark a worker pool for deletion. This is the same as updating the pool to
// set its providerId to `"null-provider"`, but does not require scope
// `worker-manager:provider:null-provider`.
//
// Required scopes:
//
// worker-manager:manage-worker-pool:<workerPoolId>
//
// See #deleteWorkerPool
func (workerManager *WorkerManager) DeleteWorkerPool(workerPoolId string) (*WorkerPoolFullDefinition, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "DELETE", "/worker-pool/"+url.QueryEscape(workerPoolId), new(WorkerPoolFullDefinition), nil)
return responseObject.(*WorkerPoolFullDefinition), err
}
// Fetch an existing worker pool defition.
//
// Required scopes:
//
// worker-manager:get-worker-pool:<workerPoolId>
//
// See #workerPool
func (workerManager *WorkerManager) WorkerPool(workerPoolId string) (*WorkerPoolFullDefinition, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/worker-pool/"+url.QueryEscape(workerPoolId), new(WorkerPoolFullDefinition), nil)
return responseObject.(*WorkerPoolFullDefinition), err
}
// Returns a signed URL for WorkerPool, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:get-worker-pool:<workerPoolId>
//
// See WorkerPool for more details.
func (workerManager *WorkerManager) WorkerPool_SignedURL(workerPoolId string, duration time.Duration) (*url.URL, error) {
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/worker-pool/"+url.QueryEscape(workerPoolId), nil, duration)
}
// Get the list of all the existing worker pools.
//
// Required scopes:
//
// worker-manager:list-worker-pools
//
// See #listWorkerPools
func (workerManager *WorkerManager) ListWorkerPools(continuationToken, limit string) (*WorkerPoolList, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/worker-pools", new(WorkerPoolList), v)
return responseObject.(*WorkerPoolList), err
}
// Returns a signed URL for ListWorkerPools, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:list-worker-pools
//
// See ListWorkerPools for more details.
func (workerManager *WorkerManager) ListWorkerPools_SignedURL(continuationToken, limit string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/worker-pools", v, duration)
}
// Report an error that occurred on a worker. This error will be included
// with the other errors in `listWorkerPoolErrors(workerPoolId)`.
//
// Workers can use this endpoint to report startup or configuration errors
// that might be associated with the worker pool configuration and thus of
// interest to a worker-pool administrator.
//
// NOTE: errors are publicly visible. Ensure that none of the content
// contains secrets or other sensitive information.
//
// Required scopes:
//
// All of:
// * assume:worker-pool:<workerPoolId>
// * assume:worker-id:<workerGroup>/<workerId>
//
// See #reportWorkerError
func (workerManager *WorkerManager) ReportWorkerError(workerPoolId string, payload *WorkerErrorReport) (*WorkerPoolError, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(payload, "POST", "/worker-pool-errors/"+url.QueryEscape(workerPoolId), new(WorkerPoolError), nil)
return responseObject.(*WorkerPoolError), err
}
// Stability: *** EXPERIMENTAL ***
//
// Get the list of worker pool errors count.
// Contains total count of errors for the past 7 days and 24 hours
// Also includes total counts grouped by titles of error and error code.
//
// # If `workerPoolId` is not specified, it will return the count of all errors
//
// Required scopes:
//
// worker-manager:list-worker-pool-errors:<workerPoolId>
//
// See #workerPoolErrorStats
func (workerManager *WorkerManager) WorkerPoolErrorStats(workerPoolId string) (*WorkerPoolErrorStats, error) {
v := url.Values{}
if workerPoolId != "" {
v.Add("workerPoolId", workerPoolId)
}
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/worker-pool-errors/stats", new(WorkerPoolErrorStats), v)
return responseObject.(*WorkerPoolErrorStats), err
}
// Returns a signed URL for WorkerPoolErrorStats, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:list-worker-pool-errors:<workerPoolId>
//
// See WorkerPoolErrorStats for more details.
func (workerManager *WorkerManager) WorkerPoolErrorStats_SignedURL(workerPoolId string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if workerPoolId != "" {
v.Add("workerPoolId", workerPoolId)
}
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/worker-pool-errors/stats", v, duration)
}
// Get the list of worker pool errors.
//
// Required scopes:
//
// worker-manager:list-worker-pool-errors:<workerPoolId>
//
// See #listWorkerPoolErrors
func (workerManager *WorkerManager) ListWorkerPoolErrors(workerPoolId, continuationToken, limit string) (*WorkerPoolErrorList, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/worker-pool-errors/"+url.QueryEscape(workerPoolId), new(WorkerPoolErrorList), v)
return responseObject.(*WorkerPoolErrorList), err
}
// Returns a signed URL for ListWorkerPoolErrors, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:list-worker-pool-errors:<workerPoolId>
//
// See ListWorkerPoolErrors for more details.
func (workerManager *WorkerManager) ListWorkerPoolErrors_SignedURL(workerPoolId, continuationToken, limit string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/worker-pool-errors/"+url.QueryEscape(workerPoolId), v, duration)
}
// Get the list of all the existing workers in a given group in a given worker pool.
//
// Required scopes:
//
// worker-manager:list-workers:<workerPoolId>/<workerGroup>
//
// See #listWorkersForWorkerGroup
func (workerManager *WorkerManager) ListWorkersForWorkerGroup(workerPoolId, workerGroup, continuationToken, limit string) (*WorkerListInAGivenWorkerPool, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/workers/"+url.QueryEscape(workerPoolId)+"/"+url.QueryEscape(workerGroup), new(WorkerListInAGivenWorkerPool), v)
return responseObject.(*WorkerListInAGivenWorkerPool), err
}
// Returns a signed URL for ListWorkersForWorkerGroup, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:list-workers:<workerPoolId>/<workerGroup>
//
// See ListWorkersForWorkerGroup for more details.
func (workerManager *WorkerManager) ListWorkersForWorkerGroup_SignedURL(workerPoolId, workerGroup, continuationToken, limit string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/workers/"+url.QueryEscape(workerPoolId)+"/"+url.QueryEscape(workerGroup), v, duration)
}
// Get a single worker.
//
// Required scopes:
//
// worker-manager:get-worker:<workerPoolId>/<workerGroup>/<workerId>
//
// See #worker
func (workerManager *WorkerManager) Worker(workerPoolId, workerGroup, workerId string) (*WorkerFullDefinition, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/workers/"+url.QueryEscape(workerPoolId)+"/"+url.QueryEscape(workerGroup)+"/"+url.QueryEscape(workerId), new(WorkerFullDefinition), nil)
return responseObject.(*WorkerFullDefinition), err
}
// Returns a signed URL for Worker, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:get-worker:<workerPoolId>/<workerGroup>/<workerId>
//
// See Worker for more details.
func (workerManager *WorkerManager) Worker_SignedURL(workerPoolId, workerGroup, workerId string, duration time.Duration) (*url.URL, error) {
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/workers/"+url.QueryEscape(workerPoolId)+"/"+url.QueryEscape(workerGroup)+"/"+url.QueryEscape(workerId), nil, duration)
}
// Create a new worker. This is only useful for worker pools where the provider
// does not create workers automatically, such as those with a `static` provider
// type. Providers that do not support creating workers will return a 400 error.
// See the documentation for the individual providers, and in particular the
// [static provider](https://docs.taskcluster.net/docs/reference/core/worker-manager/)
// for more information.
//
// Required scopes:
//
// worker-manager:create-worker:<workerPoolId>/<workerGroup>/<workerId>
//
// See #createWorker
func (workerManager *WorkerManager) CreateWorker(workerPoolId, workerGroup, workerId string, payload *WorkerCreationUpdateRequest) (*WorkerFullDefinition, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(payload, "PUT", "/workers/"+url.QueryEscape(workerPoolId)+"/"+url.QueryEscape(workerGroup)+"/"+url.QueryEscape(workerId), new(WorkerFullDefinition), nil)
return responseObject.(*WorkerFullDefinition), err
}
// Update an existing worker in-place. Like `createWorker`, this is only useful for
// worker pools where the provider does not create workers automatically.
// This method allows updating all fields in the schema unless otherwise indicated
// in the provider documentation.
// See the documentation for the individual providers, and in particular the
// [static provider](https://docs.taskcluster.net/docs/reference/core/worker-manager/)
// for more information.
//
// Required scopes:
//
// worker-manager:update-worker:<workerPoolId>/<workerGroup>/<workerId>
//
// See #updateWorker
func (workerManager *WorkerManager) UpdateWorker(workerPoolId, workerGroup, workerId string, payload *WorkerCreationUpdateRequest) (*WorkerFullDefinition, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(payload, "POST", "/workers/"+url.QueryEscape(workerPoolId)+"/"+url.QueryEscape(workerGroup)+"/"+url.QueryEscape(workerId), new(WorkerFullDefinition), nil)
return responseObject.(*WorkerFullDefinition), err
}
// Remove an existing worker. The precise behavior of this method depends
// on the provider implementing the given worker. Some providers
// do not support removing workers at all, and will return a 400 error.
// Others may begin removing the worker, but it may remain available via
// the API (perhaps even in state RUNNING) afterward.
//
// Required scopes:
//
// worker-manager:remove-worker:<workerPoolId>/<workerGroup>/<workerId>
//
// See #removeWorker
func (workerManager *WorkerManager) RemoveWorker(workerPoolId, workerGroup, workerId string) error {
cd := tcclient.Client(*workerManager)
_, _, err := (&cd).APICall(nil, "DELETE", "/workers/"+url.QueryEscape(workerPoolId)+"/"+url.QueryEscape(workerGroup)+"/"+url.QueryEscape(workerId), nil, nil)
return err
}
// Get the list of all the existing workers in a given worker pool.
//
// Required scopes:
//
// worker-manager:list-workers:<workerPoolId>
//
// See #listWorkersForWorkerPool
func (workerManager *WorkerManager) ListWorkersForWorkerPool(workerPoolId, continuationToken, limit, state string) (*WorkerListInAGivenWorkerPool, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
if state != "" {
v.Add("state", state)
}
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/workers/"+url.QueryEscape(workerPoolId), new(WorkerListInAGivenWorkerPool), v)
return responseObject.(*WorkerListInAGivenWorkerPool), err
}
// Returns a signed URL for ListWorkersForWorkerPool, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:list-workers:<workerPoolId>
//
// See ListWorkersForWorkerPool for more details.
func (workerManager *WorkerManager) ListWorkersForWorkerPool_SignedURL(workerPoolId, continuationToken, limit, state string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
if state != "" {
v.Add("state", state)
}
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/workers/"+url.QueryEscape(workerPoolId), v, duration)
}
// Register a running worker. Workers call this method on worker start-up.
//
// This call both marks the worker as running and returns the credentials
// the worker will require to perform its work. The worker must provide
// some proof of its identity, and that proof varies by provider type.
//
// See #registerWorker
func (workerManager *WorkerManager) RegisterWorker(payload *RegisterWorkerRequest) (*RegisterWorkerResponse, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(payload, "POST", "/worker/register", new(RegisterWorkerResponse), nil)
return responseObject.(*RegisterWorkerResponse), err
}
// Stability: *** EXPERIMENTAL ***
//
// Reregister a running worker.
//
// This will generate and return new Taskcluster credentials for the worker
// on that instance to use. The credentials will not live longer the
// `registrationTimeout` for that worker. The endpoint will update `terminateAfter`
// for the worker so that worker-manager does not terminate the instance.
//
// Required scopes:
//
// worker-manager:reregister-worker:<workerPoolId>/<workerGroup>/<workerId>
//
// See #reregisterWorker
func (workerManager *WorkerManager) ReregisterWorker(payload *ReregisterWorkerRequest) (*ReregisterWorkerResponse, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(payload, "POST", "/worker/reregister", new(ReregisterWorkerResponse), nil)
return responseObject.(*ReregisterWorkerResponse), err
}
// Stability: *** EXPERIMENTAL ***
//
// Get a list of all active workers of a workerType.
//
// `listWorkers` allows a response to be filtered by quarantined and non quarantined workers,
// as well as the current state of the worker.
// To filter the query, you should call the end-point with one of [`quarantined`, `workerState`]
// as a query-string option with a true or false value.
//
// The response is paged. If this end-point returns a `continuationToken`, you
// should call the end-point again with the `continuationToken` as a query-string
// option. By default this end-point will list up to 1000 workers in a single
// page. You may limit this with the query-string parameter `limit`.
//
// Required scopes:
//
// worker-manager:list-workers:<provisionerId>/<workerType>
//
// See #listWorkers
func (workerManager *WorkerManager) ListWorkers(provisionerId, workerType, continuationToken, limit, quarantined, workerState string) (*ListWorkersResponse, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
if quarantined != "" {
v.Add("quarantined", quarantined)
}
if workerState != "" {
v.Add("workerState", workerState)
}
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/provisioners/"+url.QueryEscape(provisionerId)+"/worker-types/"+url.QueryEscape(workerType)+"/workers", new(ListWorkersResponse), v)
return responseObject.(*ListWorkersResponse), err
}
// Returns a signed URL for ListWorkers, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:list-workers:<provisionerId>/<workerType>
//
// See ListWorkers for more details.
func (workerManager *WorkerManager) ListWorkers_SignedURL(provisionerId, workerType, continuationToken, limit, quarantined, workerState string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
if quarantined != "" {
v.Add("quarantined", quarantined)
}
if workerState != "" {
v.Add("workerState", workerState)
}
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/provisioners/"+url.QueryEscape(provisionerId)+"/worker-types/"+url.QueryEscape(workerType)+"/workers", v, duration)
}
// Stability: *** EXPERIMENTAL ***
//
// Get a worker from a worker-type.
//
// Required scopes:
//
// worker-manager:get-worker:<provisionerId>/<workerType>/<workerGroup>/<workerId>
//
// See #getWorker
func (workerManager *WorkerManager) GetWorker(provisionerId, workerType, workerGroup, workerId string) (*WorkerResponse, error) {
cd := tcclient.Client(*workerManager)
responseObject, _, err := (&cd).APICall(nil, "GET", "/provisioners/"+url.QueryEscape(provisionerId)+"/worker-types/"+url.QueryEscape(workerType)+"/workers/"+url.QueryEscape(workerGroup)+"/"+url.QueryEscape(workerId), new(WorkerResponse), nil)
return responseObject.(*WorkerResponse), err
}
// Returns a signed URL for GetWorker, valid for the specified duration.
//
// Required scopes:
//
// worker-manager:get-worker:<provisionerId>/<workerType>/<workerGroup>/<workerId>
//
// See GetWorker for more details.
func (workerManager *WorkerManager) GetWorker_SignedURL(provisionerId, workerType, workerGroup, workerId string, duration time.Duration) (*url.URL, error) {
cd := tcclient.Client(*workerManager)
return (&cd).SignedURL("/provisioners/"+url.QueryEscape(provisionerId)+"/worker-types/"+url.QueryEscape(workerType)+"/workers/"+url.QueryEscape(workerGroup)+"/"+url.QueryEscape(workerId), nil, duration)
}
// Respond with a service heartbeat.
//
// This endpoint is used to check on backing services this service
// depends on.
//
// See #heartbeat
func (workerManager *WorkerManager) Heartbeat() error {
cd := tcclient.Client(*workerManager)
_, _, err := (&cd).APICall(nil, "GET", "/__heartbeat__", nil, nil)
return err
}