weave connect should be best-effort, and return errors for any fails

This commit is contained in:
Paul Bellamy committed 2015-05-26 14:37:22 +01:00
1 parent d18640fc8c
commit b392a7d24d
2 files changed
+19 -10

No files matched your search

+7 -6
View File
@@ -48,7 +48,8 @@ func (cm *ConnectionMaker) Start() {
go cm.queryLoop(actionChan)
}
func (cm *ConnectionMaker) InitiateConnections(peers []string) error {
func (cm *ConnectionMaker) InitiateConnections(peers []string) []error {
errors := []error{}
addrs := make(map[string]*net.TCPAddr)
for _, peer := range peers {
host, port, err := net.SplitHostPort(peer)
@@ -56,11 +57,11 @@ func (cm *ConnectionMaker) InitiateConnections(peers []string) error {
host = peer
port = "0" // we use that as an indication that "no port was supplied"
}
addr, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%s:%s", host, port))
if err != nil {
return err
if addr, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%s:%s", host, port)); err != nil {
errors = append(errors, err)
} else {
addrs[peer] = addr
}
addrs[peer] = addr
}
cm.actionChan <- func() bool {
for peer, addr := range addrs {
@@ -72,7 +73,7 @@ func (cm *ConnectionMaker) InitiateConnections(peers []string) error {
}
return true
}
return nil
return errors
}
func (cm *ConnectionMaker) ForgetConnections(peers []string) {
+12 -4
View File
@@ -144,8 +144,8 @@ func main() {
}
router.Start()
if err := router.ConnectionMaker.InitiateConnections(peers); err != nil {
log.Fatal(err)
if errors := router.ConnectionMaker.InitiateConnections(peers); len(errors) > 0 {
log.Fatal(errorMessages(errors))
}
// The weave script always waits for a status call to succeed,
@@ -158,6 +158,14 @@ func main() {
SignalHandlerLoop(router)
}
func errorMessages(errors []error) string {
var result []string
for _, err := range errors {
result = append(result, err.Error())
}
return strings.Join(result, "\n")
}
func options() map[string]string {
options := make(map[string]string)
flag.Visit(func(f *flag.Flag) {
@@ -248,8 +256,8 @@ func handleHTTP(router *weave.Router, httpAddr string, allocator *ipam.Allocator
if err := r.ParseForm(); err != nil {
http.Error(w, fmt.Sprint("unable to parse form: ", err), http.StatusBadRequest)
}
if err := router.ConnectionMaker.InitiateConnections(r.Form["peer"]); err != nil {
http.Error(w, fmt.Sprint("invalid peer address: ", err), http.StatusBadRequest)
if errors := router.ConnectionMaker.InitiateConnections(r.Form["peer"]); len(errors) > 0 {
http.Error(w, errorMessages(errors), http.StatusBadRequest)
}
})