aboutsummaryrefslogtreecommitdiffstats
path: root/lib/agent/apiv1.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/agent/apiv1.go')
-rw-r--r--lib/agent/apiv1.go42
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
}