forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locks.go
63 lines (48 loc) · 1.25 KB
/
locks.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
package director
import (
"strconv"
"time"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type Lock struct {
Type string // e.g. "deployment"
Resource []string // e.g. ["some-deployment-name"]
ExpiresAt time.Time
}
type LockResp struct {
Type string // e.g. "deployment"
Resource []string // e.g. ["some-deployment-name"]
Timeout string // e.g. "1443889622.9964118"
}
type TimeoutTime time.Time
func (d DirectorImpl) Locks() ([]Lock, error) {
var locks []Lock
resps, err := d.client.Locks()
if err != nil {
return locks, err
}
for _, r := range resps {
f, err := strconv.ParseFloat(r.Timeout, 64)
if err != nil {
return locks, bosherr.WrapErrorf(err, "Converting timeout '%s' to float", r.Timeout)
}
lock := Lock{
Type: r.Type,
Resource: r.Resource,
ExpiresAt: time.Unix(int64(f), 0).UTC(),
}
locks = append(locks, lock)
}
return locks, nil
}
func (c Client) Locks() ([]LockResp, error) {
var locks []LockResp
err := c.clientRequest.Get("/locks", &locks)
if err != nil {
return locks, bosherr.WrapErrorf(err, "Finding locks")
}
return locks, nil
}
func (l LockResp) IsForDeployment(name string) bool {
return l.Type == "deployment" && len(l.Resource) == 1 && l.Resource[0] == name
}