2020-09-01 07:21:19 +00:00
|
|
|
package filer
|
2018-05-26 10:49:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2018-08-19 22:18:37 +00:00
|
|
|
"github.com/spf13/viper"
|
2018-05-26 10:49:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Stores []FilerStore
|
|
|
|
)
|
|
|
|
|
2018-08-19 22:17:55 +00:00
|
|
|
func (f *Filer) LoadConfiguration(config *viper.Viper) {
|
2018-05-26 10:49:46 +00:00
|
|
|
|
2018-12-06 08:44:41 +00:00
|
|
|
validateOneEnabledStore(config)
|
2018-12-06 08:32:36 +00:00
|
|
|
|
2018-05-26 10:49:46 +00:00
|
|
|
for _, store := range Stores {
|
2018-08-19 22:17:55 +00:00
|
|
|
if config.GetBool(store.GetName() + ".enabled") {
|
2020-01-29 17:09:55 +00:00
|
|
|
if err := store.Initialize(config, store.GetName()+"."); err != nil {
|
2018-05-26 10:49:46 +00:00
|
|
|
glog.Fatalf("Failed to initialize store for %s: %+v",
|
|
|
|
store.GetName(), err)
|
|
|
|
}
|
|
|
|
f.SetStore(store)
|
2018-08-19 22:17:55 +00:00
|
|
|
glog.V(0).Infof("Configure filer for %s", store.GetName())
|
2018-05-26 10:49:46 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 11:05:42 +00:00
|
|
|
// TODO load path-specific filer store here
|
|
|
|
// f.Store.AddPathSpecificStore(path, store)
|
|
|
|
|
2018-05-26 10:49:46 +00:00
|
|
|
println()
|
|
|
|
println("Supported filer stores are:")
|
|
|
|
for _, store := range Stores {
|
|
|
|
println(" " + store.GetName())
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
2018-12-06 08:44:41 +00:00
|
|
|
|
|
|
|
func validateOneEnabledStore(config *viper.Viper) {
|
|
|
|
enabledStore := ""
|
|
|
|
for _, store := range Stores {
|
|
|
|
if config.GetBool(store.GetName() + ".enabled") {
|
|
|
|
if enabledStore == "" {
|
|
|
|
enabledStore = store.GetName()
|
|
|
|
} else {
|
|
|
|
glog.Fatalf("Filer store is enabled for both %s and %s", enabledStore, store.GetName())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|