Sha256: abb3ee6a07fd5e6efb2ce692939fa63ab94bf5189685a8396ba759effc7b4713
Contents?: true
Size: 1.56 KB
Versions: 3
Compression:
Stored size: 1.56 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 |plan_id, target_plan| source_plan = ThreeScaleToolbox::Entities::ApplicationPlan.new(id: plan_id, service: source) target_plan = ThreeScaleToolbox::Entities::ApplicationPlan.new(id: target_plan['id'], service: target) missing_limits = missing_limits(source_plan.limits, target_plan.limits, metrics_map) missing_limits.each do |limit| limit.delete('links') target_plan.create_limit(metrics_map.fetch(limit.fetch('metric_id')), limit) end puts "Missing #{missing_limits.size} plan limits from target application plan " \ "#{target_plan.id}. Source plan #{plan_id}" end end private def metrics_map @metrics_map ||= Helper.metrics_mapping(source_metrics_and_methods, target_metrics_and_methods) end def missing_limits(source_limits, target_limits, metrics_map) ThreeScaleToolbox::Helper.array_difference(source_limits, target_limits) do |limit, target| ThreeScaleToolbox::Helper.compare_hashes(limit, target, ['period']) && metrics_map.fetch(limit.fetch('metric_id')) == target.fetch('metric_id') end end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems