From a26e8dde1909e68b099df338f9457b1c25ee20a9 Mon Sep 17 00:00:00 2001 From: Maciek Sufa Date: Wed, 18 Nov 2015 15:46:10 +0000 Subject: [PATCH] move the class methods for starting watchers to the watcher class --- .../kubernetes_clusters_controller.rb | 4 ++-- .../kubernetes/app/models/kubernetes/util.rb | 17 ----------------- .../app/models/watchers/cluster_pod_watcher.rb | 17 ++++++++++++++++- .../kubernetes/config/initializers/watchers.rb | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/plugins/kubernetes/app/controllers/kubernetes_clusters_controller.rb b/plugins/kubernetes/app/controllers/kubernetes_clusters_controller.rb index 6bf72f51ec..454bae704f 100644 --- a/plugins/kubernetes/app/controllers/kubernetes_clusters_controller.rb +++ b/plugins/kubernetes/app/controllers/kubernetes_clusters_controller.rb @@ -13,7 +13,7 @@ def new def create @cluster = Kubernetes::Cluster.new(new_cluster_params) success = @cluster.save - Kubernetes::Util::start_watcher(@cluster) if success + Watchers::ClusterPodWatcher::start_watcher(@cluster) if success respond_to do |format| format.html do @@ -43,7 +43,7 @@ def edit def update @cluster.assign_attributes(new_cluster_params) success = @cluster.save - Kubernetes::Util::restart_watcher(@cluster) if success + Watchers::ClusterPodWatcher::restart_watcher(@cluster) if success respond_to do |format| format.html do diff --git a/plugins/kubernetes/app/models/kubernetes/util.rb b/plugins/kubernetes/app/models/kubernetes/util.rb index 6b19607138..efee13d50e 100644 --- a/plugins/kubernetes/app/models/kubernetes/util.rb +++ b/plugins/kubernetes/app/models/kubernetes/util.rb @@ -1,5 +1,3 @@ -require 'celluloid/current' - module Kubernetes module Util def self.parse_file(contents, filepath) @@ -22,20 +20,5 @@ def self.log(message, extra_info = {}) @output_file.flush message end - - def self.pod_watcher_symbol(cluster) - "cluster_pod_watcher_#{cluster.id}".to_sym - end - - def self.start_watcher(cluster) - watcher_name = pod_watcher_symbol(cluster) - Watchers::ClusterPodWatcher.supervise as: watcher_name, args: [cluster.client] - end - - def self.restart_watcher(cluster) - watcher = Celluloid::Actor[pod_watcher_symbol(cluster)] - watcher.terminate if watcher and watcher.alive? - start_watcher(cluster) - end end end diff --git a/plugins/kubernetes/app/models/watchers/cluster_pod_watcher.rb b/plugins/kubernetes/app/models/watchers/cluster_pod_watcher.rb index f8edb434a7..975588eeff 100644 --- a/plugins/kubernetes/app/models/watchers/cluster_pod_watcher.rb +++ b/plugins/kubernetes/app/models/watchers/cluster_pod_watcher.rb @@ -34,6 +34,21 @@ def stop_watching end end + def self.pod_watcher_symbol(cluster) + "cluster_pod_watcher_#{cluster.id}".to_sym + end + + def self.start_watcher(cluster) + watcher_name = pod_watcher_symbol(cluster) + supervise as: watcher_name, args: [cluster.client] + end + + def self.restart_watcher(cluster) + watcher = Actor[pod_watcher_symbol(cluster)] + watcher.terminate if watcher and watcher.alive? + start_watcher(cluster) + end + private def handle_error(notice) @@ -49,7 +64,7 @@ def handle_notice(notice) debug notice.to_s return if handle_error(notice) rc_name = notice.object.metadata.labels['replication_controller'] - publish rc_name, notice if rc_name + publish(rc_name, notice) if rc_name end %w{debug info warn error}.each do |level| diff --git a/plugins/kubernetes/config/initializers/watchers.rb b/plugins/kubernetes/config/initializers/watchers.rb index d7a2b0df6e..e889d99948 100644 --- a/plugins/kubernetes/config/initializers/watchers.rb +++ b/plugins/kubernetes/config/initializers/watchers.rb @@ -62,4 +62,4 @@ def build_client_options Celluloid.logger = Rails.logger $CELLULOID_DEBUG = true -Kubernetes::Cluster.all.each { |cluster| Kubernetes::Util::start_watcher(cluster) } if ENV['SERVER_MODE'] +Kubernetes::Cluster.all.each { |cluster| Watchers::ClusterPodWatcher::start_watcher(cluster) } if ENV['SERVER_MODE']