-
Notifications
You must be signed in to change notification settings - Fork 64
/
test_util.go
89 lines (80 loc) · 3.07 KB
/
test_util.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
package binpacking
import (
"context"
"fmt"
"github.com/uber/peloton/pkg/hostmgr/watchevent"
"time"
mesos "github.com/uber/peloton/.gen/mesos/v1"
"github.com/uber/peloton/pkg/common/util"
"github.com/uber/peloton/pkg/hostmgr/scalar"
"github.com/uber/peloton/pkg/hostmgr/summary"
)
func CreateOfferIndex(processor watchevent.WatchProcessor) map[string]summary.HostSummary {
offerIndex := make(map[string]summary.HostSummary)
hostName0 := "hostname0"
offer0 := CreateOffer(hostName0, scalar.Resources{CPU: 1, Mem: 1, Disk: 1, GPU: 1})
summry0 := summary.New(nil, hostName0, nil, time.Duration(30*time.Second), processor)
summry0.AddMesosOffers(context.Background(), []*mesos.Offer{offer0})
offerIndex[hostName0] = summry0
hostName1 := "hostname1"
offer1 := CreateOffer(hostName1, scalar.Resources{CPU: 1, Mem: 1, Disk: 1, GPU: 4})
summry1 := summary.New(nil, hostName1, nil, time.Duration(30*time.Second), processor)
summry1.AddMesosOffers(context.Background(), []*mesos.Offer{offer1})
offerIndex[hostName1] = summry1
hostName2 := "hostname2"
offer2 := CreateOffer(hostName2, scalar.Resources{CPU: 2, Mem: 2, Disk: 2, GPU: 4})
summry2 := summary.New(nil, hostName2, nil, time.Duration(30*time.Second), processor)
summry2.AddMesosOffers(context.Background(), []*mesos.Offer{offer2})
offerIndex[hostName2] = summry2
hostName3 := "hostname3"
offer3 := CreateOffer(hostName3, scalar.Resources{CPU: 3, Mem: 3, Disk: 3, GPU: 2})
summry3 := summary.New(nil, hostName3, nil, time.Duration(30*time.Second), processor)
summry3.AddMesosOffers(context.Background(), []*mesos.Offer{offer3})
offerIndex[hostName3] = summry3
hostName4 := "hostname4"
offer4 := CreateOffer(hostName4, scalar.Resources{CPU: 3, Mem: 3, Disk: 3, GPU: 2})
summry4 := summary.New(nil, hostName4, nil, time.Duration(30*time.Second), processor)
summry4.AddMesosOffers(context.Background(), []*mesos.Offer{offer4})
offerIndex[hostName4] = summry4
return offerIndex
}
func AddHostToIndex(id int, offerIndex map[string]summary.HostSummary, processor watchevent.WatchProcessor) {
hostName := fmt.Sprintf("hostname%d", id)
offer := CreateOffer(hostName, scalar.Resources{CPU: 5, Mem: 5, Disk: 5, GPU: 5})
summry := summary.New(nil, hostName, nil, time.Duration(30*time.Second), processor)
summry.AddMesosOffers(context.Background(), []*mesos.Offer{offer})
offerIndex[hostName] = summry
}
func CreateOffer(
hostName string,
resource scalar.Resources) *mesos.Offer {
offerID := fmt.Sprintf("%s-%d", hostName, 1)
agentID := fmt.Sprintf("%s-%d", hostName, 1)
return &mesos.Offer{
Id: &mesos.OfferID{
Value: &offerID,
},
AgentId: &mesos.AgentID{
Value: &agentID,
},
Hostname: &hostName,
Resources: []*mesos.Resource{
util.NewMesosResourceBuilder().
WithName("cpus").
WithValue(resource.CPU).
Build(),
util.NewMesosResourceBuilder().
WithName("mem").
WithValue(resource.Mem).
Build(),
util.NewMesosResourceBuilder().
WithName("disk").
WithValue(resource.Disk).
Build(),
util.NewMesosResourceBuilder().
WithName("gpus").
WithValue(resource.GPU).
Build(),
},
}
}