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



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_taskObject



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_repoidObject



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_groupObject



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_tasksObject



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_syncObject



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_auditObject



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

Returns:

  • (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

#syncObject



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_sizeObject



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_stateObject



112
113
114
# File 'app/models/katello/glue/pulp/repos.rb', line 112

def sync_state
  self.sync_status[:state]
end

#sync_state_aggregatedObject



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_statusObject

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_summaryObject



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

Returns:

  • (Boolean)


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

def synced?
  !last_repo_sync_task.nil?
end