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

[WIP] Inform user of the need to scale up when enabling HA on a scaled application #721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is incorrect. What we need to check is the number of gears in the web_framework group instance. The total application gears could include database gears (separate group instance) and should not be considered here.

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