Module: Katello::Concerns::PulpDatabaseUnit::ClassMethods
- Defined in:
- app/models/katello/concerns/pulp_database_unit.rb
Instance Method Summary collapse
- #association_name ⇒ Object
- #backend_identifier_field ⇒ Object
- #content_type ⇒ Object
- #content_unit_association_id ⇒ Object
- #content_unit_class ⇒ Object
- #content_units_name ⇒ Object
- #copy_repository_associations(source_repo, dest_repo) ⇒ Object
- #db_columns_copy ⇒ Object
- #db_values_copy(source_repo, dest_repo) ⇒ Object
- #immutable_unit_types ⇒ Object
- #import_all(unit_ids, repository = nil, options = {}) ⇒ Object
- #import_for_repository(repo, options = {}) ⇒ Object
- #in_repositories(repos) ⇒ Object
- #installable_for_content_facet(facet, env = nil, content_view = nil) ⇒ Object
- #installable_for_hosts(hosts = nil) ⇒ Object
- #orphaned ⇒ Object
- #prn_identifier_field ⇒ Object
- #pulp_data(pulp_id) ⇒ Object
- #repository_association ⇒ Object
- #repository_association_class ⇒ Object
- #repository_association_class_name ⇒ Object
- #repository_association_units ⇒ Object
- #unit_id_field ⇒ Object
- #with_identifiers(ids) ⇒ Object
- #with_pulp_id(unit_pulp_ids) ⇒ Object
Instance Method Details
#association_name ⇒ Object
28 29 30 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 28 def association_name self.name.demodulize.underscore end |
#backend_identifier_field ⇒ Object
44 45 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 44 def backend_identifier_field end |
#content_type ⇒ Object
40 41 42 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 40 def content_type self::CONTENT_TYPE end |
#content_unit_association_id ⇒ Object
63 64 65 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 63 def content_unit_association_id "#{self.name.demodulize.underscore}_id".to_sym #Rpm => rpm_id end |
#content_unit_class ⇒ Object
51 52 53 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 51 def content_unit_class "::Katello::Pulp::#{self.name.demodulize}".constantize end |
#content_units_name ⇒ Object
71 72 73 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 71 def content_units_name self.name.demodulize.pluralize.underscore.to_sym end |
#copy_repository_associations(source_repo, dest_repo) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 86 def copy_repository_associations(source_repo, dest_repo) delete_query = "delete from #{repository_association_class.table_name} where repository_id = #{dest_repo.id} and #{unit_id_field} not in (select #{unit_id_field} from #{repository_association_class.table_name} where repository_id = #{source_repo.id})" ActiveRecord::Base.transaction do ActiveRecord::Base.connection.execute(delete_query) self.repository_association_class.import(db_columns_copy, db_values_copy(source_repo, dest_repo), validate: false) end end |
#db_columns_copy ⇒ Object
95 96 97 98 99 100 101 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 95 def db_columns_copy columns = [unit_id_field] columns << backend_identifier_field if backend_identifier_field columns << :repository_id columns << prn_identifier_field if prn_identifier_field columns end |
#db_values_copy(source_repo, dest_repo) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 103 def db_values_copy(source_repo, dest_repo) db_values = [] existing_unit_ids = self.repository_association_class.where(repository: dest_repo).pluck(unit_id_field) if existing_unit_ids.empty? new_units = self.repository_association_class.where(repository: source_repo) else new_units = self.repository_association_class.where(repository: source_repo).where.not("#{unit_id_field} in (?) ", existing_unit_ids) end unit_backend_identifier_field = backend_identifier_field unit_identifier_field = unit_id_field unit_prn_field = prn_identifier_field new_units.each do |unit| values = [unit[unit_identifier_field]] values << unit[unit_backend_identifier_field] if unit_backend_identifier_field values << dest_repo.id values << unit[unit_prn_field] if unit_prn_field db_values << values end db_values end |
#immutable_unit_types ⇒ Object
59 60 61 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 59 def immutable_unit_types [Katello::Rpm, Katello::Srpm] end |
#import_all(unit_ids, repository = nil, options = {}) ⇒ Object
80 81 82 83 84 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 80 def import_all(unit_ids, repository = nil, = {}) content_type = [:content_type] || self.content_type filtered_indexing = [:filtered_indexing] || false Katello::ContentUnitIndexer.new(content_type: Katello::RepositoryTypeManager.find_content_type(content_type), repository: repository, pulp_content_ids: unit_ids).import_all(filtered_indexing) end |
#import_for_repository(repo, options = {}) ⇒ Object
75 76 77 78 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 75 def import_for_repository(repo, = {}) content_type = [:content_type] || self.content_type Katello::ContentUnitIndexer.new(content_type: Katello::RepositoryTypeManager.find_content_type(content_type), repository: repo).import_all end |
#in_repositories(repos) ⇒ Object
165 166 167 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 165 def in_repositories(repos) where(:id => repository_association_class.where(:repository_id => repos).select(unit_id_field)) end |
#installable_for_content_facet(facet, env = nil, content_view = nil) ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 124 def installable_for_content_facet(facet, env = nil, content_view = nil) repos = if env && content_view Katello::Repository.in_environment(env).in_content_views([content_view]) else facet.bound_repositories.pluck(:id) end facet.send("applicable_#{content_units_name}".to_sym).in_repositories(repos) end |
#installable_for_hosts(hosts = nil) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 133 def installable_for_hosts(hosts = nil) # Main goal of this query # 1) Get me the applicable content units for these set of hosts # 2) Now further prune this list. Only include units from repos that have been "enabled" on those hosts. # In other words, prune the list to only include the units in the "bound" repositories signified by # the inner join between ContentFacetRepository and Repository<Unit> facet_repos = Katello::ContentFacetRepository.joins(:content_facet => :host).select(:repository_id) facet_content_units = content_facet_association_class.joins(:content_facet => :host).select(content_unit_association_id) if hosts hosts = ::Host.where(id: hosts) if hosts.is_a?(Array) facet_repos = facet_repos.where(hosts: { id: hosts }).reorder(nil) facet_content_units = facet_content_units.where(hosts: { id: hosts }).reorder(nil) end self.joins(repository_association_units). where(repository_association_class.table_name => { :repository_id => facet_repos, content_unit_association_id => facet_content_units }).distinct end |
#orphaned ⇒ Object
161 162 163 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 161 def orphaned left_joins(repository_association.to_sym).where("#{repository_association_class.table_name}.#{unit_id_field}" => nil) end |
#prn_identifier_field ⇒ Object
47 48 49 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 47 def prn_identifier_field self::PRN_IDENTIFIER_FIELD if self.const_defined?(:PRN_IDENTIFIER_FIELD) end |
#pulp_data(pulp_id) ⇒ Object
169 170 171 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 169 def pulp_data(pulp_id) content_unit_class.new(pulp_id) end |
#repository_association ⇒ Object
55 56 57 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 55 def repository_association repository_association_class_name.demodulize.pluralize.underscore end |
#repository_association_class ⇒ Object
36 37 38 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 36 def repository_association_class repository_association_class_name.constantize end |
#repository_association_class_name ⇒ Object
32 33 34 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 32 def repository_association_class_name "::Katello::Repository#{self.name.demodulize}" end |
#repository_association_units ⇒ Object
67 68 69 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 67 def repository_association_units repository_association_class.name.demodulize.pluralize.underscore.to_sym end |
#unit_id_field ⇒ Object
177 178 179 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 177 def unit_id_field "#{self.name.demodulize.underscore}_id" end |
#with_identifiers(ids) ⇒ Object
154 155 156 157 158 159 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 154 def with_identifiers(ids) ids = [ids] unless ids.is_a?(Array) ids.map!(&:to_s) id_integers = ids.map { |string| Integer(string) rescue -1 } where("#{self.table_name}.id in (?) or #{self.table_name}.pulp_id in (?)", id_integers, ids) end |
#with_pulp_id(unit_pulp_ids) ⇒ Object
173 174 175 |
# File 'app/models/katello/concerns/pulp_database_unit.rb', line 173 def with_pulp_id(unit_pulp_ids) where('pulp_id in (?)', unit_pulp_ids) end |