Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Inform user of the need to scale up when enabling HA on a scaled appl…
Browse files Browse the repository at this point in the history
…ication

Bug 1256952
https://bugzilla.redhat.com/show_bug.cgi?id=1256952

When an application with more than one gear ha HA enabled, a short message will now be given stating the possible need to scale the application up to actually receive the second haproxy instance.

In addition to a adding a new test, the `app_spec.rb` now requires 'net/ssh/multi' to allow the spec to be run on its own outside of the RHC spec test suite. This has been resolved.
  • Loading branch information
tiwillia committed Nov 10, 2015
1 parent 5eb2f92 commit f74c46d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/rhc/commands/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,37 @@ def tidy(app)
syntax "<app> [--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

Expand Down
17 changes: 17 additions & 0 deletions spec/rhc/commands/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f74c46d

Please sign in to comment.