Module: Glue::Pulp::Repos::InstanceMethods
- Defined in:
- app/models/katello/glue/pulp/repos.rb
Instance Method Summary collapse
- #add_repo(repo_param) ⇒ Object
- #distributions(env) ⇒ Object
- #last_repo_sync_task ⇒ Object
- #last_repo_sync_task_by_repoid ⇒ Object
- #last_repo_sync_task_group ⇒ Object
- #last_repo_sync_tasks ⇒ Object
- #last_sync ⇒ Object
- #last_sync_audit ⇒ Object
- #promoted_to?(target_env) ⇒ Boolean
- #repo_url(content_url) ⇒ Object
- #sync ⇒ Object
- #sync_size ⇒ Object
- #sync_state ⇒ Object
- #sync_state_aggregated ⇒ Object
-
#sync_status ⇒ Object
Get the most relevant status for all the repos in this Product.
- #sync_summary ⇒ Object
- #synced? ⇒ Boolean
Instance Method Details
#add_repo(repo_param) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/models/katello/glue/pulp/repos.rb', line 132 def add_repo(repo_param) repo_param[:unprotected] = repo_param[:unprotected].nil? ? false : repo_param[:unprotected] if repo_param[:download_policy].blank? && Katello::RootRepository::CONTENT_ATTRIBUTE_RESTRICTIONS[:download_policy].include?(repo_param[:content_type]) repo_param[:download_policy] = Setting[:default_download_policy] end repo_param[:mirroring_policy] = Katello::RootRepository::MIRRORING_POLICY_ADDITIVE if repo_param[:mirroring_policy].blank? RootRepository.new(repo_param.merge(:product_id => self.id)) end |
#distributions(env) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'app/models/katello/glue/pulp/repos.rb', line 16 def distributions(env) to_ret = [] self.repos(env).each do |repo| distros = repo.distributions to_ret += distros unless distros.empty? end to_ret end |
#last_repo_sync_task ⇒ Object
66 67 68 |
# File 'app/models/katello/glue/pulp/repos.rb', line 66 def last_repo_sync_task @last_sync_task ||= last_repo_sync_tasks.first end |
#last_repo_sync_task_by_repoid ⇒ Object
87 88 89 90 91 92 |
# File 'app/models/katello/glue/pulp/repos.rb', line 87 def last_repo_sync_task_by_repoid ForemanTasks::Task.latest_tasks_by_resource_ids( ::Actions::Katello::Repository::Sync.name, Katello::Repository.name, repos(self.library, nil, false).pluck(:id)) end |
#last_repo_sync_task_group ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'app/models/katello/glue/pulp/repos.rb', line 78 def last_repo_sync_task_group if last_repo_sync_task started_after = last_repo_sync_task.started_at - 30.seconds last_repo_sync_tasks.where("#{ForemanTasks::Task::DynflowTask.table_name}.started_at > '%s'", started_after.utc).uniq else [] end end |
#last_repo_sync_tasks ⇒ Object
70 71 72 73 74 75 76 |
# File 'app/models/katello/glue/pulp/repos.rb', line 70 def last_repo_sync_tasks ids = repos(self.library, nil, false).pluck(:id).join(',') label = ::Actions::Katello::Repository::Sync.name type = ::Katello::Repository.name ForemanTasks::Task.search_for("label = #{label} and resource_type = #{type} and resource_id ^ (#{ids})") .order("started_at desc") end |
#last_sync ⇒ Object
62 63 64 |
# File 'app/models/katello/glue/pulp/repos.rb', line 62 def last_sync last_repo_sync_task&.started_at&.to_s || last_sync_audit&.created_at&.to_s end |
#last_sync_audit ⇒ Object
58 59 60 |
# File 'app/models/katello/glue/pulp/repos.rb', line 58 def last_sync_audit Audited::Audit.where(:auditable_id => self.repositories, :auditable_type => Katello::Repository.name).order(:created_at).last end |
#promoted_to?(target_env) ⇒ Boolean
25 26 27 |
# File 'app/models/katello/glue/pulp/repos.rb', line 25 def promoted_to?(target_env) target_env.products.include? self end |
#repo_url(content_url) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'app/models/katello/glue/pulp/repos.rb', line 122 def repo_url(content_url) if self.provider.provider_type == Provider::CUSTOM content_url.dup else path = content_url.sub(%r{^/}, '') repo_url = cdn_configuration.url.sub(%r{/$}, '') "#{repo_url}/#{path}" end end |
#sync ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/models/katello/glue/pulp/repos.rb', line 29 def sync Rails.logger.debug "Syncing product #{self.label}" repos = self.repos(library).collect do |r| r.sync end repos.flatten end |
#sync_size ⇒ Object
116 117 118 119 120 |
# File 'app/models/katello/glue/pulp/repos.rb', line 116 def sync_size self.repos(library).inject(0) do |sum, v| sum + v.sync_status.progress.total_size end end |
#sync_state ⇒ Object
112 113 114 |
# File 'app/models/katello/glue/pulp/repos.rb', line 112 def sync_state self.sync_status[:state] end |
#sync_state_aggregated ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/models/katello/glue/pulp/repos.rb', line 94 def sync_state_aggregated presented = last_repo_sync_task_by_repoid.transform_values { |v| ::Katello::SyncStatusPresenter.new(Katello::Repository.find(v.input["repository"]["id"]), v) } worst = nil scale = [ :never_synced, :stopped, :canceled, :error, :paused, :running ] presented.each do |_repoid, task| worst = task if worst.nil? || worst.sync_progress[:state].nil? || scale.index(worst.sync_progress[:raw_state].to_sym) < scale.index(task.sync_progress[:raw_state].to_sym) end worst&.sync_progress&.fetch(:state, nil) end |
#sync_status ⇒ Object
Get the most relevant status for all the repos in this Product
42 43 44 45 46 47 |
# File 'app/models/katello/glue/pulp/repos.rb', line 42 def sync_status all_repos = repos(self.library, nil, false) task = last_repo_sync_task last_synced_repo = task ? all_repos.find { |repo| task.links.where(:resource_type => ::Katello::Repository.name).pluck(:resource_id).map(&:to_s).include?(repo.id.to_s) } : nil ::Katello::SyncStatusPresenter.new(last_synced_repo, task).sync_progress end |
#sync_summary ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/models/katello/glue/pulp/repos.rb', line 49 def sync_summary summary = {} last_repo_sync_task_by_repoid.values.each do |task| summary[task.result] ||= 0 summary[task.result] += 1 end summary end |
#synced? ⇒ Boolean
37 38 39 |
# File 'app/models/katello/glue/pulp/repos.rb', line 37 def synced? !last_repo_sync_task.nil? end |