forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offer.go
45 lines (36 loc) · 1.19 KB
/
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
41
42
43
44
45
package job
import (
"sort"
)
type JobOffer struct {
Job Job
// MachineBootIDs represents a set of machines for which this offer is valid.
// If nil or len == 0 then all machines. Must be to be sorted.
// MachineBootIDs started life as MachineBootIds in the datastore.
// It cannot be changed without a migration
MachineBootIDs []string `json:"MachineBootIds"`
}
func NewOfferFromJob(j Job, machineBootIDs []string) *JobOffer {
return &JobOffer{
Job: j,
MachineBootIDs: machineBootIDs,
}
}
// OfferedTo returns true if job is being offered to specified machine.
func (jo *JobOffer) OfferedTo(machineBootID string) bool {
// for backward compatibility: if not populated, assume all machines are considered
if len(jo.MachineBootIDs) == 0 {
return true
}
k := sort.SearchStrings(jo.MachineBootIDs, machineBootID)
return k < len(jo.MachineBootIDs) && jo.MachineBootIDs[k] == machineBootID
}
type JobBid struct {
JobName string
// MachineBootID started life as MachineBootId in the datastore.
// It cannot be changed without a migration.
MachineBootID string `json:"MachineBootId"`
}
func NewBid(jobName string, machBootID string) *JobBid {
return &JobBid{jobName, machBootID}
}