-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
32 lines (25 loc) · 1.11 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
package main
import nomad "github.com/hashicorp/nomad/api"
// LogGetter defines an interface to a nomad log recollection object
type LogGetter interface {
Logs(alloc *nomad.Allocation, follow bool, task, logType, origin string,
offset int64, cancel <-chan struct{}, q *nomad.QueryOptions) (<-chan *nomad.StreamFrame, <-chan error)
}
// Client is an interface to nomad client with the usefull functions
type Client interface {
Allocations(nodeID string, q *nomad.QueryOptions) ([]*nomad.Allocation, *nomad.QueryMeta, error)
LogGetter
}
type apiClient struct {
client *nomad.Client
}
func (c *apiClient) Allocations(nodeID string, q *nomad.QueryOptions) ([]*nomad.Allocation, *nomad.QueryMeta, error) {
return c.client.Nodes().Allocations(nodeID, q)
}
func (c *apiClient) Logs(alloc *nomad.Allocation, follow bool, task, logType, origin string,
offset int64, cancel <-chan struct{}, q *nomad.QueryOptions) (<-chan *nomad.StreamFrame, <-chan error) {
return c.client.AllocFS().Logs(alloc, follow, task, logType, origin, offset, cancel, q)
}
func newClient(client *nomad.Client) Client {
return &apiClient{client: client}
}