Revision 1545b9ec
Added by Ivan Necas almost 10 years ago
app/models/katello/content_view.rb | ||
---|---|---|
environments.where(:library => false).length > 0
|
||
end
|
||
|
||
# rubocop:disable MethodLength
|
||
def publish(options = { })
|
||
fail "Cannot publish content view without a logged in user." if ::User.current.nil?
|
||
options = { :async => true, :notify => false }.merge(options)
|
||
|
||
version = create_new_version
|
||
if cve = self.content_view_environment(organization.library)
|
||
version.content_view_environments << cve
|
||
else
|
||
self.add_environment(organization.library, version)
|
||
end
|
||
|
||
if options[:async]
|
||
task = self.async(:organization => self.organization,
|
||
:task_type => TaskStatus::TYPES[:content_view_publish][:type]).
|
||
publish_content(version, options[:notify])
|
||
|
||
version.task_status = task
|
||
version.save!
|
||
else
|
||
version.create_task_status!(
|
||
:uuid => ::UUIDTools::UUID.random_create.to_s,
|
||
:user_id => ::User.current.try(:id),
|
||
:organization => self.organization,
|
||
:state => Katello::TaskStatus::Status::WAITING,
|
||
:task_type => TaskStatus::TYPES[:content_view_publish][:type]
|
||
)
|
||
|
||
begin
|
||
publish_content(version, options[:notify])
|
||
version.task_status.update_attributes!(:state => Katello::TaskStatus::Status::FINISHED)
|
||
rescue => e
|
||
version.task_status.update_attributes!(:state => Katello::TaskStatus::Status::ERROR)
|
||
raise e
|
||
end
|
||
end
|
||
version
|
||
end
|
||
|
||
def publish_content(version, notify = false)
|
||
# 1. generate the version repositories
|
||
publish_version_content(version)
|
||
|
||
# 2. generate the library repositories
|
||
publish_library_yum_content(version)
|
||
publish_library_puppet_content(version)
|
||
|
||
# 3. update candlepin, etc
|
||
update_cp_content(self.organization.library)
|
||
|
||
clone_overrides = self.repositories.select{|r| self.filters.applicable(r).empty?}
|
||
version.trigger_contents_changed(:cloned_repo_overrides => clone_overrides, :non_archive => true)
|
||
|
||
if notify
|
||
message = _("Successfully published content view '%s'.") % name
|
||
Notify.success(message, :request_type => "content_view___publish",
|
||
:organization => self.organization)
|
||
end
|
||
rescue => e
|
||
Rails.logger.error(e)
|
||
Rails.logger.error(e.backtrace.join("\n"))
|
||
|
||
if notify
|
||
message = _("Failed to publish content view '%s'.") % self.name
|
||
Notify.exception(message, e, :request_type => "content_view___publish",
|
||
:organization => self.organization)
|
||
end
|
||
|
||
raise e
|
||
end
|
||
|
||
def publish_library_yum_content(version)
|
||
|
||
# prepare the yum repos currently in the library for the publish
|
||
async_tasks = []
|
||
repos(organization.library).each do |repo|
|
||
if repositories_to_publish_ids.include?(repo.library_instance_id)
|
||
repo.content_view_version_id = version.id
|
||
repo.save!
|
||
|
||
# this repo is in both the content view and in the library,
|
||
# so clear it and later we'll regenerate the content... this is more
|
||
# efficient than deleting the repo and recreating it...
|
||
async_tasks += repo.clear_contents
|
||
else
|
||
# this repo no longer exists in the view, so destroy it
|
||
repo.destroy
|
||
end
|
||
end
|
||
PulpTaskStatus.wait_for_tasks async_tasks unless async_tasks.blank?
|
||
|
||
async_tasks = []
|
||
repos_to_filter = []
|
||
repositories_to_publish.each do |repo|
|
||
# the repos from the content view are based upon initial synced repos, we need to
|
||
# determine if each of those repos has been cloned in library
|
||
library_clone = get_repo_clone(organization.library, repo).first
|
||
if library_clone.nil?
|
||
# this repo doesn't currently exist in the library
|
||
clone = repo.create_clone(:environment => organization.library, :content_view => self)
|
||
repos_to_filter << clone
|
||
else
|
||
# this repo already exists in the library, so update it
|
||
library_clone = Repository.find(library_clone) # reload readonly obj
|
||
repos_to_filter << library_clone
|
||
end
|
||
end
|
||
|
||
repos_to_filter.each do |repo|
|
||
associate_yum_content(repo) unless repo.puppet?
|
||
end
|
||
|
||
PulpTaskStatus.wait_for_tasks async_tasks unless async_tasks.blank?
|
||
end
|
||
|
||
def publish_library_puppet_content(version)
|
||
# prepare the puppet environment currently in the library for the publish
|
||
async_tasks = []
|
||
if puppet_env = puppet_env(organization.library)
|
||
if !content_view_puppet_modules.empty?
|
||
puppet_env.content_view_version_id = version.id
|
||
puppet_env.save!
|
||
|
||
# this puppet environment has been previously published and the version
|
||
# being published has puppet modules, so clear it and later we'll
|
||
# regenerate the content... this is more efficient than deleting the
|
||
# env/repo and recreating it...
|
||
async_tasks += puppet_env.clear_contents
|
||
else
|
||
# this content view doesn't contain any puppet modules, so destroy
|
||
# the environment
|
||
puppet_env.destroy
|
||
end
|
||
end
|
||
PulpTaskStatus.wait_for_tasks async_tasks unless async_tasks.blank?
|
||
|
||
unless content_view_puppet_modules.empty?
|
||
unless puppet_env
|
||
puppet_env = create_puppet_env(:environment => organization.library, :content_view => self)
|
||
end
|
||
associate_puppet_content(puppet_env)
|
||
end
|
||
|
||
PulpTaskStatus.wait_for_tasks async_tasks unless async_tasks.blank?
|
||
end
|
||
|
||
def publish_version_content(version)
|
||
repositories_to_publish.each do |repo|
|
||
clone = repo.create_clone(:content_view => self, :version => version)
|
||
associate_yum_content(clone)
|
||
end
|
||
|
||
unless content_view_puppet_modules.empty?
|
||
puppet_env = create_puppet_env(:content_view => self, :version => version)
|
||
associate_puppet_content(puppet_env)
|
||
end
|
||
|
||
clone_overrides = repositories_to_publish.select{|r| self.filters.applicable(r).empty?}
|
||
version.trigger_contents_changed(:cloned_repo_overrides => clone_overrides, :wait => true)
|
||
end
|
||
|
||
def duplicate_repositories
|
||
counts = repositories_to_publish.each_with_object(Hash.new(0)) do |repo, h|
|
||
h[repo.library_instance_id] += 1
|
Also available in: Unified diff
Fixes #6297 - remove unused and unreachable code that used delayed jobs