app/platform: move failover config initialization to platform (#21281)

Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-10-07 13:53:13 +03:00
коммит произвёл GitHub
родитель 5a4cac43a8
Коммит e99eba33ff
3 изменённых файлов: 16 добавлений и 27 удалений

Просмотреть файл

@@ -36,15 +36,6 @@ type ServiceConfig struct {
Cluster einterfaces.ClusterInterface Cluster einterfaces.ClusterInterface
} }
func (c *ServiceConfig) validate() error {
// Mandatory fields need to be checked here
if c.ConfigStore == nil {
return errors.New("ConfigStore is required")
}
return nil
}
// ensure the config wrapper implements `product.ConfigService` // ensure the config wrapper implements `product.ConfigService`
var _ product.ConfigService = (*PlatformService)(nil) var _ product.ConfigService = (*PlatformService)(nil)

Просмотреть файл

@@ -97,10 +97,6 @@ type PlatformService struct {
// New creates a new PlatformService. // New creates a new PlatformService.
func New(sc ServiceConfig, options ...Option) (*PlatformService, error) { func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
if err := sc.validate(); err != nil {
return nil, err
}
// Step 0: Create the PlatformService. // Step 0: Create the PlatformService.
// ConfigStore is and should be handled on a upper level. // ConfigStore is and should be handled on a upper level.
ps := &PlatformService{ ps := &PlatformService{
@@ -138,6 +134,21 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
} }
} }
// the config store is not set, we need to create a new one
if ps.configStore == nil {
innerStore, err := config.NewFileStore("config.json", true)
if err != nil {
return nil, fmt.Errorf("failed to load config from file: %w", err)
}
configStore, err := config.NewStoreFromBacking(innerStore, nil, false)
if err != nil {
return nil, fmt.Errorf("failed to load config from file: %w", err)
}
ps.configStore = configStore
}
// Step 2: Start logging. // Step 2: Start logging.
if err := ps.initLogging(); err != nil { if err := ps.initLogging(); err != nil {
return nil, fmt.Errorf("failed to initialize logging: %w", err) return nil, fmt.Errorf("failed to initialize logging: %w", err)

Просмотреть файл

@@ -201,20 +201,7 @@ func NewServer(options ...Option) (*Server, error) {
// //
// Step 1: Platform. // Step 1: Platform.
if s.platform == nil { if s.platform == nil {
innerStore, err := config.NewFileStore("config.json", true) ps, sErr := platform.New(platform.ServiceConfig{}, s.platformOptions...)
if err != nil {
return nil, errors.Wrap(err, "failed to load config")
}
configStore, err := config.NewStoreFromBacking(innerStore, nil, false)
if err != nil {
return nil, errors.Wrap(err, "failed to load config")
}
platformCfg := platform.ServiceConfig{
ConfigStore: configStore,
}
ps, sErr := platform.New(platformCfg, s.platformOptions...)
if sErr != nil { if sErr != nil {
return nil, errors.Wrap(sErr, "failed to initialize platform") return nil, errors.Wrap(sErr, "failed to initialize platform")
} }