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

Commit f74c46d

Browse files
committed
Inform user of the need to scale up when enabling HA on a scaled application
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.
1 parent 5eb2f92 commit f74c46d

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

lib/rhc/commands/app.rb

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,37 @@ def tidy(app)
376376
syntax "<app> [--namespace NAME]"
377377
takes_application :argument => true
378378
def enable_ha(app)
379-
app_action :enable_ha
379+
rest_app = find_app
380+
381+
scaleup_needed = false
382+
cant_scale_up = false
383+
gear_groups = rest_app.gear_groups
384+
gear_groups.each do |gg|
385+
if gg.attributes["scales_from"] and gg.attributes["scales_from"] > 1
386+
scaleup_needed = true
387+
if gg.attributes["scales_to"] and rest_app.gear_count == gg.attributes["scales_to"]
388+
cant_scale_up = true
389+
end
390+
end
391+
end
380392

381-
results { say "#{app} is now highly available" }
393+
rest_app.send :enable_ha
394+
results do
395+
# If the application was already scaled, a scale up may be required.
396+
if scaleup_needed
397+
say "#{app} is now configured to be highly available"
398+
if cant_scale_up
399+
msg = "You will need to scale down the application, then scale back up to create an additional " +
400+
"haproxy instance:\n rhc app scale-down #{rest_app.name} && rhc app scale-up #{rest_app.name}"
401+
else
402+
msg = "You will need to scale up the application to create an additional haproxy instance:\n" +
403+
" rhc app scale-up #{rest_app.name}"
404+
end
405+
warn msg
406+
else
407+
say "#{app} is now highly available"
408+
end
409+
end
382410
0
383411
end
384412

spec/rhc/commands/app_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'rhc/config'
55
require 'rhc/servers'
66
require 'resolv'
7+
require 'net/ssh/multi'
78

89
describe RHC::Commands::App do
910
let!(:rest_client){ MockRestClient.new }
@@ -933,6 +934,22 @@
933934
end
934935
end
935936

937+
describe 'app enable-ha on scaled application' do
938+
before do
939+
@domain = rest_client.add_domain("mockdomain")
940+
@app = @domain.add_application("app1", "mock_type", true)
941+
@app.add_cartridge('mock_cart-1')
942+
@app.scale_up
943+
end
944+
945+
let(:arguments) { ['app', 'enable-ha', 'app1'] }
946+
947+
it "should suggest scaling up to receive additional haproxy instances" do
948+
run_output.should match(/You will need to scale/)
949+
expect{ run }.to exit_with_code(0)
950+
end
951+
end
952+
936953
describe "#create_app" do
937954
it("should list cartridges when a server error happens") do
938955
subject.should_receive(:list_cartridges)

0 commit comments

Comments
 (0)