diff --git a/lib/rhc/commands/app.rb b/lib/rhc/commands/app.rb index b33bae840..9248b8a2a 100644 --- a/lib/rhc/commands/app.rb +++ b/lib/rhc/commands/app.rb @@ -376,9 +376,37 @@ def tidy(app) syntax " [--namespace NAME]" takes_application :argument => true def enable_ha(app) - app_action :enable_ha + rest_app = find_app + + scaleup_needed = false + cant_scale_up = false + gear_groups = rest_app.gear_groups + gear_groups.each do |gg| + if gg.attributes["scales_from"] and gg.attributes["scales_from"] > 1 + scaleup_needed = true + if gg.attributes["scales_to"] and rest_app.gear_count == gg.attributes["scales_to"] + cant_scale_up = true + end + end + end - results { say "#{app} is now highly available" } + rest_app.send :enable_ha + results do + # If the application was already scaled, a scale up may be required. + if scaleup_needed + say "#{app} is now configured to be highly available" + if cant_scale_up + msg = "You will need to scale down the application, then scale back up to create an additional " + + "haproxy instance:\n rhc app scale-down #{rest_app.name} && rhc app scale-up #{rest_app.name}" + else + msg = "You will need to scale up the application to create an additional haproxy instance:\n" + + " rhc app scale-up #{rest_app.name}" + end + warn msg + else + say "#{app} is now highly available" + end + end 0 end diff --git a/spec/rhc/commands/app_spec.rb b/spec/rhc/commands/app_spec.rb index 1c058a060..b08d3fa8c 100644 --- a/spec/rhc/commands/app_spec.rb +++ b/spec/rhc/commands/app_spec.rb @@ -4,6 +4,7 @@ require 'rhc/config' require 'rhc/servers' require 'resolv' +require 'net/ssh/multi' describe RHC::Commands::App do let!(:rest_client){ MockRestClient.new } @@ -933,6 +934,22 @@ end end + describe 'app enable-ha on scaled application' do + before do + @domain = rest_client.add_domain("mockdomain") + @app = @domain.add_application("app1", "mock_type", true) + @app.add_cartridge('mock_cart-1') + @app.scale_up + end + + let(:arguments) { ['app', 'enable-ha', 'app1'] } + + it "should suggest scaling up to receive additional haproxy instances" do + run_output.should match(/You will need to scale/) + expect{ run }.to exit_with_code(0) + end + end + describe "#create_app" do it("should list cartridges when a server error happens") do subject.should_receive(:list_cartridges)