Capability to add rmr message name-id mapping via configuration
Change-Id: If765b1710a90db16145d8e98e8564c135a837209
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
diff --git a/config/config-file.yaml b/config/config-file.yaml
index a75c078..daeb14f 100755
--- a/config/config-file.yaml
+++ b/config/config-file.yaml
@@ -22,6 +22,11 @@
"maxSize": 2072
"maxRetryOnFailure": 5
"threadType": 0
+ "mtypes" :
+ - "name": "TESTNAME1"
+ "id" : 55555
+ - "name": "TESTNAME2"
+ "id" : 55556
"subscription":
"host": "localhost:8088"
"timeout": 2
diff --git a/examples/config/config-file.json b/examples/config/config-file.json
index 23c4c5f..bfd885c 100755
--- a/examples/config/config-file.json
+++ b/examples/config/config-file.json
@@ -16,7 +16,11 @@
"protPort": "tcp:4560",
"maxSize": 65536,
"rxMessages": ["RIC_SUB_RESP", "RIC_SUB_FAILURE", "RIC_SUB_DEL_RESP", "RIC_INDICATION"],
- "txMessages": ["RIC_SUB_REQ", "RIC_SUB_DEL_REQ", "RIC_SGNB_ADDITION_REQ", "RIC_SGNB_ADDITION_ACK"]
+ "txMessages": ["RIC_SUB_REQ", "RIC_SUB_DEL_REQ", "RIC_SGNB_ADDITION_REQ", "RIC_SGNB_ADDITION_ACK"],
+ "mtypes" : [
+ {"name":"TESTNAME1","id":55555},
+ {"name":"TESTNAME2","id":55556}
+ ]
},
"metrics": [
{
diff --git a/pkg/xapp/config.go b/pkg/xapp/config.go
index 94e88a1..49c5e0a 100644
--- a/pkg/xapp/config.go
+++ b/pkg/xapp/config.go
@@ -27,6 +27,15 @@
"path/filepath"
)
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
+
+type mtype struct {
+ Name string
+ Id int
+}
+
type Configurator struct {
}
@@ -51,10 +60,42 @@
}
l.Info("Using config file: %s", viper.ConfigFileUsed())
+ updatemtypes := func() {
+ var mtypes []mtype
+ viper.UnmarshalKey("rmr.mtypes", &mtypes)
+
+ if len(mtypes) > 0 {
+ l.Info("Config mtypes before RICMessageTypes:%d RicMessageTypeToName:%d", len(RICMessageTypes), len(RicMessageTypeToName))
+ for _, v := range mtypes {
+ nadd := false
+ iadd := false
+ if _, ok := RICMessageTypes[v.Name]; ok == false {
+ nadd = true
+ }
+ if _, ok := RicMessageTypeToName[int(v.Id)]; ok == false {
+ iadd = true
+ }
+ if iadd != nadd {
+ l.Error("Config mtypes rmr.mtypes entry skipped due conflict with existing values %s(%t) %d(%t) ", v.Name, nadd, v.Id, iadd)
+ } else if iadd {
+ l.Info("Config mtypes rmr.mtypes entry added %s(%t) %d(%t) ", v.Name, nadd, v.Id, iadd)
+ RICMessageTypes[v.Name] = int(v.Id)
+ RicMessageTypeToName[int(v.Id)] = v.Name
+ } else {
+ l.Info("Config mtypes rmr.mtypes entry skipped %s(%t) %d(%t) ", v.Name, nadd, v.Id, iadd)
+ }
+ }
+ l.Info("Config mtypes after RICMessageTypes:%d RicMessageTypeToName:%d", len(RICMessageTypes), len(RicMessageTypeToName))
+ }
+ }
+
+ updatemtypes()
+
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
l.Info("config file %s changed ", e.Name)
+ updatemtypes()
Logger.SetLevel(viper.GetInt("logger.level"))
if len(ConfigChangeListeners) > 0 {
for _, f := range ConfigChangeListeners {