diff --git a/Gopkg.lock b/Gopkg.lock index 71167ea..12a27ba 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -82,14 +82,6 @@ revision = "6c65a5562fc06764971b7c5d05c76c75e84bdbf7" version = "v1.3.2" -[[projects]] - digest = "1:e62657cca9badaa308d86e7716083e4c5933bb78e30a17743fc67f50be26f6f4" - name = "github.com/gorilla/websocket" - packages = ["."] - pruneopts = "UT" - revision = "c3e18be99d19e6b3e8f1559eea2c161a665c4b6b" - version = "v1.4.1" - [[projects]] digest = "1:0ade334594e69404d80d9d323445d2297ff8161637f9b2d347cc6973d2d6f05b" name = "github.com/hashicorp/errwrap" @@ -194,18 +186,6 @@ pruneopts = "UT" revision = "ac5582987a2f25e8743e0ebb7259312adda05c23" -[[projects]] - digest = "1:12bcebed6dfc45cedc650f6dce60fe6ce6d27de88d9bfa8893a5b144c010d317" - name = "github.com/integration-system/golang-socketio" - packages = [ - ".", - "protocol", - "transport", - ] - pruneopts = "UT" - revision = "7513a9b590e428674e3c22ea82f46b28890cc17a" - version = "v1.0.0" - [[projects]] digest = "1:4a70938660ae196961d0285062fa7ae5b8abcf1c800f4c750803c06c2150a716" name = "github.com/integration-system/isp-etp-go" @@ -222,8 +202,8 @@ version = "v2.0.0" [[projects]] - branch = "master" - digest = "1:eb4023353677406a3c3beeb8c30e0b2f255e59287a5abca81b9eeb20a730b58a" + branch = "v2" + digest = "1:3088a1b37acb8f8717bcf73d3efa4176c03b325a9abc438b8368f3cf370bb63e" name = "github.com/integration-system/isp-lib" packages = [ "backend", @@ -238,7 +218,7 @@ "utils", ] pruneopts = "UT" - revision = "5060d1348219abd8fad3628668b229779a5314c7" + revision = "fe9b6eaee9792492dcc73cc7d158b9c8fc3d6dc1" [[projects]] branch = "master" diff --git a/Gopkg.toml b/Gopkg.toml index 32b72f7..2edc3c2 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -38,7 +38,7 @@ [[override]] name = "github.com/integration-system/isp-lib" - branch = "master" + branch = "v2" [[override]] name = "github.com/googollee/go-socket.io" diff --git a/cluster/client.go b/cluster/client.go index 4f6a053..9dc003d 100644 --- a/cluster/client.go +++ b/cluster/client.go @@ -3,6 +3,7 @@ package cluster import ( "errors" "github.com/integration-system/isp-lib/structure" + "github.com/integration-system/isp-lib/utils" log "github.com/integration-system/isp-log" jsoniter "github.com/json-iterator/go" "isp-config-service/codes" @@ -122,7 +123,7 @@ func (client *Client) listenLeader() { response, err := leaderClient.SendDeclaration(declaration, defaultApplyTimeout) if err != nil { log.Warnf(codes.SendDeclarationToLeaderError, "send declaration to leader. err: %v", err) - } else if response != Ok { + } else if response != utils.WsOkResponse { log.Warnf(codes.SendDeclarationToLeaderError, "send declaration to leader. response: %s", response) } }(client.declaration) diff --git a/cluster/const.go b/cluster/const.go index 82a496f..6f599fc 100644 --- a/cluster/const.go +++ b/cluster/const.go @@ -15,7 +15,6 @@ const ( TokenParam = "token" ClusterParam = "cluster" - Ok = "ok" ) const ( _ = iota diff --git a/cluster/leader_client.go b/cluster/leader_client.go index 32142f3..0f14519 100644 --- a/cluster/leader_client.go +++ b/cluster/leader_client.go @@ -97,8 +97,8 @@ func getUrl(address string) string { params := url.Values{} params.Add(ClusterParam, "true") - // TODO вынести ключи в константы в isp-lib и выпилить instance_uuid - params.Add("module_name", cfg.ModuleName) - params.Add("instance_uuid", "9d89354b-c728-4b48-b002-a7d3b229f151") + // TODO выпилить instance_uuid ? + params.Add(utils.ModuleNameGetParamKey, cfg.ModuleName) + params.Add(utils.InstanceUuidGetParamKey, "9d89354b-c728-4b48-b002-a7d3b229f151") return fmt.Sprintf("ws://%s:%d/isp-etp/?%s", addr.IP.String(), addr.Port, params.Encode()) } diff --git a/main.go b/main.go index c144ed6..86f2398 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ import ( "net/http" "os" "strconv" + "strings" ) const ( @@ -98,7 +99,7 @@ func initMultiplexer(addressConfiguration structure.AddressConfiguration) (net.L raftListener := m.Match(cmux.Any()) go func() { - if err := m.Serve(); err != nil { + if err := m.Serve(); !strings.Contains(err.Error(), "use of closed network connection") { log.Fatalf(codes.InitCmuxError, "serve cmux: %v", err) } }() @@ -116,7 +117,7 @@ func initWebsocket(ctx context.Context, listener net.Listener, raftStore *store. mux.HandleFunc("/isp-etp/", etpServer.ServeHttp) httpServer := &http.Server{Handler: mux} go func() { - if err := httpServer.Serve(listener); err != nil { + if err := httpServer.Serve(listener); err != nil && err != http.ErrServerClosed { log.Fatalf(codes.StartHttpServerError, "http server closed: %v", err) } }() @@ -183,13 +184,6 @@ func onShutdown(ctx context.Context, sig os.Signal) { defer close(shutdownChan) backend.StopGrpcServer() - - if err := holder.ClusterClient.Shutdown(); err != nil { - log.Warnf(codes.RaftShutdownError, "raft shutdown err: %v", err) - } else { - log.Info(codes.RaftShutdownInfo, "raft shutdown success") - } - holder.EtpServer.Close() if err := holder.HttpServer.Shutdown(ctx); err != nil { @@ -197,4 +191,10 @@ func onShutdown(ctx context.Context, sig os.Signal) { } else { log.Info(codes.ShutdownHttpServerInfo, "http server shutdown success") } + + if err := holder.ClusterClient.Shutdown(); err != nil { + log.Warnf(codes.RaftShutdownError, "raft shutdown err: %v", err) + } else { + log.Info(codes.RaftShutdownInfo, "raft shutdown success") + } } diff --git a/subs/client.go b/subs/client.go index 292350d..d1b9229 100644 --- a/subs/client.go +++ b/subs/client.go @@ -7,6 +7,7 @@ import ( "github.com/integration-system/isp-lib/bootstrap" schema2 "github.com/integration-system/isp-lib/config/schema" "github.com/integration-system/isp-lib/structure" + "github.com/integration-system/isp-lib/utils" log "github.com/integration-system/isp-log" "isp-config-service/cluster" "isp-config-service/entity" @@ -33,7 +34,7 @@ func (h *socketEventHandler) handleModuleReady(conn etp.Conn, data []byte) []byt if err != nil { return []byte(err.Error()) } - return []byte(Ok) + return []byte(utils.WsOkResponse) } func (h *socketEventHandler) handleModuleRequirements(conn etp.Conn, data []byte) []byte { @@ -55,7 +56,7 @@ func (h *socketEventHandler) handleModuleRequirements(conn etp.Conn, data []byte service.RoutesService.SubscribeRoutes(conn, state.Mesh()) } }) - return []byte(Ok) + return []byte(utils.WsOkResponse) } func (h *socketEventHandler) handleConfigSchema(conn etp.Conn, data []byte) []byte { @@ -69,21 +70,6 @@ func (h *socketEventHandler) handleConfigSchema(conn etp.Conn, data []byte) []by if err := json.Unmarshal(data, &configSchema); err != nil { return []byte(err.Error()) } - // TODO Костыль. Дважды посылаем ModuleConnected, т.к с момента первой отправки в handleConnect, - // состояние к конкретной ноде кластера может не успеть примениться - now := state.GenerateDate() - newModule := entity.Module{ - Id: state.GenerateId(), - Name: moduleName, - CreatedAt: now, - LastConnectedAt: now, - } - command := cluster.PrepareModuleConnectedCommand(newModule) - _, err = SyncApplyCommand(command, "ModuleConnectedCommand") - if err != nil { - return []byte(err.Error()) - } - // /> module := new(entity.Module) h.store.VisitReadonlyState(func(readState state.ReadonlyState) { @@ -93,6 +79,7 @@ func (h *socketEventHandler) handleConfigSchema(conn etp.Conn, data []byte) []by return []byte(fmt.Sprintf("module with name %s not found", moduleName)) } + now := state.GenerateDate() schema := entity.ConfigSchema{ Id: state.GenerateId(), Version: configSchema.Version, @@ -101,7 +88,7 @@ func (h *socketEventHandler) handleConfigSchema(conn etp.Conn, data []byte) []by CreatedAt: now, UpdatedAt: now, } - command = cluster.PrepareUpdateConfigSchemaCommand(schema) + command := cluster.PrepareUpdateConfigSchemaCommand(schema) _, _ = SyncApplyCommand(command, "UpdateConfigSchemaCommand") var configs []entity.Config @@ -125,7 +112,7 @@ func (h *socketEventHandler) handleConfigSchema(conn etp.Conn, data []byte) []by command := cluster.PrepareUpsertConfigCommand(upsertConfig) _, _ = SyncApplyCommand(command, "UpsertConfigCommand") } - return []byte(Ok) + return []byte(utils.WsOkResponse) } func (h *socketEventHandler) handleRequestConfig(conn etp.Conn, data []byte) []byte { diff --git a/subs/root.go b/subs/root.go index 9a5c62e..dadb526 100644 --- a/subs/root.go +++ b/subs/root.go @@ -15,7 +15,6 @@ import ( ) const ( - Ok = "ok" followersRoom = "cluster_followers" )