From b15a1166cd55d0f05ed2f0919598874ba108464c Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 12 Jan 2018 16:57:50 +0200 Subject: [PATCH] Replace InstanceID -> NodeID --- config/config.go | 8 +-- config/config_defaults.go | 2 +- config/config_json_test.go | 2 +- config/libconfig_json.go | 2 +- data/conf/cgrates/cgrates.json | 2 +- engine/responder.go | 2 +- general_tests/rpcclient_it_test.go | 112 ++++++++++++++--------------- utils/consts.go | 2 +- 8 files changed, 66 insertions(+), 66 deletions(-) diff --git a/config/config.go b/config/config.go index 7efedb06c..05fa68f68 100755 --- a/config/config.go +++ b/config/config.go @@ -66,7 +66,7 @@ func SetCgrConfig(cfg *CGRConfig) { func NewDefaultCGRConfig() (*CGRConfig, error) { cfg := new(CGRConfig) cfg.RALsMaxComputedUsage = make(map[string]time.Duration) - cfg.InstanceID = utils.GenUUID() + cfg.NodeID = utils.GenUUID() cfg.DataFolderPath = "/usr/share/cgrates/" cfg.SmGenericConfig = new(SmGenericConfig) cfg.cacheConfig = make(CacheConfig) @@ -183,7 +183,7 @@ func NewCGRConfigFromFolder(cfgDir string) (*CGRConfig, error) { // Holds system configuration, defaults are overwritten with values from config file if found type CGRConfig struct { - InstanceID string // Identifier for this engine instance + NodeID string // Identifier for this engine instance DataDbType string DataDbHost string // The host to connect to. Values that start with / are for UNIX domain sockets. DataDbPort string // The port to bind to. @@ -780,8 +780,8 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { } if jsnGeneralCfg != nil { - if jsnGeneralCfg.Instance_id != nil && *jsnGeneralCfg.Instance_id != "" { - self.InstanceID = *jsnGeneralCfg.Instance_id + if jsnGeneralCfg.Node_id != nil && *jsnGeneralCfg.Node_id != "" { + self.NodeID = *jsnGeneralCfg.Node_id } if jsnGeneralCfg.Logger != nil { self.Logger = *jsnGeneralCfg.Logger diff --git a/config/config_defaults.go b/config/config_defaults.go index d37f1dde7..cee53dc72 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -28,7 +28,7 @@ const CGRATES_CFG_JSON = ` // This is what you get when you load CGRateS with an empty configuration file. "general": { - "instance_id": "", // identifier of this instance in the cluster, if empty it will be autogenerated + "node_id": "", // identifier of this instance in the cluster, if empty it will be autogenerated "logger":"*syslog", // controls the destination of logs <*syslog|*stdout> "log_level": 6, // control the level of messages logged (0-emerg to 7-debug) "http_skip_tls_verify": false, // if enabled Http Client will accept any TLS certificate diff --git a/config/config_json_test.go b/config/config_json_test.go index aa6ada0af..32919c1d5 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -38,7 +38,7 @@ func TestDfNewdfCgrJsonCfgFromReader(t *testing.T) { func TestDfGeneralJsonCfg(t *testing.T) { eCfg := &GeneralJsonCfg{ - Instance_id: utils.StringPointer(""), + Node_id: utils.StringPointer(""), Logger: utils.StringPointer(utils.MetaSysLog), Log_level: utils.IntPointer(utils.LOGLEVEL_INFO), Http_skip_tls_verify: utils.BoolPointer(false), diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 2786d44a5..048d4d03e 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -20,7 +20,7 @@ package config // General config section type GeneralJsonCfg struct { - Instance_id *string + Node_id *string Logger *string Log_level *int Http_skip_tls_verify *bool diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index e3b07c210..e6f7188a9 100644 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -7,7 +7,7 @@ // This is what you get when you load CGRateS with an empty configuration file. // "general": { -// "instance_id": "", // identifier of this instance in the cluster, if empty it will be autogenerated +// "node_id": "", // identifier of this instance in the cluster, if empty it will be autogenerated // "log_level": 6, // control the level of messages logged (0-emerg to 7-debug) // "http_skip_tls_verify": false, // if enabled Http Client will accept any TLS certificate // "rounding_decimals": 5, // system level precision for floats diff --git a/engine/responder.go b/engine/responder.go index 675c60495..508943e81 100644 --- a/engine/responder.go +++ b/engine/responder.go @@ -676,7 +676,7 @@ func (rs *Responder) Status(arg string, reply *map[string]interface{}) (err erro memstats := new(runtime.MemStats) runtime.ReadMemStats(memstats) response := make(map[string]interface{}) - response[utils.InstanceID] = config.CgrConfig().InstanceID + response[utils.NodeID] = config.CgrConfig().NodeID response["MemoryUsage"] = utils.SizeFmt(float64(memstats.HeapAlloc), "") response[utils.ActiveGoroutines] = runtime.NumGoroutine() response["Footprint"] = utils.SizeFmt(float64(memstats.Sys), "") diff --git a/general_tests/rpcclient_it_test.go b/general_tests/rpcclient_it_test.go index ef7ad230a..bfa6dae8d 100644 --- a/general_tests/rpcclient_it_test.go +++ b/general_tests/rpcclient_it_test.go @@ -96,15 +96,15 @@ func TestRPCITLclStatusSecondEngine(t *testing.T) { var status map[string]interface{} if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") } else { - ral2ID = status[utils.InstanceID].(string) + ral2ID = status[utils.NodeID].(string) } if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { // Make sure second time we land on the same instance t.Error(err) - } else if status[utils.InstanceID].(string) != ral2ID { - t.Errorf("Expecting:\n%s\nReceived:\n%s", ral2ID, status[utils.InstanceID].(string)) + } else if status[utils.NodeID].(string) != ral2ID { + t.Errorf("Expecting:\n%s\nReceived:\n%s", ral2ID, status[utils.NodeID].(string)) } } @@ -120,17 +120,17 @@ func TestRPCITLclStatusFirstInitial(t *testing.T) { var status map[string]interface{} if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") - } else if status[utils.InstanceID].(string) == ral2ID { - t.Fatalf("Should receive ralID different than second one, got: %s", status[utils.InstanceID].(string)) + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") + } else if status[utils.NodeID].(string) == ral2ID { + t.Fatalf("Should receive ralID different than second one, got: %s", status[utils.NodeID].(string)) } else { - ral1ID = status[utils.InstanceID].(string) + ral1ID = status[utils.NodeID].(string) } if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { // Make sure second time we land on the same instance t.Error(err) - } else if status[utils.InstanceID].(string) != ral1ID { - t.Errorf("Expecting:\n%s\nReceived:\n%s", ral1ID, status[utils.InstanceID].(string)) + } else if status[utils.NodeID].(string) != ral1ID { + t.Errorf("Expecting:\n%s\nReceived:\n%s", ral1ID, status[utils.NodeID].(string)) } } @@ -143,17 +143,17 @@ func TestRPCITLclStatusFirstFailover(t *testing.T) { var status map[string]interface{} if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") - } else if status[utils.InstanceID].(string) == ral1ID { - t.Fatalf("Should receive ralID different than first one, got: %s", status[utils.InstanceID].(string)) + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") + } else if status[utils.NodeID].(string) == ral1ID { + t.Fatalf("Should receive ralID different than first one, got: %s", status[utils.NodeID].(string)) } else { - ral2ID = status[utils.InstanceID].(string) + ral2ID = status[utils.NodeID].(string) } if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { // Make sure second time we land on the same instance t.Error(err) - } else if status[utils.InstanceID].(string) != ral2ID { - t.Errorf("Expecting:\n%s\nReceived:\n%s", ral2ID, status[utils.InstanceID].(string)) + } else if status[utils.NodeID].(string) != ral2ID { + t.Errorf("Expecting:\n%s\nReceived:\n%s", ral2ID, status[utils.NodeID].(string)) } } @@ -164,15 +164,15 @@ func TestRPCITLclStatusFirstFailback(t *testing.T) { var status map[string]interface{} if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == ral2ID { + } else if status[utils.NodeID].(string) == ral2ID { t.Error("Should receive new ID") } else { - ral1ID = status[utils.InstanceID].(string) + ral1ID = status[utils.NodeID].(string) } if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { // Make sure second time we land on the same instance t.Error(err) - } else if status[utils.InstanceID].(string) != ral1ID { - t.Errorf("Expecting:\n%s\nReceived:\n%s", ral1ID, status[utils.InstanceID].(string)) + } else if status[utils.NodeID].(string) != ral1ID { + t.Errorf("Expecting:\n%s\nReceived:\n%s", ral1ID, status[utils.NodeID].(string)) } } @@ -204,13 +204,13 @@ func TestRPCITLclBcastStatusInitial(t *testing.T) { var status map[string]interface{} if err := rpcPoolBroadcast.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") } if err := rpcPoolBroadcast.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") } } @@ -222,13 +222,13 @@ func TestRPCITLclBcastStatusNoRals1(t *testing.T) { var status map[string]interface{} if err := rpcPoolBroadcast.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") } if err := rpcPoolBroadcast.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") } } @@ -250,13 +250,13 @@ func TestRPCITLclBcastStatusRALs2Up(t *testing.T) { var status map[string]interface{} if err := rpcPoolBroadcast.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") } if err := rpcPoolBroadcast.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") } } @@ -267,12 +267,12 @@ func TestRPCITLclStatusBcastRALs1Up(t *testing.T) { var status map[string]interface{} if err := rpcPoolBroadcast.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { + } else if status[utils.NodeID].(string) == "" { t.Error("Empty InstanceID received") } if err := rpcPoolBroadcast.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { + } else if status[utils.NodeID].(string) == "" { t.Error("Empty InstanceID received") } } @@ -340,15 +340,15 @@ func TestRPCITRmtStatusFirstInitial(t *testing.T) { var status map[string]interface{} if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") } else { - ralRmtID = status[utils.InstanceID].(string) + ralRmtID = status[utils.NodeID].(string) } if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { // Make sure second time we land on the same instance t.Error(err) - } else if status[utils.InstanceID].(string) != ralRmtID { - t.Errorf("Expecting:\n%s\nReceived:\n%s", ralRmtID, status[utils.InstanceID].(string)) + } else if status[utils.NodeID].(string) != ralRmtID { + t.Errorf("Expecting:\n%s\nReceived:\n%s", ralRmtID, status[utils.NodeID].(string)) } } @@ -366,18 +366,18 @@ func TestRPCITRmtStatusFirstFailover(t *testing.T) { var status map[string]interface{} if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") - } else if status[utils.InstanceID].(string) == ralRmtID { + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") + } else if status[utils.NodeID].(string) == ralRmtID { t.Fatal("Did not failover") } else { - ralRmtID = status[utils.InstanceID].(string) + ralRmtID = status[utils.NodeID].(string) } if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") - } else if status[utils.InstanceID].(string) != ralRmtID { + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") + } else if status[utils.NodeID].(string) != ralRmtID { t.Fatal("Did not do failover") } } @@ -396,18 +396,18 @@ func TestRPCITRmtStatusFirstFailback(t *testing.T) { var status map[string]interface{} if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") - } else if status[utils.InstanceID].(string) == ralRmtID { + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") + } else if status[utils.NodeID].(string) == ralRmtID { t.Fatal("Did not do failback") } else { - ralRmtID = status[utils.InstanceID].(string) + ralRmtID = status[utils.NodeID].(string) } if err := rpcPoolFirst.Call("Responder.Status", "", &status); err != nil { t.Error(err) - } else if status[utils.InstanceID].(string) == "" { - t.Error("Empty InstanceID received") - } else if status[utils.InstanceID].(string) != ralRmtID { + } else if status[utils.NodeID].(string) == "" { + t.Error("Empty NodeID received") + } else if status[utils.NodeID].(string) != ralRmtID { t.Fatal("Did not do failback") } } diff --git a/utils/consts.go b/utils/consts.go index 894f11db1..bd53cd595 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -331,7 +331,7 @@ const ( UpdatedAt = "UpdatedAt" HandlerArgSep = "|" FlagForceDuration = "fd" - InstanceID = "InstanceID" + NodeID = "NodeID" ActiveGoroutines = "ActiveGoroutines" SessionTTL = "SessionTTL" SessionTTLMaxDelay = "SessionTTLMaxDelay"