-
Notifications
You must be signed in to change notification settings - Fork 17
/
get_events.go
41 lines (32 loc) · 1.02 KB
/
get_events.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
package boshdirector
import (
"fmt"
"log"
"strconv"
"github.com/cloudfoundry/bosh-cli/v7/director"
"github.com/pkg/errors"
)
type BoshEvent struct {
TaskId int
}
func (c *Client) GetEvents(deploymentName, action string, logger *log.Logger) ([]BoshEvent, error) {
filter := director.EventsFilter{Deployment: deploymentName, Action: action, ObjectType: "deployment"}
logger.Printf("getting events for %v from bosh", filter)
d, err := c.Director(director.NewNoopTaskReporter())
if err != nil {
return []BoshEvent{}, errors.Wrap(err, "Failed to build director")
}
events, err := d.Events(filter)
if err != nil {
return []BoshEvent{}, errors.Wrap(err, "Failed to get the events using the director")
}
var boshEvents []BoshEvent
for _, event := range events {
taskId, err := strconv.Atoi(event.TaskID())
if err != nil {
return []BoshEvent{}, errors.New(fmt.Sprintf("could not convert task id %q to int", event.TaskID()))
}
boshEvents = append(boshEvents, BoshEvent{TaskId: taskId})
}
return boshEvents, nil
}