diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-01-04 23:42:31 +0100 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-01-04 23:42:33 +0100 |
commit | f1083a8259b3d2f560b5f3ccb8b47c94e297d7fa (patch) | |
tree | f737d46443a30c066c29eea738a34174c64ae746 /lib/agent/apiv1.go | |
parent | 45f6472d1e8ecad428da314a6d762143f033865d (diff) |
Fixed Xds-server re-connection.
Add a callback on XDS-Server connect in order to properly register to
XDS Server events in all cases (IOW on reconnection).
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/agent/apiv1.go')
-rw-r--r-- | lib/agent/apiv1.go | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/agent/apiv1.go b/lib/agent/apiv1.go index d0e5a1c..a66f451 100644 --- a/lib/agent/apiv1.go +++ b/lib/agent/apiv1.go @@ -117,6 +117,30 @@ func (s *APIService) AddXdsServer(cfg xdsconfig.XDSServerConf) (*XdsServer, erro // Declare passthrough routes s.sdksPassthroughInit(svr) + + // Register callback on Connection + svr.ConnectOn(func(server *XdsServer) error { + + // Add server to list + s.xdsServers[server.ID] = svr + + // Register event forwarder + if err := s.sdksEventsForwardInit(server); err != nil { + s.Log.Errorf("XDS Server %v - sdk event forwarding error: %v", server.ID, err) + } + + // Load projects + if err := s.projects.Init(server); err != nil { + s.Log.Errorf("XDS Server %v - project init error: %v", server.ID, err) + } + + // Registered to all events + if err := server.EventRegister(xsapiv1.EVTAll, ""); err != nil { + s.Log.Errorf("XDS Server %v - register all events error: %v", server.ID, err) + } + + return nil + }) } // Established connection @@ -127,24 +151,6 @@ func (s *APIService) AddXdsServer(cfg xdsconfig.XDSServerConf) (*XdsServer, erro delete(s.xdsServers, cfg.ID) } - // Add to map - s.xdsServers[svr.ID] = svr - - // Register event forwarder - s.sdksEventsForwardInit(svr) - - // Load projects - if err == nil && svr.Connected { - err = s.projects.Init(svr) - } - - // Registered to all events - if err == nil && svr.Connected { - if err = svr.EventRegister(xsapiv1.EVTAll, ""); err != nil { - s.Log.Errorf("XDS Server %v - register all events error: %v", svr.ID, err) - } - } - return svr, err } |