upd
This commit is contained in:
1 parent
5d4b54c39c
commit
fec8a759bc
6 files changed
+36
-39
No files matched your search
+2
-2
@@ -12,8 +12,8 @@ var SchemaService schemaService
|
||||
type schemaService struct{}
|
||||
|
||||
func (schemaService) HandleUpdateConfigSchema(schema entity.ConfigSchema, state state.State) (state.State, error) {
|
||||
_, ok := state.GetModuleById(schema.ModuleId)
|
||||
if !ok {
|
||||
module := state.GetModuleById(schema.ModuleId)
|
||||
if module == nil {
|
||||
return state, errors.Errorf("module with id %s not found", schema.ModuleId)
|
||||
}
|
||||
|
||||
|
||||
+8
-9
@@ -1,11 +1,10 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/integration-system/isp-lib/structure"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"isp-config-service/entity"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/cluster"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/service"
|
||||
)
|
||||
|
||||
@@ -13,11 +12,11 @@ func (s *Store) applyUpdateBackendDeclarationCommand(data []byte) error {
|
||||
declaration := structure.BackendDeclaration{}
|
||||
err := json.Unmarshal(data, &declaration)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpdateBackendDeclarationCommand: %w", err)
|
||||
return errors.Errorf("UpdateBackendDeclarationCommand: %w", err)
|
||||
}
|
||||
state, err := service.ClusterStateService.HandleUpdateBackendDeclarationCommand(declaration, s.state)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpdateBackendDeclarationCommand: %w", err)
|
||||
return errors.Errorf("UpdateBackendDeclarationCommand: %w", err)
|
||||
}
|
||||
s.state = state
|
||||
return nil
|
||||
@@ -27,7 +26,7 @@ func (s *Store) applyDeleteBackendDeclarationCommand(data []byte) error {
|
||||
declaration := structure.BackendDeclaration{}
|
||||
err := json.Unmarshal(data, &declaration)
|
||||
if err != nil {
|
||||
return fmt.Errorf("DeleteBackendDeclarationCommand: %w", err)
|
||||
return errors.Errorf("DeleteBackendDeclarationCommand: %w", err)
|
||||
}
|
||||
state, err := service.ClusterStateService.HandleDeleteBackendDeclarationCommand(declaration, s.state)
|
||||
if err != nil {
|
||||
@@ -39,9 +38,9 @@ func (s *Store) applyDeleteBackendDeclarationCommand(data []byte) error {
|
||||
|
||||
func (s *Store) applyUpdateConfigSchema(data []byte) error {
|
||||
schema := entity.ConfigSchema{}
|
||||
err := jsoniter.Unmarshal(data, &schema)
|
||||
err := json.Unmarshal(data, &schema)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpdateConfigSchemaCommand: %w", err)
|
||||
return errors.Errorf("UpdateConfigSchemaCommand: %w", err)
|
||||
}
|
||||
state, err := service.SchemaService.HandleUpdateConfigSchema(schema, s.state)
|
||||
if err != nil {
|
||||
@@ -55,7 +54,7 @@ func (s *Store) applyModuleConnectedCommand(data []byte) error {
|
||||
moduleConnected := cluster.ModuleConnected{}
|
||||
err := json.Unmarshal(data, &moduleConnected)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ModuleConnectedCommand: %w", err)
|
||||
return errors.Errorf("ModuleConnectedCommand: %w", err)
|
||||
}
|
||||
state, err := service.ClusterStateService.HandleModuleConnectedCommand(moduleConnected, s.state)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
@@ -21,13 +20,13 @@ func (cs *ConfigStore) Activate(config entity.Config) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
func (cs *ConfigStore) GetActiveByModuleId(moduleId string) (*entity.Config, error) {
|
||||
func (cs *ConfigStore) GetActiveByModuleId(moduleId string) *entity.Config {
|
||||
for _, conf := range cs.configs {
|
||||
if conf.ModuleId == moduleId && conf.Active {
|
||||
return &conf, nil
|
||||
return &conf
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("no active configs for moduleId %s", moduleId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cs *ConfigStore) GetById(id int64) (*entity.Config, error) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"isp-config-service/entity"
|
||||
"time"
|
||||
)
|
||||
@@ -18,22 +17,22 @@ func (ms *ModuleStore) Update(module entity.Module) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ms *ModuleStore) GetByName(name string) (entity.Module, bool) {
|
||||
func (ms *ModuleStore) GetByName(name string) *entity.Module {
|
||||
for _, module := range ms.modules {
|
||||
if module.Name == name {
|
||||
return module, true
|
||||
return &module
|
||||
}
|
||||
}
|
||||
return entity.Module{}, false
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *ModuleStore) GetById(id string) (entity.Module, bool) {
|
||||
func (ms *ModuleStore) GetById(id string) *entity.Module {
|
||||
for _, module := range ms.modules {
|
||||
if module.Id == id {
|
||||
return module, true
|
||||
return &module
|
||||
}
|
||||
}
|
||||
return entity.Module{}, false
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *ModuleStore) Create(name string) entity.Module {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"github.com/satori/go.uuid"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
@@ -17,7 +16,7 @@ func (ss *SchemaStore) Upsert(schema entity.ConfigSchema) entity.ConfigSchema {
|
||||
return schema
|
||||
}
|
||||
}
|
||||
schema.Id = uuid.NewV1().String()
|
||||
schema.Id = GenerateId()
|
||||
ss.schemas = append(ss.schemas, schema)
|
||||
return schema
|
||||
}
|
||||
|
||||
+16
-15
@@ -2,6 +2,7 @@ package state
|
||||
|
||||
import (
|
||||
"github.com/integration-system/isp-lib/structure"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/entity"
|
||||
"time"
|
||||
)
|
||||
@@ -20,7 +21,7 @@ type ReadState interface {
|
||||
GetRoutes() structure.RoutingConfig
|
||||
BackendExist(backend structure.BackendDeclaration) (exist bool)
|
||||
GetCompiledConfig(moduleName string) (map[string]interface{}, error)
|
||||
GetModuleByName(string) (entity.Module, bool)
|
||||
GetModuleByName(string) *entity.Module
|
||||
}
|
||||
|
||||
func NewState() State {
|
||||
@@ -68,13 +69,13 @@ func (s State) BackendExist(backend structure.BackendDeclaration) (exist bool) {
|
||||
}
|
||||
|
||||
func (s State) GetCompiledConfig(moduleName string) (map[string]interface{}, error) {
|
||||
module, err := s.modules.GetByName(moduleName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
module := s.modules.GetByName(moduleName)
|
||||
if module == nil {
|
||||
return nil, errors.Errorf("module with name %s not found", moduleName)
|
||||
}
|
||||
config, err := s.configs.GetActiveByModuleId(module.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
config := s.configs.GetActiveByModuleId(module.Id)
|
||||
if config == nil {
|
||||
return nil, errors.Errorf("no active configs for moduleId %s", module.Id)
|
||||
}
|
||||
commonConfigs := s.commonConfigs.GetByIds(config.CommonConfigs)
|
||||
configsToMerge := make([]map[string]interface{}, 0, len(commonConfigs))
|
||||
@@ -87,9 +88,9 @@ func (s State) GetCompiledConfig(moduleName string) (map[string]interface{}, err
|
||||
return resultData, nil
|
||||
}
|
||||
|
||||
func (s State) UpdateModuleLastConnected(moduleName string) entity.Module {
|
||||
existedModule, err := s.modules.GetByName(moduleName)
|
||||
if err != nil {
|
||||
func (s *State) UpdateModuleLastConnected(moduleName string) entity.Module {
|
||||
existedModule := s.modules.GetByName(moduleName)
|
||||
if existedModule == nil {
|
||||
module := s.modules.Create(moduleName)
|
||||
return module
|
||||
}
|
||||
@@ -98,9 +99,9 @@ func (s State) UpdateModuleLastConnected(moduleName string) entity.Module {
|
||||
return *existedModule
|
||||
}
|
||||
|
||||
func (s State) UpdateModuleLastDisconnected(moduleName string) entity.Module {
|
||||
existedModule, err := s.modules.GetByName(moduleName)
|
||||
if err != nil {
|
||||
func (s *State) UpdateModuleLastDisconnected(moduleName string) entity.Module {
|
||||
existedModule := s.modules.GetByName(moduleName)
|
||||
if existedModule == nil {
|
||||
module := s.modules.Create(moduleName)
|
||||
return module
|
||||
}
|
||||
@@ -109,11 +110,11 @@ func (s State) UpdateModuleLastDisconnected(moduleName string) entity.Module {
|
||||
return *existedModule
|
||||
}
|
||||
|
||||
func (s State) GetModuleByName(moduleName string) (entity.Module, bool) {
|
||||
func (s State) GetModuleByName(moduleName string) *entity.Module {
|
||||
return s.modules.GetByName(moduleName)
|
||||
}
|
||||
|
||||
func (s *State) GetModuleById(moduleId string) (entity.Module, bool) {
|
||||
func (s State) GetModuleById(moduleId string) *entity.Module {
|
||||
return s.modules.GetById(moduleId)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user