configuration.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package filer2
  2. import (
  3. "os"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/spf13/viper"
  6. )
  7. var (
  8. Stores []FilerStore
  9. )
  10. func (f *Filer) LoadConfiguration(config *viper.Viper) {
  11. validateOneEnabledStore(config)
  12. for _, store := range Stores {
  13. if config.GetBool(store.GetName() + ".enabled") {
  14. if err := store.Initialize(config, store.GetName()+"."); err != nil {
  15. glog.Fatalf("Failed to initialize store for %s: %+v",
  16. store.GetName(), err)
  17. }
  18. f.SetStore(store)
  19. glog.V(0).Infof("Configure filer for %s", store.GetName())
  20. return
  21. }
  22. }
  23. println()
  24. println("Supported filer stores are:")
  25. for _, store := range Stores {
  26. println(" " + store.GetName())
  27. }
  28. os.Exit(-1)
  29. }
  30. func validateOneEnabledStore(config *viper.Viper) {
  31. enabledStore := ""
  32. for _, store := range Stores {
  33. if config.GetBool(store.GetName() + ".enabled") {
  34. if enabledStore == "" {
  35. enabledStore = store.GetName()
  36. } else {
  37. glog.Fatalf("Filer store is enabled for both %s and %s", enabledStore, store.GetName())
  38. }
  39. }
  40. }
  41. }