From e0f0ccdc3b75c78d001aade133e8edd1e481bd30 Mon Sep 17 00:00:00 2001 From: uu59 Date: Wed, 4 Feb 2015 16:12:05 +0900 Subject: [PATCH 1/4] DRY --- app/models/fluentd/agent/fluentd_gem.rb | 5 +---- app/models/fluentd/agent/local_common.rb | 7 +++++++ app/models/fluentd/agent/td_agent.rb | 5 +---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/models/fluentd/agent/fluentd_gem.rb b/app/models/fluentd/agent/fluentd_gem.rb index 3be1c1a..3c013d1 100644 --- a/app/models/fluentd/agent/fluentd_gem.rb +++ b/app/models/fluentd/agent/fluentd_gem.rb @@ -43,10 +43,7 @@ class Fluentd end def dryrun!(file_path = nil) - Bundler.with_clean_env do - system("fluentd -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL) - raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero? - end + exec_dryrun("fluentd", file_path) end def config_syntax_check diff --git a/app/models/fluentd/agent/local_common.rb b/app/models/fluentd/agent/local_common.rb index 9b65971..85e0aeb 100644 --- a/app/models/fluentd/agent/local_common.rb +++ b/app/models/fluentd/agent/local_common.rb @@ -82,6 +82,13 @@ class Fluentd private + def exec_dryrun(exe, file_path = nil) + Bundler.with_clean_env do + system("#{exe} -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL) + raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero? + end + end + def backup_config return unless File.exists? config_file diff --git a/app/models/fluentd/agent/td_agent.rb b/app/models/fluentd/agent/td_agent.rb index 5c1c422..1f273ff 100644 --- a/app/models/fluentd/agent/td_agent.rb +++ b/app/models/fluentd/agent/td_agent.rb @@ -17,10 +17,7 @@ class Fluentd end def dryrun!(file_path = nil) - Bundler.with_clean_env do - system("/usr/sbin/td-agent --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL) - raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero? - end + exec_dryrun("/usr/sbin/td-agent", file_path) end case FluentdUI.platform From 8dc2be80ef56df9be14659201397db99c93e1df4 Mon Sep 17 00:00:00 2001 From: uu59 Date: Wed, 4 Feb 2015 16:13:48 +0900 Subject: [PATCH 2/4] Separate fat action --- .../fluentd/settings_controller.rb | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/app/controllers/fluentd/settings_controller.rb b/app/controllers/fluentd/settings_controller.rb index 96fe0da..b9ef70f 100644 --- a/app/controllers/fluentd/settings_controller.rb +++ b/app/controllers/fluentd/settings_controller.rb @@ -18,22 +18,9 @@ class Fluentd::SettingsController < ApplicationController def update if params[:dryrun] - if dryrun(params[:config]) - flash.now[:success] = I18n.t('messages.dryrun_is_passed') - else - flash.now[:danger] = @fluentd.agent.last_error_message - end - @config = params[:config] - render "edit" + handle_dryrun else - begin - update_config(params[:config]) - redirect_to daemon_setting_path(@fluentd) - rescue Fluent::ConfigParseError => e - @config = params[:config] - flash.now[:danger] = e.message - render "edit" - end + handle_update end end @@ -48,6 +35,25 @@ class Fluentd::SettingsController < ApplicationController @config = @fluentd.agent.config end + def handle_dryrun + if dryrun(params[:config]) + flash.now[:success] = I18n.t('messages.dryrun_is_passed') + else + flash.now[:danger] = @fluentd.agent.last_error_message + end + @config = params[:config] + render "edit" + end + + def handle_update + update_config(params[:config]) + redirect_to daemon_setting_path(@fluentd) + rescue Fluent::ConfigParseError => e + @config = params[:config] + flash.now[:danger] = e.message + render "edit" + end + def dryrun(conf) tmpfile = Tempfile.open("fluentd-test-config") tmpfile.write params[:config] From 5dcd1fdf461a0cb5d99def4c73bd784eb1818676 Mon Sep 17 00:00:00 2001 From: uu59 Date: Wed, 4 Feb 2015 16:23:06 +0900 Subject: [PATCH 3/4] more human friendly name --- app/models/fluentd/agent/local_common.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/fluentd/agent/local_common.rb b/app/models/fluentd/agent/local_common.rb index 85e0aeb..5a98569 100644 --- a/app/models/fluentd/agent/local_common.rb +++ b/app/models/fluentd/agent/local_common.rb @@ -82,9 +82,9 @@ class Fluentd private - def exec_dryrun(exe, file_path = nil) + def exec_dryrun(command, file_path = nil) Bundler.with_clean_env do - system("#{exe} -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL) + system("#{command} -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL) raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero? end end From 2096ede6edbdf4851baf59de7c7da3f6fa3e9fce Mon Sep 17 00:00:00 2001 From: uu59 Date: Wed, 4 Feb 2015 16:23:26 +0900 Subject: [PATCH 4/4] Fix typo --- spec/models/plugin_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/plugin_spec.rb b/spec/models/plugin_spec.rb index d82872c..6434e7c 100644 --- a/spec/models/plugin_spec.rb +++ b/spec/models/plugin_spec.rb @@ -38,7 +38,7 @@ describe Plugin do it { should_not be_valid } end - context "somthing filled is valid" do + context "something filled is valid" do let(:gem_name) { "foobar" } it { should be_valid } end @@ -53,7 +53,7 @@ describe Plugin do it { should_not be_valid } end - context "somthing filled is valid" do + context "something filled is valid" do let(:version) { "0.0.1" } it { should be_valid } end