[PATCH conductor 03/15] Add strict order strategy

Jozef Zigmund jzigmund at redhat.com
Thu Aug 2 02:17:07 UTC 2012


On Sun, 2012-07-22 at 12:16 +0200, ifarkas at redhat.com wrote:
> From: Imre Farkas <ifarkas at redhat.com>
> 
> ---
>  .../provider_selection/provider_selection.rb       |   12 +++++++
>  .../strategies/strict_order/strict_order.rb        |   34 ++++++++++++++++++++
>  2 files changed, 46 insertions(+)
>  create mode 100644 src/vendor/provider_selection/provider_selection.rb
>  create mode 100644 src/vendor/provider_selection/strategies/strict_order/strict_order.rb
> 
> diff --git a/src/vendor/provider_selection/provider_selection.rb b/src/vendor/provider_selection/provider_selection.rb
> new file mode 100644
> index 0000000..63ed8ef
> --- /dev/null
> +++ b/src/vendor/provider_selection/provider_selection.rb
> @@ -0,0 +1,12 @@
> +# Require strategies
> +Dir['vendor/provider_selection/strategies/*/'].each do |path|
> +  strategy_name = File.basename(path)
> +  strategy_lib_path = File.expand_path(File.join(path, "#{strategy_name}.rb"))
> +  ProviderSelection::Base.register_strategy(strategy_name, strategy_lib_path)
> +end
> +
> +# Register view path
> +#ProviderSelection::Base.add_view_path(File.expand_path(File.join('vendor', 'provider_selection', 'views')))
> +
> +# Extend I18n.load_path
> +#I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'config', 'locales', '*.yml')]
> diff --git a/src/vendor/provider_selection/strategies/strict_order/strict_order.rb b/src/vendor/provider_selection/strategies/strict_order/strict_order.rb
> new file mode 100644
> index 0000000..10aca56
> --- /dev/null
> +++ b/src/vendor/provider_selection/strategies/strict_order/strict_order.rb
> @@ -0,0 +1,34 @@
> +module ProviderSelection
> +  module Strategies
> +
> +    class StrictOrder
> +
> +      include ProviderSelection::ChainableStrategy
> +
> +      def self.include_in_listings?
> +        false
> +      end
> +
> +      def calculate
> +        rank = @strategies.calculate
> +
> +        return rank if rank.instances.empty?
> +
> +        pool = rank.instances.first.pool
> +
> +        if pool.provider_priority_groups.any?
> +          common_provider_accounts = find_common_provider_accounts
> +
> +          pool.provider_priority_groups.each do |priority_group|
> +            new_priority_group = ProviderSelection::PriorityGroup.create_from_active_record(priority_group, common_provider_accounts)

if it's possible please split this line to two rows

> +            rank.priority_groups << new_priority_group if new_priority_group.present?
> +          end
> +        end
> +
> +        rank
> +      end
> +
> +    end
> +
> +  end
> +end

-- 
Jozef Zigmund






More information about the aeolus-devel mailing list