Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions agent.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package libnetwork

//go:generate protoc -I.:Godeps/_workspace/src/github.com/gogo/protobuf --gogo_out=import_path=github.com/docker/libnetwork,Mgogoproto/gogo.proto=github.com/gogo/protobuf/gogoproto:. agent.proto

import (
"fmt"
"net"
"os"
"strings"

"github.com/Sirupsen/logrus"
"github.com/docker/go-events"
"github.com/docker/libnetwork/datastore"
"github.com/docker/libnetwork/discoverapi"
"github.com/docker/libnetwork/driverapi"
"github.com/docker/libnetwork/networkdb"
"github.com/gogo/protobuf/proto"
)

type agent struct {
Expand Down Expand Up @@ -169,8 +171,18 @@ func (ep *endpoint) addToCluster() error {
return err
}

if err := c.agent.networkDB.CreateEntry("endpoint_table", n.ID(), ep.ID(), []byte(fmt.Sprintf("%s,%s,%s,%s", ep.Name(), ep.svcName,
ep.svcID, ep.Iface().Address().IP))); err != nil {
buf, err := proto.Marshal(&EndpointRecord{
Name: ep.Name(),
ServiceName: ep.svcName,
ServiceID: ep.svcID,
EndpointIP: ep.Iface().Address().IP.String(),
})

if err != nil {
return err
}

if err := c.agent.networkDB.CreateEntry("endpoint_table", n.ID(), ep.ID(), buf); err != nil {
return err
}
}
Expand Down Expand Up @@ -310,20 +322,21 @@ func (c *controller) handleEpTableEvent(ev events.Event) {
var (
nid string
eid string
value string
value []byte
isAdd bool
epRec EndpointRecord
)

switch event := ev.(type) {
case networkdb.CreateEvent:
nid = event.NetworkID
eid = event.Key
value = string(event.Value)
value = event.Value
isAdd = true
case networkdb.DeleteEvent:
nid = event.NetworkID
eid = event.Key
value = string(event.Value)
value = event.Value
case networkdb.UpdateEvent:
logrus.Errorf("Unexpected update service table event = %#v", event)
}
Expand All @@ -335,16 +348,16 @@ func (c *controller) handleEpTableEvent(ev events.Event) {
}
n := nw.(*network)

vals := strings.Split(value, ",")
if len(vals) < 4 {
logrus.Errorf("Incorrect service table value = %s", value)
err = proto.Unmarshal(value, &epRec)
if err != nil {
logrus.Errorf("Failed to unmarshal service table value: %v", err)
return
}

name := vals[0]
svcName := vals[1]
svcID := vals[2]
ip := net.ParseIP(vals[3])
name := epRec.Name
svcName := epRec.ServiceName
svcID := epRec.ServiceID
ip := net.ParseIP(epRec.EndpointIP)

if name == "" || ip == nil {
logrus.Errorf("Invalid endpoint name/ip received while handling service table event %s", value)
Expand Down
Loading