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

Fix transformation host selection #379

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def self.get_runners_count_by_ems(ems, factory_config)

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_max_runners = ems.custom_get('Max Transformation Runners') || factory_config['ems_max_runners'] || 10
Copy link
Member

Choose a reason for hiding this comment

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

I would expect that ems_max_runners is an integer and we should not have to call to_i on line 48 when you are going to evaluate it. Also 10 should be a class constant DEFAULT_EMS_MAX_RUNNERS.

        module Common
          class Utils
            DEFAULT_EMS_MAX_RUNNERS = 10

            def initialize(handle = $evm)

You could do something like this:
ems_max_runners = (ems.custom_get('Max Transformation Runners') || factory_config['ems_max_runners'] || DEFAULT_EMS_MAX_RUNNERS).to_i

A better refactoring would be to move this logic into a method where you could potentially log where the value was coming from if you felt that was important.

def ems_max_runners
  if ems.custom_get('Max Transformation Runners')
    <log message>
    ems.custom_get('Max Transformation Runners').to_i
  elsif factory_config['ems_max_runners']
    <log message>
    factory_config['ems_max_runners'].to_i
  else
    <log message>
    DEFAULT_EMS_MAX_RUNNERS
end

Copy link
Author

Choose a reason for hiding this comment

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

ems_max_runners is not an integer when it is a custom attributes, because custom attributes are stored as strings.
Anyway, it's a good idea to create a method, as the message will help debugging.

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.to_i ? eligible_transformation_hosts(ems, factory_config).first : {}
return transformation_host_hash[:type], transformation_host_hash[:host], transformation_host_hash[:transformation_method]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def main
@handle.log(:info, "Transformation - Started On: #{start_timestamp}")

destination_ems = @handle.vmdb(:ext_management_system).find_by(:id => task.get_option(:destination_ems_id))
max_runners = destination_ems.custom_get('Max Transformation Runners').to_i || factory_config['max_transformation_runners_by_ems'] || 10
if Transformation::TransformationHosts::Common::Utils.get_runners_count_by_ems(destination_ems, factory_config) >= max_runners
max_runners = destination_ems.custom_get('Max Transformation Runners') || factory_config['max_transformation_runners_by_ems'] || 10
Copy link
Member

Choose a reason for hiding this comment

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

Same concepts apply here as well.

Copy link
Author

Choose a reason for hiding this comment

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

I'm using the embedded method to not duplicate code. A separate method is even a better idea because the default value lives in a single method.

if Transformation::TransformationHosts::Common::Utils.get_runners_count_by_ems(destination_ems, factory_config) >= max_runners.to_i
@handle.log(:info, "Too many transformations running [#{max_runners}]. Retrying.")
else
wrapper_options = ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.virtv2vwrapper_options(task)
Expand Down