diff options
Diffstat (limited to 'lib/agent/apiv1-sdks.go')
-rw-r--r-- | lib/agent/apiv1-sdks.go | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/lib/agent/apiv1-sdks.go b/lib/agent/apiv1-sdks.go index fd897fc..e48bb9a 100644 --- a/lib/agent/apiv1-sdks.go +++ b/lib/agent/apiv1-sdks.go @@ -44,44 +44,59 @@ func (s *APIService) sdksEventsForwardInit(svr *XdsServer) error { } // Forward SDK events from XDS-server to client - if _, err := svr.EventOn(xsapiv1.EVTSDKInstall, "", s._sdkEventInstallCB); err != nil { - s.Log.Errorf("XDS Server EventOn '%s' failed: %v", xsapiv1.EVTSDKInstall, err) + if _, err := svr.EventOn(xsapiv1.EVTSDKAdd, xaapiv1.EVTSDKAdd, s._sdkEventCB); err != nil { + s.Log.Errorf("XDS Server EventOn '%s' failed: %v", xsapiv1.EVTSDKAdd, err) return err } - - if _, err := svr.EventOn(xsapiv1.EVTSDKRemove, "", s._sdkEventRemoveCB); err != nil { + if _, err := svr.EventOn(xsapiv1.EVTSDKRemove, xaapiv1.EVTSDKRemove, s._sdkEventCB); err != nil { s.Log.Errorf("XDS Server EventOn '%s' failed: %v", xsapiv1.EVTSDKRemove, err) return err } + if _, err := svr.EventOn(xsapiv1.EVTSDKStateChange, xaapiv1.EVTSDKStateChange, s._sdkEventCB); err != nil { + s.Log.Errorf("XDS Server EventOn '%s' failed: %v", xsapiv1.EVTSDKStateChange, err) + return err + } + + if _, err := svr.EventOn(xsapiv1.EVTSDKManagement, "", s._sdkEventManagementCB); err != nil { + s.Log.Errorf("XDS Server EventOn '%s' failed: %v", xsapiv1.EVTSDKManagement, err) + return err + } return nil } -func (s *APIService) _sdkEventInstallCB(privD interface{}, data interface{}) error { - // assume that xsapiv1.SDKManagementMsg == xaapiv1.SDKManagementMsg - evt := xaapiv1.SDKManagementMsg{} - evtName := xaapiv1.EVTSDKInstall +func (s *APIService) _sdkEventCB(privD interface{}, data interface{}) error { + evt := xsapiv1.EventMsg{} d, err := json.Marshal(data) if err != nil { - s.Log.Errorf("Cannot marshal XDS Server %s: err=%v", evtName, err) + s.Log.Errorf("Cannot marshal XDS Server SDK event err=%v, data=%v", err, data) return err } if err = json.Unmarshal(d, &evt); err != nil { - s.Log.Errorf("Cannot unmarshal XDS Server %s: err=%v", evtName, err) + s.Log.Errorf("Cannot unmarshal XDS Server SDK event err=%v, d=%v", err, string(d)) return err } - if err := s.events.Emit(evtName, evt, ""); err != nil { + // assume that xsapiv1.SDK == xaapiv1.SDK + sdk, err := evt.DecodeSDKEvent() + if err != nil { + s.Log.Errorf("Cannot decode XDS Server SDK event: err=%v, data=%v", err, data) + return err + } + + evtName := privD.(string) + + if err := s.events.Emit(evtName, sdk, ""); err != nil { s.Log.Warningf("Cannot notify %s (from server): %v", evtName, err) return err } return nil } -func (s *APIService) _sdkEventRemoveCB(privD interface{}, data interface{}) error { +func (s *APIService) _sdkEventManagementCB(privD interface{}, data interface{}) error { // assume that xsapiv1.SDKManagementMsg == xaapiv1.SDKManagementMsg evt := xaapiv1.SDKManagementMsg{} - evtName := xaapiv1.EVTSDKRemove + evtName := xaapiv1.EVTSDKManagement d, err := json.Marshal(data) if err != nil { s.Log.Errorf("Cannot marshal XDS Server %s: err=%v", evtName, err) |