Permalink
Browse files

877947-clear-es - added index clean up after import and after delete …

…manifest

877947-clear-es - wrapped method args in parens
  • Loading branch information...
1 parent dbe7858 commit c2a2f4bef05375567cc8181111f78023084896d0 @thomasmckay thomasmckay committed Nov 28, 2012
@@ -189,104 +189,4 @@ def repositories_cloned_in_envrs
cloned_repositories = @provider.repositories.select {|r| r.promoted? }
cloned_repositories.collect {|r| [r.name, r.product.environments.select {|env| r.is_cloned_in?(env)}.map(&:name)] }
end
-
-=begin
- def find_subscriptions
- @provider = current_organization.redhat_provider
- cp_pools = Candlepin::Owner.pools current_organization.label
- subscriptions = Pool.index_pools cp_pools
-
- @grouped_subscriptions = []
- subscriptions.each do |sub|
- # Derived pools are not displayed here
- if sub.pool_derived
- next
- end
-
- # Only Red Hat provider subscriptions are shown
- p = Product.where(:cp_id => sub.product_id).first
- if p && p.provider_id == @provider.id
- @grouped_subscriptions << sub
- end
- #Product.where(:cp_id => sub.product_id).each { |product|
- # if product && product.provider_id == @provider.id
- # @grouped_subscriptions << sub
- # end
- #}
- end
-
- @grouped_subscriptions
- end
-
- def setup_subs
- # TODO: See subscriptions_controller#reformat_subscriptions for a better(?) OpenStruct implementation
-
- @provider = current_organization.redhat_provider
- all_subs = Resources::Candlepin::Owner.pools @provider.organization.label
- # We default to none imported until we can properly poll Candlepin for status of the import
- @grouped_subscriptions = {}
- all_subs.each do |sub|
- # Subscriptions with the same 'stack_id' attribute are grouped together. Not all have this
- # attribute so the 'id' is used as a default since it will be unique between
- # subscriptions.
- #
- group_id = sub['id']
- sub['productAttributes'].each do |attr|
- if attr['name'] == 'stacking_id'
- group_id = attr['value']
- elsif attr['name'] == 'support_level'
- sub['support_level'] = attr['value']
- elsif attr['name'] == 'arch'
- sub['arch'] = attr['value']
- end
- end
-
- # Other interesting attributes
- derived = false
- sub['machine_type'] = ''
- sub['attributes'].each do |attr|
- if attr['name'] == 'virt_only'
- if attr['value'] == 'true'
- sub['machine_type'] = _('Virtual')
- elsif attr['value'] == 'false'
- sub['machine_type'] = _('Physical')
- end
- elsif attr['name'] == 'pool_derived'
- if attr['value'] == 'true'
- sub['derived'] = true
- end
- end
- end
-
- # Derived pools are not displayed on the providers page
- if sub['derived'] == true
- next
- end
-
- Product.where(:cp_id => sub['productId']).each do |product|
- if product and product.provider == @provider
- @grouped_subscriptions[group_id] ||= []
- @grouped_subscriptions[group_id] << sub if !@grouped_subscriptions[group_id].include? sub
- end
- end
-x=begin TODO: Should the bundled products be displayed too?
- if sub['providedProducts'].length > 0
- sub['providedProducts'].each do |cp_product|
- product = Product.where(:cp_id => cp_product['productId']).first
- if product and product.provider == @provider
- @grouped_subscriptions[group_id] ||= []
- @grouped_subscriptions[group_id] << sub if !@grouped_subscriptions[group_id].include? sub
- end
- end
- else
- product = Product.where(:cp_id => sub['productId']).first
- if product and product.provider == @provider
- @grouped_subscriptions[group_id] ||= []
- @grouped_subscriptions[group_id] << sub if !@grouped_subscriptions[group_id].include? sub
- end
- end
-x=end
- end
- end
-=end
end
@@ -78,27 +78,7 @@ def items
# search and didn't refresh the page while the data was changing behind the scenes. Until this
# becomes a specific issue, re-indexing will not be performed constantly.
if search.nil?
- # Raw candlepin pools
- cp_pools = Resources::Candlepin::Owner.pools(current_organization.label)
- if cp_pools
- # Pool objects
- pools = cp_pools.collect{|cp_pool| ::Pool.find_pool(cp_pool['id'], cp_pool)}
-
- # Limit subscriptions to just those from Red Hat provider
- subscriptions = pools.collect do |pool|
- product = Product.where(:cp_id => pool.product_id, :provider_id => current_organization.redhat_provider.id).first
- next if product.nil?
- pool.provider_id = product.provider_id # Set so it is saved into elastic search
- pool
- end.compact
- subscriptions = [] if subscriptions.nil?
-
- # Index pools
- # Note: Only the Red Hat provider subscriptions are being indexed.
- ::Pool.index_pools(subscriptions) if subscriptions.length > 0
- else
- subscriptions = []
- end
+ subscriptions = current_organization.redhat_provider.index_subscriptions
if offset != 0
render :text => "" and return if subscriptions.empty?
@@ -287,6 +287,8 @@ def import_products_from_cp
product_to_remove_ids = (product_in_katello_ids - products_in_candlepin_ids).uniq
product_to_remove_ids.each { |cp_id| Product.find_by_cp_id(cp_id).destroy }
+
+ self.index_subscriptions
true
end
@@ -304,6 +306,33 @@ def import_error_message display_message
def exec_delete_manifest
Resources::Candlepin::Owner.destroy_imports self.organization.label, true
+ index_subscriptions
+ end
+
+ def index_subscriptions
+ # Raw candlepin pools
+ cp_pools = Resources::Candlepin::Owner.pools(self.organization.label)
+ if cp_pools
+ # Pool objects
+ pools = cp_pools.collect{|cp_pool| ::Pool.find_pool(cp_pool['id'], cp_pool)}
+
+ # Limit subscriptions to just those from Red Hat provider
+ subscriptions = pools.collect do |pool|
+ product = Product.where(:cp_id => pool.product_id, :provider_id => self.organization.redhat_provider.id).first
+ next if product.nil?
+ pool.provider_id = product.provider_id # Set so it is saved into elastic search
+ pool
+ end.compact
+ subscriptions = [] if subscriptions.nil?
+ else
+ subscriptions = []
+ end
+
+ # Index pools
+ # Note: Only the Red Hat provider subscriptions are being indexed.
+ ::Pool.index_pools(subscriptions, {:org=>self.organization.label, :provider_id=>self.organization.redhat_provider.id})
+
+ subscriptions
end
def rollback_delete_manifest
View
@@ -107,7 +107,17 @@ def self.find_pool(cp_id, pool_json=nil)
::Pool.new(pool_json) if not pool_json.nil?
end
- def self.index_pools pools
+ def self.index_pools(pools, clear_filters=nil)
+ # Clear previous pools index
+ if !clear_filters.nil?
+ results = self.search nil, 0, 0, clear_filters
+ Tire.index self.index do
+ results.each do |result|
+ remove :pool, result.id
+ end
+ end
+ end
+
json_pools = pools.collect{ |pool|
pool.as_json.merge(pool.index_options)
}

0 comments on commit c2a2f4b

Please sign in to comment.