Module: Glue::Pulp::Repos::InstanceMethods

Defined in:
app/models/katello/glue/pulp/repos.rb

Instance Method Summary collapse

Instance Method Details

#add_repo(repo_param) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/models/katello/glue/pulp/repos.rb', line 138

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::Repository::YUM_TYPE == repo_param[:content_type] ? Setting[:default_yum_mirroring_policy] : Setting[:default_non_yum_mirroring_policy]

  repo_param = repo_param.merge(:product_id => self.id)

  # Container push may concurrently call root add several times before the db can update.
  if repo_param[:is_container_push]
    root = RootRepository.find_by(repo_param)
    return root if root
  end
  RootRepository.new(repo_param)
end

#distributions(env) ⇒ Object



10
11
12
13
14
15
16
17
# File 'app/models/katello/glue/pulp/repos.rb', line 10

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_taskObject



71
72
73
# File 'app/models/katello/glue/pulp/repos.rb', line 71

def last_repo_sync_task
  @last_sync_task ||= last_repo_sync_tasks&.first
end

#last_repo_sync_task_by_repoidObject



93
94
95
96
97
98
# File 'app/models/katello/glue/pulp/repos.rb', line 93

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_groupObject



84
85
86
87
88
89
90
91
# File 'app/models/katello/glue/pulp/repos.rb', line 84

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_tasksObject



75
76
77
78
79
80
81
82
# File 'app/models/katello/glue/pulp/repos.rb', line 75

def last_repo_sync_tasks
  ids = repos(self.library, nil, false).pluck(:id).join(',')
  label = ::Actions::Katello::Repository::Sync.name
  type = ::Katello::Repository.name
  return nil if ids.empty?
  ForemanTasks::Task.search_for("label = #{label} and resource_type = #{type} and resource_id ^ (#{ids})")
    .order("started_at desc")
end

#last_syncObject



67
68
69
# File 'app/models/katello/glue/pulp/repos.rb', line 67

def last_sync
  last_repo_sync_task&.started_at&.to_s || last_sync_audit&.created_at&.to_s
end

#last_sync_auditObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/katello/glue/pulp/repos.rb', line 52

def last_sync_audit
  repository_ids = self.repositories.pluck(:id)
  return nil if repository_ids.blank?

  Audited::Audit
   .where(
    auditable_id: repository_ids,
    auditable_type: Katello::Repository.name,
    action: "sync"
   )
   .order(created_at: :desc)
   .limit(1)
   .first
end

Returns:

  • (Boolean)


19
20
21
# File 'app/models/katello/glue/pulp/repos.rb', line 19

def promoted_to?(target_env)
  target_env.products.include? self
end

#repo_url(content_url) ⇒ Object



128
129
130
131
132
133
134
135
136
# File 'app/models/katello/glue/pulp/repos.rb', line 128

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

#syncObject



23
24
25
26
27
28
29
# File 'app/models/katello/glue/pulp/repos.rb', line 23

def sync
  Rails.logger.debug "Syncing product #{self.label}"
  repos = self.repos(library).collect do |r|
    r.sync
  end
  repos.flatten
end

#sync_sizeObject



122
123
124
125
126
# File 'app/models/katello/glue/pulp/repos.rb', line 122

def sync_size
  self.repos(library).inject(0) do |sum, v|
    sum + v.sync_status.progress.total_size
  end
end

#sync_stateObject



118
119
120
# File 'app/models/katello/glue/pulp/repos.rb', line 118

def sync_state
  self.sync_status[:state]
end

#sync_state_aggregatedObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/models/katello/glue/pulp/repos.rb', line 100

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_statusObject

Get the most relevant status for all the repos in this Product



36
37
38
39
40
41
# File 'app/models/katello/glue/pulp/repos.rb', line 36

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_summaryObject



43
44
45
46
47
48
49
50
# File 'app/models/katello/glue/pulp/repos.rb', line 43

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

Returns:

  • (Boolean)


31
32
33
# File 'app/models/katello/glue/pulp/repos.rb', line 31

def synced?
  !last_repo_sync_task.nil?
end