-
Notifications
You must be signed in to change notification settings - Fork 120
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
Fix transformation host selection #379
Changes from all commits
83b3926
1040d2f
717b0f5
f7a8760
70f5df7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,26 @@ module Transformation | |
module TransformationHosts | ||
module Common | ||
class Utils | ||
def initialize(handle = $evm) | ||
@debug = true | ||
@handle = handle | ||
end | ||
|
||
def main | ||
end | ||
DEFAULT_EMS_MAX_RUNNERS = 10 | ||
DEFAULT_HOST_MAX_RUNNERS = 10 | ||
|
||
def self.get_runners_count_by_host(host, handle = $evm) | ||
handle.vmdb(:service_template_transformation_plan_task).where(:state => 'active').select { |task| task.get_option(:transformation_host_id) == host.id }.size | ||
end | ||
|
||
def self.host_max_runners(host, factory_config, max_runners = DEFAULT_HOST_MAX_RUNNERS, handle = $evm) | ||
if host.custom_get('Max Transformation Runners') | ||
handle.log(:info, "Using max transformation runners from host custom attribute: #{host.custom_get('Max Transformation Runners')}") | ||
host.custom_get('Max Transformation Runners').to_i | ||
elsif factory_config['transformation_host_max_runners'] | ||
handle.log(:info, "Using max transformation runners from factory config: #{factory_config['transformation_host_max_runners']}") | ||
factory_config['transformation_host_max_runners'].to_i | ||
else | ||
handle.log(:info, "Using default max transformation runners: #{max_runners}") | ||
max_runners | ||
end | ||
end | ||
|
||
def self.transformation_hosts(ems, factory_config) | ||
thosts = [] | ||
ems.hosts.each do |host| | ||
|
@@ -26,7 +34,7 @@ def self.transformation_hosts(ems, factory_config) | |
:host => host, | ||
:runners => { | ||
:current => get_runners_count_by_host(host), | ||
:maximum => host.custom_get('Max Transformation Runners') || factory_config['transformation_host_max_runners'] || 10 | ||
:maximum => host_max_runners(host, factory_config) | ||
} | ||
} | ||
end | ||
|
@@ -41,11 +49,23 @@ def self.get_runners_count_by_ems(ems, factory_config) | |
transformation_hosts(ems, factory_config).inject(0) { |sum, thost| sum + thost[:runners][:current] } | ||
end | ||
|
||
def self.ems_max_runners(ems, factory_config, max_runners = DEFAULT_EMS_MAX_RUNNERS, handle = $evm) | ||
if ems.custom_get('Max Transformation Runners') | ||
handle.log(:info, "Using max transformation runners from EMS custom attribute: #{ems.custom_get('Max Transformation Runners')}") | ||
ems.custom_get('Max Transformation Runners').to_i | ||
elsif factory_config['ems_max_runners'] | ||
handle.log(:info, "Using max transformation runners from factory config: #{factory_config['ems_max_runners']}") | ||
factory_config['ems_max_runners'].to_i | ||
else | ||
handle.log(:info, "Using default max transformation runners: #{max_runners}") | ||
max_runners | ||
end | ||
end | ||
|
||
def self.get_transformation_host(task, factory_config, handle = $evm) | ||
ems = handle.vmdb(:ext_management_system).find_by(:id => task.get_option(:destination_ems_id)) | ||
ems_max_runners = ems.custom_get('Max Transformation Runners').to_i || factory_config['ems_max_runners'] || 1 | ||
ems_cur_runners = get_runners_count_by_ems(ems, factory_config) | ||
transformation_host_hash = ems_cur_runners < ems_max_runners ? eligible_transformation_hosts(ems, factory_config).first : {} | ||
transformation_host_hash = ems_cur_runners < ems_max_runners(ems, factory_config) ? eligible_transformation_hosts(ems, factory_config).first : {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Were you planning to change this call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. It was |
||
return transformation_host_hash[:type], transformation_host_hash[:host], transformation_host_hash[:transformation_method] | ||
end | ||
|
||
|
@@ -118,7 +138,3 @@ def self.virtv2vwrapper_options_vmwarews2rhevm_ssh(task) | |
end | ||
end | ||
end | ||
|
||
if $PROGRAM_NAME == __FILE__ | ||
ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.new.main | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fdupont-redhat Is this just a Utility class which only has class methods that you want to embed into other classes. We don't need to have an initialize or the call at the bottom if you are going to just call it from other methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this as well as there is an empty
main
method defined. I'm good with including those changes here if appropriate but that refactoring could be in a separate PR as well since it is unrelated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's just a utility class. It is meant to be added as an embedded method. Should I remove it ? It's a bit out of scope for this PR. Maybe another cleanup PR ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so I removed the unneeded parts: initialize, main and call at end of file.