forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
107 lines (93 loc) · 3.31 KB
/
driver.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package mesos
import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/docker/swarm/cluster"
"github.com/mesos/mesos-go/mesosproto"
mesosscheduler "github.com/mesos/mesos-go/scheduler"
)
// Registered method for registered mesos framework
func (c *Cluster) Registered(driver mesosscheduler.SchedulerDriver, fwID *mesosproto.FrameworkID, masterInfo *mesosproto.MasterInfo) {
log.WithFields(log.Fields{"name": "mesos", "frameworkId": fwID.GetValue()}).Debug("Framework registered")
}
// Reregistered method for registered mesos framework
func (c *Cluster) Reregistered(mesosscheduler.SchedulerDriver, *mesosproto.MasterInfo) {
log.WithFields(log.Fields{"name": "mesos"}).Debug("Framework re-registered")
}
// Disconnected method
func (c *Cluster) Disconnected(mesosscheduler.SchedulerDriver) {
log.WithFields(log.Fields{"name": "mesos"}).Debug("Framework disconnected")
}
// ResourceOffers method
func (c *Cluster) ResourceOffers(_ mesosscheduler.SchedulerDriver, offers []*mesosproto.Offer) {
log.WithFields(log.Fields{"name": "mesos", "offers": len(offers)}).Debug("Offers received")
for _, offer := range offers {
slaveID := offer.SlaveId.GetValue()
dockerPort := c.dockerEnginePort
for _, attribute := range offer.GetAttributes() {
if attribute.GetName() == dockerPortAttribute {
switch attribute.GetType() {
case mesosproto.Value_SCALAR:
dockerPort = fmt.Sprintf("%d", int(attribute.GetScalar().GetValue()))
case mesosproto.Value_TEXT:
dockerPort = attribute.GetText().GetValue()
}
}
}
s, ok := c.slaves[slaveID]
if !ok {
engine := cluster.NewEngine(*offer.Hostname+":"+dockerPort, 0, c.engineOpts)
if err := engine.Connect(c.TLSConfig); err != nil {
log.Error(err)
} else {
s = newSlave(slaveID, engine)
c.slaves[slaveID] = s
if err := s.engine.RegisterEventHandler(c); err != nil {
log.Error(err)
}
}
}
c.addOffer(offer)
}
go c.pendingTasks.Process()
}
// OfferRescinded method
func (c *Cluster) OfferRescinded(mesosscheduler.SchedulerDriver, *mesosproto.OfferID) {
}
// StatusUpdate method
func (c *Cluster) StatusUpdate(_ mesosscheduler.SchedulerDriver, taskStatus *mesosproto.TaskStatus) {
log.WithFields(log.Fields{"name": "mesos", "state": taskStatus.State.String()}).Debug("Status update")
taskID := taskStatus.TaskId.GetValue()
slaveID := taskStatus.SlaveId.GetValue()
s, ok := c.slaves[slaveID]
if !ok {
return
}
if task, ok := s.tasks[taskID]; ok {
task.sendStatus(taskStatus)
} else {
var reason = ""
if taskStatus.Reason != nil {
reason = taskStatus.GetReason().String()
}
log.WithFields(log.Fields{
"name": "mesos",
"state": taskStatus.State.String(),
"slaveId": taskStatus.SlaveId.GetValue(),
"reason": reason,
}).Warn("Status update received for unknown slave")
}
}
// FrameworkMessage method
func (c *Cluster) FrameworkMessage(mesosscheduler.SchedulerDriver, *mesosproto.ExecutorID, *mesosproto.SlaveID, string) {
}
// SlaveLost method
func (c *Cluster) SlaveLost(mesosscheduler.SchedulerDriver, *mesosproto.SlaveID) {
}
// ExecutorLost method
func (c *Cluster) ExecutorLost(mesosscheduler.SchedulerDriver, *mesosproto.ExecutorID, *mesosproto.SlaveID, int) {
}
// Error method
func (c *Cluster) Error(d mesosscheduler.SchedulerDriver, msg string) {
log.WithFields(log.Fields{"name": "mesos"}).Error(msg)
}