seaweedfs/weed/filer2/configuration.go

52 lines
1 KiB
Go
Raw Normal View History

package filer2
import (
"os"
2019-09-02 10:28:40 +00:00
"github.com/joeslay/seaweedfs/weed/glog"
2018-08-19 22:18:37 +00:00
"github.com/spf13/viper"
)
var (
Stores []FilerStore
)
func (f *Filer) LoadConfiguration(config *viper.Viper) {
2018-12-06 08:44:41 +00:00
validateOneEnabledStore(config)
for _, store := range Stores {
if config.GetBool(store.GetName() + ".enabled") {
viperSub := config.Sub(store.GetName())
if err := store.Initialize(viperSub); err != nil {
glog.Fatalf("Failed to initialize store for %s: %+v",
store.GetName(), err)
}
f.SetStore(store)
glog.V(0).Infof("Configure filer for %s", store.GetName())
return
}
}
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())
}
}
}
}