Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure apache balancer with up to 10 members at startup #14007

Merged
Merged
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
2 changes: 1 addition & 1 deletion app/models/miq_server/environment_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def start_memcached
def prep_apache_proxying
return unless MiqEnvironment::Command.supports_apache?

MiqApache::Control.stop
MiqUiWorker.install_apache_proxy_config
MiqWebServiceWorker.install_apache_proxy_config
MiqWebsocketWorker.install_apache_proxy_config
MiqApache::Control.restart
Copy link
Member Author

Choose a reason for hiding this comment

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

Restart apache after configuring the workers/balancers.

end
end

Expand Down
53 changes: 14 additions & 39 deletions app/models/mixins/miq_web_server_worker_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'miq_apache'
class NoFreePortError < StandardError; end

module MiqWebServerWorkerMixin
extend ActiveSupport::Concern

Expand All @@ -8,6 +10,8 @@ module MiqWebServerWorkerMixin
class << self
attr_accessor :registered_ports
end

try(:maximum_workers_count=, 10)
end

module ClassMethods
Expand Down Expand Up @@ -89,8 +93,6 @@ def sync_workers
end
Copy link
Member Author

Choose a reason for hiding this comment

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

We no longer modify the configuration after adding/removing Ui/Web Service/Web Socket workers...

Copy link
Member

Choose a reason for hiding this comment

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

Is the selectable number of workers (for each type) limited to 10 in the UI ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@abellotti good question. The UI shows up to 9. Although, with advanced settings, you can choose more. This is why the maximum_workers_count is set to 10, so even if you choose more, the system won't let you go beyond that max value.

end

modify_apache_ports(ports_hash, self::PROTOCOL) if MiqEnvironment::Command.supports_apache?

result
end

Expand All @@ -110,50 +112,23 @@ def install_apache_proxy_config

_log.info("[#{options.inspect}")
MiqApache::Conf.install_default_config(options)
add_apache_balancer_members
end

def modify_apache_ports(ports_hash, protocol)
return unless MiqEnvironment::Command.supports_apache?
adds = Array(ports_hash[:adds])
deletes = Array(ports_hash[:deletes])

# Remove any already registered
adds -= self.registered_ports

return false if adds.empty? && deletes.empty?
def port_range
self::STARTING_PORT...(self::STARTING_PORT + maximum_workers_count)
end

def add_apache_balancer_members
conf = MiqApache::Conf.instance(self::BALANCE_MEMBER_CONFIG_FILE)

unless adds.empty?
_log.info("Adding port(s) #{adds.inspect}")
conf.add_ports(adds, protocol)
end

unless deletes.empty?
_log.info("Removing port(s) #{deletes.inspect}")
conf.remove_ports(deletes, protocol)
end

saved = conf.save
if saved
self.registered_ports += adds
self.registered_ports -= deletes

# Update the apache load balancer regardless but only restart apache
# when adding a new port to the balancer.
MiqServer.my_server.queue_restart_apache unless adds.empty?
_log.info("Added/removed port(s) #{adds.inspect}/#{deletes.inspect}, registered ports after #{self.registered_ports.inspect}")
end
saved
conf.add_ports(port_range.to_a, self::PROTOCOL)
conf.save
end

def reserve_port(ports)
index = 0
loop do
port = self::STARTING_PORT + index
return port unless ports.include?(port)
index += 1
end
free_ports = port_range.to_a - ports
raise NoFreePortError if free_ports.empty?
free_ports.first
end
end

Expand Down
21 changes: 21 additions & 0 deletions spec/models/miq_ui_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,25 @@
expect(MiqUiWorker.all_ports_in_use).to eq([3000])
end
end

it ".port_range" do
expect(described_class.port_range.to_a).to eq((3000..3009).to_a)
end

describe ".reserve_port" do
it "returns next free port" do
ports = (3000..3001).to_a
expect(described_class.reserve_port(ports)).to eq(3002)
end

it "raises if no ports available" do
ports = (3000..3009).to_a
expect { described_class.reserve_port(ports) }.to raise_error(NoFreePortError)
end

it "returns free port between used ports" do
ports = [3000, 3002]
expect(described_class.reserve_port(ports)).to eq(3001)
end
end
end