forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offer.go
40 lines (32 loc) · 878 Bytes
/
offer.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
package job
import (
"sort"
)
type JobOffer struct {
Job Job
// MachineIDs represents a set of machines for which this offer is valid.
// If nil or len == 0 then all machines. Must be sorted.
MachineIDs []string
}
func NewOfferFromJob(j Job, machineIDs []string) *JobOffer {
return &JobOffer{
Job: j,
MachineIDs: machineIDs,
}
}
// OfferedTo returns true if job is being offered to specified machine.
func (jo *JobOffer) OfferedTo(machineID string) bool {
// for backward compatibility: if not populated, assume all machines are considered
if len(jo.MachineIDs) == 0 {
return true
}
k := sort.SearchStrings(jo.MachineIDs, machineID)
return k < len(jo.MachineIDs) && jo.MachineIDs[k] == machineID
}
type JobBid struct {
JobName string
MachineID string
}
func NewBid(jobName string, machID string) *JobBid {
return &JobBid{jobName, machID}
}