This repository has been archived by the owner on Sep 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
port.go
52 lines (42 loc) · 1.39 KB
/
port.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
package controller
import (
"fmt"
"github.com/kandoo/beehive/Godeps/_workspace/src/github.com/golang/glog"
"github.com/1995parham/flynest/nom"
bh "github.com/kandoo/beehive"
)
type portStatusHandler struct{}
func (h portStatusHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
// FIXME(soheil): This implementation is very naive and cannot tolerate
// faults. We need to first check if the driver is the mater, and then apply
// the change. Otherwise, we need to enque this message for that driver and
// make sure we apply the log to the port status
data := msg.Data().(nom.PortStatusChanged)
dict := ctx.Dict(driversDict)
k := string(data.Port.Node)
v, err := dict.Get(k)
if err != nil {
return fmt.Errorf("NOMController: node %v not found", data.Port.Node)
}
n := v.(nodeDrivers)
if !n.isMaster(data.Driver) {
glog.Warningf("NOMController: %v ignored, %v is not master, master is %v",
data.Port, data.Driver, n.master())
return nil
}
if p, ok := n.Ports.GetPort(data.Port.UID()); ok {
if p == data.Port {
return fmt.Errorf("NOMController: duplicate port status change for %v",
data.Port)
}
n.Ports.DelPort(p)
}
n.Ports.AddPort(data.Port)
ctx.Emit(nom.PortUpdated(data.Port))
return nil
}
func (h portStatusHandler) Map(msg bh.Msg, ctx bh.MapContext) bh.MappedCells {
return bh.MappedCells{
{driversDict, string(msg.Data().(nom.PortStatusChanged).Port.Node)},
}
}