@@ -7,6 +7,7 @@ import "github.com/cloudtask/cloudtask-center/scheduler"
77import "github.com/cloudtask/libtools/gounits/logger"
88import "github.com/cloudtask/libtools/gounits/system"
99import "github.com/cloudtask/libtools/gzkwrapper"
10+ import "github.com/cloudtask/common/models"
1011import "gopkg.in/yaml.v2"
1112
1213import (
@@ -17,10 +18,12 @@ import (
1718 "os"
1819 "path/filepath"
1920 "strconv"
21+ "sync"
2022)
2123
2224var (
23- SystemConfig * Configuration = nil
25+ SystemConfig * Configuration = nil
26+ ServerConfig * models.ServerConfig = nil
2427)
2528
2629var (
3235
3336// Configuration is exported
3437type Configuration struct {
35- Version string `yaml:"version" json:"version"`
36- PidFile string `yaml:"pidfile" json:"pidfile"`
37- RetryStartup bool `yaml:"retrystartup" json:"retrystartup"`
38+ sync.RWMutex
39+ Version string `yaml:"version" json:"version"`
40+ PidFile string `yaml:"pidfile" json:"pidfile"`
41+ RetryStartup bool `yaml:"retrystartup" json:"retrystartup"`
42+ UseServerConfig bool `yaml:"useserverconfig" json:"useserverconfig"`
3843
3944 Cluster struct {
4045 Hosts string `yaml:"hosts" json:"hosts"`
@@ -60,7 +65,7 @@ type Configuration struct {
6065
6166 Cache struct {
6267 LRUSize int `yaml:"lrusize" json:"lrusize"`
63- types.StorageDriverConfigs `yaml:"storage " json:"storage "`
68+ types.StorageDriverConfigs `yaml:"storagedriver " json:"storagedriver "`
6469 } `yaml:"cache" json:"cache"`
6570
6671 Notifications notify.Notifications `yaml:"notifications" json:"notifications"`
@@ -94,7 +99,10 @@ func New(file string) error {
9499 return fmt .Errorf ("config read %s" , err .Error ())
95100 }
96101
97- conf := & Configuration {RetryStartup : true }
102+ conf := & Configuration {
103+ RetryStartup : true ,
104+ UseServerConfig : true ,
105+ }
98106 if err := yaml .Unmarshal (buf , conf ); err != nil {
99107 return ErrConfigFormatInvalid
100108 }
@@ -108,6 +116,7 @@ func New(file string) error {
108116 log .Printf ("[#etc#] version: %s\n " , SystemConfig .Version )
109117 log .Printf ("[#etc#] pidfile: %s\n " , SystemConfig .PidFile )
110118 log .Printf ("[#etc#] retrystartup: %s\n " , strconv .FormatBool (SystemConfig .RetryStartup ))
119+ log .Printf ("[#etc#] useserverconfig: %s\n " , strconv .FormatBool (SystemConfig .UseServerConfig ))
111120 log .Printf ("[#etc#] cluster: %+v\n " , SystemConfig .Cluster )
112121 log .Printf ("[#etc#] APIlisten: %+v\n " , SystemConfig .API )
113122 log .Printf ("[#etc#] scheduler: %+v\n " , SystemConfig .Scheduler )
@@ -116,6 +125,28 @@ func New(file string) error {
116125 return nil
117126}
118127
128+ //SaveServerConfig is exported
129+ func SaveServerConfig (data []byte ) error {
130+
131+ if SystemConfig != nil {
132+ value , err := models .ParseServerConfigs (data )
133+ if err != nil {
134+ return err
135+ }
136+ SystemConfig .Lock ()
137+ ServerConfig = value
138+ if value , ok := ServerConfig .StorageDriver .(map [string ]interface {}); ok {
139+ SystemConfig .Cache .StorageDriverConfigs = make (types.StorageDriverConfigs )
140+ for backend , paramters := range value {
141+ SystemConfig .Cache .StorageDriverConfigs [backend ] = paramters .(map [string ]interface {})
142+ break
143+ }
144+ }
145+ SystemConfig .Unlock ()
146+ }
147+ return nil
148+ }
149+
119150//PidFile is exported
120151func PidFile () string {
121152
@@ -134,6 +165,15 @@ func RetryStartup() bool {
134165 return false
135166}
136167
168+ //UseServerConfig is exported
169+ func UseServerConfig () bool {
170+
171+ if SystemConfig != nil {
172+ return SystemConfig .UseServerConfig
173+ }
174+ return false
175+ }
176+
137177//SchedulerConfigs is exported
138178func SchedulerConfigs () * scheduler.SchedulerConfigs {
139179
@@ -186,7 +226,7 @@ func CacheConfigs() *cache.CacheConfigs {
186226 }
187227 for backend , paramters := range SystemConfig .Cache .StorageDriverConfigs {
188228 configs .StorageBackend = types .Backend (backend )
189- configs .StorageParameters = paramters
229+ configs .StorageDriverParameters = paramters
190230 break
191231 }
192232 }
0 commit comments