Project

General

Profile

« Previous | Next » 

Revision 40e52c7b

Added by Ivan Necas over 10 years ago

Finish repo deletion orchestration

View differences:

app/lib/actions/candlepin/product/content_destroy.rb
#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Candlepin
module Product
class ContentDestroy < Candlepin::Abstract
input_format do
param :content_id
end
def run
output[:response] = ::Katello::Resources::Candlepin::Content.
destroy(input[:content_id])
end
end
end
end
end
app/lib/actions/candlepin/product/content_remove.rb
#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Candlepin
module Product
class ContentRemove < Candlepin::Abstract
input_format do
param :product_id
param :content_id
end
def run
output[:response] = ::Katello::Resources::Candlepin::Product.
remove_content(input[:product_id], input[:content_id])
end
end
end
end
end
app/lib/actions/katello/product/content_create.rb
module Actions
module Katello
module Product
class ContentCreate < Dynflow::Action
class ContentCreate < Actions::Base
middleware.use Actions::Middleware::RemoteAction
app/lib/actions/katello/product/content_destroy.rb
#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Katello
module Product
class ContentDestroy < Actions::Base
def plan(repository)
if !repository.product.provider.redhat_provider? &&
repository.other_repos_with_same_product_and_content.empty?
sequence do
plan_action(Candlepin::Product::ContentRemove,
product_id: repository.product.cp_id,
content_id: repository.content_id)
if repository.other_repos_with_same_content.empty?
plan_action(Candlepin::Product::ContentDestroy,
content_id: repository.content_id)
end
end
end
end
end
end
end
end
app/lib/actions/katello/repository/destroy.rb
def plan(repository)
action_subject(repository)
plan_action(Pulp::Repository::Destroy, pulp_id: repository.pulp_id)
plan_action(Product::ContentDestroy, repository)
repository.destroy
end
app/lib/actions/pulp/repository/destroy.rb
#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Pulp
module Repository
class Destroy < Pulp::Abstract
input_format do
param :pulp_id
end
def run
output[:response] = pulp_extensions.repository.delete(input[:pulp_id])
end
end
end
end
end
app/models/katello/glue/candlepin/content.rb
base.class_eval do
before_save :save_content_orchestration
before_destroy :destroy_content_orchestration
after_destroy :update_environment_content
after_create :rectify_gpg_key_orchestration
after_update :handle_enabled_changed
......
end
module InstanceMethods
def destroy_content_orchestration
if !self.product.provider.redhat_provider?
pre_queue.create(:name => "remove content : #{self.name}", :priority => 2, :action => [self, :del_content])
end
end
def save_content_orchestration
#until candelpin supports view content, just ignore
if self.new_record? && !self.content_view.default?
return
end
if self.new_record? && !self.product.provider.redhat_provider? && self.environment.library?
# pre_queue.create(:name => "create content : #{self.name}", :priority => 2, :action => [self, :create_content],
# :action_rollback => [self, :del_content]
#)
elsif !self.new_record? && should_update_content?
if !self.new_record? && should_update_content?
pre_queue.create(:name => "update content : #{self.name}", :priority => 2, :action => [self, :update_content])
end
end
......
end
end
def del_content
return true unless self.content_id
if other_repos_with_same_product_and_content.empty?
self.product.remove_content_by_id self.content_id
if other_repos_with_same_content.empty? && !self.product.provider.redhat_provider?
Resources::Candlepin::Content.destroy(self.content_id)
end
end
true
end
def content
return @content unless @content.nil?
unless self.content_id.nil?
app/models/katello/glue/pulp/repo.rb
base.class_eval do
before_save :save_repo_orchestration
before_destroy :destroy_repo_orchestration
lazy_accessor :pulp_repo_facts,
:initializer => (lambda do |s|
......
module InstanceMethods
def save_repo_orchestration
case orchestration_for
when :create
#pre_queue.create(:name => "create pulp repo: #{self.name}", :priority => 2, :action => [self, :create_pulp_repo])
when :update
if self.pulp_update_needed?
pre_queue.create(:name => "update pulp repo: #{self.name}", :priority => 2,
......
PulpTaskStatus.using_pulp_task(task)
end
def destroy_repo
Katello.pulp_server.extensions.repository.delete(self.pulp_id)
true
end
def other_repos_with_same_product_and_content
Repository.where(:content_id => self.content_id).in_product(self.product).pluck(:pulp_id) - [self.pulp_id]
end
......
Repository.where(:content_id => self.content_id).pluck(:pulp_id) - [self.pulp_id]
end
def destroy_repo_orchestration
pre_queue.create(:name => "delete pulp repo : #{self.name}", :priority => 3, :action => [self, :destroy_repo])
end
def package_ids
Katello.pulp_server.extensions.repository.rpm_ids(self.pulp_id)
end

Also available in: Unified diff