From ffa2827ab162b37b75349dda7e73bf873ae1fdca Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 6 Dec 2018 00:37:59 -0800 Subject: [PATCH] fail fast if two notification queues or inputs are enabled --- weed/command/filer_replication.go | 11 +++++++++++ weed/notification/configuration.go | 25 ++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/weed/command/filer_replication.go b/weed/command/filer_replication.go index 4ceb5ce4c..087a12059 100644 --- a/weed/command/filer_replication.go +++ b/weed/command/filer_replication.go @@ -41,6 +41,17 @@ func runFilerReplicate(cmd *Command, args []string) bool { var notificationInput sub.NotificationInput + enabledInput := "" + for _, input := range sub.NotificationInputs { + if config.GetBool("notification." + input.GetName() + ".enabled") { + if enabledInput == "" { + enabledInput = input.GetName() + } else { + glog.Fatalf("Notification input is enabled for both %s and %s", enabledInput, input.GetName()) + } + } + } + for _, input := range sub.NotificationInputs { if config.GetBool("notification." + input.GetName() + ".enabled") { viperSub := config.Sub("notification." + input.GetName()) diff --git a/weed/notification/configuration.go b/weed/notification/configuration.go index 1a5dfed75..f34ccf305 100644 --- a/weed/notification/configuration.go +++ b/weed/notification/configuration.go @@ -27,15 +27,26 @@ func LoadConfiguration(config *viper.Viper) { return } - for _, store := range MessageQueues { - if config.GetBool(store.GetName() + ".enabled") { - viperSub := config.Sub(store.GetName()) - if err := store.Initialize(viperSub); err != nil { + enabledQueue := "" + for _, queue := range MessageQueues { + if config.GetBool(queue.GetName() + ".enabled") { + if enabledQueue == "" { + enabledQueue = queue.GetName() + } else { + glog.Fatalf("Notification message queue is enabled for both %s and %s", enabledQueue, queue.GetName()) + } + } + } + + for _, queue := range MessageQueues { + if config.GetBool(queue.GetName() + ".enabled") { + viperSub := config.Sub(queue.GetName()) + if err := queue.Initialize(viperSub); err != nil { glog.Fatalf("Failed to initialize notification for %s: %+v", - store.GetName(), err) + queue.GetName(), err) } - Queue = store - glog.V(0).Infof("Configure notification message queue for %s", store.GetName()) + Queue = queue + glog.V(0).Infof("Configure notification message queue for %s", queue.GetName()) return } }