refactor, change id to string
This commit is contained in:
1 parent
78150b2661
commit
a2a470ad93
10 files changed
+67
-43
No files matched your search
Generated
+2
-2
@@ -233,14 +233,14 @@
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:21b7454a3f43dc141a1b48ef954bd98a506aa9aab599d9ec214a324b9864b49b"
|
||||
digest = "1:1789fb6e57949a6e4cacb74023cd30efb04b09dc6111d6ef3718241ebb23ebe9"
|
||||
name = "github.com/integration-system/isp-log"
|
||||
packages = [
|
||||
".",
|
||||
"stdcodes",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "d1d067bfc8eaa1de1d70da37578322ec72e0af04"
|
||||
revision = "a22bf2e0b56a9ef47db4a98756e39f700a99b688"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
||||
+2
-2
@@ -28,8 +28,8 @@ const (
|
||||
LeaderClientDisconnected = 0
|
||||
|
||||
// Services
|
||||
DiscoveryServiceError = 0
|
||||
RoutesServiceError = 0
|
||||
DiscoveryServiceSendModulesError = 0
|
||||
RoutesServiceSendRoutesError = 0
|
||||
|
||||
DeleteBackendDeclarationError = 0
|
||||
)
|
||||
+6
-8
@@ -9,12 +9,11 @@ type ConfigData map[string]interface{}
|
||||
|
||||
type Config struct {
|
||||
tableName string `sql:"?db_schema.configs" json:"-"`
|
||||
Id int64 `json:"id"`
|
||||
Uuid string `json:"uuid" valid:"required~Required,uuid~must be a valid uuid"`
|
||||
Id string `json:"id" valid:"required~Required"`
|
||||
Name string `json:"name" valid:"required~Required"`
|
||||
CommonConfigs []string `json:"commonConfigIds" pg:",array"`
|
||||
CommonConfigs []string `json:"commonConfigs" pg:",array"`
|
||||
Description string `json:"description"`
|
||||
ModuleId int32 `json:"moduleId" valid:"required~Required"`
|
||||
ModuleId string `json:"moduleId" valid:"required~Required"`
|
||||
Version int32 `json:"version" sql:",null"`
|
||||
Active bool `json:"active" sql:",null"`
|
||||
CreatedAt time.Time `json:"createdAt" sql:",null"`
|
||||
@@ -24,7 +23,7 @@ type Config struct {
|
||||
|
||||
type CommonConfig struct {
|
||||
tableName string `sql:"?db_schema.common_configs" json:"-"`
|
||||
Uuid string `json:"uuid" valid:"required~Required,uuid~must be a valid uuid"`
|
||||
Id string `json:"id" valid:"required~Required"`
|
||||
Name string `json:"name" valid:"required~Required"`
|
||||
Description string `json:"description"`
|
||||
Version int32 `json:"version" sql:",null"`
|
||||
@@ -35,10 +34,9 @@ type CommonConfig struct {
|
||||
|
||||
type ConfigSchema struct {
|
||||
tableName string `sql:"?db_schema.config_schemas" json:"-"`
|
||||
Id int32
|
||||
Uuid string `json:"uuid" valid:"required~Required,uuid~must be a valid uuid"`
|
||||
Id string `json:"id" valid:"required~Required"`
|
||||
Version string
|
||||
ModuleId int32
|
||||
ModuleId string
|
||||
Schema schema.Schema
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
|
||||
+1
-2
@@ -4,8 +4,7 @@ import "time"
|
||||
|
||||
type Module struct {
|
||||
tableName string `sql:"?db_schema.modules" json:"-"`
|
||||
Id int32 `json:"id"`
|
||||
Uuid string `json:"uuid" valid:"required~Required,uuid~must be a valid uuid"`
|
||||
Id string `json:"id" valid:"required~Required"`
|
||||
Name string `json:"name" valid:"required~Required"`
|
||||
Active bool `json:"active" sql:"-"`
|
||||
CreatedAt time.Time `json:"createdAt" sql:",null"`
|
||||
|
||||
@@ -87,7 +87,8 @@ func initWebsocket(bindAddress string, clusterClient *cluster.ClusterClient, raf
|
||||
}
|
||||
|
||||
func initRaft(bindAddress string, clusterCfg conf.ClusterConfiguration, declaration structure.BackendDeclaration) (*cluster.ClusterClient, *store.Store) {
|
||||
raftStore := store.NewStateStoreFromRepository()
|
||||
raftState := store.NewStateFromRepository()
|
||||
raftStore := store.NewStateStore(raftState)
|
||||
r, err := raft.NewRaft(bindAddress, clusterCfg, raftStore)
|
||||
if err != nil {
|
||||
log.Fatalf(codes.InitRaftError, "unable to create raft server. %v", err)
|
||||
|
||||
@@ -3,22 +3,40 @@
|
||||
DROP TABLE instances CASCADE;
|
||||
|
||||
ALTER TABLE configs
|
||||
ADD COLUMN uuid UUID NOT NULL DEFAULT uuid_generate_v4(),
|
||||
ADD COLUMN common_configs UUID[] NOT NULL DEFAULT '{}',
|
||||
ADD CONSTRAINT "unique_configs_uuid" UNIQUE ("uuid");
|
||||
DROP CONSTRAINT "FK_configs_moduleId_modules_id";
|
||||
|
||||
ALTER TABLE config_schemas
|
||||
ADD COLUMN uuid UUID NOT NULL DEFAULT uuid_generate_v4(),
|
||||
ADD CONSTRAINT "unique_config_schemas_uuid" UNIQUE ("uuid");
|
||||
DROP CONSTRAINT "fk_module_id__module_id";
|
||||
|
||||
|
||||
ALTER TABLE configs
|
||||
ALTER COLUMN id TYPE varchar(255),
|
||||
ALTER COLUMN module_id TYPE varchar(255),
|
||||
ADD COLUMN common_configs varchar(255)[] NOT NULL DEFAULT '{}';
|
||||
|
||||
ALTER TABLE config_schemas
|
||||
ALTER COLUMN module_id TYPE varchar(255),
|
||||
ALTER COLUMN id TYPE varchar(255);
|
||||
|
||||
ALTER TABLE modules
|
||||
ADD COLUMN uuid UUID NOT NULL DEFAULT uuid_generate_v4(),
|
||||
ADD CONSTRAINT "unique_modules_uuid" UNIQUE ("uuid");
|
||||
ALTER COLUMN id TYPE varchar(255);
|
||||
|
||||
-- Constraints
|
||||
|
||||
ALTER TABLE configs
|
||||
ADD CONSTRAINT "FK_configs_moduleId_modules_id"
|
||||
FOREIGN KEY ("module_id") REFERENCES modules ("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE config_schemas
|
||||
ADD CONSTRAINT FK_module_id__module_id FOREIGN KEY (module_id)
|
||||
REFERENCES modules (id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
|
||||
CREATE TABLE common_configs
|
||||
(
|
||||
id serial4 NOT NULL PRIMARY KEY,
|
||||
id VARCHAR(255) NOT NULL PRIMARY KEY,
|
||||
uuid UUID NOT NULL,
|
||||
name VARCHAR(255) NOT NULL DEFAULT 'unnamed',
|
||||
description TEXT,
|
||||
@@ -36,13 +54,29 @@ ALTER TABLE common_configs
|
||||
-- +goose Down
|
||||
|
||||
ALTER TABLE configs
|
||||
DROP COLUMN uuid;
|
||||
DROP CONSTRAINT "FK_configs_moduleId_modules_id";
|
||||
|
||||
ALTER TABLE config_schemas
|
||||
DROP COLUMN uuid;
|
||||
DROP CONSTRAINT "fk_module_id__module_id";
|
||||
|
||||
|
||||
ALTER TABLE configs
|
||||
ALTER COLUMN id TYPE integer;
|
||||
|
||||
ALTER TABLE config_schemas
|
||||
ALTER COLUMN id TYPE integer;
|
||||
|
||||
ALTER TABLE modules
|
||||
DROP COLUMN uuid;
|
||||
ALTER COLUMN id TYPE integer;
|
||||
|
||||
ALTER TABLE configs
|
||||
ADD CONSTRAINT "FK_configs_moduleId_modules_id"
|
||||
FOREIGN KEY ("module_id") REFERENCES modules ("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE config_schemas
|
||||
ADD CONSTRAINT FK_module_id__module_id FOREIGN KEY (module_id)
|
||||
REFERENCES modules (id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
DROP TABLE common_configs;
|
||||
|
||||
@@ -45,7 +45,7 @@ func (ds *discoveryService) Subscribe(conn ws.Conn, events []string, state state
|
||||
event = utils.ModuleConnected(event)
|
||||
err := ds.sendAddrList(conn, event, addressList)
|
||||
if err != nil {
|
||||
log.Errorf(codes.DiscoveryServiceError, "send module connected %v", err)
|
||||
log.Errorf(codes.DiscoveryServiceSendModulesError, "send module connected %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (ds *discoveryService) BroadcastModuleAddresses(moduleName string, state st
|
||||
addressList := state.GetModuleAddresses(moduleName)
|
||||
err := ds.broadcastAddrList(moduleName, event, addressList)
|
||||
if err != nil {
|
||||
log.Errorf(codes.DiscoveryServiceError, "broadcast module connected %v", err)
|
||||
log.Errorf(codes.DiscoveryServiceSendModulesError, "broadcast module connected %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -30,7 +30,7 @@ func (rs *routesService) SubscribeRoutes(conn ws.Conn, state state.ReadState) {
|
||||
routes := state.GetRoutes()
|
||||
err := rs.sendRoutes(conn, utils.ConfigSendRoutesWhenConnected, routes)
|
||||
if err != nil {
|
||||
log.Errorf(codes.RoutesServiceError, "send routes %v", err)
|
||||
log.Errorf(codes.RoutesServiceSendRoutesError, "send routes %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func (rs *routesService) BroadcastRoutes(state state.ReadState) {
|
||||
routes := state.GetRoutes()
|
||||
err := rs.broadcastRoutes(utils.ConfigSendRoutesChanged, routes)
|
||||
if err != nil {
|
||||
log.Errorf(codes.RoutesServiceError, "broadcast routes %v", err)
|
||||
log.Errorf(codes.RoutesServiceSendRoutesError, "broadcast routes %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-11
@@ -2,13 +2,12 @@ package store
|
||||
|
||||
import (
|
||||
log "github.com/integration-system/isp-log"
|
||||
"isp-config-service/cluster"
|
||||
"isp-config-service/codes"
|
||||
"isp-config-service/model"
|
||||
"isp-config-service/store/state"
|
||||
)
|
||||
|
||||
func NewStateStoreFromRepository() *Store {
|
||||
func NewStateFromRepository() state.State {
|
||||
configs, err := model.ConfigRep.Snapshot()
|
||||
if err != nil {
|
||||
log.Fatalf(codes.RestoreFromRepositoryError, "config repository: %s", err)
|
||||
@@ -26,13 +25,6 @@ func NewStateStoreFromRepository() *Store {
|
||||
log.Fatalf(codes.RestoreFromRepositoryError, "module repository: %s", err)
|
||||
}
|
||||
|
||||
store := &Store{
|
||||
state: state.NewStateFromSnapshot(configs, schemas, modules, commonConfigs),
|
||||
}
|
||||
|
||||
store.handlers = map[uint64]func([]byte) error{
|
||||
cluster.UpdateBackendDeclarationCommand: store.applyUpdateBackendDeclarationCommand,
|
||||
cluster.DeleteBackendDeclarationCommand: store.applyDeleteBackendDeclarationCommand,
|
||||
}
|
||||
return store
|
||||
st := state.NewStateFromSnapshot(configs, schemas, modules, commonConfigs)
|
||||
return st
|
||||
}
|
||||
+2
-2
@@ -98,9 +98,9 @@ func (f *fsmSnapshot) Persist(sink raft.SnapshotSink) error {
|
||||
|
||||
func (f *fsmSnapshot) Release() {}
|
||||
|
||||
func NewStateStore() *Store {
|
||||
func NewStateStore(st state.State) *Store {
|
||||
store := &Store{
|
||||
state: state.NewState(),
|
||||
state: st,
|
||||
}
|
||||
store.handlers = map[uint64]func([]byte) error{
|
||||
cluster.UpdateBackendDeclarationCommand: store.applyUpdateBackendDeclarationCommand,
|
||||
|
||||
Reference in new issue
Block a user