forked from cloudfoundry/executor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
96 lines (80 loc) · 2 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
package executor
import (
"io"
"github.com/pivotal-golang/lager"
)
//go:generate counterfeiter -o fakes/fake_client.go . Client
type Client interface {
Ping() error
AllocateContainers(requests []AllocationRequest) ([]AllocationFailure, error)
GetContainer(guid string) (Container, error)
RunContainer(*RunRequest) error
StopContainer(guid string) error
DeleteContainer(guid string) error
ListContainers(Tags) ([]Container, error)
GetAllMetrics(Tags) (map[string]Metrics, error)
GetMetrics(guid string) (ContainerMetrics, error)
RemainingResources() (ExecutorResources, error)
RemainingResourcesFrom([]Container) (ExecutorResources, error)
TotalResources() (ExecutorResources, error)
GetFiles(guid string, path string) (io.ReadCloser, error)
SubscribeToEvents() (EventSource, error)
Cleanup()
}
type ClientProvider interface {
WithLogger(logger lager.Logger) Client
}
type WorkPoolSettings struct {
CreateWorkPoolSize int
DeleteWorkPoolSize int
ReadWorkPoolSize int
MetricsWorkPoolSize int
}
//go:generate counterfeiter -o fakes/fake_event_source.go . EventSource
type EventSource interface {
Next() (Event, error)
Close() error
}
type AllocationRequest struct {
Guid string
Resource
Tags
}
func NewAllocationRequest(guid string, resource *Resource, tags Tags) AllocationRequest {
return AllocationRequest{
Guid: guid,
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,
}
}