Sha256: 685efcf1f637ce491eb3038816aa4b0cda4955e4d0f41147345726c36f8088cf

Contents?: true

Size: 1.47 KB

Versions: 10

Compression:

Stored size: 1.47 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ServiceCommand
      module CopyCommand
        class CopyLimitsTask
          include Task

          def call
            plan_mapping = Helper.application_plan_mapping(source.plans, target.plans)
            plan_mapping.each do |source_plan, target_plan|
              missing_limits = compute_missing_limits(source_plan.limits, target_plan.limits)
              missing_limits.each do |limit|
                target_plan.create_limit(metrics_map.fetch(limit.metric_id), limit.attrs)
              end
              logger.info "Missing #{missing_limits.size} plan limits from target application plan " \
                "#{target_plan.id}. Source plan #{source_plan.id}"

              plans_report[target_plan.system_name] = {'application_plan_id' => target_plan.id} unless plans_report.has_key? target_plan.system_name
              plans_report[target_plan.system_name].merge!({'missing_limits_created' => missing_limits.size})
            end
          end

          private

          def metrics_map
            @metrics_map ||= source.metrics_mapping(target)
          end

          def compute_missing_limits(source_limits, target_limits)
            ThreeScaleToolbox::Helper.array_difference(source_limits, target_limits) do |limit, target_limit|
              limit.period == target_limit.period && metrics_map.fetch(limit.metric_id) == target_limit.metric_id
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb