-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbatch.go
102 lines (81 loc) · 2.27 KB
/
batch.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
package livy
import (
"fmt"
"github.com/pkg/errors"
)
// Returns all the active Batch sessions.
func (c *Client) GetBatches(from, size int) ([]Batch, error) {
data := &GetBatchesRequest{
From: from,
Size: size,
}
req, err := c.NewRequest("GET", "/batches", data)
if err != nil {
return nil, errors.Wrap(err, "creating request")
}
var sessionsBatches GetBatchesResponse
if err := c.Do(req, &sessionsBatches); err != nil {
return nil, err
}
return sessionsBatches.Sessions, nil
}
// Start new Batch and return the created Batch object.
func (c *Client) PostBatch(batchRequest *PostBatchRequest) (*Batch, error) {
req, err := c.NewRequest("POST", "/batches", batchRequest)
if err != nil {
return nil, errors.Wrap(err, "creating request")
}
var batch Batch
if err := c.Do(req, &batch); err != nil {
return nil, err
}
return &batch, nil
}
// Returns the Batch session information.
func (c *Client) GetBatch(batchID int) (*Batch, error) {
req, err := c.NewRequest("GET", fmt.Sprintf("/batches/%d", batchID), nil)
if err != nil {
return nil, errors.Wrap(err, "creating request")
}
var batch Batch
if err := c.Do(req, &batch); err != nil {
return nil, err
}
return &batch, nil
}
// Returns the state of batch session.
func (c *Client) GetBatchState(batchID int) (string, error) {
req, err := c.NewRequest("GET", fmt.Sprintf("/batches/%d/state", batchID), nil)
if err != nil {
return "", errors.Wrap(err, "creating request")
}
var batchState GetBatchStateResponse
if err := c.Do(req, &batchState); err != nil {
return "", err
}
return batchState.State, nil
}
// Kills the Batch job.
func (c *Client) KillBatchJob(batchID int) error {
req, err := c.NewRequest("DELETE", fmt.Sprintf("/batches/%d", batchID), nil)
if err != nil {
return errors.Wrap(err, "creating request")
}
return c.Do(req, nil)
}
// Gets the log lines from this batch.
func (c *Client) GetBatchLogs(batchID, from, size int) ([]string, error) {
data := &GetBatchLogsRequest{
From: from,
Size: size,
}
req, err := c.NewRequest("GET", fmt.Sprintf("/batches/%d/logs", batchID), data)
if err != nil {
return nil, errors.Wrap(err, "creating request")
}
var batchLogs GetBatchLogsResponse
if err := c.Do(req, &batchLogs); err != nil {
return nil, err
}
return batchLogs.Log, nil
}