-
Notifications
You must be signed in to change notification settings - Fork 42
/
client.go
104 lines (88 loc) · 2.64 KB
/
client.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
package executor
import (
"io"
"code.cloudfoundry.org/lager/v3"
"code.cloudfoundry.org/routing-info/internalroutes"
)
//go:generate counterfeiter -o fakes/fake_client.go . Client
type Client interface {
Ping(logger lager.Logger) error
AllocateContainers(logger lager.Logger, traceID string, requests []AllocationRequest) []AllocationFailure
GetContainer(logger lager.Logger, guid string) (Container, error)
RunContainer(lager.Logger, string, *RunRequest) error
UpdateContainer(lager.Logger, *UpdateRequest) error
StopContainer(logger lager.Logger, traceID string, guid string) error
DeleteContainer(logger lager.Logger, traceID string, guid string) error
ListContainers(lager.Logger) ([]Container, error)
GetBulkMetrics(lager.Logger) (map[string]Metrics, error)
RemainingResources(lager.Logger) (ExecutorResources, error)
TotalResources(lager.Logger) (ExecutorResources, error)
GetFiles(logger lager.Logger, guid string, path string) (io.ReadCloser, error)
VolumeDrivers(logger lager.Logger) ([]string, error)
SubscribeToEvents(lager.Logger) (EventSource, error)
Healthy(lager.Logger) bool
SetHealthy(lager.Logger, bool)
Cleanup(lager.Logger)
}
//go:generate counterfeiter -o fakes/fake_event_source.go . EventSource
type EventSource interface {
Next() (Event, error)
Close() error
}
type AllocationRequest struct {
Guid string
GenerateLogMetrics bool
Resource
Tags
}
func NewAllocationRequest(guid string, resource *Resource, generateLogMetrics bool, tags Tags) AllocationRequest {
return AllocationRequest{
Guid: guid,
GenerateLogMetrics: generateLogMetrics,
Resource: *resource,
Tags: tags,
}
}
func (a *AllocationRequest) Validate() error {
if a.Guid == "" {
return ErrGuidNotSpecified
}
return nil
}
type AllocationFailure struct {
AllocationRequest
ErrorMsg string
}
func (fail *AllocationFailure) Error() string {
return fail.ErrorMsg
}
func NewAllocationFailure(req *AllocationRequest, msg string) AllocationFailure {
return AllocationFailure{
AllocationRequest: *req,
ErrorMsg: msg,
}
}
type RunRequest struct {
Guid string
RunInfo
Tags
}
func NewRunRequest(guid string, runInfo *RunInfo, tags Tags) RunRequest {
return RunRequest{
Guid: guid,
RunInfo: *runInfo,
Tags: tags,
}
}
type UpdateRequest struct {
Guid string
InternalRoutes internalroutes.InternalRoutes
MetricTags map[string]string
}
func NewUpdateRequest(guid string, internalRoutes internalroutes.InternalRoutes, metricTags map[string]string) UpdateRequest {
return UpdateRequest{
Guid: guid,
InternalRoutes: internalRoutes,
MetricTags: metricTags,
}
}