diff --git a/cluster/client.go b/cluster/client.go index fca390e..bf3b40c 100644 --- a/cluster/client.go +++ b/cluster/client.go @@ -87,7 +87,7 @@ func (client *ClusterClient) listenLeader() { client.onClientDisconnect(client.leaderState.leaderAddr) }) if err := leaderClient.Dial(leaderConnectionTimeout); err != nil { - log.Fatalf(codes.ConnectToLeaderError, "could not connect to leader: %v", err) + log.Fatalf(codes.LeaderClientConnectionError, "could not connect to leader: %v", err) continue } go func(declaration structure.BackendDeclaration) { diff --git a/cluster/leader_client.go b/cluster/leader_client.go index 9822eb6..569c2e2 100644 --- a/cluster/leader_client.go +++ b/cluster/leader_client.go @@ -51,7 +51,7 @@ func NewSocketLeaderClient(address string, leaderDisconnectionCallback func()) * EnableReconnection(). ReconnectionTimeout(1 * time.Second). OnReconnectionError(func(err error) { - log.Warnf(codes.LeaderClientReconnectionError, "leader client reconnection err: %v", err) + log.Warnf(codes.LeaderClientConnectionError, "leader client reconnection err: %v", err) }). BuildToConnect(socketIoAddress) err := client.On(gosocketio.OnDisconnection, func(channel *gosocketio.Channel) { @@ -61,8 +61,9 @@ func NewSocketLeaderClient(address string, leaderDisconnectionCallback func()) * leaderDisconnectionCallback() }) if err != nil { - log.Fatalf(codes.LeaderClientBindError, "leader client unable to bind event. err: %v", err) + panic(err) ////must never occurred, and will removed in future } + return &SocketLeaderClient{ c: client, } @@ -71,7 +72,7 @@ func NewSocketLeaderClient(address string, leaderDisconnectionCallback func()) * func getSocketIoUrl(address string) string { addr, err := net.ResolveTCPAddr("tcp", address) if err != nil { - panic(err) //must never occured + panic(err) //must never occurred } cfg := config.Get().(*conf.Configuration) diff --git a/codes/codes.go b/codes/codes.go index a998104..f191e6d 100644 --- a/codes/codes.go +++ b/codes/codes.go @@ -7,8 +7,7 @@ const ( ShutdownHttpServerError = 0 ShutdownHttpServerInfo = 0 - ConfigDataSerializeError = 0 - SocketIoError = 0 + SocketIoError = 0 // Raft InitRaftError = 0 @@ -19,18 +18,14 @@ const ( RaftShutdownInfo = 0 // Raft Log - InvalidLogDataCommand = 0 ApplyLogCommandError = 0 - UnknownLogCommand = 0 PrepareLogCommandError = 0 SyncApplyError = 0 // Raft Cluster - ConnectToLeaderError = 0 - SendDeclarationToLeaderError = 0 - LeaderClientReconnectionError = 0 - LeaderClientDisconnected = 0 - LeaderClientBindError = 0 + SendDeclarationToLeaderError = 0 + LeaderClientConnectionError = 0 + LeaderClientDisconnected = 0 // Services DiscoveryServiceError = 0 diff --git a/entity/config.go b/entity/config.go index 9051098..4123d02 100644 --- a/entity/config.go +++ b/entity/config.go @@ -1,24 +1,12 @@ package entity import ( - "encoding/json" "github.com/integration-system/isp-lib/config/schema" - log "github.com/integration-system/isp-log" - "isp-config-service/codes" "time" ) type ConfigData map[string]interface{} -func (cd ConfigData) ToJSON() string { - if bytes, err := json.Marshal(cd); err == nil { - return string(bytes) - } else { - log.Warnf(codes.ConfigDataSerializeError, "could not serialize config data to JSON %v", err) - return "{}" - } -} - type Config struct { tableName string `sql:"?db_schema.configs" json:"-"` Id int64 `json:"id"` diff --git a/store/store.go b/store/store.go index 67a71e0..b1c4114 100644 --- a/store/store.go +++ b/store/store.go @@ -28,7 +28,7 @@ func (s *Store) Apply(l *raft.Log) interface{} { s.lock.Lock() defer s.lock.Unlock() if len(l.Data) < 8 { - log.Fatalf(codes.InvalidLogDataCommand, "invalid log data command: %s", l.Data) + log.Fatalf(codes.ApplyLogCommandError, "invalid log data command: %s", l.Data) } command := binary.BigEndian.Uint64(l.Data[:8]) if handler, ok := s.handlers[command]; ok { @@ -37,7 +37,7 @@ func (s *Store) Apply(l *raft.Log) interface{} { log.Fatalf(codes.ApplyLogCommandError, "apply log command: %v", err) } } else { - log.Fatalf(codes.UnknownLogCommand, "unknown log command %s", command) + log.Fatalf(codes.ApplyLogCommandError, "unknown log command %s", command) } return nil }