Support for SDL config update via REST i/f
[ric-plt/xapp-frame.git] / pkg / xapp / config.go
old mode 100644 (file)
new mode 100755 (executable)
index 49c5e0a..1b4b806
@@ -21,6 +21,7 @@ package xapp
 
 import (
        "flag"
+       "fmt"
        "github.com/fsnotify/fsnotify"
        "github.com/spf13/viper"
        "os"
@@ -41,6 +42,8 @@ type Configurator struct {
 
 type ConfigChangeCB func(filename string)
 
+type SDLNotificationCB func(string, ...string)
+
 var ConfigChangeListeners []ConfigChangeCB
 
 func parseCmd() string {
@@ -114,6 +117,19 @@ func AddConfigChangeListener(f ConfigChangeCB) {
        ConfigChangeListeners = append(ConfigChangeListeners, f)
 }
 
+func PublishConfigChange(appName, eventJson string) error {
+       channel := fmt.Sprintf("CM_UPDATE:%s", appName)
+       if err := Sdl.StoreAndPublish(channel, eventJson, appName, eventJson); err != nil {
+               Logger.Error("Sdl.Store failed: %v", err)
+               return err
+       }
+       return nil
+}
+
+func (*Configurator) SetSDLNotificationCB(appName string, sdlNotificationCb SDLNotificationCB) error {
+       return Sdl.Subscribe(sdlNotificationCb, fmt.Sprintf("CM_UPDATE:%s", appName))
+}
+
 func (*Configurator) GetString(key string) string {
        return viper.GetString(key)
 }