refactoring, added DeleteBackendDeclarationCommand

This commit is contained in:
Maxim Merzhanov committed 2019-09-04 18:20:11 +03:00
1 parent d678f28909
commit 79f83e245c
12 files changed
+294 -127

No files matched your search

Generated
+93 -1
View File
@@ -1,6 +1,14 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
digest = "1:e92f5581902c345eb4ceffdcd4a854fb8f73cf436d47d837d1ec98ef1fe0a214"
name = "github.com/StackExchange/wmi"
packages = ["."]
pruneopts = "UT"
revision = "5d049714c4a64225c3c79a7cf7d02f7fb5b96338"
version = "1.0.0"
[[projects]]
branch = "master"
digest = "1:7a9140c806333a78122763d08ec6c0d7358c7fff1df8cfbb01881c5dc46e24e5"
@@ -25,6 +33,14 @@
revision = "2f1ce7a837dcb8da3ec595b1dac9d0632f0f99e8"
version = "v1.3.1"
[[projects]]
digest = "1:652880afc6b57ce0a67173f552cb35ccda816493a1da6ca20e5074a66bcd083f"
name = "github.com/buaazp/fasthttprouter"
packages = ["."]
pruneopts = "UT"
revision = "ade4e2031af3aed7fffd241084aad80a58faf421"
version = "v0.1.1"
[[projects]]
digest = "1:c1100fc71e23b6a32b2c68a5202a848fd13811d5a10b12edb8019c3667d1cd9a"
name = "github.com/cenkalti/backoff"
@@ -41,6 +57,17 @@
revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
version = "v1.4.7"
[[projects]]
digest = "1:440028f55cb322d8cb5b9d5ebec298a00b7d74690a658fe6b1c0c0b44341bfae"
name = "github.com/go-ole/go-ole"
packages = [
".",
"oleutil",
]
pruneopts = "UT"
revision = "97b6244175ae18ea6eef668034fd6565847501c9"
version = "v1.2.4"
[[projects]]
digest = "1:07f4fafe81587b642166199f41c3edcca12929fcfcc0261b00be5dea2f968f44"
name = "github.com/golang/protobuf"
@@ -186,14 +213,17 @@
revision = "5959fcea049facd9441fff9de976191accd3cf9f"
[[projects]]
digest = "1:fd6ba35c1332fa3ad5be6f4fa1206adba26c184e79f32310a0c50b6811e0e530"
digest = "1:86431b6d676940fee5c9fa74cc730041a33454271ca5069caa72049c77445dd0"
name = "github.com/integration-system/isp-lib"
packages = [
"backend",
"bootstrap",
"config",
"config/schema",
"logger",
"metric",
"proto/stubs",
"socket",
"streaming",
"structure",
"utils",
@@ -221,6 +251,26 @@
revision = "27518f6661eba504be5a7a9a9f6d9460d892ade3"
version = "v1.1.7"
[[projects]]
digest = "1:caa1da085cc12cd39d3ddb267434902f621050e1b46f7e9477b2b933df680193"
name = "github.com/klauspost/compress"
packages = [
"flate",
"gzip",
"zlib",
]
pruneopts = "UT"
revision = "2c38f6d2dc5a6a21b6851f2414f4e10adf8e3eee"
version = "v1.8.1"
[[projects]]
digest = "1:923c4d7194b42e054b2eb8a6c62824ac55e23ececc1c7e48d4da69c971c55954"
name = "github.com/klauspost/cpuid"
packages = ["."]
pruneopts = "UT"
revision = "05a8198c0f5a27739aec358908d7e12c64ce6eb7"
version = "v1.2.1"
[[projects]]
digest = "1:31e761d97c76151dde79e9d28964a812c46efc5baee4085b86f68f0c654450de"
name = "github.com/konsorten/go-windows-terminal-sequences"
@@ -309,6 +359,25 @@
revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4"
version = "v0.8.1"
[[projects]]
branch = "master"
digest = "1:5bbebe8ac19ecb6c87790a89faa20566e38ed0d6494a1d14c4f5b05d9ce2436c"
name = "github.com/rcrowley/go-metrics"
packages = ["."]
pruneopts = "UT"
revision = "cac0b30c2563378d434b5af411844adff8e32960"
[[projects]]
digest = "1:f5139e9f4441369ffb5d44fa9fae62b921457d4dc09cd873ed0fd44511cc87ee"
name = "github.com/shirou/gopsutil"
packages = [
"cpu",
"internal/common",
]
pruneopts = "UT"
revision = "d80c43f9c984a48783daf22f4bd9278006ae483a"
version = "v2.19.7"
[[projects]]
digest = "1:04457f9f6f3ffc5fea48e71d62f2ca256637dee0a04d710288e27e05c8b41976"
name = "github.com/sirupsen/logrus"
@@ -368,6 +437,26 @@
pruneopts = "UT"
revision = "a83968bda2d37294a3541b7d2207fb6f5a3559a3"
[[projects]]
digest = "1:c468422f334a6b46a19448ad59aaffdfc0a36b08fdcc1c749a0b29b6453d7e59"
name = "github.com/valyala/bytebufferpool"
packages = ["."]
pruneopts = "UT"
revision = "e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7"
version = "v1.0.0"
[[projects]]
branch = "master"
digest = "1:30fe8021645a9d9966fcede2a59c2e2f498d433687fc5cddd7de85a6a0a44c28"
name = "github.com/valyala/fasthttp"
packages = [
".",
"fasthttputil",
"stackless",
]
pruneopts = "UT"
revision = "8ce231e840720d91e22f855ddba797b3b916fc75"
[[projects]]
digest = "1:39a425f98fb19427061a693fe6bf0683c9bddec4b25b17067e34fdb465e39cb9"
name = "github.com/x-cray/logrus-prefixed-formatter"
@@ -501,16 +590,19 @@
analyzer-name = "dep"
analyzer-version = 1
input-imports = [
"github.com/asaskevich/govalidator",
"github.com/cenkalti/backoff",
"github.com/googollee/go-socket.io",
"github.com/hashicorp/raft",
"github.com/hashicorp/raft-boltdb",
"github.com/integration-system/golang-socketio",
"github.com/integration-system/isp-lib/backend",
"github.com/integration-system/isp-lib/bootstrap",
"github.com/integration-system/isp-lib/config",
"github.com/integration-system/isp-lib/config/schema",
"github.com/integration-system/isp-lib/logger",
"github.com/integration-system/isp-lib/structure",
"github.com/integration-system/isp-lib/utils",
"github.com/json-iterator/go",
"github.com/mohae/deepcopy",
"github.com/pkg/errors",
+2 -2
View File
@@ -8,6 +8,6 @@ const (
)
const (
_ = iota
BackendDeclarationCommand
ConfigSchemaCommand
UpdateBackendDeclarationCommand
DeleteBackendDeclarationCommand
)
-38
View File
@@ -1,38 +0,0 @@
package service
import (
"bytes"
"encoding/binary"
"encoding/json"
"github.com/integration-system/isp-lib/logger"
"github.com/integration-system/isp-lib/structure"
"isp-config-service/cluster"
"isp-config-service/store/state"
)
var (
ClusterStoreService clusterStoreService
)
type clusterStoreService struct{}
func (l clusterStoreService) HandleBackendDeclarationCommand(declaration structure.BackendDeclaration, state state.State) (state.State, error) {
state.UpsertBackend(declaration)
logger.Debug("HandleBackendDeclarationCommand: upserted backend", declaration.ModuleName)
DiscoveryService.BroadcastModuleAddresses(declaration.ModuleName, state)
DiscoveryService.BroadcastRoutes(state)
return state, nil
}
//TODO вынести как отдельную функция с парметрами вызова (int command, payload interface{}) ([]byte, error) для возможности переиспользования
func (l clusterStoreService) PrepareBackendDeclarationCommand(backend structure.BackendDeclaration) []byte {
var buf bytes.Buffer
buf2 := make([]byte, 8)
binary.BigEndian.PutUint64(buf2, cluster.BackendDeclarationCommand)
buf.Write(buf2)
err := json.NewEncoder(&buf).Encode(backend)
if err != nil {
logger.Fatal("PrepareBackendDeclarationCommand json encoding", err)
}
return buf.Bytes()
}
+53
View File
@@ -0,0 +1,53 @@
package service
import (
"bytes"
"encoding/binary"
"encoding/json"
"github.com/integration-system/isp-lib/logger"
"github.com/integration-system/isp-lib/structure"
"isp-config-service/cluster"
"isp-config-service/store/state"
)
var (
ClusterStateService clusterStateService
)
type clusterStateService struct{}
func (l clusterStateService) HandleUpdateBackendDeclarationCommand(declaration structure.BackendDeclaration, state state.State) (state.State, error) {
state.UpsertBackend(declaration)
logger.Debug("HandleUpdateBackendDeclarationCommand: upserted backend", declaration.ModuleName)
DiscoveryService.BroadcastModuleAddresses(declaration.ModuleName, state)
RoutesService.BroadcastRoutes(state)
return state, nil
}
func (l clusterStateService) HandleDeleteBackendDeclarationCommand(declaration structure.BackendDeclaration, state state.State) (state.State, error) {
state.DeleteBackend(declaration)
logger.Debug("HandleDeleteBackendDeclarationCommand: deleted backend", declaration.ModuleName)
DiscoveryService.BroadcastModuleAddresses(declaration.ModuleName, state)
RoutesService.BroadcastRoutes(state)
return state, nil
}
func (l clusterStateService) PrepareUpdateBackendDeclarationCommand(backend structure.BackendDeclaration) []byte {
return l.prepareCommand(cluster.UpdateBackendDeclarationCommand, backend)
}
func (l clusterStateService) PrepareDeleteBackendDeclarationCommand(backend structure.BackendDeclaration) []byte {
return l.prepareCommand(cluster.DeleteBackendDeclarationCommand, backend)
}
func (l clusterStateService) prepareCommand(command uint64, payload interface{}) []byte {
var buf bytes.Buffer
buf2 := make([]byte, 8)
binary.BigEndian.PutUint64(buf2, command)
buf.Write(buf2)
err := json.NewEncoder(&buf).Encode(payload)
if err != nil {
logger.Fatal("prepareCommand json encoding", err)
}
return buf.Bytes()
}
+3 -39
View File
@@ -26,7 +26,7 @@ type discoveryService struct {
lock sync.RWMutex
}
func (ds *discoveryService) HandleDisconnect(connId string) { //TODO где то передается целиком объект ws.Conn, привести к одному виду(думаю ws.Conn)
func (ds *discoveryService) HandleDisconnect(connId string) {
ds.lock.Lock()
defer ds.lock.Unlock()
if events, ok := ds.subs[connId]; ok {
@@ -36,7 +36,7 @@ func (ds *discoveryService) HandleDisconnect(connId string) { //TODO где то
holder.Socket.Rooms().LeaveByConnId(connId, RoutesSubscribersRoom)
}
func (ds *discoveryService) Subscribe(conn ws.Conn, events []string, state state.State) {
func (ds *discoveryService) Subscribe(conn ws.Conn, events []string, state state.ReadState) {
if len(events) == 0 {
return
}
@@ -46,6 +46,7 @@ func (ds *discoveryService) Subscribe(conn ws.Conn, events []string, state state
holder.Socket.Rooms().Join(conn, events...)
for _, event := range events {
addressList := state.GetModuleAddresses(event)
event = utils.ModuleConnected(event)
ds.sendAddrList(conn, event, addressList)
}
}
@@ -83,43 +84,6 @@ func (ds *discoveryService) sendAddrList(conn ws.Conn, event string, addressList
}
}
//TODO вынесли логику работы с роутами в отдельный сервис
func (ds *discoveryService) SubscribeRoutes(conn ws.Conn, state state.State) {
holder.Socket.Rooms().Join(conn, RoutesSubscribersRoom)
routes := state.GetRoutes()
ds.sendRoutes(conn, utils.ConfigSendRoutesWhenConnected, routes)
}
func (ds *discoveryService) BroadcastRoutes(state state.State) {
routes := state.GetRoutes()
ds.broadcastRoutes(utils.ConfigSendRoutesChanged, routes)
}
func (ds *discoveryService) broadcastRoutes(event string, routes structure.RoutingConfig) {
if bytes, err := json.Marshal(routes); err != nil {
logger.Warn(err)
} else {
err = holder.Socket.Broadcast(RoutesSubscribersRoom, event, string(bytes))
if err != nil {
logger.Error(err)
}
}
}
func (ds *discoveryService) sendRoutes(conn ws.Conn, event string, routes structure.RoutingConfig) {
if bytes, err := json.Marshal(routes); err != nil {
logger.Warn(err)
} else {
bf := backoff.WithMaxRetries(backoff.NewConstantBackOff(100*time.Millisecond), 3)
err := backoff.Retry(func() error {
return conn.Emit(event, string(bytes))
}, bf)
if err != nil {
logger.Error(err)
}
}
}
func NewDiscoveryService() *discoveryService {
return &discoveryService{
subs: make(map[string][]string),
+57
View File
@@ -0,0 +1,57 @@
package service
import (
"encoding/json"
"github.com/cenkalti/backoff"
"github.com/integration-system/isp-lib/logger"
"github.com/integration-system/isp-lib/structure"
"github.com/integration-system/isp-lib/utils"
"isp-config-service/holder"
"isp-config-service/store/state"
"isp-config-service/ws"
"time"
)
var RoutesService routesService
type routesService struct{}
func (rs *routesService) HandleDisconnect(connId string) {
holder.Socket.Rooms().LeaveByConnId(connId, RoutesSubscribersRoom)
}
func (rs *routesService) SubscribeRoutes(conn ws.Conn, state state.ReadState) {
holder.Socket.Rooms().Join(conn, RoutesSubscribersRoom)
routes := state.GetRoutes()
rs.sendRoutes(conn, utils.ConfigSendRoutesWhenConnected, routes)
}
func (rs *routesService) BroadcastRoutes(state state.ReadState) {
routes := state.GetRoutes()
rs.broadcastRoutes(utils.ConfigSendRoutesChanged, routes)
}
func (rs *routesService) broadcastRoutes(event string, routes structure.RoutingConfig) {
if bytes, err := json.Marshal(routes); err != nil {
logger.Warn(err)
} else {
err = holder.Socket.Broadcast(RoutesSubscribersRoom, event, string(bytes))
if err != nil {
logger.Error(err)
}
}
}
func (rs *routesService) sendRoutes(conn ws.Conn, event string, routes structure.RoutingConfig) {
if bytes, err := json.Marshal(routes); err != nil {
logger.Warn(err)
} else {
bf := backoff.WithMaxRetries(backoff.NewConstantBackOff(100*time.Millisecond), 3)
err := backoff.Retry(func() error {
return conn.Emit(event, string(bytes))
}, bf)
if err != nil {
logger.Error(err)
}
}
}
+18 -3
View File
@@ -6,14 +6,29 @@ import (
"isp-config-service/service"
)
func (s *Store) applyBackendDeclarationCommand(data []byte) error {
func (s *Store) applyUpdateBackendDeclarationCommand(data []byte) error {
declaration := structure.BackendDeclaration{}
err := json.Unmarshal(data, &declaration)
if err != nil {
logger.Warnf("Store.applyBackendDeclarationCommand: %s, error parse json data: %s", err.Error())
logger.Warnf("Store.applyUpdateBackendDeclarationCommand: %s, error parse json data: %s", err.Error())
return err
}
state, err := service.ClusterStoreService.HandleBackendDeclarationCommand(declaration, s.state)
state, err := service.ClusterStateService.HandleUpdateBackendDeclarationCommand(declaration, s.state)
if err != nil {
return err
}
s.state = state
return nil
}
func (s *Store) applyDeleteBackendDeclarationCommand(data []byte) error {
declaration := structure.BackendDeclaration{}
err := json.Unmarshal(data, &declaration)
if err != nil {
logger.Warnf("Store.applyDeleteBackendDeclarationCommand: %s, error parse json data: %s", err.Error())
return err
}
state, err := service.ClusterStateService.HandleDeleteBackendDeclarationCommand(declaration, s.state)
if err != nil {
return err
}
+5 -6
View File
@@ -42,10 +42,9 @@ func (m *Mesh) CheckBackendChanged(backend structure.BackendDeclaration) (change
return
}
func (m *Mesh) DeleteBackend(backend structure.BackendDeclaration) (changed bool) {
func (m *Mesh) DeleteBackend(backend structure.BackendDeclaration) {
address := backend.Address.GetAddress()
if nodes, ok := m.modulesMap[backend.ModuleName]; ok {
changed = true
delete(nodes, address)
if len(nodes) == 0 {
delete(m.modulesMap, backend.ModuleName)
@@ -54,11 +53,11 @@ func (m *Mesh) DeleteBackend(backend structure.BackendDeclaration) (changed bool
return
}
func (m *Mesh) BackendExist(backend structure.BackendDeclaration) (exist bool) { //TODO используется ?
func (m *Mesh) BackendExist(backend structure.BackendDeclaration) (exist bool) {
address := backend.Address.GetAddress()
if nodes, ok := m.modulesMap[backend.ModuleName]; ok {
exist = true
if len(nodes) == 0 {
delete(m.modulesMap, backend.ModuleName)
if _, ok := nodes[address]; ok {
exist = true
}
}
return
+19 -3
View File
@@ -8,12 +8,20 @@ type State struct {
mesh *Mesh
}
type ReadState interface {
CheckBackendChanged(backend structure.BackendDeclaration) (changed bool)
GetModuleAddresses(moduleName string) []structure.AddressConfiguration
GetRoutes() structure.RoutingConfig
BackendExist(backend structure.BackendDeclaration) (exist bool)
}
func NewState() State {
return State{
mesh: NewMesh(),
}
}
func (s *State) CheckBackendChanged(backend structure.BackendDeclaration) (changed bool) {
func (s State) CheckBackendChanged(backend structure.BackendDeclaration) (changed bool) {
return s.mesh.CheckBackendChanged(backend)
}
@@ -21,10 +29,18 @@ func (s *State) UpsertBackend(backend structure.BackendDeclaration) (changed boo
return s.mesh.UpsertBackend(backend)
}
func (s *State) GetModuleAddresses(moduleName string) []structure.AddressConfiguration {
func (s State) GetModuleAddresses(moduleName string) []structure.AddressConfiguration {
return s.mesh.GetModuleAddresses(moduleName)
}
func (s *State) GetRoutes() structure.RoutingConfig {
func (s State) GetRoutes() structure.RoutingConfig {
return s.mesh.GetRoutes()
}
func (s *State) DeleteBackend(backend structure.BackendDeclaration) {
s.mesh.DeleteBackend(backend)
}
func (s State) BackendExist(backend structure.BackendDeclaration) (exist bool) {
return s.mesh.BackendExist(backend)
}
+11 -7
View File
@@ -19,7 +19,7 @@ var (
type Store struct {
state state.State
lock sync.Mutex //TODO RWMutex
lock sync.RWMutex
handlers map[uint64]func([]byte) error
}
@@ -60,8 +60,14 @@ func (s *Store) Restore(rc io.ReadCloser) error {
return nil
}
func (s *Store) GetState() *state.State { //TODO почему указатель ? =), добавим функцию VisitState(f(state state)), попробуем с ней
return &s.state
func (s *Store) GetReadState() state.ReadState {
return s.state
}
func (s *Store) VisitReadState(f func(state.ReadState)) {
s.lock.RLock()
defer s.lock.RUnlock()
f(s.GetReadState())
}
type fsmSnapshot struct {
@@ -74,18 +80,15 @@ func (f *fsmSnapshot) Persist(sink raft.SnapshotSink) error {
if err != nil {
return err
}
if _, err := sink.Write(b); err != nil {
return err
}
return sink.Close()
}()
if err != nil {
_ = sink.Cancel()
}
return err
}
@@ -96,7 +99,8 @@ func NewStateStore() *Store {
state: state.NewState(),
}
store.handlers = map[uint64]func([]byte) error{
cluster.BackendDeclarationCommand: store.applyBackendDeclarationCommand,
cluster.UpdateBackendDeclarationCommand: store.applyUpdateBackendDeclarationCommand,
cluster.DeleteBackendDeclarationCommand: store.applyDeleteBackendDeclarationCommand,
}
return store
}
+24 -25
View File
@@ -6,68 +6,67 @@ import (
"github.com/integration-system/isp-lib/bootstrap"
"github.com/integration-system/isp-lib/logger"
"github.com/integration-system/isp-lib/structure"
"github.com/integration-system/isp-lib/utils"
"isp-config-service/service"
"isp-config-service/store/state"
"isp-config-service/ws"
)
func (h *socketEventHandler) handleModuleReady(conn ws.Conn, data []byte) {
func (h *socketEventHandler) handleModuleReady(conn ws.Conn, data []byte) string {
instanceUuid, moduleName, err := conn.Parameters()
logger.Debug("instanceUuid:", instanceUuid, "moduleName:", moduleName) // REMOVE
if err != nil {
_ = conn.Emit(utils.ErrorConnection, map[string]string{"error": err.Error()}) //эти штуки тогда убертся вовсе
return
return err.Error()
}
declaration := structure.BackendDeclaration{}
err = json.Unmarshal(data, &declaration)
if err != nil {
_ = conn.Emit(utils.ErrorConnection, map[string]string{"error": err.Error()})
logger.Warnf("handleModuleDeclaration: %s, error parse json data: %s", conn.Id(), err.Error())
return
return err.Error()
}
_, err = govalidator.ValidateStruct(declaration)
if err != nil {
errors := govalidator.ErrorsByField(err)
_ = conn.Emit(utils.ErrorConnection, map[string]map[string]string{"error": errors})
logger.Warnf("SOCKET ROUTES ERROR, handleModuleDeclaration: %s, error validate routes data: %s", conn.Id(), errors)
} else if h.store.GetState().CheckBackendChanged(declaration) {
// TODO h.store.GetState() locks
i, err := h.cluster.SyncApply(service.ClusterStoreService.PrepareBackendDeclarationCommand(declaration))
logger.Debug("cluster.SyncApply:", i, err)
return err.Error()
}
h.store.VisitReadState(func(state state.ReadState) {
if state.CheckBackendChanged(declaration) {
conn.SetBackendDeclaration(declaration)
command := service.ClusterStateService.PrepareUpdateBackendDeclarationCommand(declaration)
i, err := h.cluster.SyncApply(command)
logger.Debug("cluster.SyncApply:", i, err)
}
})
return ok
}
func (h *socketEventHandler) handleRoutesUpdate(conn ws.Conn, data []byte) {
}
func (h *socketEventHandler) handleModuleRequirements(conn ws.Conn, data []byte) {
func (h *socketEventHandler) handleModuleRequirements(conn ws.Conn, data []byte) string {
logger.Debugf("onReceivedModuleRequirements: %s %s", conn.Id(), string(data))
instanceUuid, moduleName, err := conn.Parameters()
logger.Debug("instanceUuid:", instanceUuid, "moduleName:", moduleName) // REMOVE
if err != nil {
_ = conn.Emit(utils.ErrorConnection, map[string]string{"error": err.Error()})
return
return err.Error()
}
declaration := bootstrap.ModuleRequirements{}
err = json.Unmarshal(data, &declaration)
if err != nil {
_ = conn.Emit(utils.ErrorConnection, map[string]string{"error": err.Error()})
logger.Debugf("onReceivedModuleRequirements: %s, error parse json data: %s", conn.Id(), err.Error())
return
return err.Error()
}
if declaration.RequireRoutes {
// TODO h.store.GetState() locks
service.DiscoveryService.SubscribeRoutes(conn, *h.store.GetState())
h.store.VisitReadState(func(state state.ReadState) {
service.RoutesService.SubscribeRoutes(conn, state)
})
}
// TODO h.store.GetState() locks
service.DiscoveryService.Subscribe(conn, declaration.RequiredModules, *h.store.GetState())
h.store.VisitReadState(func(state state.ReadState) {
service.DiscoveryService.Subscribe(conn, declaration.RequiredModules, state)
})
return ok
}
func (h *socketEventHandler) handleConfigSchema(conn ws.Conn, data []byte) {
+9 -3
View File
@@ -28,8 +28,8 @@ func (h *socketEventHandler) SubscribeAll() {
OnDisconnect(h.handleDisconnect).
OnError(h.handleError).
OnWithAck(cluster.ApplyCommandEvent, h.applyCommandOnLeader).
On(utils.ModuleReady, h.handleModuleReady). //TODO сделать функцию с Ack, возвращать текстовку ошибки в случае возниконовения ошибки, константу ok, если все ок
On(utils.ModuleSendRequirements, h.handleModuleRequirements)
OnWithAck(utils.ModuleReady, h.handleModuleReady).
OnWithAck(utils.ModuleSendRequirements, h.handleModuleRequirements)
}
func (h *socketEventHandler) handleConnect(conn ws.Conn) {
@@ -45,7 +45,13 @@ func (h *socketEventHandler) handleDisconnect(conn ws.Conn) {
holder.Socket.Rooms().Leave(conn, followersRoom)
}
service.DiscoveryService.HandleDisconnect(conn.Id())
//TODO при отключении топология кластера меняется, соответсвенно нужно обновлять состояние и уведомлять всех об изменении
service.RoutesService.HandleDisconnect(conn.Id())
backend := conn.GetBackendDeclaration()
if backend != nil {
command := service.ClusterStateService.PrepareDeleteBackendDeclarationCommand(*backend)
i, err := h.cluster.SyncApply(command)
logger.Debug("cluster.SyncApply:", i, err)
}
}
func (h *socketEventHandler) handleError(conn ws.Conn, err error) {